示例#1
0
				raise Exception("Invalid header in message (%s)" % str(l))
		
		ret['body'] = "\r\n".join(lines[i:])
		
		return (ret, self.getSummary(ret))

	def getSummary(self, template):
		"""
		Returns the summary of the template representing an RTSP message.
		(meaningful, short, human-understandable description)
		"""
		return template['method']


		
CodecManager.registerCodecClass('rtsp.request', RtspRequestCodec)


class RtspResponseCodec(CodecManager.Codec):
	"""
	See documentation in RtspRequestCodec.
	"""
	def __init__(self):
		CodecManager.Codec.__init__(self)
		self.setDefaultProperty('lower_case', False)
		self.setDefaultProperty('version', 'RTSP/1.0')
	
	def encode(self, template):
		status = template['status']
		reason = template['reason']
		version = template.get('version', self[version])
示例#2
0
	== See Also ==
	
	The mapping between ASN.1 and Testerman structures is documented [Asn1ToTesterman here].

	"""
	PDU = Snmpv1Asn.Message

	def getSummary(self, message):
		try:
			# message is a sequence (version, community, data = choice(...)).
			return 'SNMP v1 %s' % (message['data'][0])
		except:
			return super.getSummary(message)

CodecManager.registerCodecClass('snmp.v1', Snmpv1Codec)


class Snmpv2cCodec(BerCodec.BerCodec):
	"""
	= Identification and Properties =
	
	Codec IDs: `snmp.v2c`
	
	Properties:
	|| '''Name''' || '''Type''' || '''Default value''' || '''Description''' ||
	
	= Overview =
	
	== Decoding ==
	
示例#3
0
##

import CodecManager

import pickle
import base64
import json

class PickleCodec(CodecManager.Codec):
	def encode(self, template):
		return (pickle.dumps(template), 'pickle data')
	
	def decode(self, data):
		return (pickle.loads(data), None)

CodecManager.registerCodecClass('pickle', PickleCodec)

class Base64Codec(CodecManager.Codec):
	def encode(self, template):
		return (base64.encodestring(template), 'base64 data')
	
	def decode(self, data):
		return (base64.decodestring(data), None)

CodecManager.registerCodecClass('base64', Base64Codec)


class JsonCodec(CodecManager.Codec):
	def encode(self, template):
		return (json.dumps(template), 'json data')
示例#4
0
				if bl < cl:
					return self.needMoreData()
				elif bl > cl:
					# Truncate the body
					ret['body'] = ret['body'][:cl]
		
		return self.decoded(ret, self.getSummary(ret))

	def getSummary(self, template):
		"""
		Returns the summary of the template representing an RTSP message.
		(meaningful, short, human-understandable description)
		"""
		return '%s %s' % (template.get('method', 'GET'), template['url'])
		
CodecManager.registerCodecClass('http.request', HttpRequestCodec)


