#NEWLINE# def __init__( self , path = None , fileobj = None , mapping = None , scheme = 'default' ) : #NEWLINE# #INDENT# if ( [ path , fileobj , mapping ] . count ( None ) < 2 ) : #NEWLINE# #INDENT# raise TypeError ( 'path, fileobj and mapping are exclusive' ) #NEWLINE# #UNINDENT# self . _legacy = None #NEWLINE# self . _data = None #NEWLINE# self . scheme = fileobj #NEWLINE# if ( mapping is not None ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# self . _validate_mapping ( mapping , scheme ) #NEWLINE# self . _data = mapping #NEWLINE# #UNINDENT# except MetadataUnrecognizedVersionError : #NEWLINE# #INDENT# self . _legacy = LegacyMetadata ( mapping = mapping , scheme = scheme ) #NEWLINE# self . validate ( ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# data = None #NEWLINE# if path : #NEWLINE# #INDENT# with open ( path , 'rb' ) as f : #NEWLINE# #INDENT# data = f . read ( ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if fileobj : #NEWLINE# #INDENT# data = fileobj . read ( ) #NEWLINE# #UNINDENT# #UNINDENT# if ( data is None ) : #NEWLINE# #INDENT# self . _data = { #NEWLINE# #INDENT# 'metadata_version' : self . METADATA_VERSION , #NEWLINE# 'generator' : self . GENERATOR , #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( not isinstance ( data , text_type ) ) : #NEWLINE# #INDENT# data = data . decode ( 'utf-8' ) #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# self . _data = json . loads ( data ) #NEWLINE# self . _validate_mapping ( self . _data , scheme ) #NEWLINE# #UNINDENT# except ValueError : #NEWLINE# #INDENT# self . _legacy = LegacyMetadata ( fileobj = StringIO ( data ) , scheme = scheme ) #NEWLINE# self . validate ( )