# Path: umap2/core/usb.py
# class DescriptorType(object):
#     device = 0x01
#     configuration = 0x02
#     string = 0x03
#     interface = 0x04
#     endpoint = 0x05
#     device_qualifier = 0x06
#     other_speed_configuration = 0x07
#     interface_power = 0x08
#     bos = 0x0f
#     device_capability = 0x10
#     hid = 0x21
#     report = 0x22
#     cs_interface = 0x24
#     cs_endpoint = 0x25
#     hub = 0x29


from docopt import docopt
from binascii import unhexlify, hexlify
from umap2.core.usb import DescriptorType
import struct
    def parser_wrapper(pfn):
        def wrapper(self, desc):
            # print 'Parsing desc %02x: %s' % (desc_type, hexlify(desc))
            self.select_node(desc_type)
            node = DescriptorNode(desc_type)
            node.text = pfn(self, desc, node)
            self.push_node(node)
        return wrapper
    return parser_wrapper


def build_init(cls_name, params):
    params.insert(0, ('phy', 'phy'))
    params.insert(0, ('app', 'app'))
    s = '%s(\n    ' % (cls_name)
    s += ',\n    '.join('%s=%s' % (a, b if type(b) != int else hex(b)) for (a, b) in params)
    s += '\n)'
    return s


class Parser(object):
    transfer_types = ('USBEndpoint.transfer_type_', ['control', 'isochronous', 'bulk', 'interrupt'])
    sync_types = ('USBEndpoint.sync_type_', ['none', 'async', 'adaptive', 'synchronous'])
    usage_types = ('USBEndpoint.usage_type_', ['data', 'feedback', 'implicit_feedback'])

    def __init__(self, opts):
        self.opts = opts
        self.root_node = RootNode()
        self.curr_node = self.root_node
        self.parsers = {

# Path: umap2/core/usb.py
# class DescriptorType(object):
#     device = 0x01
#     configuration = 0x02
#     string = 0x03
#     interface = 0x04
#     endpoint = 0x05
#     device_qualifier = 0x06
#     other_speed_configuration = 0x07
#     interface_power = 0x08
#     bos = 0x0f
#     device_capability = 0x10
#     hid = 0x21
#     report = 0x22
#     cs_interface = 0x24
#     cs_endpoint = 0x25
#     hub = 0x29


# Path: umap2/utils/dev_generator.py
from docopt import docopt
from binascii import unhexlify, hexlify
from umap2.core.usb import DescriptorType
import struct

    def parser_wrapper(pfn):
        def wrapper(self, desc):
            # print 'Parsing desc %02x: %s' % (desc_type, hexlify(desc))
            self.select_node(desc_type)
            node = DescriptorNode(desc_type)
            node.text = pfn(self, desc, node)
            self.push_node(node)
        return wrapper
    return parser_wrapper


def build_init(cls_name, params):
    params.insert(0, ('phy', 'phy'))
    params.insert(0, ('app', 'app'))
    s = '%s(\n    ' % (cls_name)
    s += ',\n    '.join('%s=%s' % (a, b if type(b) != int else hex(b)) for (a, b) in params)
    s += '\n)'
    return s


class Parser(object):
    transfer_types = ('USBEndpoint.transfer_type_', ['control', 'isochronous', 'bulk', 'interrupt'])
    sync_types = ('USBEndpoint.sync_type_', ['none', 'async', 'adaptive', 'synchronous'])
    usage_types = ('USBEndpoint.usage_type_', ['data', 'feedback', 'implicit_feedback'])

    def __init__(self, opts):
        self.opts = opts
        self.root_node = RootNode()
        self.curr_node = self.root_node
        self.parsers = {

            DescriptorType.configuration: self.parse_configuration_desc,