[i5CddlTddlmZmZmZddlmZddlZejdkZGddZ d e e  DZ dS) )*) DelimitedList any_open_tag any_close_tag)datetimeN) c eZdZdZedZedZee d e rendZ ee  d eedZ ed d  e rend Z e e rend d ze e rend z dZ edeeeedezzz dZ eeed d e rendZ ed d e rendZ eezez dZ ed d e rendZ ed d e rendZ eee  dZ! ed  d!Z" ed" d#Z#e#d$e#zd%zz d&Z$ee#d$e#zd'zzd(zee#d$e#zd'zzz d)Z%e%&d*d+e"z d,Z'e(e$e'ze%z d- d-Z) ed. d/Z* edSd1e+fd2Z,edTd1e+fd4Z-ed5 d6Z. ed7 d8Z/ ed9Z0e r<e.e0Z1 e/e0Z2 ed: d;Z3 e4je5jzZ6ede7fd?Z8e(e9e:d@e;zeee;d@zzz dCZ?e@eeABe?zdDE dFZC edGZDedHZEedI dJZF eeGdKeZHeeGdLeZIeeGdMe,ZJeeGdNe-ZKeeGdOe8ZLeeGdPeDZMeeGdQeEZNdRS)Upyparsing_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')] cd|DS)zK Parse action for converting parsed integers to Python int c,g|]}t|Sint.0tts `/home/jenkins/workspace/simtester-sanitize/venv/lib/python3.11/site-packages/pyparsing/common.py z7pyparsing_common.convert_to_integer..s$$$BB$$$r___ts rconvert_to_integerz#pyparsing_common.convert_to_integers %$!$$$$rcd|DS)zL Parse action for converting parsed numbers to Python float c,g|]}t|Srfloatrs rrz5pyparsing_common.convert_to_float..s&&&bb &&&rrrs rconvert_to_floatz!pyparsing_common.convert_to_floats '&A&&&&rintegercd|DS)Nc,g|]}t|Srrrs rrz-pyparsing_common...000CGG000rrrs rzpyparsing_common.00a000rz hex integerz[+-]?\d+zsigned integercd|DS)Nc,g|]}t|Srrrs rrz-pyparsing_common...r%rrr&s rr'zpyparsing_common.r(rcd|DS)Nc,g|]}t|Srrrs rrz-pyparsing_common...222"E"II222rrr&s rr'zpyparsing_common.22222r/cd|DS)Nc,g|]}t|Srrrs rrz-pyparsing_common...r.rrr&s rr'zpyparsing_common.r/rfractionc$|d|dz S)Nrr)rs rr'zpyparsing_common.sABr-z"fraction or mixed integer-fractionz[+-]?(?:\d+\.\d*|\.\d+)z real numbercd|DS)Nc,g|]}t|Srrrs rrz-pyparsing_common...r.rrr&s rr'zpyparsing_common.r/rz@[+-]?(?:\d+(?:[eE][+-]?\d+)|(?:\d+\.\d*|\.\d+)(?:[eE][+-]?\d+)?)z$real number with scientific notationcd|DS)Nc,g|]}t|Srrrs rrz-pyparsing_common...r.rrr&s rr'zpyparsing_common.r/rnumberz[+-]?\d+\.?\d*(?:[eE][+-]?\d+)?fnumbercd|DS)Nc,g|]}t|Srrrs rrz-pyparsing_common...r.rrr&s rr'zpyparsing_common.r/rz;(?i:[+-]?(?:(?:\d+\.?\d*(?:e[+-]?\d+)?)|nan|inf(?:inity)?)) ieee_floatcd|DS)Nc,g|]}t|Srrrs rrz-pyparsing_common...)r.rrr&s 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)Nc3XK|]%}tj|!dV&dS)rN)r _ipv6_partmatchesrs r z,pyparsing_common...@s9OOB'7'B'J'J2'N'NOaOOOOOOr)sumr&s rr'zpyparsing_common.@s##OO!OOOOORSSrz::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%Y-%m-%dfmtcfd}|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|dS#t$r#}t ||t |d}~wwxYwNr)rstrptimedate ValueErrorParseExceptionstr)ssllrverOs rcvt_fnz0pyparsing_common.convert_to_date..cvt_fnfsb 6(A4499;;; 6 6 6$RSWW555 6s,0 AAArrOr[s` rconvert_to_datez pyparsing_common.convert_to_dateOs#. 6 6 6 6 6  r%Y-%m-%dT%H:%M:%S.%fcfd}|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}~wwxYwrR)rrSrUrVrW)slrrZrOs rr[z4pyparsing_common.convert_to_datetime..cvt_fnsV 4(1s333 4 4 4$Q3r77333 4s A AA rr\s` rconvert_to_datetimez$pyparsing_common.convert_to_datetimens#. 4 4 4 4 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 datetimec t|jdpd}t|jpd}t|jpd}t|jpd}t|jpd}t|jpd} t|||||t|t|dzdzS#t$r2} t||d|  | 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. 0rrizInvalid date/time: N)ryearlstripmonthdayhourminuter secondrrUrVwith_traceback __traceback__) rarbrrfrhrirjrkrlrZs r as_datetimezpyparsing_common.as_datetimes16==%%*++AGLq!!!%*1oo16;QQX]##qx}1%% eS$F S&1*PTAT=U=U     A'AR'A'ABBQQ   s4C D -DD z4[0-9a-fA-F]{8}(?:-[0-9a-fA-F]{4}){3}-[0-9a-fA-F]{12}UUIDrarbtokenscLtj|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)rarbrqs rstrip_html_tagsz pyparsing_common.strip_html_tagss* .??q JJJr,) exclude_charsz commaItem)defaultzcomma separated listcd|DS)z-Parse action to convert tokens to upper case.c6g|]}|Sr)upperrs rrz2pyparsing_common.upcase_tokens.. '''r '''rrrarbrs r upcase_tokenszpyparsing_common.upcase_tokens('Q''''rcd|DS)z-Parse action to convert tokens to lower case.c6g|]}|Sr)lowerrs rrz4pyparsing_common.downcase_tokens..r~rrrs rdowncase_tokensz pyparsing_common.downcase_tokensrra(?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)rN)r^)O__name__ __module__ __qualname____doc__ staticmethodrr!Wordnumsset_nameset_parse_actionPY_310_OR_LATERr"hexnums token_maprrCRegexsigned_integerr3add_parse_actionOptsuppress mixed_integerrMrealsci_real streamliner;r<r? identcharsidentbodycharsrB ipv4_addressrI_full_ipv6_address_short_ipv6_address add_condition_mixed_ipv6_addressCombine ipv6_address mac_addressrWr]rc iso8601_dateiso8601_datetimeroiso8601_date_validatediso8601_datetime_validateduuidrrrs ParseResultsru OneOrMoreLiteralLineEnd printablesWhite FollowedBy _commasepitemr quoted_stringcopycomma_separated_listrrrreplaced_by_pep8rrrrrrrrrrr r sppd%%\% ''\' T )     1  00   I W }-->>yyb?Q?QRRK k " # #   1  00  [ )) 3  22     .   + + 3  22  hz Y 77888 >CCC(9(9(;(;h(F$G$GGGh344m""3''' ()) -   3  22   N QRR 8 9 9   3  22   0o. 8 8 B B M M O OFK 011 )     3  22   = LMM ,     3  22  _j.11::<HHJd5\h~3*++44]CCJ$j(8A'==GG J# *f4 455   #jC*,66 7 7 8h#$$  %%SS%|3==>RSS7 1 14G GQQ   h~  0%Eh}GS\<\<5Bh~$u Rh!""]\8q!-!@!@!M!Mb%5%5%7%7%H%H%U%U"p 5H I I R R  D6*\*,,/E}/E/G/GGNK3K3K KKK\K.  I 799*$z5556#eeElljjS&A&A%AABBC      +  )= M   = 0"===h%&&e((\(((\( %* . . \huoo]^$|$4$45GI[$\$\]]!\"2"23CEU"V"VWWN L!1!1/?!S!STTM$ %5%56IK^%_%_`` L!1!1/?!S!STTM< 0 0 O OPPL!\"2"23C_"U"UVVNNNrr c<g|]}t|t|Sr) isinstance ParserElement)rvs rrr8s7 *Q 2N2Nr) corehelpersrrrrsys version_inforr varsvalues_builtin_exprsrrrrs?????????? "g-iWiWiWiWiWiWiWiWZt$%%,,..r