def ECTag_creator( tagname, tagtype, tagdata): tag = ECTag(tagname, tagtype, tagdata) result=tag.pack() print result print "#OK with [%s, %s, %s ]" % (tagname, tagtype, tagdata) return tag
def test_pack_unpack_single_tag(): # name --> 0x101 257 # type --> 6 # data --> SVN tag_in = ECTag('client_version', 'string', u'SVN') tag_bin = tag_in.pack() tag_out, len, _ = unpack_ectag(tag_bin, False) assert tag_in.tagname == tag_out.tagname print tag_out.tagname, tag_out.tagtype, tag_out.tagdata
def test_ECTag_0(): # name -> 0x101 # type -> uint8(2) # data -> 123 tag = ECTag("client_version","uint8",123 ) result = tag.pack() assert result == '\x02\x02\x02\x00\x01{' print "#OK" return tag
def test_pack_unpack_complex_tag(): subtag1 = ECTag('client_hash', 'hash16', '1234567890abcdef') subtag2 = ECTag('server_address', 'ipv4', "192.168.1.37:9527") subtag3 = ECTag('server_users', 'uint32', 0x5a5a) subtags = [ subtag1, subtag2, subtag3] maintag = ECTag('server', 'string', "aMule Server No2", subtags) maintag_bin = maintag.pack() maintag_out ,length, _ = unpack_ectag(maintag_bin, False) print maintag_out.debugrepr()
def ECPacketData(data_tuple): dtype, tags = data_tuple return pack('!BB', dtype, len(tags)) + ''.join( ECTag(name, data) for name, data in tags)
def __init__(self, op, subtags=[ ]): ECTag.__init__(self,) self.op = op self.subtags = subtags