OpenQuizz
Une application de gestion des contenus pédagogiques
pyparsing_common Class Reference

Static Public Member Functions

def convertToDate (fmt="%Y-%m-%d")
 
def convertToDatetime (fmt="%Y-%m-%dT%H:%M:%S.%f")
 
def stripHTMLTags (s, l, tokens)
 

Static Public Attributes

 convertToInteger
 
 convertToFloat
 
 integer
 
 hex_integer
 
 signed_integer
 
 fraction
 
 mixed_integer
 
 real
 
 sci_real
 
 number
 
 fnumber
 
 identifier
 
 ipv4_address
 
 ipv6_address
 
 mac_address
 
 iso8601_date
 
 iso8601_datetime
 
 uuid
 
 printables
 
 excludeChars
 
 comma_separated_list
 
 default
 
 upcaseTokens
 
 downcaseTokens
 

Detailed Description

Here are some common low-level expressions that may be useful in jump-starting parser development:
 - numeric forms (L{integers<integer>}, L{reals<real>}, L{scientific notation<sci_real>})
 - common L{programming identifiers<identifier>}
 - network addresses (L{MAC<mac_address>}, L{IPv4<ipv4_address>}, L{IPv6<ipv6_address>})
 - ISO8601 L{dates<iso8601_date>} and L{datetime<iso8601_datetime>}
 - L{UUID<uuid>}
 - L{comma-separated list<comma_separated_list>}
Parse actions:
 - C{L{convertToInteger}}
 - C{L{convertToFloat}}
 - C{L{convertToDate}}
 - C{L{convertToDatetime}}
 - C{L{stripHTMLTags}}
 - C{L{upcaseTokens}}
 - C{L{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')]

Member Function Documentation

◆ convertToDate()

def convertToDate (   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=C{"%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)]

◆ convertToDatetime()

def convertToDatetime (   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=C{"%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)]

◆ stripHTMLTags()

def stripHTMLTags (   s,
  l,
  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="http://pyparsing.wikispaces.com">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) # -> 'More info at the pyparsing wiki page'

Field Documentation

◆ comma_separated_list

comma_separated_list
static

◆ convertToFloat

convertToFloat
static

◆ convertToInteger

convertToInteger
static

◆ default

default
static

◆ downcaseTokens

downcaseTokens
static

◆ excludeChars

excludeChars
static

◆ fnumber

fnumber
static

◆ fraction

fraction
static

◆ hex_integer

hex_integer
static

◆ identifier

identifier
static

◆ integer

integer
static

◆ ipv4_address

ipv4_address
static

◆ ipv6_address

ipv6_address
static

◆ iso8601_date

iso8601_date
static

◆ iso8601_datetime

iso8601_datetime
static

◆ mac_address

mac_address
static

◆ mixed_integer

mixed_integer
static

◆ number

number
static

◆ printables

printables
static

◆ real

real
static

◆ sci_real

sci_real
static

◆ signed_integer

signed_integer
static

◆ upcaseTokens

upcaseTokens
static

◆ uuid

uuid
static

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