コード例 #1
0
ファイル: rfc3966.py プロジェクト: jablko/untwisted
import rfc5234
from qwer import *

visualSeparator = qwer('[-().]')
phonedigit = qwer('(?:', rule('rfc5234.DIGIT'), '|(?:', rule('visualSeparator'), ')?)')
globalNumberDigits = qwer('\+(?:', rule('phonedigit'), ')*', rule('rfc5234.DIGIT'), '(?:', rule('phonedigit'), ')*')
alphanum = qwer('(?:', rule('rfc5234.ALPHA'), '|', rule('rfc5234.DIGIT'), ')')
pname = qwer('(?:', rule('alphanum'), '|-)+')
paramUnreserved = qwer('[]$&+/:[]')
mark = qwer('[-!\'()*._~]')
unreserved = qwer('(?:', rule('alphanum'), '|', rule('mark'), ')')
pctEncoded = qwer('%', rule('rfc5234.HEXDIG'), rule('rfc5234.HEXDIG'))
paramchar = qwer('(?:', rule('paramUnreserved'), '|', rule('unreserved'), '|', rule('pctEncoded'), ')')
pvalue = qwer('(?:', rule('paramchar'), ')+')
parameter = qwer(';', rule('pname'), '(?:=', rule('pvalue'), ')?')
extension = qwer(';ext=(?:', rule('phonedigit'), ')+')
reserved = qwer('[$&+,/:;=?@]')
uric = qwer('(?:', rule('reserved'), '|', rule('unreserved'), '|', rule('pctEncoded'), ')')
isdnSubaddress = qwer(';isub=(?:', rule('uric'), ')+')
par = qwer('(?:', rule('parameter'), '|', rule('extension'), '|', rule('isdnSubaddress'), ')')
globalNumber = qwer(rule('globalNumberDigits'), '(?:', rule('par'), ')*')
phonedigitHex = qwer('(?:', rule('rfc5234.HEXDIG'), '|\*|#|(?:', rule('visualSeparator'), ')?)')
localNumberDigits = qwer('(?:', rule('phonedigitHex'), ')*(?:', rule('rfc5234.HEXDIG'), '|\*|#)(?:', rule('phonedigitHex'), ')*')
domainlabel = qwer('(?:', rule('alphanum'), '|', rule('alphanum'), '(?:', rule('alphanum'), '|-)*', rule('alphanum'), ')')
toplabel = qwer('(?:', rule('rfc5234.ALPHA'), '|', rule('rfc5234.ALPHA'), '(?:', rule('alphanum'), '|-)*', rule('alphanum'), ')')
domainname = qwer('(?:', rule('domainlabel'), '\.)*', rule('toplabel'), '\.?')
descriptor = qwer('(?:', rule('domainname'), '|', rule('globalNumberDigits'), ')')
context = qwer(';phone-context=', rule('descriptor'))
localNumber = qwer(rule('localNumberDigits'), '(?:', rule('par'), ')*', rule('context'), '(?:', rule('par'), ')*')
telephoneSubscriber = qwer('(?:', rule('globalNumber'), '|', rule('localNumber'), ')')
コード例 #2
0
ファイル: rfc4566.py プロジェクト: jablko/untwisted
import rfc3986, rfc5234, rfc5322
from qwer import *

# This memo descripes version 0
protoVersion = qwer('v=(?:', rule('rfc5234.DIGIT'), ')+', rule('rfc5234.CRLF'))

# String of visible characters
nonWsString = qwer('(?:', rule('rfc5234.VCHAR'), '|[\x80-\xff])+')

# Pretty side definition, but doesn't include space
username = rule('nonWsString')

# Should be unique for this username/host
sessId = qwer('(?:', rule('rfc5234.DIGIT'), ')+')

sessVersion = qwer('(?:', rule('rfc5234.DIGIT'), ')+')

# Typically "IN"
nettype = rule('token')

# Typically "IP4" or "IP6"
addrtype = rule('token')