class HttpResponseCodec(CodecManager.IncrementalCodec):
	"""
	= Identification and Properties =
	
	Codec IDs: `http.response`

	Properties:
	|| '''Name''' || '''Type''' || '''Default value''' || '''Description''' ||
	|| header_encoding || string  || `'iso8859-1'` || Encoding to use to encode header values. ||

	= Overview =

	This codec enables to encode/decode HTTP 1.0/1.1 responses,
示例#5
0
    def __init__(self):
        CodecManager.Codec.__init__(self)
        self.setDefaultProperty('filler', 0x0f)  # Usually 0x0f or 0x00

    def encode(self, template):
        """
		Template is a string of human readable digits
		"""
        return (string2tbcd(template, self['filler']), template)

    def decode(self, data):
        ret = tbcd2string(data)
        return (ret, ret)


CodecManager.registerCodecClass('tbcd', TbcdCodec)


class Packed7bitCodec(CodecManager.Codec):
    """
	Converts a template:
	type octetstring Template;
	"""
    def __init__(self):
        CodecManager.Codec.__init__(self)

    def encode(self, template):
        """
		Template is a string of human readable digits
		"""
        return (encode_7bitpacked(template, ), template)
示例#6
0
##
# The Testerman codec interface to the codec
##

class SipBasicCodec(CodecManager.Codec):
	def encode(self, template):
		return (encodeMessage(template), getSummary(template))

	def decode(self, data):
		ret = decodeMessage(data)
		summary = getSummary(ret)
		return (ret, summary)

if __name__ != '__main__':
	CodecManager.registerCodecClass('sip.basic', SipBasicCodec)

else:


	sets = [

	# Message
	('Message',
	decodeMessage, encodeMessage, [
"""INVITE sip:146127953@esg SIP/2.0
Via: SIP/2.0/UDP 172.16.4.238:57516;branch=z9hG4bK-d8754z-55019e456f11e949-1---d8754z-;rport
Max-Forwards: 70
Contact: <sip:[email protected]:57516>
To: "146127953"<sip:146127953@esg>
From: "Seb"<sip:seb@esg>;tag=f4287c66
示例#7
0
        return (m.toNetwork(), m.summary())

    def incrementalDecode(self, data, complete):
        m = Message()
        try:
            m.fromNetwork(data)
        except IncompleteMessageException:
            return (self.DECODING_NEED_MORE_DATA, 0, None, None)
        except Exception:
            return (self.DECODING_ERROR, getDecodedLength()
                    or len(data), None, None)
        return (self.DECODING_OK, m.getDecodedLength(), m.toUserland(),
                m.summary())


CodecManager.registerCodecClass('sua', SuaCodec)

if __name__ == '__main__':
    print("SUA Codec unit tests")
    print(80 * '-')
    samples = [
        # SUA ASP active / Load-share, routing context 300
        "0100040100000018000b000800000002000600080000012c",
        # SUA ERR / Refused - management blocking, network appearance 0, some diagnostic info
        "0100000000000034000c00080000000d010d0008000000000007001c0100040100000018000b000800000002000600080000012c",
        # MAP SRI
        "01000701000000cc000600080000012c01150008000000000102002c0001000780010012000000040c0001042610101010100000800200080000057880030008000000080103002c0001000780010012000000040c000104262143658739000080020008000007d28003000800000006011600080000000001010008000000ff010b004962434804000200686b1a2818060700118605010101a00d600ba1090607040000010014026c1fa11d02010102012d30158007910026151101008101ff820791261010101010000000"
    ]

    for s in samples:
        print("Testing: %s" % s)
示例#8
0
            if ns: d['ns'] = ns
            return (tag, d)

        if hasElementChild:
            # only element children
            d = {'attributes': attributes, 'children': children}
            if ns: d['ns'] = ns
            return (tag, d)

        # no child, or a single text child
        d = {'attributes': attributes, 'cdata': cdata, 'value': value}
        if ns: d['ns'] = ns
        return (tag, d)


CodecManager.registerCodecClass('xml', XmlCodec)

if __name__ == '__main__':
    CodecManager.alias('xml.noprolog', 'xml', write_prolog=False)
    CodecManager.alias('xml.iso',
                       'xml',
                       encoding="iso-8859-1",
                       write_prolog=True)
    CodecManager.alias('xml.pretty', 'xml', prettyprint=True)

    sampleNoNs = """<?xml version="1.0" encoding="utf-8" ?>
<library owner="John Smith" administrator="Héléna Utf8 and Mickaël Orangina">
	<book isbn="88888-7777788">
		<author>Mickaël Orangina</author>
		<title locale="fr">Tonnerre sous les tropiques</title>
		<title locale="us">Tropic thunder</title>
示例#9
0
	"""
	def __init__(self):
		CodecManager.Codec.__init__(self)
		self.setDefaultProperty('filler', 0x0f) # Usually 0x0f or 0x00
		
	def encode(self, template):
		"""
		Template is a string of human readable digits
		"""
		return (string2tbcd(template, self['filler']), template)
	
	def decode(self, data):
		ret = tbcd2string(data)
		return (ret, ret)

CodecManager.registerCodecClass('tbcd', TbcdCodec)


