Example #1
0
File: test.py Project: grkvlt/amqp
class Location:

  def __init__(self, longitude, latitude):
    self.longitude = longitude
    self.latitude = latitude

  def __repr__(self):
    return "Location(%r, %r)" % (self.longitude, self.latitude)

enc = TypeEncoder()
enc.deconstructors[urlparse.ParseResult] = lambda u: ("url", urlparse.urlunparse(u))
enc.deconstructors[Location] = lambda l: ("location", (l.longitude, l.latitude))


dec = TypeDecoder()
dec.constructors["url"] = lambda d, v: urlparse.urlparse(v)
dec.constructors["location"] = lambda d, v: Location(*v)

generic_dec = TypeDecoder()


l = Location(1.2, 3.4)
print "Location:", l
bytes = enc.encode(l)
print "Encoded:", repr(bytes)
print "Decoded:", dec.decode(bytes)[0], generic_dec.decode(bytes)[0]

print

u = urlparse.urlparse(u"http://www.amqp.org")
Example #2
0
    return True

TRANSPORT = load_xml("transport.xml")
MESSAGING = load_xml("messaging.xml")
SECURITY = load_xml("security.xml")
TRANSACTIONS = load_xml("transactions.xml")

TYPES = reduce(lambda x, y: x + y,
               [d.query["amqp/section/type"]
                for d in [TYPES_DOC, TRANSPORT, MESSAGING, SECURITY,
                          TRANSACTIONS]])
CLASSES = load_composite(TYPES, composite=Composite, restricted=Restricted,
                         frame=Body, sasl_frame=Body,
                         delivery_state=FieldCompare)

PROTOCOL_DECODER = TypeDecoder()
PROTOCOL_ENCODER = TypeEncoder()

for cls in CLASSES:
  PROTOCOL_ENCODER.deconstructors[cls] = lambda v: (v.TYPE, v.deconstruct())
  for d in cls.DESCRIPTORS:
    PROTOCOL_DECODER.constructors[d] = cls.construct

__all__ = ["CLASSES", "PROTOCOL_DECODER", "PROTOCOL_ENCODER", "Symbol",
           "Binary"]

for cls in CLASSES:
  globals()[cls.__name__] = cls
  __all__.append(cls.__name__)

ACCEPTED = Accepted()