hex4 = qwer('(?:', rule('rfc5234.HEXDIG'), '){1,4}')
hexseq = qwer(rule('hex4'), '(?::', rule('hex4'), ')*')
hexpart = qwer('(?:', rule('hexseq'), '|', rule('hexseq'), '::(?:', rule('hexseq'), ')?|::(?:', rule('hexseq'), ')?)')
posDigit = qwer('[1-9]')
decimalUchar = qwer('(?:', rule('rfc5234.DIGIT'), '|', rule('posDigit'), rule('rfc5234.DIGIT'), '|1(?:', rule('rfc5234.DIGIT'), '){2}|2[0-4]', rule('rfc5234.DIGIT'), '|25[0-5])')
b1 = rule('decimalUchar')
ip4Address = qwer(rule('b1'), '(?:\.', rule('decimalUchar'), '){3}')
ip6Address = qwer(rule('hexpart'), '(?::', rule('ip4Address'), ')?')
コード例 #3
0
import rfc3986
from qwer import *

# Any CHAR except CTLs or separators
token = qwer('[!#-\'*+\--9A-Z^-z|~]+')

requestUri = qwer('(?:\*|', rule('rfc3986.absoluteUri'), '|',
                  rule('rfc3986.pathAbsolute'), '|', rule('rfc3986.authority'),
                  ')')
コード例 #4
0
import rfc5234
from qwer import *

visualSeparator = qwer('[-().]')
phonedigit = qwer('(?:', rule('rfc5234.DIGIT'), '|(?:',
                  rule('visualSeparator'), ')?)')
globalNumberDigits = qwer('\+(?:', rule('phonedigit'), ')*',
                          rule('rfc5234.DIGIT'), '(?:', rule('phonedigit'),
                          ')*')
alphanum = qwer('(?:', rule('rfc5234.ALPHA'), '|', rule('rfc5234.DIGIT'), ')')
pname = qwer('(?:', rule('alphanum'), '|-)+')
paramUnreserved = qwer('[]$&+/:[]')
mark = qwer('[-!\'()*._~]')
unreserved = qwer('(?:', rule('alphanum'), '|', rule('mark'), ')')
pctEncoded = qwer('%', rule('rfc5234.HEXDIG'), rule('rfc5234.HEXDIG'))
paramchar = qwer('(?:', rule('paramUnreserved'), '|', rule('unreserved'), '|',
                 rule('pctEncoded'), ')')
pvalue = qwer('(?:', rule('paramchar'), ')+')
parameter = qwer(';', rule('pname'), '(?:=', rule('pvalue'), ')?')
extension = qwer(';ext=(?:', rule('phonedigit'), ')+')
reserved = qwer('[$&+,/:;=?@]')
uric = qwer('(?:', rule('reserved'), '|', rule('unreserved'), '|',
            rule('pctEncoded'), ')')
isdnSubaddress = qwer(';isub=(?:', rule('uric'), ')+')
par = qwer('(?:', rule('parameter'), '|', rule('extension'), '|',
           rule('isdnSubaddress'), ')')
globalNumber = qwer(rule('globalNumberDigits'), '(?:', rule('par'), ')*')
phonedigitHex = qwer('(?:', rule('rfc5234.HEXDIG'), '|\*|#|(?:',
                     rule('visualSeparator'), ')?)')