class Packed7bitCodec(CodecManager.Codec):
	"""
	Converts a template:
	type octetstring Template;
	"""
	def __init__(self):
		CodecManager.Codec.__init__(self)
		
	def encode(self, template):
		"""
		Template is a string of human readable digits
		"""
		return (encode_7bitpacked(template,), template)
示例#10
0
文件: Rtsp.py 项目: rishie/testerman
            else:
                raise Exception("Invalid header in message (%s)" % str(l))

        ret['body'] = "\r\n".join(lines[i:])

        return (ret, self.getSummary(ret))

    def getSummary(self, template):
        """
		Returns the summary of the template representing an RTSP message.
		(meaningful, short, human-understandable description)
		"""
        return template['method']


CodecManager.registerCodecClass('rtsp.request', RtspRequestCodec)


class RtspResponseCodec(CodecManager.Codec):
    """
	See documentation in RtspRequestCodec.
	"""
    def __init__(self):
        CodecManager.Codec.__init__(self)
        self.setDefaultProperty('lower_case', False)
        self.setDefaultProperty('version', 'RTSP/1.0')

    def encode(self, template):
        status = template['status']
        reason = template['reason']
        version = template.get('version', self[version])
示例#11
0
文件: Sip.py 项目: rishie/testerman
	return '\r\n'.join(ret)


##
# The Testerman codec interface to the codec
##

class SipCodec(CodecManager.Codec):
	def encode(self, template):
		return (encodeMessage(template), 'SIP message')

	def decode(self, data):
		return (decodeMessage(data), 'SIP message')

if __name__ != '__main__':
	CodecManager.registerCodecClass('sip', SipCodec)

