U
    	ڲg^5                     @   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 )
   )*)DelimitedListany_open_tagany_close_tag    )datetimec                   @   sP  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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*dJe+d(d)d*Z,e*dKe+d(d,d-Z-ed.d/Z.ed0d1Z/ed2d3Z0e1 e2 B Z3e*e+ee4d4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
 ZAe*ed?d
 ZBed@dAZCe*eDdBeZEe*eDdCeZFe*eDdDe,ZGe*eDdEe-ZHe*eDdFe5ZIe*eDdGeAZJe*eDdHeBZKdIS )Lpyparsing_commona7  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`

    Example::

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

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

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

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

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

        import uuid
        pyparsing_common.uuid.set_parse_action(token_map(uuid.UUID))
        pyparsing_common.uuid.run_tests('''
            # 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   4/tmp/pip-unpacked-wheel-8n0dx3ox/pyparsing/common.py<lambda>       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+)?fnumberz2(?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:   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      r   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                    s    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.set_parse_action(pyparsing_common.convert_to_date())
            print(date_expr.parse_string("1999-12-31"))

        prints::

            [datetime.date(1999, 12, 31)]
        c              
      sN   zt |d   W S  tk
rH } zt| |t|W 5 d }~X Y nX d S Nr   )r   strptimedate
ValueErrorParseExceptionstr)ssZllr   ver%   r   r   cvt_fn  s    z0pyparsing_common.convert_to_date.<locals>.cvt_fnr   r&   r/   r   r%   r   convert_to_date  s    z pyparsing_common.convert_to_date%Y-%m-%dT%H:%M:%S.%fc                    s    fdd}|S )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.set_parse_action(pyparsing_common.convert_to_datetime())
            print(dt_expr.parse_string("1999-12-31T23:59:59.999"))

        prints::

            [datetime.datetime(1999, 12, 31, 23, 59, 59, 999000)]
        c              
      sJ   zt |d  W S  tk
rD } zt| |t|W 5 d }~X Y nX d S r'   )r   r(   r*   r+   r,   )slr#   r.   r%   r   r   r/   1  s    z4pyparsing_common.convert_to_datetime.<locals>.cvt_fnr   r0   r   r%   r   convert_to_datetime  s    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}UUIDr3   r4   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 = 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::

            More info at the pyparsing wiki page
        r   )r   _html_stripperZtransform_stringr7   r   r   r   strip_html_tagsH  s    z pyparsing_common.strip_html_tags,)Zexclude_charsz 		commaItem )defaultzcomma separated listc                 C   s   |   S N)upperr"   r   r   r   r   k  r   c                 C   s   |   S r?   )lowerr"   r   r   r   r   n  r   a  (?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)r$   )r2   )L__name__
__module____qualname____doc__Z	token_mapintZconvert_to_integerfloatZconvert_to_floatWordnumsset_nameZset_parse_actionr	   hexnumsr   Regexsigned_integerr   Zadd_parse_actionZOptsuppressmixed_integerr!   realsci_real
streamliner   r   r   Z
identcharsZidentbodycharsr   ipv4_addressr   _full_ipv6_address_short_ipv6_addressZadd_condition_mixed_ipv6_addressCombineipv6_addressmac_addressstaticmethodr,   r1   r5   iso8601_dateiso8601_datetimeuuidr   r   r9   ParseResultsr:   	OneOrMoreLiteralLineEnd
printablesWhite
FollowedBy_commasepitemr   Zquoted_stringcopycomma_separated_listZupcase_tokensZdowncase_tokensrB   Zreplaced_by_pep8rC   rD   rE   rF   rG   rH   rI   r   r   r   r   r      s   


	
	.4r   c                 C   s   g | ]}t |tr|qS r   )
isinstanceParserElement)r   vr   r   r   
<listcomp>  s    
 rs   N)
coreZhelpersr   r   r   r   r   varsvaluesZ_builtin_exprsr   r   r   r   <module>   s      +
