Mpj5CddlddlmZmZmZddlmZddlZejdk\ZGddZ e e jDcgc]}e |e s |c}Zycc}w) )*) DelimitedList any_open_tag any_close_tag)datetimeN) c  eZdZdZedZedZeejdje rendZ ee jdjeedZ edjd je rend Z eje rend d zeje rend zjdZ ej)deeeedj-ezzzjdZ ej)eedjdje rendZ edjdje rendZ eezezjdj7Z edjdje rendZ edjdje rendZ eee jdZ! ed jd!Z" ed"jd#Z#e#d$e#zd%zzjd&Z$ee#d$e#zd'zzd(zee#d$e#zd'zzzjd)Z%e%jMd*d+e"zjd,Z'e(e$e'ze%zjd-jd-Z) ed.jd/Z* edQd0e+fd1Z,edRd0e+fd2Z-ed3jd4Z. ed5jd6Z/ ed7Z0e r.e.j)e0Z1 e/j)e0Z2 ed8jd9Z3 e4j,e5j,zZ6ed:e+d;ede;zee?zee=d@e>e;d>zzzj7jdAZ?e@eeAje?zdBCjdDZC edEZDedFZEedGjdHZF eeGdIeZHeeGdJeZIeeGdKe,ZJeeGdLe-ZKeeGdMe8ZLeeGdNeDZMeeGdOeEZNyP)Spyparsing_commona Here are some common low-level expressions that may be useful in jump-starting parser development: - numeric forms (:class:`integers`, :class:`reals`, :class:`scientific notation`) - common :class:`programming identifiers` - network addresses (:class:`MAC`, :class:`IPv4`, :class:`IPv6`) - ISO8601 :class:`dates` and :class:`datetime` - :class:`UUID` - :class:`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___ttts ^/mnt/ssd/data/Dropbox/adrian/scripts/msg_venv/lib/python3.12/site-packages/pyparsing/common.pyconvert_to_integerz#pyparsing_common.convert_to_integers #$$BB$$$c>|Dcgc] }t|c}Scc}w)zL Parse action for converting parsed numbers to Python float floatrs rconvert_to_floatz!pyparsing_common.convert_to_floats %&&bb &&&rintegerc>|Dcgc] }t|c}Scc}wNrrrs rzpyparsing_common.a0CG00rz hex integerz[+-]?\d+zsigned integerc>|Dcgc] }t|c}Scc}wrrrs rr zpyparsing_common.r!rc>|Dcgc] }t|c}Scc}wrrrs rr zpyparsing_common.2"E"I22r/c>|Dcgc] }t|c}Scc}wrrrs rr zpyparsing_common.r%rfractionc|d|dz S)Nr)rs rr zpyparsing_common.sAB-z"fraction or mixed integer-fractionz[+-]?(?:\d+\.\d*|\.\d+)z real numberc>|Dcgc] }t|c}Scc}wrrrs rr zpyparsing_common.r%rz@[+-]?(?:\d+(?:[eE][+-]?\d+)|(?:\d+\.\d*|\.\d+)(?:[eE][+-]?\d+)?)z$real number with scientific notationc>|Dcgc] }t|c}Scc}wrrrs rr zpyparsing_common.r%rnumberz[+-]?\d+\.?\d*(?:[eE][+-]?\d+)?fnumberc>|Dcgc] }t|c}Scc}wrrrs rr zpyparsing_common.r%rz;(?i:[+-]?(?:(?:\d+\.?\d*(?:e[+-]?\d+)?)|nan|inf(?:inity)?)) ieee_floatc>|Dcgc] }t|c}Scc}wrrrs rr zpyparsing_common.)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)rz::zshort IPv6 addressc,td|DdkS)Nc3`K|]&}tjj|s#d(yw)rN)r _ipv6_partmatches).0rs r z,pyparsing_common...@s$OB'7'B'B'J'J2'NaOs$..)sum)rs rr zpyparsing_common.@s#O!OORSSr,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 addressfmtcfd}|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|djS#t$r}t ||t |d}~wwxYwNr)rstrptimedate ValueErrorParseExceptionstr)ssllrverBs rcvt_fnz0pyparsing_common.convert_to_date..cvt_fnfsK 6((A499;; 6$RSW55 6s&* AA  Ar+rBrNs` rconvert_to_datez pyparsing_common.convert_to_dateOs. 6  r,cfd}|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|dS#t$r}t||t |d}~wwxYwrE)rrFrHrIrJ)slrrMrBs rrNz4pyparsing_common.convert_to_datetime..cvt_fnsB 4((1s33 4$Q3r733 4s A;Ar+rOs` rconvert_to_datetimez$pyparsing_common.convert_to_datetimens. 4  r,z7(?P\d{4})(?:-(?P\d\d)(?:-(?P\d\d))?)?z ISO8601 datez(?P\d{4})-(?P\d\d)-(?P\d\d)[T ](?P\d\d):(?P\d\d)(:(?P\d\d(\.\d*)?)?)?(?PZ|[+-]\d\d:?\d\d)?zISO8601 datetimec t|jjdxsd}t|jxsd}t|jxsd}t|j xsd}t|j xsd}t|jxsd} t|||||t|t|dzdzS#t$r/} t||d| j| jdd} ~ 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. 0rrizInvalid date/time: N)ryearlstripmonthdayhourminutersecondrrHrIwith_traceback __traceback__) rSrTrrXrZr[r\r]r^rMs r as_datetimezpyparsing_common.as_datetimes166==%*+AGGLq!!%%*1o166;QQXX]#qxx}1% eS$F S&1*PTAT=U   A)(?:(?:(?Phttps?|ftp):)?\/\/)(?:(?P\S+(?::\S*)?)@)?(?P(?!(?: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\d{2,5}))?(?P\/[^?# ]*)?(\?(?P[^#]*))?(#(?P\S*))?)urlconvertToIntegerconvertToFloat convertToDateconvertToDatetime stripHTMLTags upcaseTokensdowncaseTokensN)z%Y-%m-%d)z%Y-%m-%dT%H:%M:%S.%f)O__name__ __module__ __qualname____doc__ staticmethodrrWordnumsset_nameset_parse_actionPY_310_OR_LATERrhexnums token_maprr6Regexsigned_integerr(add_parse_actionOptsuppress mixed_integerrArealsci_real streamliner0r1r3 identcharsidentbodycharsr5 ipv4_addressr<_full_ipv6_address_short_ipv6_address add_condition_mixed_ipv6_addressCombine ipv6_address mac_addressrJrPrU iso8601_dateiso8601_datetimeraiso8601_date_validatediso8601_datetime_validateduuidrrre ParseResultsrg OneOrMoreLiteralLineEnd printablesWhite FollowedBy _commasepitemr quoted_stringcopycomma_separated_listrprurvreplaced_by_pep8rwrxryrzr{r|r}r+r,rr r sxpd%% '' T )    0  I W }->>yb?QRK k " #   0 [ )) 2      + + 2 hz Y 78 >CC(9(9(;h(F$GGGh34m""3' () -   2  N QR 8 9   2  0o. 8 8 B M M OFK 01 )    2  = LM ,    2 _j.1::<HJd\h~3*+44]CJ$j(8A'==GG J# *f4 45   jC*,66 7 8h#$  %%S%|3==>RS 1 14G GQQ  h~  0Eh}GS<<Bh~$ Rh!"]8!-!@!@!Mb%5%7%H%H%U"p H I R R D6*\**,/E}/E/E/GGNK3K3K KK.   9*z56eEljS&A%AABC    + ) M   = 0"=h%&e(((( * . \huo]^$$45GI[$\]!"23CEU"VWN !1/?!STM$%56IK^%_` !1/?!STM 0 OPL!"23C_"UVNr,r )corehelpersrrrrsys version_inforr varsvalues isinstance ParserElement_builtin_exprs)vs0rrsg?? ""g-iWiW\$%,,. *Q 2NAs A"A"