"""


ALPHANUM = Word(string.ascii_letters + string.digits)

LBRACKET = L("[").suppress()
RBRACKET = L("]").suppress()
LPAREN = L("(").suppress()
RPAREN = L(")").suppress()
COMMA = L(",").suppress()
SEMICOLON = L(";").suppress()
AT = L("@").suppress()

PUNCTUATION = Word("-_.")
IDENTIFIER_END = ALPHANUM | (ZeroOrMore(PUNCTUATION) + ALPHANUM)
IDENTIFIER = Combine(ALPHANUM + ZeroOrMore(IDENTIFIER_END))

NAME = IDENTIFIER("name")
EXTRA = IDENTIFIER

URI = Regex(r'[^ ]+')("url")
URL = (AT + URI)

EXTRAS_LIST = EXTRA + ZeroOrMore(COMMA + EXTRA)
EXTRAS = (LBRACKET + Optional(EXTRAS_LIST) + RBRACKET)("extras")

VERSION_PEP440 = Regex(Specifier._regex_str, re.VERBOSE | re.IGNORECASE)
VERSION_LEGACY = Regex(LegacySpecifier._regex_str, re.VERBOSE | re.IGNORECASE)

VERSION_ONE = VERSION_PEP440 ^ VERSION_LEGACY
VERSION_MANY = Combine(VERSION_ONE + ZeroOrMore(COMMA + VERSION_ONE),
Exemplo n.º 2
0
import pyparsing
import datetime, time
import os

from pip._vendor.pyparsing import Word, Combine, hexnums, Group, Optional, nums, alphanums

# print "Flows are ", flows

LBRACE = '('
RBRACE = ')'
COMMA = ','
COLON = ':'
EQUAL = '='

in_port = packets = proto = tos = ttl = src = dst = op = Word(nums)
ipAddress = Combine(Word(nums) + ('.' + Word(nums)) * 3)
twohex = Word(hexnums, exact=2)
macAddress = Combine(twohex + (':' + twohex) * 5)
eth_type = Combine('0x' + Word(hexnums, exact=4))
frag = Word(alphanums)

eth = Group("eth" + LBRACE + "src" + EQUAL + macAddress("src") + COMMA +
            "dst" + EQUAL + macAddress("dst") + RBRACE)
arp = Group("arp" + LBRACE + "sip" + EQUAL + ipAddress("sip") + COMMA + "tip" +
            EQUAL + ipAddress("tip") + COMMA + "op" + EQUAL + op("op") +
            COMMA + "sha" + EQUAL + macAddress("sha") + COMMA + "tha" + EQUAL +
            macAddress("tha") + RBRACE)
ipv4 = Group("ipv4" + LBRACE + "src" + EQUAL + ipAddress("src") + COMMA +
             "dst" + EQUAL + ipAddress("dst") + COMMA + "proto" + EQUAL +
             proto("proto") + COMMA + "tos" + EQUAL + tos("tos") + COMMA +
             "ttl" + EQUAL + ttl("ttl") + COMMA + "frag" + EQUAL +