Skip to content

Commit

Permalink
Improve contact metadata parsing (geopython#141)
Browse files Browse the repository at this point in the history
  • Loading branch information
sgillies committed Dec 9, 2007
1 parent 990c9a1 commit 079e7dd
Showing 1 changed file with 34 additions and 17 deletions.
51 changes: 34 additions & 17 deletions owslib/wms.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,9 @@ def __init__(self, infoset):

# contact person
contact = self._root.find('Service/ContactInformation')
if contact is not None:
## sometimes there is a contact block that is empty, so make
## sure there are children to parse
if contact is not None and contact.getchildren():
self.provider = ContactMetadata(contact)
else:
self.provider = None
Expand Down Expand Up @@ -319,25 +321,40 @@ def __init__(self, elem):
methods.append((verb.tag, {'url': url}))
self.methods = dict(methods)


class ContactMetadata:
"""Abstraction for contact details advertised in GetCapabilities.
"""
"""Abstraction for contact details advertised in GetCapabilities.
"""
def __init__(self, elem):
self.name = elem.find('ContactPersonPrimary/ContactPerson').text
self.email = elem.find('ContactElectronicMailAddress').text

def __init__(self, elem):
self.name = elem.find('ContactPersonPrimary/ContactPerson').text
self.organization = elem.find('ContactPersonPrimary/ContactOrganization').text
address = elem.find('ContactAddress')
if address is not None:
try:
self.address = address.find('Address').text
self.city = address.find('City').text
self.region = address.find('StateOrProvince').text
self.postcode = address.find('Postcode').text
self.country = address.find('Country').text
except: pass
self.email = elem.find('ContactElectronicMailAddress').text
self.address = self.city = self.region = None
self.postcode = self.country = None

address = elem.find('ContactAddress')
if address is not None:
street = address.find('Address')
if street is not None: self.address = street.text

city = address.find('City')
if city is not None: self.city = city.text

region = address.find('StateOrProvince')
if region is not None: self.region = region.text

postcode = address.find('PostCode')
if postcode is not None: self.postcode = postcode.text

country = address.find('Country')
if country is not None: self.country = country.text

organization = elem.find('ContactPersonPrimary/ContactOrganization')
if organization is not None: self.organization = organization.text
else:self.organization = None

position = elem.find('ContactPosition')
if position is not None: self.position = position.text
else: self.position = None

# Deprecated classes follow
# TODO: remove
Expand Down

0 comments on commit 079e7dd

Please sign in to comment.