1212
1313""" ISO metadata parser """
1414
15- import warnings
16-
1715from owslib .etree import etree
1816from owslib import util
1917from owslib .namespaces import Namespaces
@@ -35,6 +33,7 @@ class MD_Metadata(object):
3533 def __init__ (self , md = None ):
3634
3735 if md is None :
36+ self .md = None
3837 self .xml = None
3938 self .identifier = None
4039 self .parentidentifier = None
@@ -50,7 +49,6 @@ def __init__(self, md=None):
5049 self .stdver = None
5150 self .locales = []
5251 self .referencesystem = None
53- self .identification = None
5452 self .contentinfo = None
5553 self .serviceidentification = None
5654 self .identificationinfo = []
@@ -59,6 +57,7 @@ def __init__(self, md=None):
5957 self .dataquality = None
6058 self .acquisition = None
6159 else :
60+ self .md = md
6261 if hasattr (md , 'getroot' ): # standalone document
6362 self .xml = etree .tostring (md .getroot ())
6463 else : # part of a larger document
@@ -116,28 +115,8 @@ def __init__(self, md=None):
116115 else :
117116 self .referencesystem = None
118117
119- # TODO: merge .identificationinfo into .identification
120- warnings .warn (
121- 'the .identification and .serviceidentification properties will merge into '
122- '.identification being a list of properties. This is currently implemented '
123- 'in .identificationinfo. '
124- 'Please see https://github.com/geopython/OWSLib/issues/38 for more information' ,
125- FutureWarning )
126-
127- val = md .find (util .nspath_eval ('gmd:identificationInfo/gmd:MD_DataIdentification' , namespaces ))
128- val2 = md .find (util .nspath_eval ('gmd:identificationInfo/srv:SV_ServiceIdentification' , namespaces ))
129-
130- if val is not None :
131- self .identification = MD_DataIdentification (val , 'dataset' )
132- self .serviceidentification = None
133- elif val2 is not None :
134- self .identification = MD_DataIdentification (val2 , 'service' )
135- self .serviceidentification = SV_ServiceIdentification (val2 )
136- else :
137- self .identification = None
138- self .serviceidentification = None
139-
140118 self .identificationinfo = []
119+
141120 for idinfo in md .findall (util .nspath_eval ('gmd:identificationInfo' , namespaces )):
142121 if len (idinfo ) > 0 :
143122 val = list (idinfo )[0 ]
@@ -176,6 +155,22 @@ def __init__(self, md=None):
176155 else :
177156 self .acquisition = None
178157
158+ def get_all_contacts (self ):
159+ """get all contacts in document"""
160+
161+ contacts = []
162+
163+ for ii in self .identificationinfo :
164+ for iic in ii .contact :
165+ contacts .append (iic )
166+
167+ for ct in ['creator' , 'publisher' , 'contributor' ]:
168+ iict = getattr (ii , ct )
169+ if iict :
170+ contacts .append (iict )
171+
172+ return list (filter (None , contacts ))
173+
179174 def get_default_locale (self ):
180175 """ get default gmd:PT_Locale based on gmd:language """
181176
@@ -318,27 +313,18 @@ class MD_Keywords(object):
318313 Class for the metadata MD_Keywords element
319314 """
320315 def __init__ (self , md = None ):
321- warnings .warn (
322- 'The .keywords_object attribute will become .keywords proper in the next release. '
323- '.keywords_object is a list of ibstances of the Keyword class. '
324- 'See for https://github.com/geopython/OWSLib/pull/765 more details.' ,
325- FutureWarning )
326-
327316 if md is None :
328317 self .keywords = []
329- self .keywords_object = []
330318 self .type = None
331319 self .thesaurus = None
332320 self .kwdtype_codeList = 'http://standards.iso.org/ittf/PubliclyAvailableStandards/ISO_19139_Schemas/resources/codelist/gmxCodelists.xml#MD_KeywordTypeCode'
333321 else :
334322 self .keywords = []
335- self .keywords_object = []
336323 val = md .findall (util .nspath_eval ('gmd:keyword/gco:CharacterString' , namespaces ))
337324 if len (val ) == 0 :
338325 val = md .findall (util .nspath_eval ('gmd:keyword/gmx:Anchor' , namespaces ))
339326 for word in val :
340- self .keywords .append (util .testXMLValue (word ))
341- self .keywords_object .append (Keyword (word ))
327+ self .keywords .append (Keyword (word ))
342328 self .type = None
343329 val = md .find (util .nspath_eval ('gmd:type/gmd:MD_KeywordTypeCode' , namespaces ))
344330 self .type = util .testXMLAttribute (val , 'codeListValue' )
@@ -348,8 +334,8 @@ def __init__(self, md=None):
348334 if val is not None :
349335 self .thesaurus = {}
350336
351- thesaurus = val .find (util .nspath_eval ('gmd:title/gco:CharacterString' , namespaces ))
352- self .thesaurus ['title' ] = util .testXMLValue (thesaurus )
337+ title = val .find (util .nspath_eval ('gmd:title/gco:CharacterString' , namespaces ))
338+ self .thesaurus ['title' ] = util .testXMLValue (title )
353339 self .thesaurus ['url' ] = None
354340
355341 if self .thesaurus ['title' ] is None : # try gmx:Anchor
@@ -358,12 +344,12 @@ def __init__(self, md=None):
358344 self .thesaurus ['title' ] = util .testXMLValue (t )
359345 self .thesaurus ['url' ] = t .attrib .get (util .nspath_eval ('xlink:href' , namespaces ))
360346
361- thesaurus = val .find (util .nspath_eval ('gmd:date/gmd:CI_Date/gmd:date/gco:Date' , namespaces ))
362- self .thesaurus ['date' ] = util .testXMLValue (thesaurus )
347+ date_ = val .find (util .nspath_eval ('gmd:date/gmd:CI_Date/gmd:date/gco:Date' , namespaces ))
348+ self .thesaurus ['date' ] = util .testXMLValue (date_ )
363349
364- thesaurus = val .find (
350+ datetype = val .find (
365351 util .nspath_eval ('gmd:date/gmd:CI_Date/gmd:dateType/gmd:CI_DateTypeCode' , namespaces ))
366- self .thesaurus ['datetype' ] = util .testXMLAttribute (thesaurus , 'codeListValue' )
352+ self .thesaurus ['datetype' ] = util .testXMLAttribute (datetype , 'codeListValue' )
367353
368354
369355class MD_DataIdentification (object ):
@@ -401,8 +387,6 @@ def __init__(self, md=None, identtype=None):
401387 self .graphicoverview = []
402388 self .contact = []
403389 self .keywords = []
404- self .keywords_object = []
405- self .keywords2 = []
406390 self .topiccategory = []
407391 self .supplementalinformation = None
408392 self .extent = None
@@ -593,50 +577,9 @@ def __init__(self, md=None, identtype=None):
593577 if val :
594578 self .spatialrepresentationtype .append (val )
595579
596- warnings .warn (
597- 'The .keywords and .keywords2 properties will merge into the '
598- '.keywords property in the future, with .keywords becoming a list '
599- 'of MD_Keywords instances. This is currently implemented in .keywords2. '
600- 'Please see https://github.com/geopython/OWSLib/issues/301 for more information' ,
601- FutureWarning )
602-
603580 self .keywords = []
604-
605- for i in md .findall (util .nspath_eval ('gmd:descriptiveKeywords' , namespaces )):
606- mdkw = {}
607- mdkw ['type' ] = _testCodeListValue (i .find (util .nspath_eval (
608- 'gmd:MD_Keywords/gmd:type/gmd:MD_KeywordTypeCode' , namespaces )))
609-
610- mdkw ['thesaurus' ] = {}
611-
612- val = i .find (util .nspath_eval (
613- 'gmd:MD_Keywords/gmd:thesaurusName/gmd:CI_Citation/gmd:title/gco:CharacterString' , namespaces ))
614- mdkw ['thesaurus' ]['title' ] = util .testXMLValue (val )
615-
616- val = i .find (util .nspath_eval (
617- 'gmd:MD_Keywords/gmd:thesaurusName/gmd:CI_Citation/gmd:date/gmd:CI_Date/gmd:date/gco:Date' ,
618- namespaces ))
619- mdkw ['thesaurus' ]['date' ] = util .testXMLValue (val )
620-
621- val = i .find (util .nspath_eval (
622- 'gmd:MD_Keywords/gmd:thesaurusName/gmd:CI_Citation/gmd:date/gmd:CI_Date/gmd:dateType/gmd:CI_DateTypeCode' ,
623- namespaces ))
624- mdkw ['thesaurus' ]['datetype' ] = util .testXMLAttribute (val , 'codeListValue' )
625-
626- mdkw ['keywords' ] = []
627-
628- for k in i .findall (util .nspath_eval ('gmd:MD_Keywords/gmd:keyword' , namespaces )):
629- val = k .find (util .nspath_eval ('gco:CharacterString' , namespaces ))
630- if val is not None :
631- val2 = util .testXMLValue (val )
632- if val2 is not None :
633- mdkw ['keywords' ].append (val2 )
634-
635- self .keywords .append (mdkw )
636-
637- self .keywords2 = []
638581 for mdkw in md .findall (util .nspath_eval ('gmd:descriptiveKeywords/gmd:MD_Keywords' , namespaces )):
639- self .keywords2 .append (MD_Keywords (mdkw ))
582+ self .keywords .append (MD_Keywords (mdkw ))
640583
641584 self .topiccategory = []
642585 for i in md .findall (util .nspath_eval ('gmd:topicCategory/gmd:MD_TopicCategoryCode' , namespaces )):
0 commit comments