o
    Ëý°jˆ2  ã                   @   sP   d dl T d dlmZmZmZ ddlmZ G dd„ dƒZdd„ eeƒ ¡ D ƒZ	d	S )
é   )Ú*)Údelimited_listÚany_open_tagÚany_close_tagé    )Údatetimec                   @   s$  e Zd ZdZeeƒZ	 eeƒZ	 e	e
ƒ d¡ e¡Z	 e	eƒ d¡ eedƒ¡Z	 edƒ d¡ e¡Z	 eƒ  e¡d eƒ  e¡  d¡Z	 e d	d
„ ¡ eeeedƒ ¡ e ƒ B  d¡Z	 e e¡ edƒ d¡ e¡Z	 edƒ d¡ e¡Z	 eeB eB  d¡ ¡ Z	 edƒ d¡ e¡Z	 e	eeƒ d¡Z 	 edƒ d¡Z!	 edƒ d¡Z"e"de" d   d¡Z#ee"de" d  ƒd ee"de" d  ƒ  d¡Z$e$ %dd
„ ¡ d e!  d!¡Z&e'e#e&B e$B  d"¡ƒ d"¡Z(	 ed#ƒ d$¡Z)	 e*dCd&e+fd'd(„ƒZ,e*dDd&e+fd*d+„ƒZ-ed,ƒ d-¡Z.	 ed.ƒ d/¡Z/	 ed0ƒ d1¡Z0	 e1 ¡ e2 ¡ B Z3e*d2e+d3ed4e4fd5d6„ƒZ5e'e6e7d7ƒ e8ƒ   e	e9d7d8� ee:d9ƒe;e8ƒ d7B ƒ  ƒ ƒƒ ¡  d:¡Z<e=ee> ?¡ e<B d;d<�ƒ d=¡Z@	 e*ed>d
„ ƒƒZA	 e*ed?d
„ ƒƒZB	 ed@ƒ dA¡ZCeZDeZEe,ZFe-ZGe5ZHeAZIeBZJdBS )EÚ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:`convertToInteger`
    - :class:`convertToFloat`
    - :class:`convertToDate`
    - :class:`convertToDatetime`
    - :class:`stripHTMLTags`
    - :class:`upcaseTokens`
    - :class:`downcaseTokens`

    Example::

        pyparsing_common.number.runTests('''
            # any int or real number, returned as the appropriate type
            100
            -100
            +100
            3.14159
            6.02e23
            1e-12
            ''')

        pyparsing_common.fnumber.runTests('''
            # any int or real number, returned as float
            100
            -100
            +100
            3.14159
            6.02e23
            1e-12
            ''')

        pyparsing_common.hex_integer.runTests('''
            # hex numbers
            100
            FF
            ''')

        pyparsing_common.fraction.runTests('''
            # fractions
            1/2
            -3/4
            ''')

        pyparsing_common.mixed_integer.runTests('''
            # mixed fractions
            1
            1/2
            -3/4
            1-3/4
            ''')

        import uuid
        pyparsing_common.uuid.setParseAction(tokenMap(uuid.UUID))
        pyparsing_common.uuid.runTests('''
            # uuid
            12345678-1234-5678-1234-567812345678
            ''')

    prints::

        # 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]

        # 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]

        # hex numbers
        100
        [256]

        FF
        [255]

        # fractions
        1/2
        [0.5]

        -3/4
        [-0.75]

        # mixed fractions
        1
        [1]

        1/2
        [0.5]

        -3/4
        [-0.75]

        1-3/4
        [1.75]

        # uuid
        12345678-1234-5678-1234-567812345678
        [UUID('12345678-1234-5678-1234-567812345678')]
    Úintegerzhex integeré   z[+-]?\d+zsigned integerú/Úfractionc                 C   s   | d | d  S )Nr   éÿÿÿÿ© )Úttr   r   ú�/root/aizidognhua/tmp/workspace/projects/ec89d86c-575f-41c9-af57-ac45cbdbf775/venv/lib/python3.10/site-packages/pip/_vendor/pyparsing/common.pyÚ<lambda>¹   s    zpyparsing_common.<lambda>ú-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 notationÚnumberz[+-]?\d+\.?\d*([eE][+-]?\d+)?ÚfnumberÚ
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ú:é   zfull IPv6 address)r   é   z::zshort IPv6 addressc                 C   s   t dd„ | D ƒƒdk S )Nc                 s   s    � | ]}t j |¡rd V  qdS )r   N)r   Ú
_ipv6_partÚmatches)Ú.0r   r   r   r   Ú	<genexpr>í   s   € z,pyparsing_common.<lambda>.<locals>.<genexpr>é   )Úsum©Útr   r   r   r   í   s    z::ffff:zmixed 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-%dÚfmtc                    ó   ‡ fdd„}|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::

            date_expr = pyparsing_common.iso8601_date.copy()
            date_expr.setParseAction(pyparsing_common.convertToDate())
            print(date_expr.parseString("1999-12-31"))

        prints::

            [datetime.date(1999, 12, 31)]
        c              
      s@   zt  |d ˆ ¡ ¡ W S  ty } zt| |t|ƒƒ‚d }~ww ©Nr   )r   ÚstrptimeÚdateÚ
