Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python 3 compatiability fixes; measurement result example changes #230

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions wof/WaterML.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,15 @@ def showIndent(outfile, level):
def quote_xml(inStr):
if not inStr:
return ''
s1 = (isinstance(inStr, basestring) and inStr or
s1 = (isinstance(inStr, str) and inStr or
'%s' % inStr)
s1 = s1.replace('&', '&')
s1 = s1.replace('<', '&lt;')
s1 = s1.replace('>', '&gt;')
return s1

def quote_attrib(inStr):
s1 = (isinstance(inStr, basestring) and inStr or
s1 = (isinstance(inStr, str) and inStr or
'%s' % inStr)
s1 = s1.replace('&', '&amp;')
s1 = s1.replace('<', '&lt;')
Expand Down
60 changes: 30 additions & 30 deletions wof/WaterML_1_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ def quote_xml(inStr):
"Escape markup chars, but do not modify CDATA sections."
if not inStr:
return ''
s1 = (isinstance(inStr, basestring) and inStr or
s1 = (isinstance(inStr, str) and inStr or
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that I don't have any stake in this so when I say that in almost 2019 and going all in for Python 3 is 👍 take it with a grain of salt.

If Python 2 and 3 support is needed you may look into tools like six and lines like this one, for example, would be six.string_types instead.

'%s' % inStr)
s2 = ''
pos = 0
Expand All @@ -413,7 +413,7 @@ def quote_xml_aux(inStr):


def quote_attrib(inStr):
s1 = (isinstance(inStr, basestring) and inStr or
s1 = (isinstance(inStr, str) and inStr or
'%s' % inStr)
s1 = s1.replace(u'&', u'&amp;')
s1 = s1.replace(u'<', u'&lt;')
Expand Down Expand Up @@ -826,7 +826,7 @@ class VariableInfoType(GeneratedsSuper):
superclass = None
def __init__(self, metadataTime=None, oid=None, variableCode=None, variableName=None, variableDescription=None, valueType=None, dataType=None, generalCategory=None, sampleMedium=None, unit=None, options=None, note=None, related=None, extension=None, noDataValue=None, timeScale=None, speciation=None, categories=None, variableProperty=None):
self.original_tagname_ = None
if isinstance(metadataTime, basestring):
if isinstance(metadataTime, str):
initvalue_ = datetime.datetime.strptime(metadataTime, '%Y-%m-%dT%H:%M:%S')
else:
initvalue_ = metadataTime
Expand Down Expand Up @@ -1321,7 +1321,7 @@ class QueryInfoType(GeneratedsSuper):
superclass = None
def __init__(self, creationTime=None, queryURL=None, criteria=None, note=None, extension=None):
self.original_tagname_ = None
if isinstance(creationTime, basestring):
if isinstance(creationTime, str):
initvalue_ = datetime.datetime.strptime(creationTime, '%Y-%m-%dT%H:%M:%S')
else:
initvalue_ = creationTime
Expand Down Expand Up @@ -1701,22 +1701,22 @@ class TimePeriodType(GeneratedsSuper):
superclass = None
def __init__(self, beginDateTime=None, endDateTime=None, beginDateTimeUTC=None, endDateTimeUTC=None, extensiontype_=None):
self.original_tagname_ = None
if isinstance(beginDateTime, basestring):
if isinstance(beginDateTime, str):
initvalue_ = datetime.datetime.strptime(beginDateTime, '%Y-%m-%dT%H:%M:%S')
else:
initvalue_ = beginDateTime
self.beginDateTime = initvalue_
if isinstance(endDateTime, basestring):
if isinstance(endDateTime, str):
initvalue_ = datetime.datetime.strptime(endDateTime, '%Y-%m-%dT%H:%M:%S')
else:
initvalue_ = endDateTime
self.endDateTime = initvalue_
if isinstance(beginDateTimeUTC, basestring):
if isinstance(beginDateTimeUTC, str):
initvalue_ = datetime.datetime.strptime(beginDateTimeUTC, '%Y-%m-%dT%H:%M:%S')
else:
initvalue_ = beginDateTimeUTC
self.beginDateTimeUTC = initvalue_
if isinstance(endDateTimeUTC, basestring):
if isinstance(endDateTimeUTC, str):
initvalue_ = datetime.datetime.strptime(endDateTimeUTC, '%Y-%m-%dT%H:%M:%S')
else:
initvalue_ = endDateTimeUTC
Expand Down Expand Up @@ -1883,7 +1883,7 @@ class TimeSingleType(TimePeriodType):
def __init__(self, beginDateTime=None, endDateTime=None, beginDateTimeUTC=None, endDateTimeUTC=None, timeSingle=None):
self.original_tagname_ = None
super(TimeSingleType, self).__init__(beginDateTime, endDateTime, beginDateTimeUTC, endDateTimeUTC, )
if isinstance(timeSingle, basestring):
if isinstance(timeSingle, str):
initvalue_ = datetime.datetime.strptime(timeSingle, '%Y-%m-%dT%H:%M:%S')
else:
initvalue_ = timeSingle
Expand Down Expand Up @@ -3038,7 +3038,7 @@ def __init__(self, codedVocabularyTerm=None, sampleID=None, methodCode=None, qua
self.methodCode = _cast(None, methodCode)
self.qualityControlLevelCode = _cast(None, qualityControlLevelCode)
self.methodID = _cast(int, methodID)
if isinstance(metadataTime, basestring):
if isinstance(metadataTime, str):
initvalue_ = datetime.datetime.strptime(metadataTime, '%Y-%m-%dT%H:%M:%S')
else:
initvalue_ = metadataTime
Expand All @@ -3049,13 +3049,13 @@ def __init__(self, codedVocabularyTerm=None, sampleID=None, methodCode=None, qua
self.censorCode = _cast(None, censorCode)
self.accuracyStdDev = _cast(float, accuracyStdDev)
self.offsetTypeID = _cast(int, offsetTypeID)
if isinstance(dateTime, basestring):
if isinstance(dateTime, str):
initvalue_ = datetime.datetime.strptime(dateTime, '%Y-%m-%dT%H:%M:%S')
else:
initvalue_ = dateTime
self.dateTime = initvalue_
self.offsetTypeCode = _cast(None, offsetTypeCode)
if isinstance(dateTimeUTC, basestring):
if isinstance(dateTimeUTC, str):
initvalue_ = datetime.datetime.strptime(dateTimeUTC, '%Y-%m-%dT%H:%M:%S')
else:
initvalue_ = dateTimeUTC
Expand Down Expand Up @@ -4189,10 +4189,10 @@ def __init__(self, sourceID=None, sourceCode=None, organization=None, sourceDesc
self.contactInformation = []
else:
self.contactInformation = contactInformation
if sourceLink is None:
self.sourceLink = []
else:
self.sourceLink = sourceLink
# if sourceLink is None:
# self.sourceLink = []
# else:
# self.sourceLink = sourceLink
self.citation = citation
def factory(*args_, **kwargs_):
if SourceType.subclass:
Expand All @@ -4213,11 +4213,11 @@ def set_contactInformation(self, contactInformation): self.contactInformation =
def add_contactInformation(self, value): self.contactInformation.append(value)
def insert_contactInformation_at(self, index, value): self.contactInformation.insert(index, value)
def replace_contactInformation_at(self, index, value): self.contactInformation[index] = value
def get_sourceLink(self): return self.sourceLink
def set_sourceLink(self, sourceLink): self.sourceLink = sourceLink
def add_sourceLink(self, value): self.sourceLink.append(value)
def insert_sourceLink_at(self, index, value): self.sourceLink.insert(index, value)
def replace_sourceLink_at(self, index, value): self.sourceLink[index] = value
# def get_sourceLink(self): return self.sourceLink
# def set_sourceLink(self, sourceLink): self.sourceLink = sourceLink
# def add_sourceLink(self, value): self.sourceLink.append(value)
# def insert_sourceLink_at(self, index, value): self.sourceLink.insert(index, value)
# def replace_sourceLink_at(self, index, value): self.sourceLink[index] = value
def get_citation(self): return self.citation
def set_citation(self, citation): self.citation = citation
def get_sourceID(self): return self.sourceID
Expand All @@ -4234,7 +4234,7 @@ def hasContent_(self):
self.sourceDescription is not None or
self.metadata is not None or
self.contactInformation or
self.sourceLink or
# self.sourceLink or
self.citation is not None
):
return True
Expand Down Expand Up @@ -4282,9 +4282,9 @@ def exportChildren(self, outfile, level, namespace_='', name_='SourceType', from
if contactInformation_ is not None:
contactInformation_.export(outfile, level, namespace_, name_='contactInformation', pretty_print=pretty_print)
#for sourceLink_ in self.sourceLink:
if self.sourceLink is not None:
showIndent(outfile, level, pretty_print)
outfile.write(u'<%ssourceLink>%s</%ssourceLink>%s' % (namespace_, self.gds_format_string(quote_xml(self.sourceLink), input_name='sourceLink'), namespace_, eol_))
#if self.sourceLink is not None:
# showIndent(outfile, level, pretty_print)
# outfile.write(u'<%ssourceLink>%s</%ssourceLink>%s' % (namespace_, self.gds_format_string(quote_xml(self.sourceLink), input_name='sourceLink'), namespace_, eol_))

if self.citation is not None:
showIndent(outfile, level, pretty_print)
Expand Down Expand Up @@ -4329,10 +4329,10 @@ def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
obj_.build(child_)
self.contactInformation.append(obj_)
obj_.original_tagname_ = 'contactInformation'
elif nodeName_ == 'sourceLink':
sourceLink_ = child_.text
sourceLink_ = self.gds_validate_string(sourceLink_, node, 'sourceLink')
self.sourceLink.append(sourceLink_)
#elif nodeName_ == 'sourceLink':
# sourceLink_ = child_.text
# sourceLink_ = self.gds_validate_string(sourceLink_, node, 'sourceLink')
# self.sourceLink.append(sourceLink_)
elif nodeName_ == 'citation':
citation_ = child_.text
citation_ = self.gds_validate_string(citation_, node, 'citation')
Expand Down Expand Up @@ -7221,7 +7221,7 @@ class SiteInfoType(SourceInfoType):
def __init__(self, metadataTime=None, oid=None, siteName=None, siteCode=None, timeZoneInfo=None, geoLocation=None, elevation_m=None, verticalDatum=None, note=None, extension=None, altname=None, siteType=None, siteProperty=None):
self.original_tagname_ = None
super(SiteInfoType, self).__init__()
if isinstance(metadataTime, basestring):
if isinstance(metadataTime, str):
initvalue_ = datetime.datetime.strptime(metadataTime, '%Y-%m-%dT%H:%M:%S')
else:
initvalue_ = metadataTime
Expand Down
4 changes: 2 additions & 2 deletions wof/apps/spyned_1_0.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import (absolute_import, division, print_function)

import StringIO
from io import StringIO
import logging

from spyne.decorator import rpc
Expand Down Expand Up @@ -38,7 +38,7 @@ def GetSites(ctx, site=None, authToken=None):
logging.debug(site)
logging.debug(siteArg)
siteResponse = wof_inst.create_get_site_response(siteArg)
outStream = StringIO.StringIO()
outStream = StringIO()
siteResponse.export(outStream, 0, name_="sitesResponse",
namespacedef_=NSDEF)
return outStream.getvalue()
Expand Down
4 changes: 2 additions & 2 deletions wof/apps/waterml2.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import (absolute_import, division, print_function)

import StringIO
from io import StringIO
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may needs to treat things as BytesIO instead.

import logging
import datetime
import os
Expand Down Expand Up @@ -89,7 +89,7 @@ def GetValues(self, location, variable, startDate=None,
#full format: %Y-%m-%dT%H:%M:%S.%f%z

def isoformat(value, format='%Y-%m-%dT%H:%M:%S%z'):
if isinstance(value, basestring):
if isinstance(value, str):
try:
value = parse(value)
except:
Expand Down
15 changes: 9 additions & 6 deletions wof/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,6 @@

from dateutil.parser import parse

from lxml import etree
from lxml.etree import XMLParser
from lxml.etree import XMLSyntaxError

import pytz

from spyne.application import Application
from spyne.const.http import HTTP_405
from spyne.error import RequestNotAllowed
Expand All @@ -27,6 +21,15 @@
from spyne.server.http import HttpTransportContext
from spyne.server.wsgi import WsgiApplication


import pytz
from lxml import etree
from lxml.etree import XMLParser
from lxml.etree import XMLSyntaxError




from wof.WofWsdls import WofWSDL_1_0, WofWSDL_1_1
from wof.apps.spyned_1_0 import TWOFService as wml10
from wof.apps.spyned_1_1 import TWOFService as wml11
Expand Down
4 changes: 2 additions & 2 deletions wof/core_1_0.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,8 +427,8 @@ def create_source_element(self, sourceResult):
source = WaterML.SourceType(
sourceID=sourceResult.SourceID,
Organization=sourceResult.Organization,
SourceDescription=sourceResult.SourceDescription,
SourceLink=sourceResult.SourceLink)
SourceDescription=sourceResult.SourceDescription)
#SourceLink=sourceResult.SourceLink

contactInfo = self.create_contact_info_element(sourceResult)

Expand Down
16 changes: 9 additions & 7 deletions wof/core_1_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,15 @@ def config_from_file(self, file_name):
self.link = config.link

def get_site_code(self, siteArg):

if siteArg is None:
return None
if ':' in siteArg:
networkname, siteCode = siteArg.split(':', 1)
networkname = networkname.lower()
if self.network == networkname:
return siteCode
else:
return None
# if self.network == networkname:
return siteCode
# else:
# return None
return siteArg

def get_variable_code(self, varArg):
Expand Down Expand Up @@ -806,11 +807,12 @@ def create_series_element(self, seriesResult):
try:
beginDateTime = dateutil.parser.parse(beginDateTime)
except Exception as inst:
logging.warn('bad datetime conversion on beginDateTime:' + inst.message) # noqa
logging.warn('bad datetime conversion on beginDateTime:' + str(inst) +
' beginDateTime ' + str(beginDateTime)) # noqa
try:
endDateTime = dateutil.parser.parse(endDateTime)
except Exception as inst:
logging.warn('bad datetime conversion on endDateTime:' + inst.message) # noqa
logging.warn('bad datetime conversion on endDateTime:' + str(inst)) # noqa

# TimeInterval.
if beginDateTime is None:
Expand Down
Loading