Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def prep_schema_doc(infile, outfile, inpath, options):
doc1 = etree.parse(infile)
root1 = doc1.getroot()
params = Params()
params.parent_url = infile
params.base_url = os.path.split(inpath)[0]
inserts = []
if not options.no_collect_includes:
collect_inserts(root1, params, inserts, options)
root2 = copy.copy(root1)
clear_includes_and_imports(root2)
for insert_node in inserts:
root2.append(insert_node)
else:
root2 = root1
if not options.no_redefine_groups:
process_groups(root2)
raise_anon_complextypes(root2)
fix_type_names(root2, options)
doc2 = etree.ElementTree(root2)
def get_all_root_file_paths(
infile,
inpath='',
catalogpath=None,
shallow=False):
load_catalog(catalogpath)
doc1 = etree.parse(infile)
root1 = doc1.getroot()
rootPaths = []
params = Params()
params.parent_url = infile
params.base_url = os.path.split(inpath)[0]
get_root_file_paths(root1, params, rootPaths, shallow)
rootPaths.append(inpath)
return rootPaths
if sys.version_info.major == 2:
urllib_urlopen = urllib2.urlopen
urllib_httperror = urllib2.HTTPError
else:
urllib_urlopen = urllib.request.urlopen
urllib_httperror = urllib.error.HTTPError
try:
urlfile = urllib_urlopen(locn)
content = urlfile.read()
urlfile.close()
params.parent_url = locn
params.base_url = os.path.split(locn)[0]
except urllib_httperror:
msg = "Can't find file %s referenced in %s." % (
locn, params.parent_url, )
raise SchemaIOError(msg)
else:
if os.path.exists(locn):
infile = open(locn)
unencoded_content = infile.read()
if sys.version_info.major == 2:
content = unencoded_content
else:
content = unencoded_content.encode()
infile.close()
params.parent_url = locn
params.base_url = os.path.split(locn)[0]
if content is None:
msg = "Can't find file %s referenced in %s." % (
locn, params.parent_url, )
raise SchemaIOError(msg)
## if content is None:
raise SchemaIOError(msg)
else:
if os.path.exists(locn):
infile = open(locn)
unencoded_content = infile.read()
if sys.version_info.major == 2:
content = unencoded_content
else:
content = unencoded_content.encode()
infile.close()
params.parent_url = locn
params.base_url = os.path.split(locn)[0]
if content is None:
msg = "Can't find file %s referenced in %s." % (
locn, params.parent_url, )
raise SchemaIOError(msg)
## if content is None:
## msg = "Can't find file %s referenced in %s." % (
## locn, params.parent_url, )
## raise SchemaIOError(msg)
return content
elif name == 'arg':
obj = arg.factory()
stackObj = SaxStackElement('arg', obj)
self.stack.append(stackObj)
done = 1
elif name == 'data-type':
stackObj = SaxStackElement('data_type', None)
self.stack.append(stackObj)
done = 1
elif name == 'ancillary':
obj = arg.factory()
stackObj = SaxStackElement('ancillary', obj)
self.stack.append(stackObj)
done = 1
elif name == 'role':
stackObj = SaxStackElement('role', None)
self.stack.append(stackObj)
done = 1
if not done:
self.reportError('"%s" element not allowed here.' % name)
elif name == 'base-impl-url':
stackObj = SaxStackElement('base_impl_url', None)
self.stack.append(stackObj)
done = 1
elif name == 'behaviors':
obj = behaviors.factory()
stackObj = SaxStackElement('behaviors', obj)
self.stack.append(stackObj)
done = 1
elif name == 'behavior':
obj = behavior.factory()
stackObj = SaxStackElement('behavior', obj)
self.stack.append(stackObj)
done = 1
elif name == 'class':
stackObj = SaxStackElement('klass', None)
self.stack.append(stackObj)
done = 1
elif name == 'name':
stackObj = SaxStackElement('name', None)
self.stack.append(stackObj)
done = 1
elif name == 'return-type':
stackObj = SaxStackElement('return_type', None)
self.stack.append(stackObj)
done = 1
elif name == 'args':
obj = args.factory()
stackObj = SaxStackElement('args', obj)
self.stack.append(stackObj)
done = 1
elif name == 'impl-url':
def startElement(self, name, attrs):
done = 0
if name == 'xml-behavior':
obj = xml-behavior.factory()
stackObj = SaxStackElement('xml-behavior', obj)
self.stack.append(stackObj)
done = 1
elif name == 'base-impl-url':
stackObj = SaxStackElement('base_impl_url', None)
self.stack.append(stackObj)
done = 1
elif name == 'behaviors':
obj = behaviors.factory()
stackObj = SaxStackElement('behaviors', obj)
self.stack.append(stackObj)
done = 1
elif name == 'behavior':
obj = behavior.factory()
stackObj = SaxStackElement('behavior', obj)
self.stack.append(stackObj)
done = 1
elif name == 'class':
stackObj = SaxStackElement('klass', None)
self.stack.append(stackObj)
done = 1
elif name == 'name':
stackObj = SaxStackElement('name', None)
self.stack.append(stackObj)
done = 1
elif name == 'return-type':
obj = xml-behavior.factory()
stackObj = SaxStackElement('xml-behavior', obj)
self.stack.append(stackObj)
done = 1
elif name == 'base-impl-url':
stackObj = SaxStackElement('base_impl_url', None)
self.stack.append(stackObj)
done = 1
elif name == 'behaviors':
obj = behaviors.factory()
stackObj = SaxStackElement('behaviors', obj)
self.stack.append(stackObj)
done = 1
elif name == 'behavior':
obj = behavior.factory()
stackObj = SaxStackElement('behavior', obj)
self.stack.append(stackObj)
done = 1
elif name == 'class':
stackObj = SaxStackElement('klass', None)
self.stack.append(stackObj)
done = 1
elif name == 'name':
stackObj = SaxStackElement('name', None)
self.stack.append(stackObj)
done = 1
elif name == 'return-type':
stackObj = SaxStackElement('return_type', None)
self.stack.append(stackObj)
done = 1
elif name == 'args':
obj = args.factory()
done = 1
elif name == 'name':
stackObj = SaxStackElement('name', None)
self.stack.append(stackObj)
done = 1
elif name == 'return-type':
stackObj = SaxStackElement('return_type', None)
self.stack.append(stackObj)
done = 1
elif name == 'args':
obj = args.factory()
stackObj = SaxStackElement('args', obj)
self.stack.append(stackObj)
done = 1
elif name == 'impl-url':
stackObj = SaxStackElement('impl_url', None)
self.stack.append(stackObj)
done = 1
elif name == 'ancillaries':
obj = ancillaries.factory()
stackObj = SaxStackElement('ancillaries', obj)
self.stack.append(stackObj)
done = 1
elif name == 'arg':
obj = arg.factory()
stackObj = SaxStackElement('arg', obj)
self.stack.append(stackObj)
done = 1
elif name == 'data-type':
stackObj = SaxStackElement('data_type', None)
self.stack.append(stackObj)
done = 1
elif name == 'return-type':
stackObj = SaxStackElement('return_type', None)
self.stack.append(stackObj)
done = 1
elif name == 'args':
obj = args.factory()
stackObj = SaxStackElement('args', obj)
self.stack.append(stackObj)
done = 1
elif name == 'impl-url':
stackObj = SaxStackElement('impl_url', None)
self.stack.append(stackObj)
done = 1
elif name == 'ancillaries':
obj = ancillaries.factory()
stackObj = SaxStackElement('ancillaries', obj)
self.stack.append(stackObj)
done = 1
elif name == 'arg':
obj = arg.factory()
stackObj = SaxStackElement('arg', obj)
self.stack.append(stackObj)
done = 1
elif name == 'data-type':
stackObj = SaxStackElement('data_type', None)
self.stack.append(stackObj)
done = 1
elif name == 'ancillary':
obj = arg.factory()
stackObj = SaxStackElement('ancillary', obj)
self.stack.append(stackObj)
done = 1