<s> """<STR_LIT>""" <EOL> try : <EOL> import json <EOL> except ImportError : <EOL> import simplejson as json <EOL> PRIMITIVE_TYPES = ( <EOL> '<STR_LIT:null>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT:string>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT:int>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT:float>' , <EOL> '<STR_LIT>' , <EOL> ) <EOL> NAMED_TYPES = ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT:error>' , <EOL> ) <EOL> VALID_TYPES = PRIMITIVE_TYPES + NAMED_TYPES + ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ) <EOL> SCHEMA_RESERVED_PROPS = ( <EOL> '<STR_LIT:type>' , <EOL> '<STR_LIT:name>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT:size>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ) <EOL> FIELD_RESERVED_PROPS = ( <EOL> '<STR_LIT:default>' , <EOL> '<STR_LIT:name>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT:type>' , <EOL> ) <EOL> VALID_FIELD_SORT_ORDERS = ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT:ignore>' , <EOL> ) <EOL> class AvroException ( Exception ) : <EOL> pass <EOL> class SchemaParseException ( AvroException ) : <EOL> pass <EOL> class Schema ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , type , other_props = None ) : <EOL> if not isinstance ( type , basestring ) : <EOL> fail_msg = '<STR_LIT>' <EOL> raise SchemaParseException ( fail_msg ) <EOL> elif type not in VALID_TYPES : <EOL> fail_msg = '<STR_LIT>' % type <EOL> raise SchemaParseException ( fail_msg ) <EOL> if not hasattr ( self , '<STR_LIT>' ) : self . _props = { } <EOL> self . set_prop ( '<STR_LIT:type>' , type ) <EOL> self . type = type <EOL> self . _props . update ( other_props or { } ) <EOL> props = property ( lambda self : self . _props ) <EOL> other_props = property ( lambda self : get_other_props ( self . _props , SCHEMA_RESERVED_PROPS ) , <EOL> doc = "<STR_LIT>" ) <EOL> def get_prop ( self , key ) : <EOL> return self . _props . get ( key ) <EOL> def set_prop ( self , key , value ) : <EOL> self . _props [ key ] = value <EOL> def __str__ ( self ) : <EOL> return json . dumps ( self . to_json ( ) ) <EOL> def to_json ( self , names ) : <EOL> """<STR_LIT>""" <EOL> raise Exception ( "<STR_LIT>" ) <EOL> class Name ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , name_attr , space_attr , default_space ) : <EOL> """<STR_LIT>""" <EOL> if not ( isinstance ( name_attr , basestring ) or ( name_attr is None ) ) : <EOL> fail_msg = '<STR_LIT>' <EOL> raise SchemaParseException ( fail_msg ) <EOL> elif name_attr == "<STR_LIT>" : <EOL> fail_msg = '<STR_LIT>' <EOL> raise SchemaParseException ( fail_msg ) <EOL> if not ( isinstance ( space_attr , basestring ) or ( space_attr is None ) ) : <EOL> fail_msg = '<STR_LIT>' <EOL> raise SchemaParseException ( fail_msg ) <EOL> elif name_attr == "<STR_LIT>" : <EOL> fail_msg = '<STR_LIT>' <EOL> raise SchemaParseException ( fail_msg ) <EOL> if not ( isinstance ( default_space , basestring ) or ( default_space is None ) ) : <EOL> fail_msg = '<STR_LIT>' <EOL> raise SchemaParseException ( fail_msg ) <EOL> elif name_attr == "<STR_LIT>" : <EOL> fail_msg = '<STR_LIT>' <EOL> raise SchemaParseException ( fail_msg ) <EOL> self . _full = None ; <EOL> if name_attr is None or name_attr == "<STR_LIT>" : <EOL> return ; <EOL> if ( name_attr . find ( '<STR_LIT:.>' ) < <NUM_LIT:0> ) : <EOL> if ( space_attr is not None ) and ( space_attr != "<STR_LIT>" ) : <EOL> self . _full = "<STR_LIT>" % ( space_attr , name_attr ) <EOL> else : <EOL> if ( default_space is not None ) and ( default_space != "<STR_LIT>" ) : <EOL> self . _full = "<STR_LIT>" % ( default_space , name_attr ) <EOL> else : <EOL> self . _full = name_attr <EOL> else : <EOL> self . _full = name_attr <EOL> def __eq__ ( self , other ) : <EOL> if not isinstance ( other , Name ) : <EOL> return False <EOL> return ( self . fullname == other . fullname ) <EOL> fullname = property ( lambda self : self . _full ) <EOL> def get_space ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . _full is None : <EOL> return None <EOL> if ( self . _full . find ( '<STR_LIT:.>' ) > <NUM_LIT:0> ) : <EOL> return self . _full . rsplit ( "<STR_LIT:.>" , <NUM_LIT:1> ) [ <NUM_LIT:0> ] <EOL> else : <EOL> return "<STR_LIT>" <EOL> class Names ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , default_namespace = None ) : <EOL> self . names = { } <EOL> self . default_namespace = default_namespace <EOL> def has_name ( self , name_attr , space_attr ) : <EOL> test = Name ( name_attr , space_attr , self . default_namespace ) . fullname <EOL> return self . names . has_key ( test ) <EOL> def get_name ( self , name_attr , space_attr ) : <EOL> test = Name ( name_attr , space_attr , self . default_namespace ) . fullname <EOL> if not self . names . has_key ( test ) : <EOL> return None <EOL> return self . names [ test ] <EOL> def prune_namespace ( self , properties ) : <EOL> """<STR_LIT>""" <EOL> if self . default_namespace is None : <EOL> return properties <EOL> if '<STR_LIT>' not in properties : <EOL> return properties <EOL> if properties [ '<STR_LIT>' ] != self . default_namespace : <EOL> return properties <EOL> prunable = properties . copy ( ) <EOL> del ( prunable [ '<STR_LIT>' ] ) <EOL> return prunable <EOL> def add_name ( self , name_attr , space_attr , new_schema ) : <EOL> """<STR_LIT>""" <EOL> to_add = Name ( name_attr , space_attr , self . default_namespace ) <EOL> if to_add . fullname in VALID_TYPES : <EOL> fail_msg = '<STR_LIT>' % to_add . fullname <EOL> raise SchemaParseException ( fail_msg ) <EOL> elif self . names . has_key ( to_add . fullname ) : <EOL> fail_msg = '<STR_LIT>' % to_add . fullname <EOL> raise SchemaParseException ( fail_msg ) <EOL> self . names [ to_add . fullname ] = new_schema <EOL> return to_add <EOL> class NamedSchema ( Schema ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , type , name , namespace = None , names = None , other_props = None ) : <EOL> if not name : <EOL> fail_msg = '<STR_LIT>' <EOL> raise SchemaParseException ( fail_msg ) <EOL> elif not isinstance ( name , basestring ) : <EOL> fail_msg = '<STR_LIT>' <EOL> raise SchemaParseException ( fail_msg ) <EOL> elif namespace is not None and not isinstance ( namespace , basestring ) : <EOL> fail_msg = '<STR_LIT>' <EOL> raise SchemaParseException ( fail_msg ) <EOL> Schema . __init__ ( self , type , other_props ) <EOL> new_name = names . add_name ( name , namespace , self ) <EOL> self . set_prop ( '<STR_LIT:name>' , name ) <EOL> if namespace is not None : <EOL> self . set_prop ( '<STR_LIT>' , new_name . get_space ( ) ) <EOL> self . _fullname = new_name . fullname <EOL> def name_ref ( self , names ) : <EOL> if self . namespace == names . default_namespace : <EOL> return self . name <EOL> else : <EOL> return self . fullname <EOL> name = property ( lambda self : self . get_prop ( '<STR_LIT:name>' ) ) <EOL> namespace = property ( lambda self : self . get_prop ( '<STR_LIT>' ) ) <EOL> fullname = property ( lambda self : self . _fullname ) <EOL> class Field ( object ) : <EOL> def __init__ ( self , type , name , has_default , default = None , <EOL> order = None , names = None , doc = None , other_props = None ) : <EOL> if not name : <EOL> fail_msg = '<STR_LIT>' <EOL> raise SchemaParseException ( fail_msg ) <EOL> elif not isinstance ( name , basestring ) : <EOL> fail_msg = '<STR_LIT>' <EOL> raise SchemaParseException ( fail_msg ) <EOL> elif order is not None and order not in VALID_FIELD_SORT_ORDERS : <EOL> fail_msg = '<STR_LIT>' % order <EOL> raise SchemaParseException ( fail_msg ) <EOL> self . _props = { } <EOL> self . _has_default = has_default <EOL> self . _props . update ( other_props or { } ) <EOL> if ( isinstance ( type , basestring ) and names is not None <EOL> and names . has_name ( type , None ) ) : <EOL> type_schema = names . get_name ( type , None ) <EOL> else : <EOL> try : <EOL> type_schema = make_avsc_object ( type , names ) <EOL> except Exception , e : <EOL> fail_msg = '<STR_LIT>' % ( type , e ) <EOL> raise SchemaParseException ( fail_msg ) <EOL> self . set_prop ( '<STR_LIT:type>' , type_schema ) <EOL> self . set_prop ( '<STR_LIT:name>' , name ) <EOL> self . type = type_schema <EOL> self . name = name <EOL> if has_default : self . set_prop ( '<STR_LIT:default>' , default ) <EOL> if order is not None : self . set_prop ( '<STR_LIT>' , order ) <EOL> if doc is not None : self . set_prop ( '<STR_LIT>' , doc ) <EOL> default = property ( lambda self : self . get_prop ( '<STR_LIT:default>' ) ) <EOL> has_default = property ( lambda self : self . _has_default ) <EOL> order = property ( lambda self : self . get_prop ( '<STR_LIT>' ) ) <EOL> doc = property ( lambda self : self . get_prop ( '<STR_LIT>' ) ) <EOL> props = property ( lambda self : self . _props ) <EOL> other_props = property ( lambda self : get_other_props ( self . _props , FIELD_RESERVED_PROPS ) , <EOL> doc = "<STR_LIT>" ) <EOL> def get_prop ( self , key ) : <EOL> return self . _props . get ( key ) <EOL> def set_prop ( self , key , value ) : <EOL> self . _props [ key ] = value <EOL> def __str__ ( self ) : <EOL> return json . dumps ( self . to_json ( ) ) <EOL> def to_json ( self , names = None ) : <EOL> if names is None : <EOL> names = Names ( ) <EOL> to_dump = self . props . copy ( ) <EOL> to_dump [ '<STR_LIT:type>' ] = self . type . to_json ( names ) <EOL> return to_dump <EOL> def __eq__ ( self , that ) : <EOL> to_cmp = json . loads ( str ( self ) ) <EOL> return to_cmp == json . loads ( str ( that ) ) <EOL> class PrimitiveSchema ( Schema ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , type ) : <EOL> if type not in PRIMITIVE_TYPES : <EOL> raise AvroException ( "<STR_LIT>" % type ) <EOL> Schema . __init__ ( self , type ) <EOL> self . fullname = type <EOL> def to_json ( self , names = None ) : <EOL> if len ( self . props ) == <NUM_LIT:1> : <EOL> return self . fullname <EOL> else : <EOL> return self . props <EOL> def __eq__ ( self , that ) : <EOL> return self . props == that . props <EOL> class FixedSchema ( NamedSchema ) : <EOL> def __init__ ( self , name , namespace , size , names = None , other_props = None ) : <EOL> if not isinstance ( size , int ) : <EOL> fail_msg = '<STR_LIT>' <EOL> raise AvroException ( fail_msg ) <EOL> NamedSchema . __init__ ( self , '<STR_LIT>' , name , namespace , names , other_props ) <EOL> self . set_prop ( '<STR_LIT:size>' , size ) <EOL> size = property ( lambda self : self . get_prop ( '<STR_LIT:size>' ) ) <EOL> def to_json ( self , names = None ) : <EOL> if names is None : <EOL> names = Names ( ) <EOL> if self . fullname in names . names : <EOL> return self . name_ref ( names ) <EOL> else : <EOL> names . names [ self . fullname ] = self <EOL> return names . prune_namespace ( self . props ) <EOL> def __eq__ ( self , that ) : <EOL> return self . props == that . props <EOL> class EnumSchema ( NamedSchema ) : <EOL> def __init__ ( self , name , namespace , symbols , names = None , doc = None , other_props = None ) : <EOL> if not isinstance ( symbols , list ) : <EOL> fail_msg = '<STR_LIT>' <EOL> raise AvroException ( fail_msg ) <EOL> elif False in [ isinstance ( s , basestring ) for s in symbols ] : <EOL> fail_msg = '<STR_LIT>' <EOL> raise AvroException ( fail_msg ) <EOL> elif len ( set ( symbols ) ) < len ( symbols ) : <EOL> fail_msg = '<STR_LIT>' % symbols <EOL> raise AvroException ( fail_msg ) <EOL> NamedSchema . __init__ ( self , '<STR_LIT>' , name , namespace , names , other_props ) <EOL> self . set_prop ( '<STR_LIT>' , symbols ) <EOL> if doc is not None : self . set_prop ( '<STR_LIT>' , doc ) <EOL> symbols = property ( lambda self : self . get_prop ( '<STR_LIT>' ) ) <EOL> doc = property ( lambda self : self . get_prop ( '<STR_LIT>' ) ) <EOL> def to_json ( self , names = None ) : <EOL> if names is None : <EOL> names = Names ( ) <EOL> if self . fullname in names . names : <EOL> return self . name_ref ( names ) <EOL> else : <EOL> names . names [ self . fullname ] = self <EOL> return names . prune_namespace ( self . props ) <EOL> def __eq__ ( self , that ) : <EOL> return self . props == that . props <EOL> class ArraySchema ( Schema ) : <EOL> def __init__ ( self , items , names = None , other_props = None ) : <EOL> Schema . __init__ ( self , '<STR_LIT>' , other_props ) <EOL> if isinstance ( items , basestring ) and names . has_name ( items , None ) : <EOL> items_schema = names . get_name ( items , None ) <EOL> else : <EOL> try : <EOL> items_schema = make_avsc_object ( items , names ) <EOL> except SchemaParseException , e : <EOL> fail_msg = '<STR_LIT>' % ( items , e , names . names . keys ( ) ) <EOL> raise SchemaParseException ( fail_msg ) <EOL> self . set_prop ( '<STR_LIT>' , items_schema ) <EOL> items = property ( lambda self : self . get_prop ( '<STR_LIT>' ) ) <EOL> def to_json ( self , names = None ) : <EOL> if names is None : <EOL> names = Names ( ) <EOL> to_dump = self . props . copy ( ) <EOL> item_schema = self . get_prop ( '<STR_LIT>' ) <EOL> to_dump [ '<STR_LIT>' ] = item_schema . to_json ( names ) <EOL> return to_dump <EOL> def __eq__ ( self , that ) : <EOL> to_cmp = json . loads ( str ( self ) ) <EOL> return to_cmp == json . loads ( str ( that ) ) <EOL> class MapSchema ( Schema ) : <EOL> def __init__ ( self , values , names = None , other_props = None ) : <EOL> Schema . __init__ ( self , '<STR_LIT>' , other_props ) <EOL> if isinstance ( values , basestring ) and names . has_name ( values , None ) : <EOL> values_schema = names . get_name ( values , None ) <EOL> else : <EOL> try : <EOL> values_schema = make_avsc_object ( values , names ) <EOL> except : <EOL> fail_msg = '<STR_LIT>' <EOL> raise SchemaParseException ( fail_msg ) <EOL> self . set_prop ( '<STR_LIT>' , values_schema ) <EOL> values = property ( lambda self : self . get_prop ( '<STR_LIT>' ) ) <EOL> def to_json ( self , names = None ) : <EOL> if names is None : <EOL> names = Names ( ) <EOL> to_dump = self . props . copy ( ) <EOL> to_dump [ '<STR_LIT>' ] = self . get_prop ( '<STR_LIT>' ) . to_json ( names ) <EOL> return to_dump <EOL> def __eq__ ( self , that ) : <EOL> to_cmp = json . loads ( str ( self ) ) <EOL> return to_cmp == json . loads ( str ( that ) ) <EOL> class UnionSchema ( Schema ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , schemas , names = None ) : <EOL> if not isinstance ( schemas , list ) : <EOL> fail_msg = '<STR_LIT>' <EOL> raise SchemaParseException ( fail_msg ) <EOL> Schema . __init__ ( self , '<STR_LIT>' ) <EOL> schema_objects = [ ] <EOL> for schema in schemas : <EOL> if isinstance ( schema , basestring ) and names . has_name ( schema , None ) : <EOL> new_schema = names . get_name ( schema , None ) <EOL> else : <EOL> try : <EOL> new_schema = make_avsc_object ( schema , names ) <EOL> except Exception , e : <EOL> raise SchemaParseException ( '<STR_LIT>' % str ( e ) ) <EOL> if ( new_schema . type in VALID_TYPES and new_schema . type not in NAMED_TYPES <EOL> and new_schema . type in [ schema . type for schema in schema_objects ] ) : <EOL> raise SchemaParseException ( '<STR_LIT>' % new_schema . type ) <EOL> elif new_schema . type == '<STR_LIT>' : <EOL> raise SchemaParseException ( '<STR_LIT>' ) <EOL> else : <EOL> schema_objects . append ( new_schema ) <EOL> self . _schemas = schema_objects <EOL> schemas = property ( lambda self : self . _schemas ) <EOL> def to_json ( self , names = None ) : <EOL> if names is None : <EOL> names = Names ( ) <EOL> to_dump = [ ] <EOL> for schema in self . schemas : <EOL> to_dump . append ( schema . to_json ( names ) ) <EOL> return to_dump <EOL> def __eq__ ( self , that ) : <EOL> to_cmp = json . loads ( str ( self ) ) <EOL> return to_cmp == json . loads ( str ( that ) ) <EOL> class ErrorUnionSchema ( UnionSchema ) : <EOL> def __init__ ( self , schemas , names = None ) : <EOL> UnionSchema . __init__ ( self , [ '<STR_LIT:string>' ] + schemas , names ) <EOL> def to_json ( self , names = None ) : <EOL> if names is None : <EOL> names = Names ( ) <EOL> to_dump = [ ] <EOL> for schema in self . schemas : <EOL> if schema . type == '<STR_LIT:string>' : continue <EOL> to_dump . append ( schema . to_json ( names ) ) <EOL> return to_dump <EOL> class RecordSchema ( NamedSchema ) : <EOL> @ staticmethod <EOL> def make_field_objects ( field_data , names ) : <EOL> """<STR_LIT>""" <EOL> field_objects = [ ] <EOL> field_names = [ ] <EOL> for i , field in enumerate ( field_data ) : <EOL> if hasattr ( field , '<STR_LIT>' ) and callable ( field . get ) : <EOL> type = field . get ( '<STR_LIT:type>' ) <EOL> name = field . get ( '<STR_LIT:name>' ) <EOL> has_default = False <EOL> default = None <EOL> if field . has_key ( '<STR_LIT:default>' ) : <EOL> has_default = True <EOL> default = field . get ( '<STR_LIT:default>' ) <EOL> order = field . get ( '<STR_LIT>' ) <EOL> doc = field . get ( '<STR_LIT>' ) <EOL> other_props = get_other_props ( field , FIELD_RESERVED_PROPS ) <EOL> new_field = Field ( type , name , has_default , default , order , names , doc , <EOL> other_props ) <EOL> if new_field . name in field_names : <EOL> fail_msg = '<STR_LIT>' % new_field . name <EOL> raise SchemaParseException ( fail_msg ) <EOL> field_names . append ( new_field . name ) <EOL> else : <EOL> raise SchemaParseException ( '<STR_LIT>' % field ) <EOL> field_objects . append ( new_field ) <EOL> return field_objects <EOL> def __init__ ( self , name , namespace , fields , names = None , schema_type = '<STR_LIT>' , <EOL> doc = None , other_props = None ) : <EOL> if fields is None : <EOL> fail_msg = '<STR_LIT>' <EOL> raise SchemaParseException ( fail_msg ) <EOL> elif not isinstance ( fields , list ) : <EOL> fail_msg = '<STR_LIT>' <EOL> raise SchemaParseException ( fail_msg ) <EOL> if schema_type == '<STR_LIT>' : <EOL> Schema . __init__ ( self , schema_type , other_props ) <EOL> else : <EOL> NamedSchema . __init__ ( self , schema_type , name , namespace , names , <EOL> other_props ) <EOL> if schema_type == '<STR_LIT>' : <EOL> old_default = names . default_namespace <EOL> names . default_namespace = Name ( name , namespace , <EOL> names . default_namespace ) . get_space ( ) <EOL> field_objects = RecordSchema . make_field_objects ( fields , names ) <EOL> self . set_prop ( '<STR_LIT>' , field_objects ) <EOL> if doc is not None : self . set_prop ( '<STR_LIT>' , doc ) <EOL> if schema_type == '<STR_LIT>' : <EOL> names . default_namespace = old_default <EOL> fields = property ( lambda self : self . get_prop ( '<STR_LIT>' ) ) <EOL> doc = property ( lambda self : self . get_prop ( '<STR_LIT>' ) ) <EOL> @ property <EOL> def fields_dict ( self ) : <EOL> fields_dict = { } <EOL> for field in self . fields : <EOL> fields_dict [ field . name ] = field <EOL> return fields_dict <EOL> def to_json ( self , names = None ) : <EOL> if names is None : <EOL> names = Names ( ) <EOL> if self . type == '<STR_LIT>' : <EOL> return [ f . to_json ( names ) for f in self . fields ] <EOL> if self . fullname in names . names : <EOL> return self . name_ref ( names ) <EOL> else : <EOL> names . names [ self . fullname ] = self <EOL> to_dump = names . prune_namespace ( self . props . copy ( ) ) <EOL> to_dump [ '<STR_LIT>' ] = [ f . to_json ( names ) for f in self . fields ] <EOL> return to_dump <EOL> def __eq__ ( self , that ) : <EOL> to_cmp = json . loads ( str ( self ) ) <EOL> return to_cmp == json . loads ( str ( that ) ) <EOL> def get_other_props ( all_props , reserved_props ) : <EOL> """<STR_LIT>""" <EOL> if hasattr ( all_props , '<STR_LIT>' ) and callable ( all_props . items ) : <EOL> return dict ( [ ( k , v ) for ( k , v ) in all_props . items ( ) if k not in <EOL> reserved_props ] ) <EOL> def make_avsc_object ( json_data , names = None ) : <EOL> """<STR_LIT>""" <EOL> if names == None : <EOL> names = Names ( ) <EOL> if hasattr ( json_data , '<STR_LIT>' ) and callable ( json_data . get ) : <EOL> type = json_data . get ( '<STR_LIT:type>' ) <EOL> other_props = get_other_props ( json_data , SCHEMA_RESERVED_PROPS ) <EOL> if type in PRIMITIVE_TYPES : <EOL> return PrimitiveSchema ( type ) <EOL> elif type in NAMED_TYPES : <EOL> name = json_data . get ( '<STR_LIT:name>' ) <EOL> namespace = json_data . get ( '<STR_LIT>' , names . default_namespace ) <EOL> if type == '<STR_LIT>' : <EOL> size = json_data . get ( '<STR_LIT:size>' ) <EOL> return FixedSchema ( name , namespace , size , names , other_props ) <EOL> elif type == '<STR_LIT>' : <EOL> symbols = json_data . get ( '<STR_LIT>' ) <EOL> doc = json_data . get ( '<STR_LIT>' ) <EOL> return EnumSchema ( name , namespace , symbols , names , doc , other_props ) <EOL> elif type in [ '<STR_LIT>' , '<STR_LIT:error>' ] : <EOL> fields = json_data . get ( '<STR_LIT>' ) <EOL> doc = json_data . get ( '<STR_LIT>' ) <EOL> return RecordSchema ( name , namespace , fields , names , type , doc , other_props ) <EOL> else : <EOL> raise SchemaParseException ( '<STR_LIT>' % type ) <EOL> elif type in VALID_TYPES : <EOL> if type == '<STR_LIT>' : <EOL> items = json_data . get ( '<STR_LIT>' ) <EOL> return ArraySchema ( items , names , other_props ) <EOL> elif type == '<STR_LIT>' : <EOL> values = json_data . get ( '<STR_LIT>' ) <EOL> return MapSchema ( values , names , other_props ) <EOL> elif type == '<STR_LIT>' : <EOL> declared_errors = json_data . get ( '<STR_LIT>' ) <EOL> return ErrorUnionSchema ( declared_errors , names ) <EOL> else : <EOL> raise SchemaParseException ( '<STR_LIT>' % type ) <EOL> elif type is None : <EOL> raise SchemaParseException ( '<STR_LIT>' % json_data ) <EOL> else : <EOL> raise SchemaParseException ( '<STR_LIT>' % type ) <EOL> elif isinstance ( json_data , list ) : <EOL> return UnionSchema ( json_data , names ) <EOL> elif json_data in PRIMITIVE_TYPES : <EOL> return PrimitiveSchema ( json_data ) <EOL> else : <EOL> fail_msg = "<STR_LIT>" % json_data <EOL> raise SchemaParseException ( fail_msg ) <EOL> def parse ( json_string ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> json_data = json . loads ( json_string ) <EOL> except : <EOL> raise SchemaParseException ( '<STR_LIT>' % json_string ) <EOL> names = Names ( ) <EOL> return make_avsc_object ( json_data , names ) </s>