ValueErrorÚParseExceptionÚstr)ÚssÚllr   Úve©r#   r   r   Úcvt_fn  s   €ÿz0pyparsing_common.convert_to_date.<locals>.cvt_fnr   ©r#   r/   r   r.   r   Úconvert_to_dateü   ó   z pyparsing_common.convert_to_dateú%Y-%m-%dT%H:%M:%S.%fc                    r$   )a  Helper 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::

            dt_expr = pyparsing_common.iso8601_datetime.copy()
            dt_expr.setParseAction(pyparsing_common.convertToDatetime())
            print(dt_expr.parseString("1999-12-31T23:59:59.999"))

        prints::

            [datetime.datetime(1999, 12, 31, 23, 59, 59, 999000)]
        c              
      s<   z	t  |d ˆ ¡W S  ty } zt| |t|ƒƒ‚d }~ww r%   )r   r&   r(   r)   r*   )ÚsÚlr!   r-   r.   r   r   r/   *  s   €ÿz4pyparsing_common.convert_to_datetime.<locals>.cvt_fnr   r0   r   r.   r   Úconvert_to_datetime  r2   z$pyparsing_common.convert_to_datetimez7(?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)?zISO8601 datetimez2[0-9a-fA-F]{8}(-[0-9a-fA-F]{4}){3}-[0-9a-fA-F]{12}ÚUUIDr4   r5   Útokensc                 C   s   t j |d ¡S )a  Parse action to remove HTML tags from web page HTML source

        Example::

            # 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 = makeHTMLTags("TD")
            table_text = td + SkipTo(td_end).setParseAction(pyparsing_common.stripHTMLTags)("body") + td_end
            print(table_text.parseString(text).body)

        Prints::

            More info at the pyparsing wiki page
        r   )r   Ú_html_stripperÚtransform_string)r4   r5   r8   r   r   r   Ústrip_html_tagsA  s   z pyparsing_common.strip_html_tagsú,)Úexclude_charsz 	Ú	commaItemÚ )Údefaultzcomma separated listc                 C   ó   |   ¡ S ©N)Úupperr    r   r   r   r   d  ó    c                 C   rA   rB   )Úlowerr    r   r   r   r   g  rD   a÷  ^(?:(?:(?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*))?$ÚurlN)r"   )r3   )KÚ__name__Ú
__module__Ú__qualname__Ú__doc__Ú	token_mapÚintÚconvert_to_integerÚfloatÚconvert_to_floatÚWordÚnumsÚset_nameÚset_parse_actionr	   Úhexnumsr   ÚRegexÚsigned_integerr   Úadd_parse_actionÚOptÚsuppressÚmixed_integerr   ÚrealÚsci_realÚsetNameÚ
streamliner   r   Ú
identcharsÚidentbodycharsr   Úipv4_addressr   Ú_full_ipv6_addressÚ_short_ipv6_addressÚadd_conditionÚ_mixed_ipv6_addressÚCombineÚipv6_addressÚmac_addressÚstaticmethodr*   r1   r6   Úiso8601_dateÚiso8601_datetimeÚuuidr   r   r9   ÚParseResultsr;   Ú	OneOrMoreÚLiteralÚLineEndÚ
printablesÚWhiteÚ
FollowedByÚ_commasepitemr   Úquoted_stringÚcopyÚcomma_separated_listÚupcase_tokensÚdowncase_tokensrF   ÚconvertToIntegerÚconvertToFloatÚconvertToDateÚconvertToDatetimeÚstripHTMLTagsÚupcaseTokensÚdowncaseTokensr   r   r   r   r      s    ÿý
ÿ
þüþ
ýýýÿþÿÿþüÿÿÿüÿþÿþÿþÿ
þýÿÿöÿþý.Ò2r   c                 C   s   g | ]	}t |tƒr|‘qS r   )Ú
isinstanceÚParserElement)r   Úvr   r   r   Ú
<listcomp>¦  s
    
ÿÿr„   N)
ÚcoreÚhelpersr   r   r   r   r   ÚvarsÚvaluesÚ_builtin_exprsr   r   r   r   Ú<module>   s      !

ÿ