else:


	sets = [

	# NameAddr
	("NameAddr",
	decode_NameAddr, encode_NameAddr, [
	'sip:user@domain',
	'sip:123@domain;user=phone',
	'tel:12345',
	'<sip:user@domain>',
	'<sip:123@domain;user=phone>',
	'<tel:12345>',
示例#12
0
文件: Sdp.py 项目: rolfschr/testerman
				media = { 'name_transport': line[2:], 'bandwidths': [], 'attributes': []}
				ret['media'].append(media)
				
			if media is None:
				# Session parameters
				if line.startswith('v='):	ret['version'] = line[2:]
				elif line.startswith('o='):	ret['originator'] = line[2:]
				elif line.startswith('s='):	ret['name'] = line[2:]
				elif line.startswith('i='):	ret['information'] = line[2:]
				elif line.startswith('u='):	ret['description_uri'] = line[2:]
				elif line.startswith('e='):	ret['email_address'] = line[2:]
				elif line.startswith('p='):	ret['phone_number'] = line[2:]
				elif line.startswith('c='):	ret['connection'] = line[2:]
				elif line.startswith('k='):	ret['key'] = line[2:]
				elif line.startswith('t='):	ret['time'] = line[2:]
				elif line.startswith('r='):	ret['repeats'].append(line[2:])
				elif line.startswith('b='):	ret['bandwidths'].append(line[2:])
				elif line.startswith('a='):	ret['attributes'].append(line[2:])
			else:
				if line.startswith('i='):	media['title'] = line[2:]
				elif line.startswith('c='):	media['connection'] = line[2:]
				elif line.startswith('k='):	media['key'] = line[2:]
				elif line.startswith('b='):	media['bandwidths'].append(line[2:])
				elif line.startswith('a='):	media['attributes'].append(line[2:])
		
		return (ret, 'SDP')
		
CodecManager.registerCodecClass('sdp', SdpCodec)


示例#13
0
##
# MAP (2+) Codec
# To compile MapAsn: cd ber && ./py_output.py asn/AMP-All.asn > MapAsn.py
##

import CodecManager

import ber.BerCodec as BerCodec
import ber.MapAsn as MapAsn

# SMS management: SRI and MT Forward
class RoutingInfoForSM_ArgCodec(BerCodec.BerCodec):
	PDU = MapAsn.RoutingInfoForSM_Arg
	def getSummary(self, message): return 'RoutingInfoForSM-Arg'
CodecManager.registerCodecClass('map.RoutingInfoForSM-Arg', RoutingInfoForSM_ArgCodec)

class RoutingInfoForSM_ResCodec(BerCodec.BerCodec):
	PDU = MapAsn.RoutingInfoForSM_Res
	def getSummary(self, message): return 'RoutingInfoForSM-Res'
CodecManager.registerCodecClass('map.RoutingInfoForSM-Res', RoutingInfoForSM_ResCodec)

class MT_ForwardSM_ArgCodec(BerCodec.BerCodec):
	PDU = MapAsn.MT_ForwardSM_Arg
	def getSummary(self, message): return 'MT-ForwardSM-Arg'
CodecManager.registerCodecClass('map.MT-ForwardSM-Arg', MT_ForwardSM_ArgCodec)

class MT_ForwardSM_ResCodec(BerCodec.BerCodec):
	PDU = MapAsn.MT_ForwardSM_Res
	def getSummary(self, message): return 'MT-ForwardSM-Res'
CodecManager.registerCodecClass('map.MT-ForwardSM-Res', MT_ForwardSM_ResCodec)
示例#14
0
##
# This file is part of Testerman, a test automation system.
# Copyright (c) 2008-2009 Sebastien Lefevre and other contributors
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation; either version 2 of the License, or (at your option) any later
# version.
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
# details.
##

##
# ZLIB/GZIP codec.
##

import CodecManager

import zlib

class GZipCodec(CodecManager.Codec):
	def encode(self, template):
		return (zlib.compress(template), 'GZIP data')
	
	def decode(self, data):
		return (zlib.decompress(data), None)

CodecManager.registerCodecClass('gzip', GZipCodec)
示例#15
0
	== See Also ==
	
	The mapping between ASN.1 and Testerman structures is documented [Asn1ToTesterman here].

	"""
    PDU = Snmpv1Asn.Message

    def getSummary(self, message):
        try:
            # message is a sequence (version, community, data = choice(...)).
            return 'SNMP v1 %s' % (message['data'][0])
        except:
            return super.getSummary(message)


CodecManager.registerCodecClass('snmp.v1', Snmpv1Codec)


class Snmpv2cCodec(BerCodec.BerCodec):
    """
	= Identification and Properties =
	
	Codec IDs: `snmp.v2c`
	
	Properties:
	|| '''Name''' || '''Type''' || '''Default value''' || '''Description''' ||
	
	= Overview =
	
	== Decoding ==
	
示例#16
0
                ret['media'].append(media)

            if media is None:
                # Session parameters
                if line.startswith('v='): ret['version'] = line[2:]
                elif line.startswith('o='): ret['originator'] = line[2:]
                elif line.startswith('s='): ret['name'] = line[2:]
                elif line.startswith('i='): ret['information'] = line[2:]
                elif line.startswith('u='): ret['description_uri'] = line[2:]
                elif line.startswith('e='): ret['email_address'] = line[2:]
                elif line.startswith('p='): ret['phone_number'] = line[2:]
                elif line.startswith('c='): ret['connection'] = line[2:]
                elif line.startswith('k='): ret['key'] = line[2:]
                elif line.startswith('t='): ret['time'] = line[2:]
                elif line.startswith('r='): ret['repeats'].append(line[2:])
                elif line.startswith('b='): ret['bandwidths'].append(line[2:])
                elif line.startswith('a='): ret['attributes'].append(line[2:])
            else:
                if line.startswith('i='): media['title'] = line[2:]
                elif line.startswith('c='): media['connection'] = line[2:]
                elif line.startswith('k='): media['key'] = line[2:]
                elif line.startswith('b='):
                    media['bandwidths'].append(line[2:])
                elif line.startswith('a='):
                    media['attributes'].append(line[2:])

        return (ret, 'SDP')


CodecManager.registerCodecClass('sdp', SdpCodec)
示例#17
0
		"""
		tag = element.tagName
		
		# Now retrieve children, if any
		children = []
		for node in element.childNodes:
			if node.nodeType == node.ELEMENT_NODE:
				children.append(self._decode(node))
			# We should return only if these nodes are the first one.. ?
			elif node.nodeType == node.TEXT_NODE and node.nodeValue.strip():
				return (tag, node.nodeValue.strip())
			# Ignore other final node types (cdata, comments, ...)
		
		return (tag, children) 

CodecManager.registerCodecClass('xer.lite', XerLiteCodec)


if __name__ == '__main__':
	CodecManager.alias('xer.noprolog', 'xer.lite', write_prolog = False)
	CodecManager.alias('xer.iso', 'xer.lite', encoding = "iso-8859-1")
	CodecManager.alias('xer.canonical', 'xer.lite', canonical = True)
	
	sample = """<?xml version="1.0"?>
<library>
	<administrator>Héléna Utf8</administrator>
	<book>
		<isbn>89084-89089</isbn>
		<author>Philippe Kendall</author>
		<author>Mickaël Orangina</author>
		<title>Tropic thunder</title>
示例#18
0
文件: Xml.py 项目: rolfschr/testerman
			if ns: d['ns'] = ns
			return (tag, d)

		if hasElementChild:
			# only element children
			d = { 'attributes': attributes, 'children': children }
			if ns: d['ns'] = ns
			return (tag, d)

		# no child, or a single text child
		d = { 'attributes': attributes, 'cdata': cdata, 'value': value }
		if ns: d['ns'] = ns
		return (tag, d)
	

CodecManager.registerCodecClass('xml', XmlCodec)


if __name__ == '__main__':
	CodecManager.alias('xml.noprolog', 'xml', write_prolog = False)
	CodecManager.alias('xml.iso', 'xml', encoding = "iso-8859-1", write_prolog = True)
	CodecManager.alias('xml.pretty', 'xml', prettyprint = True)
	
	sampleNoNs = """<?xml version="1.0" encoding="utf-8" ?>
<library owner="John Smith" administrator="Héléna Utf8 and Mickaël Orangina">
	<book isbn="88888-7777788">
		<author>Mickaël Orangina</author>
		<title locale="fr">Tonnerre sous les tropiques</title>
		<title locale="us">Tropic thunder</title>
		<title locale="es">No <i>habla</i> espagnol</title>
		<summary><![CDATA[This is a CDATA section <-> <-- this is a tie fighter]]></summary>
示例#19
0
			cert, ski = SoapSecurity.loadCertFromPem(c)
			certificatesDb[ski] = cert
		
		cert = SoapSecurity.verifyMessage(doc, certificatesDb = certificatesDb)
		
		if not cert:
			raise Exception("This message has not been signed by the claimed party.")

		ret = {}
		ret['message'] = data
		ret['signedBy'] = ('certificate', cert.as_pem().strip())			
		return (ret, "XML data verified as signed by '%s'" % cert.get_subject().as_text())

	

CodecManager.registerCodecClass('soap11.ds', SoapDigitalSignatureCodec)


if __name__ == '__main__':
	CodecManager.alias('ds', 'soap11.ds')
	
	sampleEnv = """<?xml version="1.0" encoding="utf-8" ?>
<soapenv:Envelope xmlns:ns="http://www.eservglobal.com/homesend/tews/2.0" xmlns:ns1="http://www.eservglobal.com/homesend/types/2.0" xmlns:ns2="http://www.eservglobal.com/homesend/tews/2.1" xmlns:ns3="http://www.eservglobal.com/homesend/types/2.1" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
   <soapenv:Body>
<library owner="John Smith" administrator="Héléna Utf8 and Mickaël Orangina" xmlns="http://default" xmlns:b="http://base">
	<book isbn="88888-7777788">
		<b:author>Mickaël Orangina</b:author>
		<title locale="fr">Tonnerre sous les tropiques</title>
		<title locale="us">Tropic thunder</title>
		<title locale="es">No <i>habla</i> espagnol</title>
		<b:summary><![CDATA[This is a CDATA section <-> <-- this is a tie fighter]]></b:summary>
示例#20
0
	return ''.join(ret)

##
# SMS-DELIVER
##		
class SmsTpduSmsDeliverCodec(CodecManager.Codec):
	def __init__(self):
		CodecManager.Codec.__init__(self)

	def encode(self, template):
		return (encodeSmsDeliver(template), 'SMS-DELIVER')

	def decode(self, data):
		return (decodeSmsDeliver(data), 'SMS-DELIVER')

CodecManager.registerCodecClass('sms.tpdu.SMS-DELIVER', SmsTpduSmsDeliverCodec)


if __name__ == '__main__':
	import binascii
	def o(x):
		return binascii.unhexlify(x.replace(' ', ''))

	def oo(x):
		return binascii.hexlify(x)
	
	tpduSmsDeliver = "04039177f70010901091215571406fd3373b2c4fcf41311828168bc562b1582c168bc562b1582c168bc562b1582c168bc562b1582c168bc562b1582c168bc562b1582c168bc562b1582c168bc562b1582c168bc562b1582c168bc562b1582c168bc562b1582c168bc562b1584c36a3d500"
	
	print 80*'-'
	print "SMS TPDU SM-TL Codec unit tests"
	print 80*'-'
示例#21
0
	== See Also ==
	
	The mapping between ASN.1 and Testerman structures is documented [Asn1ToTesterman here].

	"""
	PDU = TcapAsn.TCMessage

	def getSummary(self, message):
		try:
			# message is expected to be a choice (begin/end/continue...)
			return 'TCAP %s' % message[0]
		except:
			return super.getSummary(message)

CodecManager.registerCodecClass('tcap', TcapCodec)

class DialoguePDUCodec(BerCodec.BerCodec):
	PDU = TcapDialoguePdusAsn.DialoguePDU
	def getSummary(self, message): return 'DialoguePDU'
CodecManager.registerCodecClass('tcap.DialoguePDU', DialoguePDUCodec)

if __name__ == '__main__':
	import binascii
	
	tcapBegin = \
	 "62644804000227846b3e283c060700118605010101a031602fa109060704000001001302be222820060704000001010101a015a01380099622123008016901f98106a807000000016c1ca11a02010102013b301204010f0405a3986c36028006a80700000001"

# From gsm_map_with_ussd_string.pcap sample
	tcapBegin2 = \
	 "626a48042f3b46026b3a2838060700118605010101a02d602b80020780a109060704000001001302be1a2818060704000001010101a00da00b80099656051124006913f66c26a12402010102013b301c04010f040eaa180da682dd6c31192d36bbdd468007917267415827f2"
示例#22
0
	
	def decode(self, data):
		d = asn1.decode(self.PDU, data)
		summary = self.getSummary(d)
		return (d, summary)
	
	def getSummary(self, message):
		"""
		You may reimplement this function to get
		a more accurate summary according to the userland PDU.
		@type  message: Testerman userland message
		@param message: decoded message corresponding to your PDU
		"""
		return str(self.PDU.__class__)

"""
# Example:

# TCAP Codec
# To compile TcapAsn: ./py_output.py asn/tcap.asn > TcapAsn.py


import CodecManager

import ber.BerCodec as BerCodec
import ber.TcapAsn as TcapAsn

class TcapCodec(BerCodec.BerCodec):
	PDU = TcapAsn.TCMessage

	def getSummary(self, message):
示例#23
0
##
# Sample codecs
##

import CodecManager

import pickle
import base64


class PickleCodec(CodecManager.Codec):
    def encode(self, template):
        return (pickle.dumps(template), 'pickle data')

    def decode(self, data):
        return (pickle.loads(data), None)


CodecManager.registerCodecClass('pickle', PickleCodec)


class Base64Codec(CodecManager.Codec):
    def encode(self, template):
        return (base64.encodestring(template), 'base64 data')

    def decode(self, data):
        return (base64.decodestring(data), None)


CodecManager.registerCodecClass('base64', Base64Codec)
示例#24
0
				if bl < cl:
					return self.needMoreData()
				elif bl > cl:
					# Truncate the body
					ret['body'] = ret['body'][:cl]
		
		return self.decoded(ret, self.getSummary(ret))

	def getSummary(self, template):
		"""
		Returns the summary of the template representing an RTSP message.
		(meaningful, short, human-understandable description)
		"""
		return '%s %s' % (template.get('method', 'GET'), template['url'])
		
CodecManager.registerCodecClass('http.request', HttpRequestCodec)


class HttpResponseCodec(CodecManager.IncrementalCodec):
	"""
	= Identification and Properties =
	
	Codec IDs: `http.response`

	Properties:
	|| '''Name''' || '''Type''' || '''Default value''' || '''Description''' ||
	|| header_encoding || string  || `'iso8859-1'` || Encoding to use to encode header values. ||

	= Overview =

	This codec enables to encode/decode HTTP 1.0/1.1 responses,
示例#25
0
	== See Also ==
	
	The mapping between ASN.1 and Testerman structures is documented [Asn1ToTesterman here].

	"""
	PDU = TcapAsn.TCMessage

	def getSummary(self, message):
		try:
			# message is expected to be a choice (begin/end/continue...)
			return 'TCAP %s' % message[0]
		except:
			return super.getSummary(message)

CodecManager.registerCodecClass('tcap', TcapCodec)

class DialoguePDUCodec(BerCodec.BerCodec):
	PDU = TcapDialoguePdusAsn.DialoguePDU
	def getSummary(self, message): return 'DialoguePDU'
CodecManager.registerCodecClass('tcap.DialoguePDU', DialoguePDUCodec)

if __name__ == '__main__':
	import binascii
	
	tcapBegin = \
	 "62644804000227846b3e283c060700118605010101a031602fa109060704000001001302be222820060704000001010101a015a01380099622123008016901f98106a807000000016c1ca11a02010102013b301204010f0405a3986c36028006a80700000001"

# From gsm_map_with_ussd_string.pcap sample
	tcapBegin2 = \
	 "626a48042f3b46026b3a2838060700118605010101a02d602b80020780a109060704000001001302be1a2818060704000001010101a00da00b80099656051124006913f66c26a12402010102013b301c04010f040eaa180da682dd6c31192d36bbdd468007917267415827f2"
示例#26
0
##
# SMS-DELIVER
##
class SmsTpduSmsDeliverCodec(CodecManager.Codec):
    def __init__(self):
        CodecManager.Codec.__init__(self)

    def encode(self, template):
        return (encodeSmsDeliver(template), 'SMS-DELIVER')

    def decode(self, data):
        return (decodeSmsDeliver(data), 'SMS-DELIVER')


CodecManager.registerCodecClass('sms.tpdu.SMS-DELIVER', SmsTpduSmsDeliverCodec)

if __name__ == '__main__':
    import binascii

    def o(x):
        return binascii.unhexlify(x.replace(' ', ''))

    def oo(x):
        return binascii.hexlify(x)

    tpduSmsDeliver = "04039177f70010901091215571406fd3373b2c4fcf41311828168bc562b1582c168bc562b1582c168bc562b1582c168bc562b1582c168bc562b1582c168bc562b1582c168bc562b1582c168bc562b1582c168bc562b1582c168bc562b1582c168bc562b1582c168bc562b1584c36a3d500"

    print(80 * '-')
    print("SMS TPDU SM-TL Codec unit tests")
    print(80 * '-')
示例#27
0
		"""
		tag = element.tagName
		
		# Now retrieve children, if any
		children = []
		for node in element.childNodes:
			if node.nodeType == node.ELEMENT_NODE:
				children.append(self._decode(node))
			# We should return only if these nodes are the first one.. ?
			elif node.nodeType == node.TEXT_NODE and node.nodeValue.strip():
				return (tag, node.nodeValue.strip())
			# Ignore other final node types (cdata, comments, ...)
		
		return (tag, children) 

CodecManager.registerCodecClass('xer.lite', XerLiteCodec)


if __name__ == '__main__':
	CodecManager.alias('xer.noprolog', 'xer.lite', write_prolog = False)
	CodecManager.alias('xer.iso', 'xer.lite', encoding = "iso-8859-1")
	CodecManager.alias('xer.canonical', 'xer.lite', canonical = True)
	
	sample = """<?xml version="1.0"?>
<library>
	<administrator>Héléna Utf8</administrator>
	<book>
		<isbn>89084-89089</isbn>
		<author>Philippe Kendall</author>
		<author>Mickaël Orangina</author>
		<title>Tropic thunder</title>
示例#28
0
# Copyright (c) 2008-2009 Sebastien Lefevre and other contributors
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation; either version 2 of the License, or (at your option) any later
# version.
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
# details.
##

##
# ZLIB/GZIP codec.
##

import CodecManager

import zlib


class GZipCodec(CodecManager.Codec):
    def encode(self, template):
        return (zlib.compress(template), 'GZIP data')

    def decode(self, data):
        return (zlib.decompress(data), None)


CodecManager.registerCodecClass('gzip', GZipCodec)
示例#29
0
            certificatesDb[ski] = cert

        cert = SoapSecurity.verifyMessage(doc, certificatesDb=certificatesDb)

        if not cert:
            raise Exception(
                "This message has not been signed by the claimed party.")

        ret = {}
        ret['message'] = data
        ret['signedBy'] = ('certificate', cert.as_pem().strip())
        return (ret, "XML data verified as signed by '%s'" %
                cert.get_subject().as_text())


CodecManager.registerCodecClass('soap11.ds', SoapDigitalSignatureCodec)

if __name__ == '__main__':
    CodecManager.alias('ds', 'soap11.ds')

    sampleEnv = """<?xml version="1.0" encoding="utf-8" ?>
<soapenv:Envelope xmlns:ns="http://www.eservglobal.com/homesend/tews/2.0" xmlns:ns1="http://www.eservglobal.com/homesend/types/2.0" xmlns:ns2="http://www.eservglobal.com/homesend/tews/2.1" xmlns:ns3="http://www.eservglobal.com/homesend/types/2.1" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
   <soapenv:Body>
<library owner="John Smith" administrator="Héléna Utf8 and Mickaël Orangina" xmlns="http://default" xmlns:b="http://base">
	<book isbn="88888-7777788">
		<b:author>Mickaël Orangina</b:author>
		<title locale="fr">Tonnerre sous les tropiques</title>
		<title locale="us">Tropic thunder</title>
		<title locale="es">No <i>habla</i> espagnol</title>
		<b:summary><![CDATA[This is a CDATA section <-> <-- this is a tie fighter]]></b:summary>
	</book>
示例#30
0
##
# MAP (2+) Codec
# To compile MapAsn: cd ber && ./py_output.py asn/AMP-All.asn > MapAsn.py
##

import CodecManager

import ber.BerCodec as BerCodec
import ber.MapAsn as MapAsn

# SMS management: SRI and MT Forward
class RoutingInfoForSM_ArgCodec(BerCodec.BerCodec):
	PDU = MapAsn.RoutingInfoForSM_Arg
	def getSummary(self, message): return 'RoutingInfoForSM-Arg'
CodecManager.registerCodecClass('map.RoutingInfoForSM-Arg', RoutingInfoForSM_ArgCodec)

class RoutingInfoForSM_ResCodec(BerCodec.BerCodec):
	PDU = MapAsn.RoutingInfoForSM_Res
	def getSummary(self, message): return 'RoutingInfoForSM-Res'
CodecManager.registerCodecClass('map.RoutingInfoForSM-Res', RoutingInfoForSM_ResCodec)

class MT_ForwardSM_ArgCodec(BerCodec.BerCodec):
	PDU = MapAsn.MT_ForwardSM_Arg
	def getSummary(self, message): return 'MT-ForwardSM-Arg'
CodecManager.registerCodecClass('map.MT-ForwardSM-Arg', MT_ForwardSM_ArgCodec)

class MT_ForwardSM_ResCodec(BerCodec.BerCodec):
	PDU = MapAsn.MT_ForwardSM_Res
	def getSummary(self, message): return 'MT-ForwardSM-Res'
CodecManager.registerCodecClass('map.MT-ForwardSM-Res', MT_ForwardSM_ResCodec)