File: namespaces.py

package info (click to toggle)
qgis 2.4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 374,696 kB
  • ctags: 66,263
  • sloc: cpp: 396,139; ansic: 241,070; python: 130,609; xml: 14,884; perl: 1,290; sh: 1,287; sql: 500; yacc: 268; lex: 242; makefile: 168
file content (136 lines) | stat: -rw-r--r-- 5,258 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
class Namespaces(object):
    """
        Class for holding and maniputlating a dictionary containing the various namespaces for
        each standard.
    """

    namespace_dict = {
        'atom'  :   'http://www.w3.org/2005/Atom',
        'csw'   :   'http://www.opengis.net/cat/csw/2.0.2',
        'dc'    :   'http://purl.org/dc/elements/1.1/',
        'dct'   :   'http://purl.org/dc/terms/',
        'dif'   :   'http://gcmd.gsfc.nasa.gov/Aboutus/xml/dif/',
        'draw'  :   'gov.usgs.cida.gdp.draw',
        'fes'   :   'http://www.opengis.net/fes/2.0',
        'fgdc'  :   'http://www.opengis.net/cat/csw/csdgm',
        'gco'   :   'http://www.isotc211.org/2005/gco',
        'gmd'   :   'http://www.isotc211.org/2005/gmd',
        'gml'   :   'http://www.opengis.net/gml',
        'gml311':   'http://www.opengis.net/gml',
        'gml32' :   'http://www.opengis.net/gml/3.2',
        'gmx'   :   'http://www.isotc211.org/2005/gmx',
        'gts'   :   'http://www.isotc211.org/2005/gts',
        'ogc'   :   'http://www.opengis.net/ogc',
        'om'    :   'http://www.opengis.net/om/1.0',
        'om10'  :   'http://www.opengis.net/om/1.0',
        'om100' :   'http://www.opengis.net/om/1.0',
        'om20'  :   'http://www.opengis.net/om/2.0',
        'ows'   :   'http://www.opengis.net/ows',
        'ows100':   'http://www.opengis.net/ows',
        'ows110':   'http://www.opengis.net/ows/1.1',
        'ows200':   'http://www.opengis.net/ows/2.0',
        'rim'   :   'urn:oasis:names:tc:ebxml-regrep:xsd:rim:3.0',
        'rdf'   :   'http://www.w3.org/1999/02/22-rdf-syntax-ns#',
        'sml'   :   'http://www.opengis.net/sensorML/1.0.1',
        'sml101':   'http://www.opengis.net/sensorML/1.0.1',
        'sos'   :   'http://www.opengis.net/sos/1.0',
        'sos20' :   'http://www.opengis.net/sos/2.0',
        'srv'   :   'http://www.isotc211.org/2005/srv',
        'swe'   :   'http://www.opengis.net/swe/1.0.1',
        'swe10' :   'http://www.opengis.net/swe/1.0',
        'swe101':   'http://www.opengis.net/swe/1.0.1',
        'swe20' :   'http://www.opengis.net/swe/2.0',
        'swes'  :   'http://www.opengis.net/swes/2.0',
        'tml'   :   'ttp://www.opengis.net/tml',
        'wfs'   :   'http://www.opengis.net/wfs',
        'wfs20' :   'http://www.opengis.net/wfs/2.0',
        'wcs'   :   'http://www.opengis.net/wcs',
        'wps'   :   'http://www.opengis.net/wps/1.0.0',
        'wps100':   'http://www.opengis.net/wps/1.0.0',
        'xlink' :   'http://www.w3.org/1999/xlink',
        'xs'    :   'http://www.w3.org/2001/XMLSchema',
        'xs2'   :   'http://www.w3.org/XML/Schema',
        'xsi'   :   'http://www.w3.org/2001/XMLSchema-instance'
    }    

    def get_namespace(self, key):
        """
            Retrieves a namespace from the dictionary

            Example:
            --------

            >>> from owslib.namespaces import Namespaces
            >>> ns = Namespaces()
            >>> ns.get_namespace('csw')
            'http://www.opengis.net/cat/csw/2.0.2'
            >>> ns.get_namespace('wfs20')
            'http://www.opengis.net/wfs/2.0'
        """
        retval = None
        if key in self.namespace_dict.keys():
            retval = self.namespace_dict[key]
        return retval
    
    def get_versioned_namespace(self, key, ver=None):
        """
            Retrieves a namespace from the dictionary with a specific version number

            Example:
            --------

            >>> from owslib.namespaces import Namespaces
            >>> ns = Namespaces()
            >>> ns.get_versioned_namespace('ows')
            'http://www.opengis.net/ows'
            >>> ns.get_versioned_namespace('ows','1.1.0')
            'http://www.opengis.net/ows/1.1'
        """
        
        if ver is None:
            return self.get_namespace(key)

        version = ''
        # Strip the decimals out of the passed in version
        for s in ver.split('.'):
            version += s
        
        key += version

        retval = None
        if key in self.namespace_dict.keys():
            retval = self.namespace_dict[key]
            
        return retval
    
    def get_namespaces(self, keys=None):
        """
            Retrieves a dict of namespaces from the namespace mapping

            Parameters
            ----------
            - keys: List of keys query and return

            Example:
            --------
            >>> ns = Namespaces()
            >>> ns.get_namespaces(['csw','gmd'])
            { 'csw' : http://www.opengis.net/cat/csw/2.0.2', 'gmd' : 'http://www.isotc211.org/2005/gmd' }
            >>> ns.get_namespaces('csw')
            { 'csw' : http://www.opengis.net/cat/csw/2.0.2' }
            >>> ns.get_namespaces()
            {...}
        """
        # If we aren't looking for any namespaces in particular return the whole dict
        if keys is None or len(keys) == 0:
            return self.namespace_dict

        if isinstance(keys, unicode) or isinstance(keys, str):
            return { keys: self.get_namespace(keys) }

        retval = {}
        for key in keys:
            if key in self.namespace_dict.keys():
                retval[key] = self.namespace_dict[key]

        return retval