Ejemplo n.º 1
0
    def respond(self):
        # Check if all objects have been received
        if not self.response or not all(self.response.values()):
            return False

        items = list(self.get_items()) or self.response.values()

        result = []

        # Build objects from protobuf responses
        for item in items:
            if item is None:
                continue

            content_type, data = item

            # Get item descriptor
            descriptor = self.find_descriptor(content_type)

            # Build object from data
            item = Parser.construct(self.sp, self.response_type, descriptor, data)
            item.dict_update(self.defaults)

            result.append(item)

        # Emit success event
        if len(self.requests) == 1 and not self.multi:
            self.emit('success', result[0] if result else None)
        else:
            self.emit('success', result)

        return True
Ejemplo n.º 2
0
    def construct(cls, sp, data):
        obj = TunigoResponse()

        # Parse items
        obj.items = []

        for container in data.get('items', []):
            for tag, item in container.items():
                obj.items.append(Parser.parse(sp, Parser.Tunigo, tag, item))

        # Fill extras
        obj.total = data.get('totalItems')
        obj.regions = data.get('regions')
        obj.products = data.get('products')

        return obj
Ejemplo n.º 3
0
    def respond(self):
        # Check if all objects have been received
        if not self.response or not all(self.response.values()):
            awaiting = [
                key for (key, value) in self.response.items() if not value
            ]
            log.debug('Waiting for %s item(s) - %s', len(awaiting),
                      repr(awaiting))
            return False

        log.debug('Building object(s) from %s item(s)', len(self.response))

        items = list(self.get_items()) or self.response.values()

        result = []

        # Build objects from protobuf responses
        for item in items:
            if item is None:
                continue

            content_type, data = item

            # Get item descriptor
            descriptor = self.find_descriptor(content_type)

            # Build object from data
            item = Parser.construct(self.sp, self.response_type, descriptor,
                                    data)
            item.dict_update(self.defaults)

            result.append(item)

        log.debug('Returning %s object(s) to response callback', len(result))

        # Emit success event
        if len(self.requests) == 1 and not self.multi:
            self.emit('success', result[0] if result else None)
        else:
            self.emit('success', result)

        return True
Ejemplo n.º 4
0
    def respond(self):
        # Check if all objects have been received
        if not self.response or not all(self.response.values()):
            awaiting = [key for (key, value) in self.response.items() if not value]
            log.debug('Waiting for %s item(s) - %s', len(awaiting), repr(awaiting))
            return False

        log.debug('Building object(s) from %s item(s)', len(self.response))

        items = list(self.get_items()) or self.response.values()

        result = []

        # Build objects from protobuf responses
        for item in items:
            if item is None:
                continue

            content_type, data = item

            # Get item descriptor
            descriptor = self.find_descriptor(content_type)

            # Build object from data
            item = Parser.construct(self.sp, self.response_type, descriptor, data)
            item.dict_update(self.defaults)

            result.append(item)

        log.debug('Returning %s object(s) to response callback', len(result))

        # Emit success event
        if len(self.requests) == 1 and not self.multi:
            self.emit('success', result[0] if result else None)
        else:
            self.emit('success', result)

        return True
Ejemplo n.º 5
0
 def parse_node(cls, sp, node):
     return Parser.parse(sp, 'XML', node.tag, node)