Commit 09805b57 authored by nagylzs's avatar nagylzs

Fix input file encodings for Python 3

parent 6d4930f8
......@@ -225,7 +225,7 @@ _log = logging.getLogger(__name__)
# Do not modify the following VERSION comments.
# Used by updateversion.py.
##VERSION##
VERSION = '2.29.15'
VERSION = '2.29.16'
##VERSION##
BaseStrTypes = six.string_types
......@@ -252,7 +252,7 @@ NoDates = False
NoVersion = False
AlwaysExportDefault = False
Dirpath = []
ExternalEncoding = sys.getdefaultencoding()
ExternalEncoding = ''
Namespacedef = ''
NoNameSpaceDefs = False
CleanupNameList = [(re.compile('[-:.]'), '_')]
......@@ -5727,7 +5727,11 @@ class GeneratedsSuper(object):
@staticmethod
def gds_encode(instring):
if sys.version_info.major == 2:
return instring.encode(ExternalEncoding)
if ExternalEncoding:
encoding = ExternalEncoding
else:
encoding = 'utf-8'
return instring.encode(encoding)
else:
return instring
@staticmethod
......@@ -6908,7 +6912,7 @@ def parseAndGenerate(
if xschemaFileName == '-':
infile = sys.stdin
else:
infile = open(xschemaFileName, 'r')
infile = open(xschemaFileName, 'rb')
if SingleFileOutput:
parser = make_parser()
dh = XschemaHandler()
......@@ -7226,7 +7230,7 @@ def main():
processIncludes = 1
namespacedef = ''
NoNameSpaceDefs = False
ExternalEncoding = sys.getdefaultencoding()
ExternalEncoding = ''
NoDates = False
NoVersion = False
NoQuestions = False
......
......@@ -40,7 +40,7 @@ except ImportError:
# Do not modify the following VERSION comments.
# Used by updateversion.py.
##VERSION##
VERSION = '2.29.15'
VERSION = '2.29.16'
##VERSION##
CatalogDict = {}
......@@ -63,7 +63,7 @@ def load_catalog(catalogpath):
global CatalogBaseUrl
if catalogpath:
CatalogBaseUrl = os.path.split(catalogpath)[0]
catalog = etree.parse(open(catalogpath))
catalog = etree.parse(open(catalogpath, "rb"))
for elements in catalog.getroot().findall(
"{urn:oasis:names:tc:entity:xmlns:xml:catalog}public"):
CatalogDict[elements.get("publicId")] = elements.get("uri")
......@@ -95,6 +95,7 @@ def get_all_root_file_paths(
catalogpath=None,
shallow=False):
load_catalog(catalogpath)
# Note: infile has been opened in binary mode.
doc1 = etree.parse(infile)
root1 = doc1.getroot()
rootPaths = []
......@@ -209,12 +210,13 @@ def resolve_ref(node, params, options):
raise SchemaIOError(msg)
else:
if os.path.exists(locn):
infile = open(locn)
unencoded_content = infile.read()
if sys.version_info.major == 2:
infile = open(locn)
unencoded_content = infile.read()
content = unencoded_content
else:
content = unencoded_content.encode()
infile = open(locn, 'rb')
content = infile.read()
infile.close()
params.parent_url = locn
params.base_url = os.path.split(locn)[0]
......@@ -319,6 +321,7 @@ def make_file(outFileName, options):
def prep_schema_doc(infile, outfile, inpath, options):
# Note: infile has been opened in binary mode.
doc1 = etree.parse(infile)
root1 = doc1.getroot()
params = Params()
......
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