def fields_to_partial_json(self):
        """Serialize fields to JSON."""
        jobj = {}
        for slot, field in self._fields.iteritems():
            value = getattr(self, slot)

            if field.omit(value):
                logging.debug('Omitting empty field "%s" (%s)', slot, value)
            else:
                try:
                    jobj[field.json_name] = field.encode(value)
                except errors.SerializationError as error:
                    raise errors.SerializationError(
                        'Could not encode {0} ({1}): {2}'.format(
                            slot, value, error))
        return jobj
示例#2
0
    def fields_to_partial_json(self):
        """Serialize fields to JSON."""
        jobj = {}
        omitted = set()
        for slot, field in six.iteritems(self._fields):
            value = getattr(self, slot)

            if field.omit(value):
                omitted.add((slot, value))
            else:
                try:
                    jobj[field.json_name] = field.encode(value)
                except errors.SerializationError as error:
                    raise errors.SerializationError(
                        'Could not encode {0} ({1}): {2}'.format(
                            slot, value, error))
        return jobj
示例#3
0
    def fields_to_partial_json(self):
        """Serialize fields to JSON."""
        jobj = {}
        omitted = set()
        for slot, field in six.iteritems(self._fields):
            value = getattr(self, slot)

            if field.omit(value):
                omitted.add((slot, value))
            else:
                try:
                    jobj[field.json_name] = field.encode(value)
                except errors.SerializationError as error:
                    raise errors.SerializationError(
                        'Could not encode {0} ({1}): {2}'.format(
                            slot, value, error))
        if omitted:
            # pylint: disable=star-args
            logger.debug('Omitted empty fields: %s', ', '.join(
                '{0!s}={1!r}'.format(*field) for field in omitted))
        return jobj
 def y(value):
     if value == 500:
         raise errors.SerializationError()
     return value