Skip to content

Commit

Permalink
Merge pull request #1 from NASA-IMPACT/rollback
Browse files Browse the repository at this point in the history
Rollback to Python 2
  • Loading branch information
sharkinsspatial authored Jun 29, 2020
2 parents 476a1c9 + b178f06 commit df8b4bb
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 29 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## ESPA Python Library - V2.0.0
## ESPA Python Library - V1.1.0

### Available library modules
- [ENVIHeader](docs/envi-README.md)
Expand Down
12 changes: 6 additions & 6 deletions espa/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from espa.collection.property_dictionary import PropertyDict
from espa.collection.xml_interface import XMLError
from espa.collection.xml_interface import XMLInterface
from espa.metadata.metadata_api import MetadataError
from espa.metadata.metadata_api import Metadata
from espa.image.envi import ENVIHeader
from collection.property_dictionary import PropertyDict
from collection.xml_interface import XMLError
from collection.xml_interface import XMLInterface
from metadata.metadata_api import MetadataError
from metadata.metadata_api import Metadata
from image.envi import ENVIHeader
4 changes: 2 additions & 2 deletions espa/collection/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
from espa.collection.property_dictionary import PropertyDict
from espa.collection.xml_interface import XMLInterface
from property_dictionary import PropertyDict
from xml_interface import XMLInterface
4 changes: 2 additions & 2 deletions espa/collection/property_dictionary.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ def __init__(self, *args, **kwargs):
super(PropertyDict, self).__init__()
for arg in args:
if isinstance(arg, dict):
for key, value in list(arg.items()):
for key, value in arg.items():
self[key] = self.parse(value)
else:
raise TypeError('Unsupported argument {0}'.format(type(arg)))

if kwargs:
for key, value in list(kwargs.items()):
for key, value in kwargs.items():
self[key] = self.parse(value)

@classmethod
Expand Down
11 changes: 5 additions & 6 deletions espa/collection/xml_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import os
import logging
from io import StringIO, BytesIO
from cStringIO import StringIO


from lxml import etree as etree
Expand Down Expand Up @@ -64,7 +64,7 @@ def __init__(self, xml_xsd, xml_filename=None):

# Create a schema from the XSD
try:
self.xml_schema = etree.XMLSchema(file=BytesIO(xml_xsd))
self.xml_schema = etree.XMLSchema(file=StringIO(xml_xsd))
except etree.LxmlError:
self.logger.exception('LXML Error')
raise XMLError('Schema Creation Error - See LXML Error')
Expand Down Expand Up @@ -95,7 +95,7 @@ def parse(self, xml_filename=None):
name = xml_filename

# Read the file into a string to be used for parsing
with open(name, 'rb') as xml_fd:
with open(name, 'r') as xml_fd:
xml_text = xml_fd.read()

try:
Expand Down Expand Up @@ -158,9 +158,8 @@ def write(self, xml_filename=None):
try:
# Create and populate a temporary file
temp_name = 'temp_ESPA_XML_{0}'.format(name)
with open(temp_name, 'wb') as xml_fd:
xml_fd.write(bytes('<?xml version="1.0" encoding="utf-8"?>\n',
'UTF-8'))
with open(temp_name, 'w') as xml_fd:
xml_fd.write('<?xml version="1.0" encoding="utf-8"?>\n')
xml_fd.write(etree.tostring(self.xml_object, encoding='utf-8',
pretty_print=True))

Expand Down
2 changes: 1 addition & 1 deletion espa/image/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from espa.image.envi import ENVIHeader
from envi import ENVIHeader
6 changes: 3 additions & 3 deletions espa/image/envi.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import os
import sys
import logging
from io import StringIO
from cStringIO import StringIO


class ENVIHeader(object):
Expand Down Expand Up @@ -76,15 +76,15 @@ def find_ending_bracket(fd):
if not line.strip().endswith('}'):
find_ending_bracket(tmp_fd)
hdr_text.write('description = {{{0}}}\n'
.format(description))
.format(description))

elif line.startswith('band names'):
# This may be on multiple lines so read lines until
# we find the closing brace
if not line.strip().endswith('}'):
find_ending_bracket(tmp_fd)
hdr_text.write('band names = {{{0}}}\n'
.format(band_names))
.format(band_names))

elif line.startswith('data type'):
if data_type is not None:
Expand Down
2 changes: 1 addition & 1 deletion espa/metadata/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from espa.metadata.metadata_api import Metadata
from metadata_api import Metadata
10 changes: 5 additions & 5 deletions espa/metadata/metadata_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import os
import sys
import logging
import urllib.request

import urllib2
logging.basicConfig(stream=sys.stdout, level=logging.DEBUG)

from lxml import objectify as objectify

Expand Down Expand Up @@ -70,7 +70,7 @@ def __init__(self, xml_filename=None):
# to retrieve the schema

if os.path.isfile(xsd_path):
with open(xsd_path, 'rb') as xsd_fd:
with open(xsd_path, 'r') as xsd_fd:
xml_xsd = xsd_fd.read()
logger.info('Using XSD source {0} for validation'
.format(xsd_path))
Expand All @@ -81,7 +81,7 @@ def __init__(self, xml_filename=None):
# provided

# Read the file into a string to be used for parsing
with open(xml_filename, 'rb') as xml_fd:
with open(xml_filename, 'r') as xml_fd:
xml_text = xml_fd.read()

# Load the file into an objectify object
Expand All @@ -99,7 +99,7 @@ def __init__(self, xml_filename=None):
' XML data')

# Read the schema
xsd_fd = urllib.request.urlopen(xsd_uri)
xsd_fd = urllib2.urlopen(xsd_uri)
xml_xsd = xsd_fd.read()
xsd_fd.close()
logger.info('Using XSD source {0} for validation'.format(xsd_uri))
Expand Down
4 changes: 2 additions & 2 deletions unittests/test_metadata_api.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/usr/bin/env python3
#!/usr/bin/env python


import os
import unittest
from io import StringIO
from cStringIO import StringIO
from lxml import objectify as objectify


Expand Down

0 comments on commit df8b4bb

Please sign in to comment.