How to use the avro.schema.AvroException function in avro

To help you get started, we’ve selected a few avro examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github apache / avro / lang / py / avro / io.py View on Github external
return decoder.skip_bytes()
    elif writers_schema.type == 'fixed':
      return self.skip_fixed(writers_schema, decoder)
    elif writers_schema.type == 'enum':
      return self.skip_enum(writers_schema, decoder)
    elif writers_schema.type == 'array':
      return self.skip_array(writers_schema, decoder)
    elif writers_schema.type == 'map':
      return self.skip_map(writers_schema, decoder)
    elif writers_schema.type in ['union', 'error_union']:
      return self.skip_union(writers_schema, decoder)
    elif writers_schema.type in ['record', 'error', 'request']:
      return self.skip_record(writers_schema, decoder)
    else:
      fail_msg = "Unknown schema type: %s" % writers_schema.type
      raise schema.AvroException(fail_msg)
github apache / avro / lang / py3 / avro / io.py View on Github external
return decoder.skip_bytes()
    elif writer_schema.type == 'fixed':
      return self.skip_fixed(writer_schema, decoder)
    elif writer_schema.type == 'enum':
      return self.skip_enum(writer_schema, decoder)
    elif writer_schema.type == 'array':
      return self.skip_array(writer_schema, decoder)
    elif writer_schema.type == 'map':
      return self.skip_map(writer_schema, decoder)
    elif writer_schema.type in ['union', 'error_union']:
      return self.skip_union(writer_schema, decoder)
    elif writer_schema.type in ['record', 'error', 'request']:
      return self.skip_record(writer_schema, decoder)
    else:
      fail_msg = "Unknown schema type: %s" % writer_schema.type
      raise schema.AvroException(fail_msg)
github thisismedium / message-db / mdb / avro / marshall.py View on Github external
def read_data(self, writers_schema, readers_schema, decoder):

        ## NOTE: no schema reconciliation

        method = 'read_%s' % writers_schema.type
        if hasattr(decoder, method):
            return getattr(decoder, method)()
        elif hasattr(self, method):
            datum = getattr(self, method)(writers_schema, readers_schema, decoder)
            return types.cast(datum, types.from_schema(writers_schema))
        else:
            raise _s.AvroException('Unknown type: %r.' % writers_schema.type)
github johnj / php5-xcom / src / py / avro / genericio.py View on Github external
def readdata(self, actual, expected, decoder):
    if actual.gettype() == schema.UNION:
      actual = actual.getelementtypes()[int(decoder.readlong())]
    if expected.gettype() == schema.UNION:
      expected = self._resolve(actual, expected)
    if actual.gettype() == schema.NULL:
      return None
    fn = self.__readfn.get(actual.gettype())
    if fn is not None:
      return fn(actual, expected, decoder)
    else:
      raise schema.AvroException("Unknown type: "+schema.stringval(actual));
github apache / avro / lang / py / avro / ipc.py View on Github external
SYSTEM_ERROR_SCHEMA = schema.parse('["string"]')

# protocol cache
REMOTE_HASHES = {}
REMOTE_PROTOCOLS = {}

BIG_ENDIAN_INT_STRUCT = avro.io.struct_class('!I')
BUFFER_HEADER_LENGTH = 4
BUFFER_SIZE = 8192

#
# Exceptions
#

class AvroRemoteException(schema.AvroException):
  """
  Raised when an error message is sent by an Avro requestor or responder.
  """
  def __init__(self, fail_msg=None):
    schema.AvroException.__init__(self, fail_msg)

class ConnectionClosedException(schema.AvroException):
  pass

#
# Base IPC Classes (Requestor/Responder)
#

class BaseRequestor(object):
  """Base class for the client side of a protocol interaction."""
  def __init__(self, local_protocol, transceiver):
github apache / avro / lang / py3 / avro / io.py View on Github external
INT_MIN_VALUE = -(1 << 31)
INT_MAX_VALUE = (1 << 31) - 1
LONG_MIN_VALUE = -(1 << 63)
LONG_MAX_VALUE = (1 << 63) - 1

STRUCT_INT = struct.Struct('!I')     # big-endian unsigned int
STRUCT_FLOAT = struct.Struct('I')   # big-endian unsigned int


# ------------------------------------------------------------------------------
# Exceptions


class AvroTypeException(schema.AvroException):
  """Raised when datum is not an example of schema."""
  def __init__(self, expected_schema, datum):
    pretty_expected = json.dumps(json.loads(str(expected_schema)), indent=2)
    fail_msg = "The datum %s is not an example of the schema %s"\
               % (datum, pretty_expected)
    schema.AvroException.__init__(self, fail_msg)


class SchemaResolutionException(schema.AvroException):
  def __init__(self, fail_msg, writer_schema=None, reader_schema=None):
    pretty_writers = json.dumps(json.loads(str(writer_schema)), indent=2)
    pretty_readers = json.dumps(json.loads(str(reader_schema)), indent=2)
    if writer_schema: fail_msg += "\nWriter's Schema: %s" % pretty_writers
    if reader_schema: fail_msg += "\nReader's Schema: %s" % pretty_readers
    schema.AvroException.__init__(self, fail_msg)
github apache / avro / lang / py3 / avro / io.py View on Github external
map_val = self._read_default_value(field_schema.values, json_val)
        read_map[key] = map_val
      return read_map
    elif field_schema.type in ['union', 'error_union']:
      return self._read_default_value(field_schema.schemas[0], default_value)
    elif field_schema.type == 'record':
      read_record = {}
      for field in field_schema.fields:
        json_val = default_value.get(field.name)
        if json_val is None: json_val = field.default
        field_val = self._read_default_value(field.type, json_val)
        read_record[field.name] = field_val
      return read_record
    else:
      fail_msg = 'Unknown type: %s' % field_schema.type
      raise schema.AvroException(fail_msg)
github apache / avro / lang / py / avro / ipc.py View on Github external
def write_call_request(self, message_name, request_datum, encoder):
    """
    The format of a call request is:
      * request metadata, a map with values of type bytes
      * the message name, an Avro string, followed by
      * the message parameters. Parameters are serialized according to
        the message's request declaration.
    """
    # request metadata (not yet implemented)
    request_metadata = {}
    META_WRITER.write(request_metadata, encoder)

    # message name
    message = self.local_protocol.messages.get(message_name)
    if message is None:
      raise schema.AvroException('Unknown message: %s' % message_name)
    encoder.write_utf8(message.name)

    # message parameters
    self.write_request(message.request, request_datum, encoder)
github rbystrit / avro_gen / avrogen / avrojson.py View on Github external
if isinstance(json_obj, collections.Mapping):
            items = list(six.iteritems(json_obj))
            if not items:
                return None

            value_type = items[0][0]
            value = items[0][1]
            for s in writers_schema.schemas:
                name = self._fullname(s)
                if name == value_type:
                    return self._generic_from_json(value, s, readers_schema)

        for s in writers_schema.schemas:
            if self.validate(s, json_obj, skip_logical_types=True):
                return self._generic_from_json(json_obj, s, readers_schema)
        raise schema.AvroException('Datum union type not in schema: %s', value_type)