Qucs-S S-parameter Viewer & RF Synthesis Tools
Loading...
Searching...
No Matches
Static Public Member Functions | Static Public Attributes | Static Protected Attributes | List of all members
pip._vendor.pyparsing.common.pyparsing_common Class Reference

Static Public Member Functions

 convert_to_date (str fmt="%Y-%m-%d")
 
 convert_to_datetime (str fmt="%Y-%m-%dT%H:%M:%S.%f")
 
 strip_html_tags (str s, int l, ParseResults tokens)
 

Static Public Attributes

 convert_to_integer = token_map(int)
 
 convert_to_float = token_map(float)
 
 integer = Word(nums).set_name("integer").set_parse_action(convert_to_integer)
 
tuple hex_integer
 
tuple signed_integer
 
tuple fraction
 
tuple mixed_integer
 
tuple real
 
tuple sci_real
 
tuple number = (sci_real | real | signed_integer).setName("number").streamline()
 
tuple fnumber
 
 identifier = Word(identchars, identbodychars).set_name("identifier")
 
 ipv4_address
 
 ipv6_address
 
 mac_address
 
 iso8601_date
 
 iso8601_datetime
 
 uuid = Regex(r"[0-9a-fA-F]{8}(-[0-9a-fA-F]{4}){3}-[0-9a-fA-F]{12}").set_name("UUID")
 
 comma_separated_list
 
 upcase_tokens = staticmethod(token_map(lambda t: t.upper()))
 
 downcase_tokens = staticmethod(token_map(lambda t: t.lower()))
 
 url
 
 convertToInteger = convert_to_integer
 
 convertToFloat = convert_to_float
 
 convertToDate = convert_to_date
 
 convertToDatetime = convert_to_datetime
 
 stripHTMLTags = strip_html_tags
 
 upcaseTokens = upcase_tokens
 
 downcaseTokens = downcase_tokens
 

Static Protected Attributes

 _ipv6_part = Regex(r"[0-9a-fA-F]{1,4}").set_name("hex_integer")
 
tuple _full_ipv6_address
 
tuple _short_ipv6_address
 
tuple _mixed_ipv6_address = ("::ffff:" + ipv4_address).set_name("mixed IPv6 address")
 
 _html_stripper = any_open_tag.suppress() | any_close_tag.suppress()
 
tuple _commasepitem
 

Detailed Description

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')]

Member Function Documentation

◆ convert_to_date()

pip._vendor.pyparsing.common.pyparsing_common.convert_to_date ( str   fmt = "%Y-%m-%d")
static
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)]

◆ convert_to_datetime()

pip._vendor.pyparsing.common.pyparsing_common.convert_to_datetime ( str   fmt = "%Y-%m-%dT%H:%M:%S.%f")
static
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)]

◆ strip_html_tags()

pip._vendor.pyparsing.common.pyparsing_common.strip_html_tags ( str  s,
int  l,
ParseResults  tokens 
)
static
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

Member Data Documentation

◆ _commasepitem

tuple pip._vendor.pyparsing.common.pyparsing_common._commasepitem
staticprotected
Initial value:
= (
Combine(
OneOrMore(
~Literal(",")
+ ~LineEnd()
+ Word(printables, exclude_chars=",")
+ Opt(White(" \t") + ~FollowedBy(LineEnd() | ","))
)
)
.streamline()
.set_name("commaItem")
)

◆ _full_ipv6_address

tuple pip._vendor.pyparsing.common.pyparsing_common._full_ipv6_address
staticprotected
Initial value:
= (_ipv6_part + (":" + _ipv6_part) * 7).set_name(
"full IPv6 address"
)

◆ _short_ipv6_address

tuple pip._vendor.pyparsing.common.pyparsing_common._short_ipv6_address
staticprotected
Initial value:
= (
Opt(_ipv6_part + (":" + _ipv6_part) * (0, 6))
+ "::"
+ Opt(_ipv6_part + (":" + _ipv6_part) * (0, 6))
).set_name("short IPv6 address")

◆ comma_separated_list

pip._vendor.pyparsing.common.pyparsing_common.comma_separated_list
static
Initial value:
= DelimitedList(
Opt(quoted_string.copy() | _commasepitem, default="")
).set_name("comma separated list")

◆ fnumber

tuple pip._vendor.pyparsing.common.pyparsing_common.fnumber
static
Initial value:
= (
Regex(r"[+-]?\d+\.?\d*([eE][+-]?\d+)?")
.set_name("fnumber")
.set_parse_action(convert_to_float)
)

◆ fraction

tuple pip._vendor.pyparsing.common.pyparsing_common.fraction
static
Initial value:
= (
signed_integer().set_parse_action(convert_to_float)
+ "/"
+ signed_integer().set_parse_action(convert_to_float)
).set_name("fraction")

◆ hex_integer

tuple pip._vendor.pyparsing.common.pyparsing_common.hex_integer
static
Initial value:
= (
Word(hexnums).set_name("hex integer").set_parse_action(token_map(int, 16))
)

◆ ipv4_address

pip._vendor.pyparsing.common.pyparsing_common.ipv4_address
static
Initial value:
= Regex(
r"(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}"
).set_name("IPv4 address")

◆ ipv6_address

pip._vendor.pyparsing.common.pyparsing_common.ipv6_address
static
Initial value:
= Combine(
(_full_ipv6_address | _mixed_ipv6_address | _short_ipv6_address).set_name(
"IPv6 address"
)
).set_name("IPv6 address")

◆ iso8601_date

pip._vendor.pyparsing.common.pyparsing_common.iso8601_date
static
Initial value:
= Regex(
r"(?P<year>\d{4})(?:-(?P<month>\d\d)(?:-(?P<day>\d\d))?)?"
).set_name("ISO8601 date")

◆ iso8601_datetime

pip._vendor.pyparsing.common.pyparsing_common.iso8601_datetime
static
Initial value:
= Regex(
r"(?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)?"
).set_name("ISO8601 datetime")

◆ mac_address

pip._vendor.pyparsing.common.pyparsing_common.mac_address
static
Initial value:
= Regex(
r"[0-9a-fA-F]{2}([:.-])[0-9a-fA-F]{2}(?:\1[0-9a-fA-F]{2}){4}"
).set_name("MAC address")

◆ mixed_integer

tuple pip._vendor.pyparsing.common.pyparsing_common.mixed_integer
static
Initial value:
= (
fraction | signed_integer + Opt(Opt("-").suppress() + fraction)
).set_name("fraction or mixed integer-fraction")

◆ real

tuple pip._vendor.pyparsing.common.pyparsing_common.real
static
Initial value:
= (
Regex(r"[+-]?(?:\d+\.\d*|\.\d+)")
.set_name("real number")
.set_parse_action(convert_to_float)
)

◆ sci_real

tuple pip._vendor.pyparsing.common.pyparsing_common.sci_real
static
Initial value:
= (
Regex(r"[+-]?(?:\d+(?:[eE][+-]?\d+)|(?:\d+\.\d*|\.\d+)(?:[eE][+-]?\d+)?)")
.set_name("real number with scientific notation")
.set_parse_action(convert_to_float)
)

◆ signed_integer

tuple pip._vendor.pyparsing.common.pyparsing_common.signed_integer
static
Initial value:
= (
Regex(r"[+-]?\d+")
.set_name("signed integer")
.set_parse_action(convert_to_integer)
)

The documentation for this class was generated from the following file: