-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathcommon.py
54 lines (39 loc) · 1.23 KB
/
common.py
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
import lxml.etree as etree
import sys
import urllib
PY2 = sys.version_info[0] == 2
URL = 'http://localhost:5000/wps'
NAMESPACES = {
'xlink': "http://www.w3.org/1999/xlink",
'wps': "http://www.opengis.net/wps/1.0.0",
'ows': "http://www.opengis.net/ows/1.1",
'gml': "http://www.opengis.net/gml",
'xsi': "http://www.w3.org/2001/XMLSchema-instance",
'ogr': "http://ogr.maptools.org/"
}
if not PY2:
import urllib.request
def get_response(url, post_data=None):
response = None
if PY2:
response = urllib.urlopen(url, data=post_data)
else:
#if post_data:
# post_data = post_data.decode()
response = urllib.request.urlopen(url, data=post_data)
return response
def get_schema(url):
schema = get_response(url)
xmlschema_doc = etree.parse(schema)
return etree.XMLSchema(xmlschema_doc)
def validate_file(path, schema):
body_doc = etree.parse(path)
schema = get_schema(schema)
return schema.validate(body_doc)
def validate(url, schema, post_data=None):
response = get_response(url, post_data)
info = response.info()
body = response.read()
body_doc = etree.fromstring(body)
schema = get_schema(schema)
return schema.validate(body_doc)