localNumberDigits = qwer('(?:', rule('phonedigitHex'), ')*(?:',
                         rule('rfc5234.HEXDIG'), '|\*|#)(?:',
コード例 #5
0
ファイル: rfc3261.py プロジェクト: jablko/untwisted
import rfc2616, rfc3966, rfc5234
from qwer import *

alphanum = qwer('(?:', rule('rfc5234.ALPHA'), '|', rule('rfc5234.DIGIT'), ')')
mark = qwer('[!\'()*\-._~]')
unreserved = qwer('(?:', rule('alphanum'), '|', rule('mark'), ')')
escaped = qwer('%', rule('rfc5234.HEXDIG'), rule('rfc5234.HEXDIG'))
userUnreserved = qwer('[$&+,/;=?]')
user = qwer('(?:', rule('unreserved'), '|', rule('escaped'), '|', rule('userUnreserved'), ')+')
password = qwer('(?:', rule('unreserved'), '|', rule('escaped'), '|[$&+,=])*')
userinfo = qwer('(?:', rule('user'), '|', rule('rfc3966.telephoneSubscriber'), ')(?::', rule('password'), ')?@')
domainlabel = qwer('(?:', rule('alphanum'), '|', rule('alphanum'), '(?:', rule('alphanum'), '|-)*', rule('alphanum'), ')')
toplabel = qwer('(?:', rule('rfc5234.ALPHA'), '|', rule('rfc5234.ALPHA'), '(?:', rule('alphanum'), '|-)*', rule('alphanum'), ')')
hostname = qwer('(?:', rule('domainlabel'), '\.)*', rule('toplabel'), '\.?')
hex4 = qwer('(?:', rule('rfc5234.HEXDIG'), '){1,4}')
hexseq = qwer(rule('hex4'), '(?::', rule('hex4'), ')*')
hexpart = qwer('(?:', rule('hexseq'), '|', rule('hexseq'), '::(?:', rule('hexseq'), ')?|::(?:', rule('hexseq'), ')?)')
ipv4address = qwer('(?:', rule('rfc5234.DIGIT'), '){1,3}\.(?:', rule('rfc5234.DIGIT'), '){1,3}\.(?:', rule('rfc5234.DIGIT'), '){1,3}\.(?:', rule('rfc5234.DIGIT'), '){1,3}')
ipv6address = qwer(rule('hexpart'), '(?::', rule('ipv4address'), ')?')
ipv6reference = qwer('\[', rule('ipv6address'), ']')
host = qwer('(?:', rule('hostname'), '|', rule('ipv4address'), '|', rule('ipv6reference'), ')')
port = qwer('(?:', rule('rfc5234.DIGIT'), ')+')
hostport = qwer(rule('host'), '(?::', rule('port'), ')?')
token = qwer('(?:', rule('alphanum'), '|[-!%*+\'._`~])+')
otherTransport = rule('token')
transportParam = qwer('transport=(?:udp|tcp|sctp|tls|', rule('otherTransport'), ')')
otherUser = rule('token')
userParam = qwer('user=(?:phone|ip|', rule('otherUser'), ')')
extensionMethod = rule('token')
method = qwer('(?:INVITE|ACK|OPTIONS|BYE|CANCEL|REGISTER|', rule('extensionMethod'), ')')
methodParam = qwer('method=', rule('method'))
コード例 #6
0
import rfc5234, rfc5322
from qwer import *

letDig = qwer('(?:', rule('rfc5234.ALPHA'), '|', rule('rfc5234.DIGIT'), ')')
ldhStr = qwer('(?:', rule('rfc5234.ALPHA'), '|', rule('rfc5234.DIGIT'), '|-)*',
              rule('letDig'))
subDomain = qwer(rule('letDig'), '(?:', rule('ldhStr'), ')?')
domain = qwer(rule('subDomain'), '(?:\.', rule('subDomain'), ')*')

# Representing a decimal integer value in the range 0 through 255
snum = qwer('(?:', rule('rfc5234.DIGIT'), '){1,3}')

ipv4AddressLiteral = qwer(rule('snum'), '(?:\.', rule('snum'), '){3}')
ipv6Hex = qwer('(?:', rule('rfc5234.HEXDIG'), '){1,4}')
ipv6Full = qwer(rule('ipv6Hex'), '(?::', rule('ipv6Hex'), '){7}')

# The "::" represents at least 2 16-bit groups of zeros.  No more than 6 groups
# in addition to the "::" may be present
ipv6Comp = qwer('(?:', rule('ipv6Hex'), '(?::',
                rule('ipv6Hex'), '){,5})?::(?:', rule('ipv6Hex'), '(?::',
                rule('ipv6Hex'), '){,5})?')

ipv6v4Full = qwer(rule('ipv6Hex'), '(?::', rule('ipv6Hex'), '){5}:',
                  rule('ipv4AddressLiteral'))

# The "::" represents at least 2 16-bit groups of zeros.  No more than 4 groups
# in addition to the "::" and IPv4-address-literal may be present
ipv6v4Comp = qwer('(?:', rule('ipv6Hex'), '(?::',
                  rule('ipv6Hex'), '){,3})?::(?:', rule('ipv6Hex'), '(?::',
                  rule('ipv6Hex'), '){,3}:)?', rule('ipv4AddressLiteral'))
コード例 #7
0
ファイル: rfc6265.py プロジェクト: jablko/openid
import rfc2616
from qwer import *
from untwisted import rfc5234

cookieName = rule('rfc2616.token')

# US-ASCII characters excluding CTLs, whitespace DQUOTE, comma,
# semicolon, and backslash
cookieOctet = qwer('[!#-+--:<-[\]-~]')

cookieValue = qwer('(?:(?:', rule('cookieOctet'), ')*|(?:', rule('rfc5234.DQUOTE'), '(?:', rule('cookieOctet'), ')*', rule('rfc5234.DQUOTE'), '))')
cookiePair = qwer(rule('cookieName'), '=', rule('cookieValue'))
cookieString = qwer(rule('cookiePair'), '(?:; ', rule('cookiePair'), ')*')
コード例 #8
0
from qwer import *

ALPHA = qwer('[A-Za-z]')

# Use local newlines
CRLF = qwer('\r\n')

DIGIT = qwer('\d')
DQUOTE = qwer('"')
HEXDIG = qwer('[\dABCDEF]')

# 8 bits of data
OCTET = qwer('[\0-\xff]')

# Visible (printing) characters
VCHAR = qwer('[!-~]')

# White space
WSP = qwer('[\t ]')
コード例 #9
0
ファイル: rfc5321.py プロジェクト: jablko/qwer
import rfc5234, rfc5322
from qwer import *

letDig = qwer('(?:', rule('rfc5234.ALPHA'), '|', rule('rfc5234.DIGIT'), ')')
ldhStr = qwer('(?:', rule('rfc5234.ALPHA'), '|', rule('rfc5234.DIGIT'), '|-)*', rule('letDig'))
subDomain = qwer(rule('letDig'), '(?:', rule('ldhStr'), ')?')
domain = qwer(rule('subDomain'), '(?:\.', rule('subDomain'), ')*')

# Representing a decimal integer value in the range 0 through 255
snum = qwer('(?:', rule('rfc5234.DIGIT'), '){1,3}')

ipv4AddressLiteral = qwer(rule('snum'), '(?:\.', rule('snum'), '){3}')
ipv6Hex = qwer('(?:', rule('rfc5234.HEXDIG'), '){1,4}')
ipv6Full = qwer(rule('ipv6Hex'), '(?::', rule('ipv6Hex'), '){7}')

# The "::" represents at least 2 16-bit groups of zeros.  No more than 6 groups
# in addition to the "::" may be present
ipv6Comp = qwer('(?:', rule('ipv6Hex'), '(?::', rule('ipv6Hex'), '){,5})?::(?:', rule('ipv6Hex'), '(?::', rule('ipv6Hex'), '){,5})?')

ipv6v4Full = qwer(rule('ipv6Hex'), '(?::', rule('ipv6Hex'), '){5}:', rule('ipv4AddressLiteral'))

# The "::" represents at least 2 16-bit groups of zeros.  No more than 4 groups
# in addition to the "::" and IPv4-address-literal may be present
ipv6v4Comp = qwer('(?:', rule('ipv6Hex'), '(?::', rule('ipv6Hex'), '){,3})?::(?:', rule('ipv6Hex'), '(?::', rule('ipv6Hex'), '){,3}:)?', rule('ipv4AddressLiteral'))

ipv6Addr = qwer('(?:', rule('ipv6Full'), '|', rule('ipv6Comp'), '|', rule('ipv6v4Full'), '|', rule('ipv6v4Comp'), ')')
ipv6AddressLiteral = qwer('IPv6:', rule('ipv6Addr'))

# Standardized-tag MUST be specified in a Standards-Track RFC and registered
# with IANA
standardizedTag = qwer(rule('ldhStr'))
コード例 #10
0
ファイル: rfc4871.py プロジェクト: jablko/mail
from qwer import *
from untwisted import rfc5234, rfc5322

ALNUMPUNC = qwer('(?:', rfc5234.ALPHA, '|', rfc5234.DIGIT, '|_)')
tagName = qwer(rfc5234.ALPHA, '(?:', ALNUMPUNC, ')*')

# EXCLAMATION to TILDE except SEMICOLON
VALCHAR = qwer('[!-:<-~]')

tval = qwer('(?:', VALCHAR, ')+')

# WSP and FWS prohibited at beginning and end
tagValue = qwer('(?:', tval, '(?:(?:', rfc5234.WSP, '|', rfc5322.FWS, ')+', tval, ')*)?')

tagSpec = qwer('(?:', rfc5322.FWS, ')?', tagName, '(?:', rfc5322.FWS, ')?=(?:', rfc5322.FWS, ')?', tagValue, '(?:', rfc5322.FWS, ')?')
tagList = qwer(tagSpec, '(?:;', tagSpec, ')*;?')
コード例 #11
0
ファイル: sip.py プロジェクト: jablko/untwisted
def client(method, requestUri, initiator):
  match = qwer(rfc3261.requestUri, '$').match(requestUri, '( host, hostname, maddrParam, port )')

  # We define TARGET as the value of the maddr parameter of the URI, if
  # present, otherwise, the host value of the hostport component of the URI
  if match.maddrParam:
    target = match.maddrParam.host

  else:
    target = match.host

  if match.port:
    port = match.port

  elif target.hostname:
    try:
      result = yield dns.lookup('_sip._udp.' + str(target), dns.SRV)

    except dns.message as e:
      if dns.nameError != e.rcode:
        raise

      port = 'sip'

    else:
      target = result.answer.target
      port = result.answer.port

  else:
    port = 'sip'

  transport = yield udp.connect(str(target), port)()

  asdf = request()

  asdf.method = method
  asdf.requestUri = requestUri
  asdf.sipVersion = 'SIP/2.0'

  asdf.header.append('To', requestUri)
  asdf.header.append('From', initiator + ';tag=' + untwisted.randstr(6, '!%\'*+-.0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_`abcdefghijklmnopqrstuvwxyz~'))
  asdf.header.append('Call-ID', untwisted.randstr(6, '!"%\'()*+-./0123456789:<>?ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]_`abcdefghijklmnopqrstuvwxyz{}~') + '@' + domain)
  asdf.header.append('CSeq', '0 ' + method)

  # A UAC MUST insert a Max-Forwards header field into each request it
  # originates with a value that SHOULD be 70
  asdf.header.append('Max-Forwards', '70')

  host, port = transport.socket.getsockname()
  sentBy = host + ':' + str(port)

  # The branch ID inserted by an element compliant with this specification MUST
  # always begin with the characters "z9hG4bK"
  #asdf.header.append('Via', 'SIP/2.0/UDP {};branch=z9hG4bK'.format(sentBy) + untwisted.randstr(6, '!%\'*+-.0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_`abcdefghijklmnopqrstuvwxyz~'))
  asdf.header.append('Via', 'SIP/2.0/UDP {0};branch=z9hG4bK'.format(sentBy) + untwisted.randstr(6, '!%\'*+-.0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_`abcdefghijklmnopqrstuvwxyz~'))

  asdf.content = ''

  transport.write(str(asdf))

  while True:
    recv = yield transport.recv()

    match = rfc3261.response.match(recv, '( sipVersion, statusCode, reasonPhrase, messageBody )')
    if int(match.statusCode) not in range(100, 200):
      result = response()

      result.sipVersion = str(match.sipVersion)
      result.statusCode = int(match.statusCode)
      result.reasonPhrase = str(match.reasonPhrase)

      result.content = str(match.messageBody)

      if int(result) not in range(200, 300):
        raise result

      #return ...
      raise StopIteration(result)
コード例 #12
0
import rfc5234
from qwer import *

decOctet = qwer('(?:', rule('rfc5234.DIGIT'), # 0-9
  '|[1-9]', rule('rfc5234.DIGIT'), # 10-99
  '|1(?:', rule('rfc5234.DIGIT'), '){2}', # 100-199
  '|2[0-4]', rule('rfc5234.DIGIT'), # 200-249
  '|25[0-5])') # 250-255

ipv4Address = qwer(rule('decOctet'), '\.', rule('decOctet'), '\.', rule('decOctet'), '\.', rule('decOctet'))

# 16 bits of address represented in hexadecimal
h16 = qwer('(?:', rule('rfc5234.HEXDIG'), '){1,4}')

# least-significant 32 bits of address
ls32 = qwer('(?:', rule('h16'), ':', rule('h16'), '|', rule('ipv4Address'), ')')

ipv6Address = qwer('(?:(?:', rule('h16'), ':){6}', rule('ls32'),
  '|::(?:', rule('h16'), ':){5}', rule('ls32'),
  '|(?:', rule('h16'), ')?::(?:', rule('h16'), ':){4}', rule('ls32'),
  '|(?:(?:', rule('h16'), ':){,1}', rule('h16'), ')?::(?:', rule('h16'), ':){3}', rule('ls32'),
  '|(?:(?:', rule('h16'), ':){,2}', rule('h16'), ')?::(?:', rule('h16'), ':){2}', rule('ls32'),
  '|(?:(?:', rule('h16'), ':){,3}', rule('h16'), ')?::', rule('h16'), ':', rule('ls32'),
  '|(?:(?:', rule('h16'), ':){,4}', rule('h16'), ')?::', rule('ls32'),
  '|(?:(?:', rule('h16'), ':){,5}', rule('h16'), ')?::', rule('h16'),
  '|(?:(?:', rule('h16'), ':){,6}', rule('h16'), ')?::)')
unreserved = qwer('(?:', rule('rfc5234.ALPHA'), '|', rule('rfc5234.DIGIT'), '|[-._~])')
subDelims = qwer('[!$&\'()*+,;=]')
ipvFuture = qwer('v(?:', rule('rfc5234.HEXDIG'), ')+\.(?:', rule('unreserved'), '|', rule('subDelims'), '|:)+')
ipLiteral = qwer('\[(?:', rule('ipv6Address'), '|', rule('ipvFuture'), ')]')
scheme = qwer(rule('rfc5234.ALPHA'), '(?:', rule('rfc5234.ALPHA'), '|', rule('rfc5234.DIGIT'), '|[+\-.])*')
コード例 #13
0
import rfc5234
from qwer import *

# Folding white space
FWS = qwer('(?:(?:', rule('rfc5234.WSP'), ')*', rule('rfc5234.CRLF'), ')?(?:', rule('rfc5234.WSP'), ')+')

# Printable US-ASCII characters not including "(", ")", or "\"
ctext = qwer('[!-\'*-[\]-~]')

quotedPair = qwer('\\\(?:', rule('rfc5234.VCHAR'), '|', rule('rfc5234.WSP'), ')')

# Recursive
ccontent = qwer('(?:', rule('ctext'), '|', rule('quotedPair'), ')')

comment = qwer('\((?:(?:', rule('FWS'), ')?', rule('ccontent'), ')*(?:', rule('FWS'), ')?\)')
CFWS = qwer('(?:(?:(?:', rule('FWS'), ')?', rule('comment'), ')+(?:', rule('FWS'), ')?|', rule('FWS'), ')')

# Printable US-ASCII characters not including specials.  Used for atoms
atext = qwer('(?:[!#$%&\'*+\-/=?^_`{|}~]|', rule('rfc5234.ALPHA'), '|', rule('rfc5234.DIGIT'), ')')

atom = qwer('(?:', rule('CFWS'), ')?(?:', rule('atext'), ')+(?:', rule('CFWS'), ')?')

# Printable US-ASCII characters not including "\" or the quote character
qtext = qwer('[!#-[\]-~]')

qcontent = qwer('(?:', rule('qtext'), '|', rule('quotedPair'), ')')
quotedString = qwer('(?:', rule('CFWS'), ')?', rule('rfc5234.DQUOTE'), '(?:(?:', rule('FWS'), ')?', rule('qcontent'), ')*(?:', rule('FWS'), ')?', rule('rfc5234.DQUOTE'), '(?:', rule('CFWS'), ')?')
word = qwer('(?:', rule('atom'), '|', rule('quotedString'), ')')
phrase = qwer('(?:', rule('word'), ')+')
displayName = rule('phrase')
dotAtomText = qwer('(?:', rule('atext'), ')+(?:\.(?:', rule('atext'), ')+)*')
コード例 #14
0
ファイル: rfc2616.py プロジェクト: jablko/openid
from qwer import *

# Any CHAR except CTLs or separators
token = qwer('[!#-\'*+\--9A-Z^-z|~]+')
コード例 #15
0
ファイル: rfc2616.py プロジェクト: jablko/untwisted
import rfc3986
from qwer import *

# Any CHAR except CTLs or separators
token = qwer('[!#-\'*+\--9A-Z^-z|~]+')

requestUri = qwer('(?:\*|', rule('rfc3986.absoluteUri'), '|', rule('rfc3986.pathAbsolute'), '|', rule('rfc3986.authority'), ')')
コード例 #16
0
def client(method, requestUri, initiator):
    match = qwer(rfc3261.requestUri,
                 '$').match(requestUri, '( host, hostname, maddrParam, port )')

    # We define TARGET as the value of the maddr parameter of the URI, if
    # present, otherwise, the host value of the hostport component of the URI
    if match.maddrParam:
        target = match.maddrParam.host

    else:
        target = match.host

    if match.port:
        port = match.port

    elif target.hostname:
        try:
            result = yield dns.lookup('_sip._udp.' + str(target), dns.SRV)

        except dns.message as e:
            if dns.nameError != e.rcode:
                raise

            port = 'sip'

        else:
            target = result.answer.target
            port = result.answer.port

    else:
        port = 'sip'

    transport = yield udp.connect(str(target), port)()

    asdf = request()

    asdf.method = method
    asdf.requestUri = requestUri
    asdf.sipVersion = 'SIP/2.0'

    asdf.header.append('To', requestUri)
    asdf.header.append(
        'From', initiator + ';tag=' + untwisted.randstr(
            6,
            '!%\'*+-.0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_`abcdefghijklmnopqrstuvwxyz~'
        ))
    asdf.header.append(
        'Call-ID',
        untwisted.randstr(
            6,
            '!"%\'()*+-./0123456789:<>?ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]_`abcdefghijklmnopqrstuvwxyz{}~'
        ) + '@' + domain)
    asdf.header.append('CSeq', '0 ' + method)

    # A UAC MUST insert a Max-Forwards header field into each request it
    # originates with a value that SHOULD be 70
    asdf.header.append('Max-Forwards', '70')

    host, port = transport.socket.getsockname()
    sentBy = host + ':' + str(port)

    # The branch ID inserted by an element compliant with this specification MUST
    # always begin with the characters "z9hG4bK"
    #asdf.header.append('Via', 'SIP/2.0/UDP {};branch=z9hG4bK'.format(sentBy) + untwisted.randstr(6, '!%\'*+-.0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_`abcdefghijklmnopqrstuvwxyz~'))
    asdf.header.append(
        'Via',
        'SIP/2.0/UDP {0};branch=z9hG4bK'.format(sentBy) + untwisted.randstr(
            6,
            '!%\'*+-.0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_`abcdefghijklmnopqrstuvwxyz~'
        ))

    asdf.content = ''

    transport.write(str(asdf))

    while True:
        recv = yield transport.recv()

        match = rfc3261.response.match(
            recv, '( sipVersion, statusCode, reasonPhrase, messageBody )')
        if int(match.statusCode) not in range(100, 200):
            result = response()

            result.sipVersion = str(match.sipVersion)
            result.statusCode = int(match.statusCode)
            result.reasonPhrase = str(match.reasonPhrase)

            result.content = str(match.messageBody)

            if int(result) not in range(200, 300):
                raise result

            #return ...
            raise StopIteration(result)
コード例 #17
0
import rfc3986, rfc5234, rfc5322
from qwer import *

# This memo descripes version 0
protoVersion = qwer('v=(?:', rule('rfc5234.DIGIT'), ')+', rule('rfc5234.CRLF'))

# String of visible characters
nonWsString = qwer('(?:', rule('rfc5234.VCHAR'), '|[\x80-\xff])+')

# Pretty side definition, but doesn't include space
username = rule('nonWsString')

# Should be unique for this username/host
sessId = qwer('(?:', rule('rfc5234.DIGIT'), ')+')

sessVersion = qwer('(?:', rule('rfc5234.DIGIT'), ')+')

# Typically "IN"
nettype = rule('token')

# Typically "IP4" or "IP6"
addrtype = rule('token')

hex4 = qwer('(?:', rule('rfc5234.HEXDIG'), '){1,4}')
hexseq = qwer(rule('hex4'), '(?::', rule('hex4'), ')*')
hexpart = qwer('(?:', rule('hexseq'), '|', rule('hexseq'), '::(?:',
               rule('hexseq'), ')?|::(?:', rule('hexseq'), ')?)')
posDigit = qwer('[1-9]')
decimalUchar = qwer('(?:', rule('rfc5234.DIGIT'), '|', rule('posDigit'),
                    rule('rfc5234.DIGIT'), '|1(?:', rule('rfc5234.DIGIT'),
                    '){2}|2[0-4]', rule('rfc5234.DIGIT'), '|25[0-5])')
コード例 #18
0
ファイル: rfc5322.py プロジェクト: jablko/qwer
import rfc5234
from qwer import *

# Folding white space
FWS = qwer('(?:(?:', rule('rfc5234.WSP'), ')*', rule('rfc5234.CRLF'), ')?(?:', rule('rfc5234.WSP'), ')+')

# Printable US-ASCII characters not including "(", ")", or "\"
ctext = qwer('[!-\'*-[\]-~]')

quotedPair = qwer('\\\(?:', rule('rfc5234.VCHAR'), '|', rule('rfc5234.WSP'), ')')

# Recursive
ccontent = qwer('(?:', rule('ctext'), '|', rule('quotedPair'), ')')

comment = qwer('\((?:(?:', rule('FWS'), ')?', rule('ccontent'), ')*(?:', rule('FWS'), ')?\)')
CFWS = qwer('(?:(?:(?:', rule('FWS'), ')?', rule('comment'), ')+(?:', rule('FWS'), ')?|', rule('FWS'), ')')

# Printable US-ASCII characters not including specials.  Used for atoms
atext = qwer('(?:[!#$%&\'*+\-/=?^_`{|}~]|', rule('rfc5234.ALPHA'), '|', rule('rfc5234.DIGIT'), ')')

atom = qwer('(?:', rule('CFWS'), ')?(?:', rule('atext'), ')+(?:', rule('CFWS'), ')?')

# Printable US-ASCII characters not including "\" or the quote character
qtext = qwer('[!#-[\]-~]')

qcontent = qwer('(?:', rule('qtext'), '|', rule('quotedPair'), ')')
quotedString = qwer('(', rule('CFWS'), ')?', rule('rfc5234.DQUOTE'), '(?:(?:', rule('FWS'), ')?', rule('qcontent'), ')*(?:', rule('FWS'), ')?', rule('rfc5234.DQUOTE'), '(?:', rule('CFWS'), ')?')
word = qwer('(?:', rule('atom'), '|', rule('quotedString'), ')')
phrase = qwer('(?:', rule('word'), ')+')
displayName = qwer(rule('phrase'))
dotAtomText = qwer('(?:', rule('atext'), ')+(?:\.(?:', rule('atext'), ')+)*')
コード例 #19
0
import rfc2616, rfc3966, rfc5234
from qwer import *

alphanum = qwer('(?:', rule('rfc5234.ALPHA'), '|', rule('rfc5234.DIGIT'), ')')
mark = qwer('[!\'()*\-._~]')
unreserved = qwer('(?:', rule('alphanum'), '|', rule('mark'), ')')
escaped = qwer('%', rule('rfc5234.HEXDIG'), rule('rfc5234.HEXDIG'))
userUnreserved = qwer('[$&+,/;=?]')
user = qwer('(?:', rule('unreserved'), '|', rule('escaped'), '|',
            rule('userUnreserved'), ')+')
password = qwer('(?:', rule('unreserved'), '|', rule('escaped'), '|[$&+,=])*')
userinfo = qwer('(?:', rule('user'), '|', rule('rfc3966.telephoneSubscriber'),
                ')(?::', rule('password'), ')?@')
domainlabel = qwer('(?:', rule('alphanum'), '|', rule('alphanum'), '(?:',
                   rule('alphanum'), '|-)*', rule('alphanum'), ')')
toplabel = qwer('(?:', rule('rfc5234.ALPHA'), '|', rule('rfc5234.ALPHA'),
                '(?:', rule('alphanum'), '|-)*', rule('alphanum'), ')')
hostname = qwer('(?:', rule('domainlabel'), '\.)*', rule('toplabel'), '\.?')
hex4 = qwer('(?:', rule('rfc5234.HEXDIG'), '){1,4}')
hexseq = qwer(rule('hex4'), '(?::', rule('hex4'), ')*')
hexpart = qwer('(?:', rule('hexseq'), '|', rule('hexseq'), '::(?:',
               rule('hexseq'), ')?|::(?:', rule('hexseq'), ')?)')
ipv4address = qwer('(?:', rule('rfc5234.DIGIT'), '){1,3}\.(?:',
                   rule('rfc5234.DIGIT'), '){1,3}\.(?:', rule('rfc5234.DIGIT'),
                   '){1,3}\.(?:', rule('rfc5234.DIGIT'), '){1,3}')
ipv6address = qwer(rule('hexpart'), '(?::', rule('ipv4address'), ')?')
ipv6reference = qwer('\[', rule('ipv6address'), ']')
host = qwer('(?:', rule('hostname'), '|', rule('ipv4address'), '|',
            rule('ipv6reference'), ')')
port = qwer('(?:', rule('rfc5234.DIGIT'), ')+')
hostport = qwer(rule('host'), '(?::', rule('port'), ')?')