Commit 6f697bd9 authored by Dave Kuhlman's avatar Dave Kuhlman

Merged in mustafa_cosar/generateds/mustafa/generate-enums (pull request #34)

Generate enums
parents 4a2db77f 63839d6e
......@@ -256,6 +256,7 @@ ExternalEncoding = ''
Namespacedef = ''
NoNameSpaceDefs = False
CleanupNameList = [(re.compile('[-:.]'), '_')]
PythonIdentifierRegex = re.compile('^[_A-Za-z][_A-Za-z0-9]*$')
NamespacesDict = {}
SchemaNamespaceDict = {}
......@@ -606,6 +607,9 @@ class SimpleTypeElement(XschemaElementBase):
def getAttributeGroup(self):
return self.attributeGroup
def getEnumValues(self):
return self.values
def setListType(self, listType):
self.listType = listType
......@@ -6671,10 +6675,44 @@ def generateFromTree(wrt, prefix, elements, processed):
def generateSimpleTypes(wrt, prefix, simpleTypeDict):
for simpletype in simpleTypeDict.keys():
wrt('class %s(object):\n' % simpletype)
wrt(' pass\n')
wrt('\n\n')
def validateIdentifier(name):
validPythonIdentifier = True
if not PythonIdentifierRegex.match(name):
# it may start with a digit
escapedName = '_%s' % name
if PythonIdentifierRegex.match(escapedName):
return NameTable.get(escapedName, escapedName)
else:
raise ValueError
return NameTable.get(name, name)
def writeEnumClass(simpleType):
enumValues = simpleType.getEnumValues()
if enumValues:
try:
className = validateIdentifier(simpleType.getName())
except ValueError:
err_msg(
'*** The Simple Type name "%s" is not a valid '
'Python identifier\n' % simpleType.getName())
sys.exit(1)
wrt('class %s(object):\n' % simpleType.getName())
for enumValue in enumValues:
try:
validatedEnumValue = validateIdentifier(enumValue)
except ValueError:
err_msg(
'*** The enumeration value "%s" is not a valid Python '
'identifier\n' % enumValue)
sys.exit(1)
wrt(' %s=\'%s\'\n' % (validatedEnumValue, enumValue))
wrt('\n\n')
for simpletypeName in sorted(simpleTypeDict.keys()):
if ':' not in simpletypeName:
continue
simpleType = simpleTypeDict[simpletypeName]
writeEnumClass(simpleType)
def getImportsForExternalXsds(root):
......@@ -6745,7 +6783,7 @@ def generate(outfileName, subclassFilename, behaviorFilename,
processed = []
externalImports = getImportsForExternalXsds(root)
generateHeader(wrt, prefix, options, args, externalImports)
#generateSimpleTypes(outfile, prefix, SimpleTypeDict)
generateSimpleTypes(wrt, prefix, SimpleTypeDict)
DelayedElements = set()
DelayedElements_subclass = set()
elements = root.getChildren()
......
......@@ -2,7 +2,7 @@
#
# Generated by generateDS.py.
# Python 2.7.14 (default, Sep 23 2017, 22:06:14) [GCC 7.2.0]
# Python 2.7.12 (default, Dec 4 2017, 14:50:18) [GCC 5.4.0 20160609]
#
# Command line options:
# ('--no-dates', '')
......
......@@ -3,7 +3,7 @@
#
# Generated by generateDS.py.
# Python 2.7.14 (default, Sep 23 2017, 22:06:14) [GCC 7.2.0]
# Python 2.7.12 (default, Dec 4 2017, 14:50:18) [GCC 5.4.0 20160609]
#
# Command line options:
# ('--no-dates', '')
......
......@@ -726,6 +726,21 @@ def _cast(typ, value):
#
class RelationType(object):
down='down'
add='add'
class RelationType2(object):
up='up'
subtract='subtract'
class RelationType3(object):
right='right'
divide='divide'
class SpecialDate(GeneratedsSuper):
member_data_items_ = [
MemberSpec_('SpecialProperty', 'xs:string', 0, 1, {'use': 'optional'}),
......
......@@ -725,6 +725,13 @@ def _cast(typ, value):
#
class USState(object):
AK='AK'
AL='AL'
AR='AR'
PA='PA'
class PurchaseOrderType(GeneratedsSuper):
member_data_items_ = [
MemberSpec_('orderDate', 'date', 0, 1, {'use': 'optional'}),
......
......@@ -2,7 +2,7 @@
#
# Generated by generateDS.py.
# Python 2.7.14 (default, Sep 23 2017, 22:06:14) [GCC 7.2.0]
# Python 2.7.12 (default, Dec 4 2017, 14:50:18) [GCC 5.4.0 20160609]
#
# Command line options:
# ('--no-dates', '')
......
......@@ -3,7 +3,7 @@
#
# Generated by generateDS.py.
# Python 2.7.14 (default, Sep 23 2017, 22:06:14) [GCC 7.2.0]
# Python 2.7.12 (default, Dec 4 2017, 14:50:18) [GCC 5.4.0 20160609]
#
# Command line options:
# ('--no-dates', '')
......@@ -725,6 +725,13 @@ def _cast(typ, value):
#
class USState(object):
AK='AK'
AL='AL'
AR='AR'
PA='PA'
class PurchaseOrderType(GeneratedsSuper):
member_data_items_ = [
MemberSpec_('orderDate', 'date', 0, 1, {'use': 'optional'}),
......
......@@ -2,7 +2,7 @@
#
# Generated by generateDS.py.
# Python 2.7.14 (default, Sep 23 2017, 22:06:14) [GCC 7.2.0]
# Python 2.7.12 (default, Dec 4 2017, 14:50:18) [GCC 5.4.0 20160609]
#
# Command line options:
# ('--no-dates', '')
......
......@@ -3,7 +3,7 @@
#
# Generated by generateDS.py.
# Python 2.7.14 (default, Sep 23 2017, 22:06:14) [GCC 7.2.0]
# Python 2.7.12 (default, Dec 4 2017, 14:50:18) [GCC 5.4.0 20160609]
#
# Command line options:
# ('--no-dates', '')
......
......@@ -726,6 +726,13 @@ def _cast(typ, value):
#
class ArrayTypes(object):
float_='float'
int='int'
Name='Name'
token='token'
class people(GeneratedsSuper):
member_data_items_ = [
MemberSpec_('comments', 'comments', 1, 0, {u'maxOccurs': u'unbounded', u'type': u'comments', u'name': u'comments'}, None),
......
......@@ -726,6 +726,13 @@ def _cast(typ, value):
#
class ArrayTypes(object):
float_='float'
int='int'
Name='Name'
token='token'
class people(GeneratedsSuper):
"""A list of people."""
member_data_items_ = [
......
......@@ -726,6 +726,13 @@ def _cast(typ, value):
#
class ArrayTypes(object):
float_='float'
int='int'
Name='Name'
token='token'
class tomato_people(GeneratedsSuper):
member_data_items_ = [
MemberSpec_('comments', 'comments', 1, 0, {u'maxOccurs': u'unbounded', u'type': u'comments', u'name': u'comments'}, None),
......
......@@ -726,6 +726,21 @@ def _cast(typ, value):
#
class RelationType(object):
down='down'
add='add'
class RelationType2(object):
down='down'
add='add'
class RelationType3(object):
down='down'
add='add'
class SpecialDate(GeneratedsSuper):
member_data_items_ = [
MemberSpec_('SpecialProperty', 'xs:string', 0, 1, {'use': 'optional'}),
......
......@@ -728,6 +728,13 @@ def _cast(typ, value):
#
class ArrayTypes(object):
float_='float'
int='int'
Name='Name'
token='token'
class peopleType(GeneratedsSuper):
member_data_items_ = [
MemberSpec_('comments', 'commentsType', 1, 0, {u'maxOccurs': u'unbounded', u'type': u'commentsType', u'name': u'comments'}, None),
......
......@@ -726,6 +726,13 @@ def _cast(typ, value):
#
class token_enum_st(object):
float_='float'
int='int'
Name='Name'
token='token'
class containerType(GeneratedsSuper):
member_data_items_ = [
MemberSpec_('sample1', 'simpleOneType', 1, 0, {u'maxOccurs': u'unbounded', u'type': u'simpleOneType', u'name': u'sample1'}, None),
......
This diff is collapsed.
......@@ -2,7 +2,7 @@
#
# Generated by generateDS.py.
# Python 2.7.14 (default, Sep 23 2017, 22:06:14) [GCC 7.2.0]
# Python 2.7.12 (default, Dec 4 2017, 14:50:18) [GCC 5.4.0 20160609]
#
# Command line options:
# ('--no-dates', '')
......
......@@ -3,7 +3,7 @@
#
# Generated by generateDS.py.
# Python 2.7.14 (default, Sep 23 2017, 22:06:14) [GCC 7.2.0]
# Python 2.7.12 (default, Dec 4 2017, 14:50:18) [GCC 5.4.0 20160609]
#
# Command line options:
# ('--no-dates', '')
......@@ -726,6 +726,13 @@ def _cast(typ, value):
#
class token_enum_st(object):
float_='float'
int='int'
Name='Name'
token='token'
class containerType(GeneratedsSuper):
member_data_items_ = [
MemberSpec_('sample1', 'simpleOneType', 1, 0, {u'maxOccurs': u'unbounded', u'type': u'simpleOneType', u'name': u'sample1'}, None),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment