Files
intellecton/venv/lib/python3.12/site-packages/pyparsing/__pycache__/common.cpython-312.pyc
T

302 lines
18 KiB
Plaintext
Raw Normal View History

Ë
vRj5CãóÎddl­ddlmZmZmZddlmZddlZejdk\ZGdd«Z e
e «j«Dcgc]}e |e
«sŒ
|Œc}Zycc}w) é)Ú*)Ú
DelimitedListÚ any_open_tagÚ
any_close_tagé)ÚdatetimeN)éé
c ó
eZdZdZed«Zed«Zee«jd«je rend«Z ee
«jd«jeed««Z ed«jd «je rend
«Z e«je rend «d ze«je rend
«zjd«Z ej)d«eeeed«j-«ez«zzjd«Z ej)e«ed«jd«je rend«Z ed«jd«je rend«Z eezezjd«j7«Z ed«jd«je rend«Z ed«jd«je rend«Z eee «jd«Z! ed «jd!«Z" ed"«jd#«Z#e#d$e#zd%zzjd&«Z$ee#d$e#zd'zz«d(zee#d$e#zd'zz«zjd)«Z%e%jMd*„«d+e"zjd,«Z'e(e$e'ze%zjd-««jd-«Z) ed.«jd/«Z* edQd0e+fd1„«Z,edRd0e+fd2„«Z-ed3«jd4«Z. ed5«jd6«Z/ ed7„«Z0e r.e.«j)e0«Z1 e/«j)e0«Z2 ed8«jd9«Z3 e4j,«e5j,«zZ6ed:e+d;ed<e7fd=„«Z8e(e9e:d>«e;«zee<d>¬?«zee=d@«e>e;«d>z«z«z««j7«jdA«Z?e@eeAj…«e?zdB¬C««jdD«ZC edE„«ZDedF„«ZEedG«jdH«ZF eeGdIe««ZHeeGdJe««ZIeeGdKe,««ZJeeGdLe-««ZKeeGdMe8««ZLeeGdNeD««ZMeeGdOeE««ZNyP)SÚpyparsing_commona
Here are some common low-level expressions that may be useful in
jump-starting parser development:
- numeric forms (:class:`integers<integer>`, :class:`reals<real>`,
:class:`scientific notation<sci_real>`)
- common :class:`programming identifiers<identifier>`
- network addresses (:class:`MAC<mac_address>`,
:class:`IPv4<ipv4_address>`, :class:`IPv6<ipv6_address>`)
- ISO8601 :class:`dates<iso8601_date>` and
:class:`datetime<iso8601_datetime>`
- :class:`UUID<uuid>`
- :class:`comma-separated list<comma_separated_list>`
- :class:`url`
Parse actions:
- :class:`convert_to_integer`
- :class:`convert_to_float`
- :class:`convert_to_date`
- :class:`convert_to_datetime`
- :class:`strip_html_tags`
- :class:`upcase_tokens`
- :class:`downcase_tokens`
Examples:
.. testcode::
pyparsing_common.number.run_tests('''
# any int or real number, returned as the appropriate type
100
-100
+100
3.14159
6.02e23
1e-12
''')
.. testoutput::
:options: +NORMALIZE_WHITESPACE
# any int or real number, returned as the appropriate type
100
[100]
-100
[-100]
+100
[100]
3.14159
[3.14159]
6.02e23
[6.02e+23]
1e-12
[1e-12]
.. testcode::
pyparsing_common.fnumber.run_tests('''
# any int or real number, returned as float
100
-100
+100
3.14159
6.02e23
1e-12
''')
.. testoutput::
:options: +NORMALIZE_WHITESPACE
# any int or real number, returned as float
100
[100.0]
-100
[-100.0]
+100
[100.0]
3.14159
[3.14159]
6.02e23
[6.02e+23]
1e-12
[1e-12]
.. testcode::
pyparsing_common.hex_integer.run_tests('''
# hex numbers
100
FF
''')
.. testoutput::
:options: +NORMALIZE_WHITESPACE
# hex numbers
100
[256]
FF
[255]
.. testcode::
pyparsing_common.fraction.run_tests('''
# fractions
1/2
-3/4
''')
.. testoutput::
:options: +NORMALIZE_WHITESPACE
# fractions
1/2
[0.5]
-3/4
[-0.75]
.. testcode::
pyparsing_common.mixed_integer.run_tests('''
# mixed fractions
1
1/2
-3/4
1-3/4
''')
.. testoutput::
:options: +NORMALIZE_WHITESPACE
# mixed fractions
1
[1]
1/2
[0.5]
-3/4
[-0.75]
1-3/4
[1.75]
.. testcode::
import uuid
pyparsing_common.uuid.set_parse_action(token_map(uuid.UUID))
pyparsing_common.uuid.run_tests('''
# uuid
12345678-1234-5678-1234-567812345678
''')
.. testoutput::
:options: +NORMALIZE_WHITESPACE
# uuid
12345678-1234-5678-1234-567812345678
[UUID('12345678-1234-5678-1234-567812345678')]
có>|Dcgc]
}t|«Œc}Scc}w)zK
Parse action for converting parsed integers to Python int
©Úint©Ú__Útts úS/home/antigravity/intellecton/venv/lib/python3.12/site-packages/pyparsing/common.pyÚconvert_to_integerz#pyparsing_common.convert_to_integer¾sð
#$Ö$˜B”B•Ò$ùÒcó>|Dcgc]
}t|«Œc}Scc}w)zL
Parse action for converting parsed numbers to Python float
©Úfloatrs rÚconvert_to_floatz!pyparsing_common.convert_to_floatÅsð
%&Ö&˜b”b• Ò&ùÒ&rÚintegercó>|Dcgc]
}t|«Œc}Scc}w©Nr©rrs rú<lambda>zpyparsing_common.<lambda>Òó¨aÖœC 0€ùÒ0rz hex integeréz[+-]?\d+zsigned integercó>|Dcgc]
}t|«Œc}Scc}wrrrs rr zpyparsing_common.<lambda>âr!rcó>|Dcgc]
}t|«Œc}Scc}wrrrs rr zpyparsing_common.<lambda>ëó°Ö2¨"œE "2€ùÒ2rú/có>|Dcgc]
}t|«Œc}Scc}wrrrs rr zpyparsing_common.<lambda>ñr%rÚfractioncó|d|dz S)Nréÿÿÿÿ©)rs rr zpyparsing_common.<lambda>õs¨¨A©°°B±©óú-z"fraction or mixed integer-fractionz[+-]?(?:\d+\.\d*|\.\d+)z real numbercó>|Dcgc]
}t|«Œc}Scc}wrrrs rr zpyparsing_common.<lambda>r%rz@[+-]?(?:\d+(?:[eE][+-]?\d+)|(?:\d+\.\d*|\.\d+)(?:[eE][+-]?\d+)?)z$real number with scientific notationcó>|Dcgc]
}t|«Œc}Scc}wrrrs rr zpyparsing_common.<lambda>r%rÚnumberz[+-]?\d+\.?\d*(?:[eE][+-]?\d+)?Úfnumbercó>|Dcgc]
}t|«Œc}Scc}wrrrs rr zpyparsing_common.<lambda>r%rz;(?i:[+-]?(?:(?:\d+\.?\d*(?:e[+-]?\d+)?)|nan|inf(?:inity)?))Ú
ieee_floatcó>|Dcgc]
}t|«Œc}Scc}wrrrs rr zpyparsing_common.<lambda>)r%rÚ
identifierzQ(?:25[0-5]|2[0-4][0-9]|1?[0-9]{1,2})(?:\.(?:25[0-5]|2[0-4][0-9]|1?[0-9]{1,2})){3}z IPv4 addressz[0-9a-fA-F]{1,4}Ú hex_integerúzfull IPv6 address)réz::zshort IPv6 addresscó,td|D««dkS)Nc3ó`K|]&}tjj|«sŒ#dŒ(y­w)rN)r Ú
_ipv6_partÚmatches)Ú.0rs rú <genexpr>z,pyparsing_common.<lambda>.<locals>.<genexpr>@s$èø€ÒO˜BÔ'7×'BÑ'B×'JÑ'JÈ2Õ'N”aÑOùs$.§.é)Úsum)rs rr zpyparsing_common.<lambda>@s”#ÑO OÐRSÑS€r,z::ffff:zmixed IPv6 addressz IPv6 addressz:[0-9a-fA-F]{2}([:.-])[0-9a-fA-F]{2}(?:\1[0-9a-fA-F]{2}){4}z MAC addressÚfmtcóˆfd}|S)a
Helper to create a parse action for converting parsed date string to Python datetime.date
Params -
- fmt - format to be passed to datetime.strptime (default= ``"%Y-%m-%d"``)
Example:
.. testcode::
date_expr = pyparsing_common.iso8601_date.copy()
date_expr.set_parse_action(pyparsing_common.convert_to_date())
print(date_expr.parse_string("1999-12-31"))
prints:
.. testoutput::
[datetime.date(1999, 12, 31)]
có¢ tj|d«j«S#t$r}t ||t |««d}~wwxYw©Nr)rÚstrptimeÚdateÚ
ValueErrorÚParseExceptionÚstr)ÚssÚllrÚverBs €rÚcvt_fnz0pyparsing_common.convert_to_date.<locals>.cvt_fnfsKø€ð
רA©°Ó;øÜò
$ R¨¬S°«WÓ5ûð
6úsƒ&*ª A³A Á Ar+©rBrNs` rÚconvert_to_datez pyparsing_common.convert_to_dateOsø€ô. ˆ
r,cóˆfd}|S)a[Helper to create a parse action for converting parsed
datetime string to Python :class:`datetime.datetime`
Params -
- fmt - format to be passed to :class:`datetime.strptime` (default= ``"%Y-%m-%dT%H:%M:%S.%f"``)
Example:
.. testcode::
dt_expr = pyparsing_common.iso8601_datetime.copy()
dt_expr.set_parse_action(pyparsing_common.convert_to_datetime())
print(dt_expr.parse_string("1999-12-31T23:59:59.999"))
prints:
.. testoutput::
[datetime.datetime(1999, 12, 31, 23, 59, 59, 999000)]
có† tj|d«S#t$r}t||t |««d}~wwxYwrE)rrFrHrIrJ)ÚlrrMrBs €rrNz4pyparsing_common.convert_to_datetime.<locals>.cvt_fn…sBø€ð
ר1©¨sÓ3øÜò
$ Q¨¬3¨r«7Ó3ûð
4úsƒœ A¥;»Ar+rOs` rÚconvert_to_datetimez$pyparsing_common.convert_to_datetimensø€ô. ˆ
r,z7(?P<year>\d{4})(?:-(?P<month>\d\d)(?:-(?P<day>\d\d))?)?z ISO8601 datez†(?P<year>\d{4})-(?P<month>\d\d)-(?P<day>\d\d)[T ](?P<hour>\d\d):(?P<minute>\d\d)(:(?P<second>\d\d(\.\d*)?)?)?(?P<tz>Z|[+-]\d\d:?\d\d)?zISO8601 datetimec ót|jjd«xsd«}t|jxsd«}t|jxsd«}t|j
xsd«}t|j xsd«}t|jxsd«} t|||||t|«t|dzdz««S#t$r/} t||d| «j| j«dd} ~ wwxYw)aParse action to convert parsed dates or datetimes to a Python
:class:`datetime.datetime`.
This parse action will use the year, month, day, etc. results
names defined in the ISO8601 date expressions, but it can be
used with any expression that provides one or more of these fields.
Omitted fields will default to fields from Jan 1, 00:00:00.
Invalid dates will raise a :class:`ParseException` with the
error message indicating the invalid date fields.
Ú0rrzInvalid date/time: N)rÚyearÚlstripÚmonthÚdayÚhourÚminuterÚsecondrrHrIÚwith_tracebackÚ
__traceback__)
rSrTrrXrZr[r\r]r^rMs
rÚ as_datetimezpyparsing_common.as_datetime—ô1—6‘6—=‘= ÓÓÜA—G‘G’L˜qÓÜ!—%‘%’*˜1‹oˆÜ1—6‘6’;˜QÓˆÜQ—X‘X’] ÓÜq—x‘x’} 1Óð ÜØe˜S $¨´°F³ ¼SÀ&È1Á*ÐPTÑATÓ=Uóð
øôò Ü   AÐ)<¸R¸DÐ'AÓB×× Ñ óàð
ûð úsÂ'(CÃ DÃ*DÄDz4[0-9a-fA-F]{8}(?:-[0-9a-fA-F]{4}){3}-[0-9a-fA-F]{12}ÚUUIDrSrTÚtokenscóFtjj|d«S)a\Parse action to remove HTML tags from web page HTML source
Example:
.. testcode::
# strip HTML links from normal text
text = '<td>More info at the <a href="https://github.com/pyparsing/pyparsing/wiki">pyparsing</a> wiki page</td>'
td, td_end = make_html_tags("TD")
table_text = td + SkipTo(td_end).set_parse_action(
pyparsing_common.strip_html_tags)("body") + td_end
print(table_text.parse_string(text).body)
Prints:
.. testoutput::
More info at the pyparsing wiki page
r)r Ú_html_stripperÚtransform_string)rSrTrcs rÚstrip_html_tagsz pyparsing_common.strip_html_tagsÂsô* ×.×ÀqÁ ÓJr,ú,)Ú
exclude_charsz Ú commaItemÚ)Údefaultzcomma separated listcóH|Dcgc]}|j«Œc}Scc}w)z-Parse action to convert tokens to upper case.)Úupper©rSrTrrs rÚ
upcase_tokenszpyparsing_common.upcase_tokensêóð&'Ö'˜r
Ò'ùÒcóH|Dcgc]}|j«Œc}Scc}w)z-Parse action to convert tokens to lower case.)Úlowerros rÚdowncase_tokensz pyparsing_common.downcase_tokensïrqrr(?P<url>(?:(?:(?P<scheme>https?|ftp):)?\/\/)(?:(?P<auth>\S+(?::\S*)?)@)?(?P<host>(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z0-9\u00a1-\uffff][a-z0-9\u00a1-\uffff_-]{0,62})?[a-z0-9\u00a1-\uffff]\.)+(?:[a-z\u00a1-\uffff]{2,}\.?))(:(?P<port>\d{2,5}))?(?P<path>\/[^?# ]*)?(\?(?P<query>[^#]*))?(#(?P<fragment>\S*))?)ÚurlÚconvertToIntegerÚconvertToFloatÚ
convertToDateÚconvertToDatetimeÚ
stripHTMLTagsÚ upcaseTokensÚdowncaseTokensN)z%Y-%m-%d)z%Y-%m-%dT%H:%M:%S.%f)OÚ__name__Ú
__module__Ú __qualname__Ú__doc__Ú staticmethodrrÚWordÚnumsÚset_nameÚset_parse_actionÚPY_310_OR_LATERrÚhexnumsÚ token_maprr6ÚRegexÚsigned_integerr(Úadd_parse_actionÚOptÚsuppressÚ
mixed_integerrAÚrealÚsci_realÚ
streamliner0r1r3Ú
identcharsÚidentbodycharsr5Ú ipv4_addressr<Ú_full_ipv6_addressÚ_short_ipv6_addressÚ
add_conditionÚ_mixed_ipv6_addressÚCombineÚ ipv6_addressÚ mac_addressrJrPrUÚ iso8601_dateÚiso8601_datetimeraÚiso8601_date_validatedÚiso8601_datetime_validatedÚuuidrrreÚ ParseResultsrgÚ OneOrMoreÚLiteralÚLineEndÚ
printablesÚWhiteÚ
FollowedByÚ