# Path: src/txamqp/spec.py
# def pythonize(name):
#     name = str(name)
#     for key, val in REPLACE.items():
#         name = name.replace(key, val)
#     try:
#         name = KEYWORDS[name]
#     except KeyError:
#         pass
#     return name


from io import BytesIO
from twisted.python import log
from six import with_metaclass
from . import codec
from .spec import pythonize

class PayloadMeta(type):
    def __new__(cls, name, bases, cls_members):
        for req in ("encode", "decode", "type"):
            if req not in cls_members:
                raise TypeError("%s must define %s" % (name, req))

        t = type.__new__(cls, name, bases, cls_members)
        if t.type is not None:
            Frame.DECODERS[t.type] = t
        return t


class Payload(with_metaclass(PayloadMeta, object)):
    type = None

    def encode(self, enc): raise NotImplementedError

    @staticmethod
    def decode(spec, dec): raise NotImplementedError


class Method(Payload):
    type = Frame.METHOD

    def __init__(self, method, *args):
        if len(args) != len(method.fields):
            argspec = ["%s: %s" % (pythonize(f.name), f.type)
                       for f in method.fields]
            raise TypeError("%s.%s expecting (%s), got %s" %

# Path: src/txamqp/spec.py
# def pythonize(name):
#     name = str(name)
#     for key, val in REPLACE.items():
#         name = name.replace(key, val)
#     try:
#         name = KEYWORDS[name]
#     except KeyError:
#         pass
#     return name


# Path: src/txamqp/connection.py
from io import BytesIO
from twisted.python import log
from six import with_metaclass
from . import codec
from .spec import pythonize


class PayloadMeta(type):
    def __new__(cls, name, bases, cls_members):
        for req in ("encode", "decode", "type"):
            if req not in cls_members:
                raise TypeError("%s must define %s" % (name, req))

        t = type.__new__(cls, name, bases, cls_members)
        if t.type is not None:
            Frame.DECODERS[t.type] = t
        return t


class Payload(with_metaclass(PayloadMeta, object)):
    type = None

    def encode(self, enc): raise NotImplementedError

    @staticmethod
    def decode(spec, dec): raise NotImplementedError


class Method(Payload):
    type = Frame.METHOD

    def __init__(self, method, *args):
        if len(args) != len(method.fields):
            argspec = ["%s: %s" % (pythonize(f.name), f.type)
                       for f in method.fields]
            raise TypeError("%s.%s expecting (%s), got %s" %

                            (pythonize(method.klass.name),