コード例 #1
0
def BuildC11Type(schemaName,
                 schemaValue,
                 isSchema=False,
                 manualCodeHeaders=None,
                 manualCodeSourcesVariable=None,
                 manualCodeSourcesFunction=None,
                 manualCodeParsersFrom=None,
                 manualCodeParsersTo=None):
    if u'title' not in schemaValue:
        return (None, 1,
                u'can\'t get the attribute `title` in %s' % schemaName)
    c11Type = None
    if not isSchema and u'type' in schemaValue:
        schemaValueType = schemaValue[u'type']
        if schemaValueType == u'bool' or schemaValueType == u'boolean':
            c11Type = C11TypeBool()
        elif schemaValueType == u'integer':
            c11Type = C11TypeInteger()
        elif schemaValueType == u'number':
            c11Type = C11TypeNumber()
        elif schemaValueType == u'string':
            c11Type = C11TypeString()
        elif schemaValueType == u'array':
            c11Type = C11TypeArray()
        #elif schemaValueType == u'object':
        #    c11Type = C11TypeMap()
    if c11Type == None:
        c11Type = C11TypeStruct()
    c11Type.setSchema(schemaName, schemaValue)
    c11Type.setCodes(manualCodeHeaders, manualCodeSourcesVariable,
                     manualCodeSourcesFunction, manualCodeParsersFrom,
                     manualCodeParsersTo)
    return (c11Type, 0, None)
コード例 #2
0
ファイル: c11variable.py プロジェクト: fayhot/libgltf
    def revise(self, c11Types):
        variableSchemaValue = self.schemaValue
        if u'type' in self.schemaValue:
            schemaValueType = self.schemaValue[u'type']
            if schemaValueType == u'object' and u'additionalProperties' in self.schemaValue:
                schemaValueType = u'map'
                variableSchemaValue = self.schemaValue[u'additionalProperties']
        elif u'$ref' in self.schemaValue:
            schemaValueType = self.schemaValue[u'$ref']
        elif u'allOf' in self.schemaValue and len(
                self.schemaValue[u'allOf']
        ) > 0 and u'$ref' in self.schemaValue[u'allOf'][0]:
            schemaValueType = self.schemaValue[u'allOf'][0][u'$ref']
            #schemaValueType = u'array'
            #variableSchemaValue = self.schemaValue[u'allOf'][0]
        elif u'anyOf' in self.schemaValue and len(
                self.schemaValue[u'anyOf']) > 0:
            for schemaValueAnyOf in self.schemaValue[u'anyOf']:
                if u'type' not in schemaValueAnyOf:
                    continue
                schemaValueType = schemaValueAnyOf[u'type']
                break
        else:
            return (0, None)

        if schemaValueType == u'bool' or schemaValueType == u'boolean':
            self.c11Type = C11TypeBool()
            self.typeName = u'bool'
        elif schemaValueType == u'integer':
            self.c11Type = C11TypeInteger()
            self.typeName = u'integer'
        elif schemaValueType == u'number':
            self.c11Type = C11TypeNumber()
            self.typeName = u'number'
        elif schemaValueType == u'string':
            self.c11Type = C11TypeString()
            self.typeName = u'string'
        elif schemaValueType == u'array':
            self.c11Type = C11TypeArray()
            self.typeName = u'array'
            self.c11Type.setItemSchema(variableSchemaValue)
        elif schemaValueType == u'map':
            self.c11Type = C11TypeMap()
            self.typeName = u'map'
            self.c11Type.setItemSchema(variableSchemaValue)
        else:
            if schemaValueType not in c11Types:
                if u'additionalProperties' in self.schemaValue:
                    schemaValueAdditionalProperties = self.schemaValue[
                        u'additionalProperties']
                    if u'$ref' in schemaValueAdditionalProperties:
                        schemaValueType = schemaValueAdditionalProperties[
                            u'$ref']
            if schemaValueType in c11Types:
                self.c11Type = c11Types[schemaValueType]
                self.typeName = u'struct'
            else:
                self.c11Type = C11TypeNone()
        self.c11Type.revise(c11Types)
        return (0, None)
コード例 #3
0
 def setSchema(self, schemaName, schemaValue):
     C11Type.setSchema(self, schemaName, schemaValue)
     if u'type' in schemaValue:
         schemaValueType = schemaValue[u'type']
         if schemaValueType == u'bool' or schemaValueType == u'boolean':
             self.c11Type = C11TypeBool()
         elif schemaValueType == u'integer':
             self.c11Type = C11TypeInteger()
         elif schemaValueType == u'number':
             self.c11Type = C11TypeNumber()
         elif schemaValueType == u'string':
             self.c11Type = C11TypeString()
         elif schemaValueType == u'array':
             self.c11Type = C11TypeArray()
     if self.c11Type == None:
         if u'allOf' in schemaValue:
             schemaValueAllOf = schemaValue[u'allOf']
             for schemaValueAllOfItem in schemaValueAllOf:
                 if u'$ref' in schemaValueAllOfItem:
                     self.parents[schemaValueAllOfItem[u'$ref']] = None
         if u'properties' in schemaValue:
             schemaValueProperties = schemaValue[u'properties']
             for key in schemaValueProperties:
                 self.variables[key] = C11Variable(
                     key, schemaValueProperties[key])
コード例 #4
0
ファイル: __init__.py プロジェクト: gitter-badger/libgltf
def BuildC11Type(schemaName, schemaValue, isSchema=False):
    if u'title' not in schemaValue:
        return (None, 1, u'can\'t get the attribute `title` in %s' % schemaName)
    c11Type = None
    if not isSchema and u'type' in schemaValue:
        schemaValueType = schemaValue[u'type']
        if schemaValueType == u'bool' or schemaValueType == u'boolean':
            c11Type = C11TypeBool()
        elif schemaValueType == u'integer':
            c11Type = C11TypeInteger()
        elif schemaValueType == u'number':
            c11Type = C11TypeNumber()
        elif schemaValueType == u'string':
            c11Type = C11TypeString()
        elif schemaValueType == u'array':
            c11Type = C11TypeArray()
        #elif schemaValueType == u'object':
        #    c11Type = C11TypeMap()
    if c11Type == None:
        c11Type = C11TypeStruct()
    c11Type.setSchema(schemaName, schemaValue)
    return (c11Type, 0, None)
コード例 #5
0
 def buildC11Type(self, schemaValue):
     c11Type = None
     if u'type' in schemaValue:
         schemaValueType = schemaValue[u'type']
         if schemaValueType == u'bool' or schemaValueType == u'boolean':
             from c11typebool import C11TypeBool
             c11Type = C11TypeBool()
         elif schemaValueType == u'integer':
             from c11typeinteger import C11TypeInteger
             c11Type = C11TypeInteger()
         elif schemaValueType == u'number':
             from c11typenumber import C11TypeNumber
             c11Type = C11TypeNumber()
         elif schemaValueType == u'string':
             from c11typestring import C11TypeString
             c11Type = C11TypeString()
         elif schemaValueType == u'array':
             from c11typearray import C11TypeArray
             c11Type = C11TypeArray()
     if c11Type == None:
         from c11typestruct import C11TypeStruct
         c11Type = C11TypeStruct()
     return (c11Type, 0, None)