K i)8ddlddlmZmZmZddlmZGddZeejDcgc]}e |e s |c}Z ycc}w))*) DelimitedList any_open_tag any_close_tag)datetimec z eZdZdZeeZ eeZ e e jdjeZ e ejdjeedZ edjdjeZ ejedzejezjdZ ej'd eeeed j+ezzzjd Z ej'eed jd jeZ edjdjeZ eezezjdj5Z edjdjeZ edjdjeZ e eejdZ edjdZ! edjdZ"e"de"zdzzjdZ#ee"de"zdzzdzee"de"zdzzzjdZ$e$jKd d!e!zjd"Z&e'e#e&ze$zjd#jd#Z( ed$jd%Z) e*dFd&e+fd'Z,e*dGd&e+fd(Z-ed)jd*Z. ed+jd,Z/ ed-jd.Z0 e1j*e2j*zZ3e*d/e+d0ed1e4fd2Z5e'e6e7d3e8ze e9d34zee:d5e;e8d3zzzj5jd6Z<e=ee>jeeZEe*eDd?eZFe*eDd@e,ZGe*eDdAe-ZHe*eDdBe5ZIe*eDdCeAZJe*eDdDeBZKyE)Hpyparsing_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')] integerz hex integerz[+-]?\d+zsigned integer/fractionc|d|dz S)Nr)tts V/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/pyparsing/common.pyzpyparsing_common.sAB-z"fraction or mixed integer-fractionz[+-]?(?:\d+\.\d*|\.\d+)z real numberz@[+-]?(?:\d+(?:[eE][+-]?\d+)|(?:\d+\.\d*|\.\d+)(?:[eE][+-]?\d+)?)z$real number with scientific notationnumberz[+-]?\d+\.?\d*(?:[eE][+-]?\d+)?fnumberz;(?i:[+-]?(?:(?:\d+\.?\d*(?:e[+-]?\d+)?)|nan|inf(?:inity)?)) ieee_float identifierzK(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$..)sumts rrzpyparsing_common.s#O!OORSSrz::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)ssllrver)s rcvt_fnz0pyparsing_common.convert_to_date..cvt_fn;sK 6((A499;; 6$RSW55 6s&* AA  Arr)r5s` rconvert_to_datez pyparsing_common.convert_to_date$s. 6  rcfd}|S)aIHelper to create a parse action for converting parsed datetime string to Python datetime.datetime Params - - fmt - format to be passed to 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}~wwxYwr,)rr-r/r0r1)slr(r4r)s rr5z4pyparsing_common.convert_to_datetime..cvt_fnZsB 4((1s33 4$Q3r733 4s A;Arr6s` rconvert_to_datetimez$pyparsing_common.convert_to_datetimeCs. 4  rz7(?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 datetimez2[0-9a-fA-F]{8}(-[0-9a-fA-F]{4}){3}-[0-9a-fA-F]{12}UUIDr:r;tokenscFtjj|dS)a\Parse action to remove HTML tags from web page HTML source Example: .. testcode:: # strip HTML links from normal text text = 'More info at the pyparsing wiki page' 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_strippertransform_string)r:r;r>s rstrip_html_tagsz pyparsing_common.strip_html_tagsqs* ..??q JJr,) exclude_charsz commaItem)defaultzcomma separated listc"|jSN)upperr's rrzpyparsing_common.s QWWYrc"|jSrI)lowerr's rrzpyparsing_common.s qwwyra(?P(?:(?:(?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)L__name__ __module__ __qualname____doc__ token_mapintconvert_to_integerfloatconvert_to_floatWordnumsset_nameset_parse_actionr hexnumsrRegexsigned_integerradd_parse_actionOptsuppress mixed_integerr&realsci_real streamlinerrr identcharsidentbodycharsr ipv4_addressr!_full_ipv6_address_short_ipv6_address add_condition_mixed_ipv6_addressCombine ipv6_address mac_address staticmethodr1r7r< iso8601_dateiso8601_datetimeuuidrrr@ ParseResultsrB OneOrMoreLiteralLineEnd printablesWhite FollowedBy _commasepitemr quoted_stringcopycomma_separated_list upcase_tokensdowncase_tokensrMreplaced_by_pep8rNrOrPrQrRrSrTrrrr r spd#3!'4j!!),==>PQGD W }->>yb?QRG k " #  , - W ))*:;     + +,< = >hz  U 78 >CC(9(9(;h(F$GGGh34g""3' () -  * + M QR 8 9  * + /o. 8 8 B M M OFG 01 )   * + 4 LM ,   * + ]j.1::<HJdVh~3*+44]CJ$j(8A'==GG J# *f4 45   jC*,66 7 8h#$  %%S%|3==>RS 1 14G GQQ  h~  0Eh}GS<<Bh~$ Rh!"] F G P PQW XD5*\**,/E}/E/E/GGNK3K3K KK.   9*z56eEljS&A%AABC    + ) M   = 0"=h%&e +>!?@M7"9-@#ABO7 * . \huo]^$$45GI[$\]!"23CEU"VWN !1/?!STM$%56IK^%_` !1/?!STM 0 OPL!"23C_"UVNrr N) corehelpersrrrrr varsvalues isinstance ParserElement_builtin_exprs)vs0rrsT??WWWWx$%,,. *Q 2NAs AA