diff options
Diffstat (limited to 'lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/pair')
13 files changed, 0 insertions, 1448 deletions
diff --git a/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/pair/__init__.py b/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/pair/__init__.py deleted file mode 100755 index 6d3f5aa9..00000000 --- a/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/pair/__init__.py +++ /dev/null @@ -1,20 +0,0 @@ - -# Copyright (c) Twisted Matrix Laboratories. -# See LICENSE for details. - - -""" - -Twisted Pair: The framework of your ethernet. - -Low-level networking transports and utilities. - -See also twisted.protocols.ethernet, twisted.protocols.ip, -twisted.protocols.raw and twisted.protocols.rawudp. - -Maintainer: Tommi Virtanen - -""" - -from twisted.pair._version import version -__version__ = version.short() diff --git a/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/pair/_version.py b/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/pair/_version.py deleted file mode 100755 index 4f1e2e40..00000000 --- a/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/pair/_version.py +++ /dev/null @@ -1,3 +0,0 @@ -# This is an auto-generated file. Do not edit it. -from twisted.python import versions -version = versions.Version('twisted.pair', 12, 2, 0) diff --git a/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/pair/ethernet.py b/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/pair/ethernet.py deleted file mode 100755 index b432c6fc..00000000 --- a/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/pair/ethernet.py +++ /dev/null @@ -1,56 +0,0 @@ -# -*- test-case-name: twisted.pair.test.test_ethernet -*- -# Copyright (c) Twisted Matrix Laboratories. -# See LICENSE for details. - -# - - -"""Support for working directly with ethernet frames""" - -import struct - - -from twisted.internet import protocol -from twisted.pair import raw -from zope.interface import implements, Interface - - -class IEthernetProtocol(Interface): - """An interface for protocols that handle Ethernet frames""" - def addProto(): - """Add an IRawPacketProtocol protocol""" - - def datagramReceived(): - """An Ethernet frame has been received""" - -class EthernetHeader: - def __init__(self, data): - - (self.dest, self.source, self.proto) \ - = struct.unpack("!6s6sH", data[:6+6+2]) - -class EthernetProtocol(protocol.AbstractDatagramProtocol): - - implements(IEthernetProtocol) - - def __init__(self): - self.etherProtos = {} - - def addProto(self, num, proto): - proto = raw.IRawPacketProtocol(proto) - if num < 0: - raise TypeError, 'Added protocol must be positive or zero' - if num >= 2**16: - raise TypeError, 'Added protocol must fit in 16 bits' - if num not in self.etherProtos: - self.etherProtos[num] = [] - self.etherProtos[num].append(proto) - - def datagramReceived(self, data, partial=0): - header = EthernetHeader(data[:14]) - for proto in self.etherProtos.get(header.proto, ()): - proto.datagramReceived(data=data[14:], - partial=partial, - dest=header.dest, - source=header.source, - protocol=header.proto) diff --git a/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/pair/ip.py b/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/pair/ip.py deleted file mode 100755 index de03bd41..00000000 --- a/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/pair/ip.py +++ /dev/null @@ -1,72 +0,0 @@ -# -*- test-case-name: twisted.pair.test.test_ip -*- -# Copyright (c) Twisted Matrix Laboratories. -# See LICENSE for details. - -# - - -"""Support for working directly with IP packets""" - -import struct -import socket - -from twisted.internet import protocol -from twisted.pair import raw -from zope.interface import implements - - -class IPHeader: - def __init__(self, data): - - (ihlversion, self.tos, self.tot_len, self.fragment_id, frag_off, - self.ttl, self.protocol, self.check, saddr, daddr) \ - = struct.unpack("!BBHHHBBH4s4s", data[:20]) - self.saddr = socket.inet_ntoa(saddr) - self.daddr = socket.inet_ntoa(daddr) - self.version = ihlversion & 0x0F - self.ihl = ((ihlversion & 0xF0) >> 4) << 2 - self.fragment_offset = frag_off & 0x1FFF - self.dont_fragment = (frag_off & 0x4000 != 0) - self.more_fragments = (frag_off & 0x2000 != 0) - -MAX_SIZE = 2L**32 - -class IPProtocol(protocol.AbstractDatagramProtocol): - implements(raw.IRawPacketProtocol) - - def __init__(self): - self.ipProtos = {} - - def addProto(self, num, proto): - proto = raw.IRawDatagramProtocol(proto) - if num < 0: - raise TypeError, 'Added protocol must be positive or zero' - if num >= MAX_SIZE: - raise TypeError, 'Added protocol must fit in 32 bits' - if num not in self.ipProtos: - self.ipProtos[num] = [] - self.ipProtos[num].append(proto) - - def datagramReceived(self, - data, - partial, - dest, - source, - protocol): - header = IPHeader(data) - for proto in self.ipProtos.get(header.protocol, ()): - proto.datagramReceived(data=data[20:], - partial=partial, - source=header.saddr, - dest=header.daddr, - protocol=header.protocol, - version=header.version, - ihl=header.ihl, - tos=header.tos, - tot_len=header.tot_len, - fragment_id=header.fragment_id, - fragment_offset=header.fragment_offset, - dont_fragment=header.dont_fragment, - more_fragments=header.more_fragments, - ttl=header.ttl, - ) diff --git a/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/pair/raw.py b/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/pair/raw.py deleted file mode 100755 index 0d3875ba..00000000 --- a/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/pair/raw.py +++ /dev/null @@ -1,35 +0,0 @@ -# Copyright (c) Twisted Matrix Laboratories. -# See LICENSE for details. - -# - -"""Interface definitions for working with raw packets""" - -from twisted.internet import protocol -from zope.interface import Interface - -class IRawDatagramProtocol(Interface): - """An interface for protocols such as UDP, ICMP and TCP.""" - - def addProto(): - """ - Add a protocol on top of this one. - """ - - def datagramReceived(): - """ - An IP datagram has been received. Parse and process it. - """ - -class IRawPacketProtocol(Interface): - """An interface for low-level protocols such as IP and ARP.""" - - def addProto(): - """ - Add a protocol on top of this one. - """ - - def datagramReceived(): - """ - An IP datagram has been received. Parse and process it. - """ diff --git a/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/pair/rawudp.py b/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/pair/rawudp.py deleted file mode 100755 index 1425e6bd..00000000 --- a/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/pair/rawudp.py +++ /dev/null @@ -1,55 +0,0 @@ -# -*- test-case-name: twisted.pair.test.test_rawudp -*- -# Copyright (c) Twisted Matrix Laboratories. -# See LICENSE for details. - -# - -"""Implementation of raw packet interfaces for UDP""" - -import struct - -from twisted.internet import protocol -from twisted.pair import raw -from zope.interface import implements - -class UDPHeader: - def __init__(self, data): - - (self.source, self.dest, self.len, self.check) \ - = struct.unpack("!HHHH", data[:8]) - -class RawUDPProtocol(protocol.AbstractDatagramProtocol): - implements(raw.IRawDatagramProtocol) - def __init__(self): - self.udpProtos = {} - - def addProto(self, num, proto): - if not isinstance(proto, protocol.DatagramProtocol): - raise TypeError, 'Added protocol must be an instance of DatagramProtocol' - if num < 0: - raise TypeError, 'Added protocol must be positive or zero' - if num >= 2**16: - raise TypeError, 'Added protocol must fit in 16 bits' - if num not in self.udpProtos: - self.udpProtos[num] = [] - self.udpProtos[num].append(proto) - - def datagramReceived(self, - data, - partial, - source, - dest, - protocol, - version, - ihl, - tos, - tot_len, - fragment_id, - fragment_offset, - dont_fragment, - more_fragments, - ttl): - header = UDPHeader(data) - for proto in self.udpProtos.get(header.dest, ()): - proto.datagramReceived(data[8:], - (source, header.source)) diff --git a/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/pair/test/__init__.py b/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/pair/test/__init__.py deleted file mode 100755 index 5aa286eb..00000000 --- a/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/pair/test/__init__.py +++ /dev/null @@ -1 +0,0 @@ -'pair tests' diff --git a/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/pair/test/test_ethernet.py b/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/pair/test/test_ethernet.py deleted file mode 100755 index 2b675fe8..00000000 --- a/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/pair/test/test_ethernet.py +++ /dev/null @@ -1,226 +0,0 @@ -# Copyright (c) Twisted Matrix Laboratories. -# See LICENSE for details. - -# -from twisted.trial import unittest - -from twisted.internet import protocol, reactor, error -from twisted.python import failure, components -from twisted.pair import ethernet, raw -from zope.interface import implements - -class MyProtocol: - implements(raw.IRawPacketProtocol) - - def __init__(self, expecting): - self.expecting = list(expecting) - - def datagramReceived(self, data, **kw): - assert self.expecting, 'Got a packet when not expecting anymore.' - expect = self.expecting.pop(0) - assert expect == (data, kw), \ - "Expected %r, got %r" % ( - expect, (data, kw), - ) - -class EthernetTestCase(unittest.TestCase): - def testPacketParsing(self): - proto = ethernet.EthernetProtocol() - p1 = MyProtocol([ - - ('foobar', { - 'partial': 0, - 'dest': "123456", - 'source': "987654", - 'protocol': 0x0800, - }), - - ]) - proto.addProto(0x0800, p1) - - proto.datagramReceived("123456987654\x08\x00foobar", - partial=0) - - assert not p1.expecting, \ - 'Should not expect any more packets, but still want %r' % p1.expecting - - - def testMultiplePackets(self): - proto = ethernet.EthernetProtocol() - p1 = MyProtocol([ - - ('foobar', { - 'partial': 0, - 'dest': "123456", - 'source': "987654", - 'protocol': 0x0800, - }), - - ('quux', { - 'partial': 1, - 'dest': "012345", - 'source': "abcdef", - 'protocol': 0x0800, - }), - - ]) - proto.addProto(0x0800, p1) - - proto.datagramReceived("123456987654\x08\x00foobar", - partial=0) - proto.datagramReceived("012345abcdef\x08\x00quux", - partial=1) - - assert not p1.expecting, \ - 'Should not expect any more packets, but still want %r' % p1.expecting - - - def testMultipleSameProtos(self): - proto = ethernet.EthernetProtocol() - p1 = MyProtocol([ - - ('foobar', { - 'partial': 0, - 'dest': "123456", - 'source': "987654", - 'protocol': 0x0800, - }), - - ]) - - p2 = MyProtocol([ - - ('foobar', { - 'partial': 0, - 'dest': "123456", - 'source': "987654", - 'protocol': 0x0800, - }), - - ]) - - proto.addProto(0x0800, p1) - proto.addProto(0x0800, p2) - - proto.datagramReceived("123456987654\x08\x00foobar", - partial=0) - - assert not p1.expecting, \ - 'Should not expect any more packets, but still want %r' % p1.expecting - assert not p2.expecting, \ - 'Should not expect any more packets, but still want %r' % p2.expecting - - def testWrongProtoNotSeen(self): - proto = ethernet.EthernetProtocol() - p1 = MyProtocol([]) - proto.addProto(0x0801, p1) - - proto.datagramReceived("123456987654\x08\x00foobar", - partial=0) - proto.datagramReceived("012345abcdef\x08\x00quux", - partial=1) - - def testDemuxing(self): - proto = ethernet.EthernetProtocol() - p1 = MyProtocol([ - - ('foobar', { - 'partial': 0, - 'dest': "123456", - 'source': "987654", - 'protocol': 0x0800, - }), - - ('quux', { - 'partial': 1, - 'dest': "012345", - 'source': "abcdef", - 'protocol': 0x0800, - }), - - ]) - proto.addProto(0x0800, p1) - - p2 = MyProtocol([ - - ('quux', { - 'partial': 1, - 'dest': "012345", - 'source': "abcdef", - 'protocol': 0x0806, - }), - - ('foobar', { - 'partial': 0, - 'dest': "123456", - 'source': "987654", - 'protocol': 0x0806, - }), - - ]) - proto.addProto(0x0806, p2) - - proto.datagramReceived("123456987654\x08\x00foobar", - partial=0) - proto.datagramReceived("012345abcdef\x08\x06quux", - partial=1) - proto.datagramReceived("123456987654\x08\x06foobar", - partial=0) - proto.datagramReceived("012345abcdef\x08\x00quux", - partial=1) - - assert not p1.expecting, \ - 'Should not expect any more packets, but still want %r' % p1.expecting - assert not p2.expecting, \ - 'Should not expect any more packets, but still want %r' % p2.expecting - - def testAddingBadProtos_WrongLevel(self): - """Adding a wrong level protocol raises an exception.""" - e = ethernet.EthernetProtocol() - try: - e.addProto(42, "silliness") - except components.CannotAdapt: - pass - else: - raise AssertionError, 'addProto must raise an exception for bad protocols' - - - def testAddingBadProtos_TooSmall(self): - """Adding a protocol with a negative number raises an exception.""" - e = ethernet.EthernetProtocol() - try: - e.addProto(-1, MyProtocol([])) - except TypeError, e: - if e.args == ('Added protocol must be positive or zero',): - pass - else: - raise - else: - raise AssertionError, 'addProto must raise an exception for bad protocols' - - - def testAddingBadProtos_TooBig(self): - """Adding a protocol with a number >=2**16 raises an exception.""" - e = ethernet.EthernetProtocol() - try: - e.addProto(2**16, MyProtocol([])) - except TypeError, e: - if e.args == ('Added protocol must fit in 16 bits',): - pass - else: - raise - else: - raise AssertionError, 'addProto must raise an exception for bad protocols' - - def testAddingBadProtos_TooBig2(self): - """Adding a protocol with a number >=2**16 raises an exception.""" - e = ethernet.EthernetProtocol() - try: - e.addProto(2**16+1, MyProtocol([])) - except TypeError, e: - if e.args == ('Added protocol must fit in 16 bits',): - pass - else: - raise - else: - raise AssertionError, 'addProto must raise an exception for bad protocols' diff --git a/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/pair/test/test_ip.py b/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/pair/test/test_ip.py deleted file mode 100755 index ed1623b6..00000000 --- a/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/pair/test/test_ip.py +++ /dev/null @@ -1,417 +0,0 @@ -# Copyright (c) Twisted Matrix Laboratories. -# See LICENSE for details. - -# -from twisted.trial import unittest - -from twisted.internet import protocol, reactor, error -from twisted.python import failure, components -from twisted.pair import ip, raw -from zope import interface - -class MyProtocol: - interface.implements(raw.IRawDatagramProtocol) - - def __init__(self, expecting): - self.expecting = list(expecting) - - def datagramReceived(self, data, **kw): - assert self.expecting, 'Got a packet when not expecting anymore.' - expectData, expectKw = self.expecting.pop(0) - - expectKwKeys = expectKw.keys(); expectKwKeys.sort() - kwKeys = kw.keys(); kwKeys.sort() - assert expectKwKeys == kwKeys, "Expected %r, got %r" % (expectKwKeys, kwKeys) - - for k in expectKwKeys: - assert expectKw[k] == kw[k], "Expected %s=%r, got %r" % (k, expectKw[k], kw[k]) - assert expectKw == kw, "Expected %r, got %r" % (expectKw, kw) - assert expectData == data, "Expected %r, got %r" % (expectData, data) - -class IPTestCase(unittest.TestCase): - def testPacketParsing(self): - proto = ip.IPProtocol() - p1 = MyProtocol([ - - ('foobar', { - 'partial': 0, - 'dest': '1.2.3.4', - 'source': '5.6.7.8', - 'protocol': 0x0F, - 'version': 4, - 'ihl': 20, - 'tos': 7, - 'tot_len': 20+6, - 'fragment_id': 0xDEAD, - 'fragment_offset': 0x1EEF, - 'dont_fragment': 0, - 'more_fragments': 1, - 'ttl': 0xC0, - }), - - ]) - proto.addProto(0x0F, p1) - - proto.datagramReceived("\x54" #ihl version - + "\x07" #tos - + "\x00\x1a" #tot_len - + "\xDE\xAD" #id - + "\xBE\xEF" #frag_off - + "\xC0" #ttl - + "\x0F" #protocol - + "FE" #checksum - + "\x05\x06\x07\x08" + "\x01\x02\x03\x04" + "foobar", - partial=0, - dest='dummy', - source='dummy', - protocol='dummy', - ) - - assert not p1.expecting, \ - 'Should not expect any more packets, but still want %r' % p1.expecting - - def testMultiplePackets(self): - proto = ip.IPProtocol() - p1 = MyProtocol([ - - ('foobar', { - 'partial': 0, - 'dest': '1.2.3.4', - 'source': '5.6.7.8', - 'protocol': 0x0F, - 'version': 4, - 'ihl': 20, - 'tos': 7, - 'tot_len': 20+6, - 'fragment_id': 0xDEAD, - 'fragment_offset': 0x1EEF, - 'dont_fragment': 0, - 'more_fragments': 1, - 'ttl': 0xC0, - }), - - ('quux', { - 'partial': 1, - 'dest': '5.4.3.2', - 'source': '6.7.8.9', - 'protocol': 0x0F, - 'version': 4, - 'ihl': 20, - 'tos': 7, - 'tot_len': 20+6, - 'fragment_id': 0xDEAD, - 'fragment_offset': 0x1EEF, - 'dont_fragment': 0, - 'more_fragments': 1, - 'ttl': 0xC0, - }), - - ]) - proto.addProto(0x0F, p1) - proto.datagramReceived("\x54" #ihl version - + "\x07" #tos - + "\x00\x1a" #tot_len - + "\xDE\xAD" #id - + "\xBE\xEF" #frag_off - + "\xC0" #ttl - + "\x0F" #protocol - + "FE" #checksum - + "\x05\x06\x07\x08" + "\x01\x02\x03\x04" + "foobar", - partial=0, - dest='dummy', - source='dummy', - protocol='dummy', - ) - proto.datagramReceived("\x54" #ihl version - + "\x07" #tos - + "\x00\x1a" #tot_len - + "\xDE\xAD" #id - + "\xBE\xEF" #frag_off - + "\xC0" #ttl - + "\x0F" #protocol - + "FE" #checksum - + "\x06\x07\x08\x09" + "\x05\x04\x03\x02" + "quux", - partial=1, - dest='dummy', - source='dummy', - protocol='dummy', - ) - - assert not p1.expecting, \ - 'Should not expect any more packets, but still want %r' % p1.expecting - - - def testMultipleSameProtos(self): - proto = ip.IPProtocol() - p1 = MyProtocol([ - - ('foobar', { - 'partial': 0, - 'dest': '1.2.3.4', - 'source': '5.6.7.8', - 'protocol': 0x0F, - 'version': 4, - 'ihl': 20, - 'tos': 7, - 'tot_len': 20+6, - 'fragment_id': 0xDEAD, - 'fragment_offset': 0x1EEF, - 'dont_fragment': 0, - 'more_fragments': 1, - 'ttl': 0xC0, - }), - - ]) - - p2 = MyProtocol([ - - ('foobar', { - 'partial': 0, - 'dest': '1.2.3.4', - 'source': '5.6.7.8', - 'protocol': 0x0F, - 'version': 4, - 'ihl': 20, - 'tos': 7, - 'tot_len': 20+6, - 'fragment_id': 0xDEAD, - 'fragment_offset': 0x1EEF, - 'dont_fragment': 0, - 'more_fragments': 1, - 'ttl': 0xC0, - }), - - ]) - - proto.addProto(0x0F, p1) - proto.addProto(0x0F, p2) - - proto.datagramReceived("\x54" #ihl version - + "\x07" #tos - + "\x00\x1a" #tot_len - + "\xDE\xAD" #id - + "\xBE\xEF" #frag_off - + "\xC0" #ttl - + "\x0F" #protocol - + "FE" #checksum - + "\x05\x06\x07\x08" + "\x01\x02\x03\x04" + "foobar", - partial=0, - dest='dummy', - source='dummy', - protocol='dummy', - ) - - assert not p1.expecting, \ - 'Should not expect any more packets, but still want %r' % p1.expecting - assert not p2.expecting, \ - 'Should not expect any more packets, but still want %r' % p2.expecting - - def testWrongProtoNotSeen(self): - proto = ip.IPProtocol() - p1 = MyProtocol([]) - proto.addProto(1, p1) - - proto.datagramReceived("\x54" #ihl version - + "\x07" #tos - + "\x00\x1a" #tot_len - + "\xDE\xAD" #id - + "\xBE\xEF" #frag_off - + "\xC0" #ttl - + "\x0F" #protocol - + "FE" #checksum - + "\x05\x06\x07\x08" + "\x01\x02\x03\x04" + "foobar", - partial=0, - dest='dummy', - source='dummy', - protocol='dummy', - ) - - def testDemuxing(self): - proto = ip.IPProtocol() - p1 = MyProtocol([ - - ('foobar', { - 'partial': 0, - 'dest': '1.2.3.4', - 'source': '5.6.7.8', - 'protocol': 0x0F, - 'version': 4, - 'ihl': 20, - 'tos': 7, - 'tot_len': 20+6, - 'fragment_id': 0xDEAD, - 'fragment_offset': 0x1EEF, - 'dont_fragment': 0, - 'more_fragments': 1, - 'ttl': 0xC0, - }), - - ('quux', { - 'partial': 1, - 'dest': '5.4.3.2', - 'source': '6.7.8.9', - 'protocol': 0x0F, - 'version': 4, - 'ihl': 20, - 'tos': 7, - 'tot_len': 20+6, - 'fragment_id': 0xDEAD, - 'fragment_offset': 0x1EEF, - 'dont_fragment': 0, - 'more_fragments': 1, - 'ttl': 0xC0, - }), - - ]) - proto.addProto(0x0F, p1) - - p2 = MyProtocol([ - - ('quux', { - 'partial': 1, - 'dest': '5.4.3.2', - 'source': '6.7.8.9', - 'protocol': 0x0A, - 'version': 4, - 'ihl': 20, - 'tos': 7, - 'tot_len': 20+6, - 'fragment_id': 0xDEAD, - 'fragment_offset': 0x1EEF, - 'dont_fragment': 0, - 'more_fragments': 1, - 'ttl': 0xC0, - }), - - ('foobar', { - 'partial': 0, - 'dest': '1.2.3.4', - 'source': '5.6.7.8', - 'protocol': 0x0A, - 'version': 4, - 'ihl': 20, - 'tos': 7, - 'tot_len': 20+6, - 'fragment_id': 0xDEAD, - 'fragment_offset': 0x1EEF, - 'dont_fragment': 0, - 'more_fragments': 1, - 'ttl': 0xC0, - }), - - - ]) - proto.addProto(0x0A, p2) - - proto.datagramReceived("\x54" #ihl version - + "\x07" #tos - + "\x00\x1a" #tot_len - + "\xDE\xAD" #id - + "\xBE\xEF" #frag_off - + "\xC0" #ttl - + "\x0A" #protocol - + "FE" #checksum - + "\x06\x07\x08\x09" + "\x05\x04\x03\x02" + "quux", - partial=1, - dest='dummy', - source='dummy', - protocol='dummy', - ) - proto.datagramReceived("\x54" #ihl version - + "\x07" #tos - + "\x00\x1a" #tot_len - + "\xDE\xAD" #id - + "\xBE\xEF" #frag_off - + "\xC0" #ttl - + "\x0F" #protocol - + "FE" #checksum - + "\x05\x06\x07\x08" + "\x01\x02\x03\x04" + "foobar", - partial=0, - dest='dummy', - source='dummy', - protocol='dummy', - ) - proto.datagramReceived("\x54" #ihl version - + "\x07" #tos - + "\x00\x1a" #tot_len - + "\xDE\xAD" #id - + "\xBE\xEF" #frag_off - + "\xC0" #ttl - + "\x0F" #protocol - + "FE" #checksum - + "\x06\x07\x08\x09" + "\x05\x04\x03\x02" + "quux", - partial=1, - dest='dummy', - source='dummy', - protocol='dummy', - ) - proto.datagramReceived("\x54" #ihl version - + "\x07" #tos - + "\x00\x1a" #tot_len - + "\xDE\xAD" #id - + "\xBE\xEF" #frag_off - + "\xC0" #ttl - + "\x0A" #protocol - + "FE" #checksum - + "\x05\x06\x07\x08" + "\x01\x02\x03\x04" + "foobar", - partial=0, - dest='dummy', - source='dummy', - protocol='dummy', - ) - - assert not p1.expecting, \ - 'Should not expect any more packets, but still want %r' % p1.expecting - assert not p2.expecting, \ - 'Should not expect any more packets, but still want %r' % p2.expecting - - def testAddingBadProtos_WrongLevel(self): - """Adding a wrong level protocol raises an exception.""" - e = ip.IPProtocol() - try: - e.addProto(42, "silliness") - except components.CannotAdapt: - pass - else: - raise AssertionError, 'addProto must raise an exception for bad protocols' - - - def testAddingBadProtos_TooSmall(self): - """Adding a protocol with a negative number raises an exception.""" - e = ip.IPProtocol() - try: - e.addProto(-1, MyProtocol([])) - except TypeError, e: - if e.args == ('Added protocol must be positive or zero',): - pass - else: - raise - else: - raise AssertionError, 'addProto must raise an exception for bad protocols' - - - def testAddingBadProtos_TooBig(self): - """Adding a protocol with a number >=2**32 raises an exception.""" - e = ip.IPProtocol() - try: - e.addProto(2L**32, MyProtocol([])) - except TypeError, e: - if e.args == ('Added protocol must fit in 32 bits',): - pass - else: - raise - else: - raise AssertionError, 'addProto must raise an exception for bad protocols' - - def testAddingBadProtos_TooBig2(self): - """Adding a protocol with a number >=2**32 raises an exception.""" - e = ip.IPProtocol() - try: - e.addProto(2L**32+1, MyProtocol([])) - except TypeError, e: - if e.args == ('Added protocol must fit in 32 bits',): - pass - else: - raise - else: - raise AssertionError, 'addProto must raise an exception for bad protocols' diff --git a/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/pair/test/test_rawudp.py b/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/pair/test/test_rawudp.py deleted file mode 100755 index f53f0783..00000000 --- a/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/pair/test/test_rawudp.py +++ /dev/null @@ -1,327 +0,0 @@ -# Copyright (c) Twisted Matrix Laboratories. -# See LICENSE for details. - -# -from twisted.trial import unittest - -from twisted.internet import protocol, reactor, error -from twisted.python import failure -from twisted.pair import rawudp - -class MyProtocol(protocol.DatagramProtocol): - def __init__(self, expecting): - self.expecting = list(expecting) - - def datagramReceived(self, data, (host, port)): - assert self.expecting, 'Got a packet when not expecting anymore.' - expectData, expectHost, expectPort = self.expecting.pop(0) - - assert expectData == data, "Expected data %r, got %r" % (expectData, data) - assert expectHost == host, "Expected host %r, got %r" % (expectHost, host) - assert expectPort == port, "Expected port %d=0x%04x, got %d=0x%04x" % (expectPort, expectPort, port, port) - -class RawUDPTestCase(unittest.TestCase): - def testPacketParsing(self): - proto = rawudp.RawUDPProtocol() - p1 = MyProtocol([ - - ('foobar', 'testHost', 0x43A2), - - ]) - proto.addProto(0xF00F, p1) - - proto.datagramReceived("\x43\xA2" #source - + "\xf0\x0f" #dest - + "\x00\x06" #len - + "\xDE\xAD" #check - + "foobar", - partial=0, - dest='dummy', - source='testHost', - protocol='dummy', - version='dummy', - ihl='dummy', - tos='dummy', - tot_len='dummy', - fragment_id='dummy', - fragment_offset='dummy', - dont_fragment='dummy', - more_fragments='dummy', - ttl='dummy', - ) - - assert not p1.expecting, \ - 'Should not expect any more packets, but still want %r' % p1.expecting - - def testMultiplePackets(self): - proto = rawudp.RawUDPProtocol() - p1 = MyProtocol([ - - ('foobar', 'testHost', 0x43A2), - ('quux', 'otherHost', 0x33FE), - - ]) - proto.addProto(0xF00F, p1) - proto.datagramReceived("\x43\xA2" #source - + "\xf0\x0f" #dest - + "\x00\x06" #len - + "\xDE\xAD" #check - + "foobar", - partial=0, - dest='dummy', - source='testHost', - protocol='dummy', - version='dummy', - ihl='dummy', - tos='dummy', - tot_len='dummy', - fragment_id='dummy', - fragment_offset='dummy', - dont_fragment='dummy', - more_fragments='dummy', - ttl='dummy', - ) - proto.datagramReceived("\x33\xFE" #source - + "\xf0\x0f" #dest - + "\x00\x05" #len - + "\xDE\xAD" #check - + "quux", - partial=0, - dest='dummy', - source='otherHost', - protocol='dummy', - version='dummy', - ihl='dummy', - tos='dummy', - tot_len='dummy', - fragment_id='dummy', - fragment_offset='dummy', - dont_fragment='dummy', - more_fragments='dummy', - ttl='dummy', - ) - - assert not p1.expecting, \ - 'Should not expect any more packets, but still want %r' % p1.expecting - - - def testMultipleSameProtos(self): - proto = rawudp.RawUDPProtocol() - p1 = MyProtocol([ - - ('foobar', 'testHost', 0x43A2), - - ]) - - p2 = MyProtocol([ - - ('foobar', 'testHost', 0x43A2), - - ]) - - proto.addProto(0xF00F, p1) - proto.addProto(0xF00F, p2) - - proto.datagramReceived("\x43\xA2" #source - + "\xf0\x0f" #dest - + "\x00\x06" #len - + "\xDE\xAD" #check - + "foobar", - partial=0, - dest='dummy', - source='testHost', - protocol='dummy', - version='dummy', - ihl='dummy', - tos='dummy', - tot_len='dummy', - fragment_id='dummy', - fragment_offset='dummy', - dont_fragment='dummy', - more_fragments='dummy', - ttl='dummy', - ) - - assert not p1.expecting, \ - 'Should not expect any more packets, but still want %r' % p1.expecting - assert not p2.expecting, \ - 'Should not expect any more packets, but still want %r' % p2.expecting - - def testWrongProtoNotSeen(self): - proto = rawudp.RawUDPProtocol() - p1 = MyProtocol([]) - proto.addProto(1, p1) - - proto.datagramReceived("\x43\xA2" #source - + "\xf0\x0f" #dest - + "\x00\x06" #len - + "\xDE\xAD" #check - + "foobar", - partial=0, - dest='dummy', - source='testHost', - protocol='dummy', - version='dummy', - ihl='dummy', - tos='dummy', - tot_len='dummy', - fragment_id='dummy', - fragment_offset='dummy', - dont_fragment='dummy', - more_fragments='dummy', - ttl='dummy', - ) - - def testDemuxing(self): - proto = rawudp.RawUDPProtocol() - p1 = MyProtocol([ - - ('foobar', 'testHost', 0x43A2), - ('quux', 'otherHost', 0x33FE), - - ]) - proto.addProto(0xF00F, p1) - - p2 = MyProtocol([ - - ('quux', 'otherHost', 0xA401), - ('foobar', 'testHost', 0xA302), - - ]) - proto.addProto(0xB050, p2) - - proto.datagramReceived("\xA4\x01" #source - + "\xB0\x50" #dest - + "\x00\x05" #len - + "\xDE\xAD" #check - + "quux", - partial=0, - dest='dummy', - source='otherHost', - protocol='dummy', - version='dummy', - ihl='dummy', - tos='dummy', - tot_len='dummy', - fragment_id='dummy', - fragment_offset='dummy', - dont_fragment='dummy', - more_fragments='dummy', - ttl='dummy', - ) - proto.datagramReceived("\x43\xA2" #source - + "\xf0\x0f" #dest - + "\x00\x06" #len - + "\xDE\xAD" #check - + "foobar", - partial=0, - dest='dummy', - source='testHost', - protocol='dummy', - version='dummy', - ihl='dummy', - tos='dummy', - tot_len='dummy', - fragment_id='dummy', - fragment_offset='dummy', - dont_fragment='dummy', - more_fragments='dummy', - ttl='dummy', - ) - proto.datagramReceived("\x33\xFE" #source - + "\xf0\x0f" #dest - + "\x00\x05" #len - + "\xDE\xAD" #check - + "quux", - partial=0, - dest='dummy', - source='otherHost', - protocol='dummy', - version='dummy', - ihl='dummy', - tos='dummy', - tot_len='dummy', - fragment_id='dummy', - fragment_offset='dummy', - dont_fragment='dummy', - more_fragments='dummy', - ttl='dummy', - ) - proto.datagramReceived("\xA3\x02" #source - + "\xB0\x50" #dest - + "\x00\x06" #len - + "\xDE\xAD" #check - + "foobar", - partial=0, - dest='dummy', - source='testHost', - protocol='dummy', - version='dummy', - ihl='dummy', - tos='dummy', - tot_len='dummy', - fragment_id='dummy', - fragment_offset='dummy', - dont_fragment='dummy', - more_fragments='dummy', - ttl='dummy', - ) - - assert not p1.expecting, \ - 'Should not expect any more packets, but still want %r' % p1.expecting - assert not p2.expecting, \ - 'Should not expect any more packets, but still want %r' % p2.expecting - - def testAddingBadProtos_WrongLevel(self): - """Adding a wrong level protocol raises an exception.""" - e = rawudp.RawUDPProtocol() - try: - e.addProto(42, "silliness") - except TypeError, e: - if e.args == ('Added protocol must be an instance of DatagramProtocol',): - pass - else: - raise - else: - raise AssertionError, 'addProto must raise an exception for bad protocols' - - - def testAddingBadProtos_TooSmall(self): - """Adding a protocol with a negative number raises an exception.""" - e = rawudp.RawUDPProtocol() - try: - e.addProto(-1, protocol.DatagramProtocol()) - except TypeError, e: - if e.args == ('Added protocol must be positive or zero',): - pass - else: - raise - else: - raise AssertionError, 'addProto must raise an exception for bad protocols' - - - def testAddingBadProtos_TooBig(self): - """Adding a protocol with a number >=2**16 raises an exception.""" - e = rawudp.RawUDPProtocol() - try: - e.addProto(2**16, protocol.DatagramProtocol()) - except TypeError, e: - if e.args == ('Added protocol must fit in 16 bits',): - pass - else: - raise - else: - raise AssertionError, 'addProto must raise an exception for bad protocols' - - def testAddingBadProtos_TooBig2(self): - """Adding a protocol with a number >=2**16 raises an exception.""" - e = rawudp.RawUDPProtocol() - try: - e.addProto(2**16+1, protocol.DatagramProtocol()) - except TypeError, e: - if e.args == ('Added protocol must fit in 16 bits',): - pass - else: - raise - else: - raise AssertionError, 'addProto must raise an exception for bad protocols' diff --git a/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/pair/topfiles/NEWS b/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/pair/topfiles/NEWS deleted file mode 100644 index 2161528e..00000000 --- a/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/pair/topfiles/NEWS +++ /dev/null @@ -1,62 +0,0 @@ -Twisted Pair 12.2.0 (2012-08-26) -================================ - -No significant changes have been made for this release. - - -Twisted Pair 12.1.0 (2012-06-02) -================================ - -No significant changes have been made for this release. - - -Twisted Pair 12.0.0 (2012-02-10) -================================ - -No significant changes have been made for this release. - - -Twisted Pair 11.1.0 (2011-11-15) -================================ - -No significant changes have been made for this release. - - -Twisted Pair 11.0.0 (2011-04-01) -================================ - -No significant changes have been made for this release. - - -Twisted Pair 10.2.0 (2010-11-29) -================================ - -No significant changes have been made for this release. - - -Twisted Pair 10.1.0 (2010-06-27) -================================ - -No significant changes have been made for this release. - - -Twisted Pair 10.0.0 (2010-03-01) -================================ - -Other ------ - - #4170 - - -Twisted Pair 9.0.0 (2009-11-24) -=============================== - -Other ------ - - #3540, #4050 - - -Pair 8.2.0 (2008-12-16) -======================= - -No interesting changes since Twisted 8.0. diff --git a/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/pair/topfiles/README b/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/pair/topfiles/README deleted file mode 100644 index 8d022a91..00000000 --- a/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/pair/topfiles/README +++ /dev/null @@ -1,4 +0,0 @@ -Twisted Pair 12.2.0 - -Twisted Pair depends on Twisted Core. For TUN/TAP access, python-eunuchs -(<http://pypi.python.org/pypi/python-eunuchs/0.0.0>) is also required. diff --git a/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/pair/tuntap.py b/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/pair/tuntap.py deleted file mode 100755 index e3ece5e0..00000000 --- a/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/pair/tuntap.py +++ /dev/null @@ -1,170 +0,0 @@ -# Copyright (c) Twisted Matrix Laboratories. -# See LICENSE for details. - -# -import errno, os -from twisted.python import log, reflect, components -from twisted.internet import base, fdesc, error -from twisted.pair import ethernet, ip - -""" -You need Eunuchs for twisted.pair.tuntap to work. - -Eunuchs is a library containing the missing manly parts of -UNIX API for Python. - -Eunuchs is a library of Python extension that complement the standard -libraries in parts where full support for the UNIX API (or the Linux -API) is missing. - -Most of the functions wrapped by Eunuchs are low-level, dirty, but -absolutely necessary functions for real systems programming. The aim is -to have the functions added to mainstream Python libraries. - -Current list of functions included: - - - fchdir(2) - - recvmsg(2) and sendmsg(2), including use of cmsg(3) - - socketpair(2) - - support for TUN/TAP virtual network interfaces - -Eunuchs doesn't have a proper web home right now, but you can fetch -the source from http://ftp.debian.org/debian/pool/main/e/eunuch --- debian users can just use 'apt-get install python-eunuchs'. - -""" -from eunuchs.tuntap import opentuntap, TuntapPacketInfo, makePacketInfo - -class TuntapPort(base.BasePort): - """A Port that reads and writes packets from/to a TUN/TAP-device. - - TODO: Share general start/stop etc implementation details with - twisted.internet.udp.Port. - """ - maxThroughput = 256 * 1024 # max bytes we read in one eventloop iteration - - def __init__(self, interface, proto, maxPacketSize=8192, reactor=None): - if components.implements(proto, ethernet.IEthernetProtocol): - self.ethernet = 1 - else: - self.ethernet = 0 - assert components.implements(proto, ip.IIPProtocol) # XXX: fix me - base.BasePort.__init__(self, reactor) - self.interface = interface - self.protocol = proto - self.maxPacketSize = maxPacketSize - self.setLogStr() - - def __repr__(self): - return "<%s on %s>" % (self.protocol.__class__, self.interface) - - def startListening(self): - """Create and bind my socket, and begin listening on it. - - This is called on unserialization, and must be called after creating a - server to begin listening on the specified port. - """ - self._bindSocket() - self._connectToProtocol() - - def _bindSocket(self): - log.msg("%s starting on %s"%(self.protocol.__class__, self.interface)) - try: - fd, name = opentuntap(name=self.interface, - ethernet=self.ethernet, - packetinfo=0) - except OSError, e: - raise error.CannotListenError, (None, self.interface, e) - fdesc.setNonBlocking(fd) - self.interface = name - self.connected = 1 - self.fd = fd - - def fileno(self): - return self.fd - - def _connectToProtocol(self): - self.protocol.makeConnection(self) - self.startReading() - - def doRead(self): - """Called when my socket is ready for reading.""" - read = 0 - while read < self.maxThroughput: - try: - data = os.read(self.fd, self.maxPacketSize) - read += len(data) -# pkt = TuntapPacketInfo(data) - self.protocol.datagramReceived(data, - partial=0 # pkt.isPartial(), - ) - except OSError, e: - if e.errno in (errno.EWOULDBLOCK,): - return - else: - raise - except IOError, e: - if e.errno in (errno.EAGAIN, errno.EINTR): - return - else: - raise - except: - log.deferr() - - def write(self, datagram): - """Write a datagram.""" -# header = makePacketInfo(0, 0) - try: - return os.write(self.fd, datagram) - except IOError, e: - if e.errno == errno.EINTR: - return self.write(datagram) - elif e.errno == errno.EMSGSIZE: - raise error.MessageLengthError, "message too long" - elif e.errno == errno.ECONNREFUSED: - raise error.ConnectionRefusedError - else: - raise - - def writeSequence(self, seq): - self.write("".join(seq)) - - def loseConnection(self): - """Stop accepting connections on this port. - - This will shut down my socket and call self.connectionLost(). - """ - self.stopReading() - if self.connected: - from twisted.internet import reactor - reactor.callLater(0, self.connectionLost) - - stopListening = loseConnection - - def connectionLost(self, reason=None): - """Cleans up my socket. - """ - log.msg('(Tuntap %s Closed)' % self.interface) - base.BasePort.connectionLost(self, reason) - if hasattr(self, "protocol"): - # we won't have attribute in ConnectedPort, in cases - # where there was an error in connection process - self.protocol.doStop() - self.connected = 0 - os.close(self.fd) - del self.fd - - def setLogStr(self): - self.logstr = reflect.qual(self.protocol.__class__) + " (TUNTAP)" - - def logPrefix(self): - """Returns the name of my class, to prefix log entries with. - """ - return self.logstr - - def getHost(self): - """ - Returns a tuple of ('TUNTAP', interface), indicating - the servers address - """ - return ('TUNTAP',)+self.interface |