Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def parse_location(self,xml=None):
if xml is not None:
try:
self._root = etree.parse(xml)
except:
self._root = xml
# try:
xml_dict = _xml_to_dict(self._root)
geogs = self._findall('geogLocation')
self.geo_coords = list()
self.srs = list()
for g in geogs:
self.geo_coords.append((testXMLValue(g.find(ns(self._ns) + 'longitude')),testXMLValue(g.find(ns(self._ns) + 'latitude'))))
self.srs.append(g.attrib.get('srs'))
locsite = self._findall('localSiteXY')
self.local_sites = list()
self.notes = list()
self.projections = list()
for ls in locsite:
z = testXMLValue(ls.find(ns(self._ns) + 'Z'))
if z is not None:
self.local_sites.append((testXMLValue(ls.find(ns(self._ns) + 'X')),testXMLValue(ls.find(ns(self._ns) + 'Y')),z))
else:
def parse_query_info(self, xml=None):
if xml is not None:
try:
self._root = etree.parse(xml)
except:
self._root = xml
# try:
# create queryinfo object from dict
xml_dict = _xml_to_dict(self._root)
self.creation_time = parser.parse(xml_dict.get('creation_time')) if xml_dict.get('creation_time') is not None else None
self.notes = [testXMLValue(note) for note in self._findall('note')]
self.criteria = Criteria(self._find('criteria'), self._ns)
# except:
def parse_variable(self,xml=None):
if xml is not None:
try:
self._root = etree.parse(xml)
except:
self._root = xml
# try:
xml_dict = _xml_to_dict(self._root)
self.value_type = xml_dict.get('value_type')
self.data_type = xml_dict.get('data_type')
self.general_category = xml_dict.get('general_category')
self.sample_medium = xml_dict.get('sample_medium')
self.no_data_value = xml_dict.get('no_data_value')
self.variable_name = xml_dict.get('variable_name')
self.variable_code = xml_dict.get('variable_code')
self.variable_description = xml_dict.get('variable_description')
self.speciation = xml_dict.get('speciation')
# notes and properties
notes = [(note.attrib.get('title'),testXMLValue(note)) for note in self._findall('note')]
none_notes = [note[1] for note in notes if note[0] is None]
self.notes = dict([note for note in notes if note[0] is not None])
if len(none_notes) > 0:
self.notes['none'] = none_notes
def parse_criteria(self, xml=None):
if xml is not None:
try:
self._root = etree.parse(xml)
except:
self._root = xml
# try:
xml_dict = _xml_to_dict(self._root,depth=4)
self.method_called = self._root.attrib.get('MethodCalled')
self.location_param = xml_dict.get('location_param')
self.variable_param = xml_dict.get('variable_param')
try:
self.begin_date_time = parser.parse(xml_dict['begin_date_time'])
except:
self.begin_date_time = None
try:
self.end_date_time = parser.parse(xml_dict['end_date_time'])
except:
self.end_date_time = None
self.parameters = [(param.attrib.get('name'),param.attrib.get('value')) for param in self._findall('parameter')]
# except:
def parse_category(self):
try:
xml_dict = _xml_to_dict(self._root)
self.data_value = xml_dict.get('data_value')
self.description = xml_dict.get('description')
self.id = self._root.attrib.get('categoryID')
except:
raise
def parse_siteinfo(self,xml=None):
if xml is not None:
try:
self._root = etree.parse(xml)
except:
self._root = xml
# try:
xml_dict = _xml_to_dict(self._root)
self.site_name = xml_dict.get('site_name')
self.site_codes = [testXMLValue(code) for code in self._findall('siteCode')]
self.elevation = xml_dict.get('elevation_m')
self.vertical_datum = xml_dict.get('vertical_datum')
self.site_types = [testXMLValue(typ) for typ in self._findall('siteType')]
self.site_properties = dict([(prop.attrib.get('name'),testXMLValue(prop)) for prop in self._findall('siteProperty')])
self.altname = xml_dict.get('altname')
self.notes = [testXMLValue(note) for note in self._findall('note')]
# sub-objects
tzi = self._find('timeZoneInfo')
if tzi is not None:
self.time_zone_info = TimeZoneInfo(tzi, self._ns)
self.location = Location(self._find('geoLocation'), self._ns)
def parse_source(self):
try:
xml_dict = _xml_to_dict(self._root)
self.id = self._root.attrib.get("sourceID", None)
self.code = xml_dict.get('source_code')
self.organization = xml_dict.get('organization')
self.description = xml_dict.get('source_description')
self.links = [testXMLValue(link) for link in self._findall('sourceLink')]
self.citation = xml_dict.get('citation')
# metadata
self.topic_category = xml_dict.get('topic_category')
self.title = xml_dict.get('title')
self.abstract = xml_dict.get('abstract')
self.profile_version = xml_dict.get('profile_version')
self.metadata_link = xml_dict.get('metadata_link')
# contact info
self.contact_info = [ContactInformation(ci,self._ns) for ci in self._findall('contactInformation')]
except:
raise
def parse_siteinfo(self,xml=None):
if xml is not None:
try:
self._root = etree.parse(xml)
except:
self._root = xml
# try:
# the following two lines add by Drew, 11/19/2015
siteCodeEle = self._find('siteCode')
self.net_work = siteCodeEle.attrib["network"]
xml_dict = _xml_to_dict(self._root)
self.site_name = xml_dict.get('site_name')
self.site_codes = [testXMLValue(code) for code in self._findall('siteCode')]
self.elevation = xml_dict.get('elevation_m')
self.vertical_datum = xml_dict.get('vertical_datum')
self.site_types = [testXMLValue(typ) for typ in self._findall('siteType')]
self.site_properties = dict([(prop.attrib.get('name'),testXMLValue(prop)) for prop in self._findall('siteProperty')])
self.altname = xml_dict.get('altname')
self.notes = [testXMLValue(note) for note in self._findall('note')]
# sub-objects
tzi = self._find('timeZoneInfo')
if tzi is not None:
self.time_zone_info = TimeZoneInfo(tzi, self._ns)
self.location = Location(self._find('geoLocation'), self._ns)
def parse_location(self,xml=None):
if xml is not None:
try:
self._root = etree.parse(xml)
except:
self._root = xml
# try:
xml_dict = _xml_to_dict(self._root)
geogs = self._findall('geogLocation')
self.geo_coords = list()
self.srs = list()
for g in geogs:
self.geo_coords.append((testXMLValue(g.find(ns(self._ns) + 'longitude')),testXMLValue(g.find(ns(self._ns) + 'latitude'))))
self.srs.append(g.attrib.get('srs'))
locsite = self._findall('localSiteXY')
self.local_sites = list()
self.notes = list()
self.projections = list()
for ls in locsite:
z = testXMLValue(ls.find(ns(self._ns) + 'Z'))
if z is not None:
self.local_sites.append((testXMLValue(ls.find(ns(self._ns) + 'X')),testXMLValue(ls.find(ns(self._ns) + 'Y')),z))
else:
def parse_query_info(self, xml=None):
if xml is not None:
try:
self._root = etree.parse(xml)
except:
self._root = xml
# try:
# create queryinfo object from dict
xml_dict = _xml_to_dict(self._root)
self.creation_time = parser.parse(xml_dict.get('creation_time')) if xml_dict.get('creation_time') is not None else None
self.notes = [testXMLValue(note) for note in self._findall('note')]
self.criteria = Criteria(self._find('criteria'), self._ns)
# except: