• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

geopython / pywps / 5487252648

pending completion
5487252648

push

github

web-flow
Support Python3.10/3.11, documentation fixes, and general codebase cleanup (#677)

* docstring adjustments, removal of unused imports, renaming of internal variables accoing to PEP8 conventions, update URL targets

* remove references to Travis-CI, formatting adjustments

* standardize requirements for readability

* Mention support for Python3.10 and Python3.11

* Add Zeitsperre to CONTRIBUTORS.md

* update installation instructions to reflect modern python approaches and changes to GitHub repository

* Add CI builds for Python3.10 and Python3.11

* remove unused imports

* undo regression

* silence DeprecationWarning for newer sqlalchemy

* fix bad installation command

* cleanup docstrings, remove unused imports

* update actions versions

* ran "isort --py 37 --profile black"

---------

Co-authored-by: MacPingu <cehbrecht@users.noreply.github.com>

160 of 160 new or added lines in 31 files covered. (100.0%)

5106 of 6278 relevant lines covered (81.33%)

0.81 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

70.51
/pywps/app/basic.py
1
##################################################################
2
# Copyright 2018 Open Source Geospatial Foundation and others    #
3
# licensed under MIT, Please consult LICENSE.txt for details     #
4
##################################################################
5
"""
1✔
6
XML tools
7
"""
8

9
import logging
1✔
10
from typing import Tuple
1✔
11

12
from werkzeug.wrappers import Response
1✔
13

14
import pywps.configuration as config
1✔
15

16
LOGGER = logging.getLogger('PYWPS')
1✔
17

18

19
def get_xpath_ns(version):
1✔
20
    """Get xpath namespace for specified WPS version.
21

22
    Versions 1.0.0 or 2.0.0 are supported.
23
    """
24

25
    def xpath_ns(ele, path):
1✔
26
        """Function, which will return xpath namespace for given
27
        element and xpath
28
        """
29
        if version == "1.0.0":
1✔
30
            from pywps import namespaces100
1✔
31
            nsp = namespaces100
1✔
32
        elif version == "2.0.0":
×
33
            from pywps import namespaces200
×
34
            nsp = namespaces200
×
35
        else:
36
            raise NotImplementedError(version)
×
37
        return ele.xpath(path, namespaces=nsp)
1✔
38

39
    return xpath_ns
1✔
40

41

42
def make_response(doc, content_type):
1✔
43
    """Response serializer."""
44
    if not content_type:
1✔
45
        content_type = get_default_response_mimetype()
×
46
    response = Response(doc, content_type=content_type)
1✔
47
    response.status_percentage = 100
1✔
48
    return response
1✔
49

50

51
def get_default_response_mimetype():
1✔
52
    default_mimetype = config.get_config_value('server', 'default_mimetype')
1✔
53
    return default_mimetype
1✔
54

55

56
def get_json_indent():
1✔
57
    json_ident = int(config.get_config_value('server', 'json_indent'))
1✔
58
    return json_ident if json_ident >= 0 else None
1✔
59

60

61
def get_response_type(accept_mimetypes, default_mimetype) -> Tuple[bool, str]:
1✔
62
    """
63
    This function determinate if the response should be JSON or XML based on
64
    the accepted mimetypes of the request and the default mimetype provided,
65
    which will be used in case both are equally accepted.
66

67
    :param accept_mimetypes: determinate which mimetypes are accepted
68
    :param default_mimetype: "text/xml", "application/json"
69
    :return: Tuple[bool, str] -
70
        bool - True: The response type is JSON, False: Otherwise - XML
71
        str - The output mimetype
72
    """
73
    accept_json = \
1✔
74
        accept_mimetypes.accept_json or \
75
        accept_mimetypes.best is None or \
76
        'json' in accept_mimetypes.best.lower()
77
    accept_xhtml = \
1✔
78
        accept_mimetypes.accept_xhtml or \
79
        accept_mimetypes.best is None or \
80
        'xml' in accept_mimetypes.best.lower()
81
    if not default_mimetype:
1✔
82
        default_mimetype = get_default_response_mimetype()
1✔
83
    json_is_default = 'json' in default_mimetype or '*' in default_mimetype
1✔
84
    json_response = (accept_json and (not accept_xhtml or json_is_default)) or \
1✔
85
                    (json_is_default and accept_json == accept_xhtml)
86
    mimetype = 'application/json' if json_response else 'text/xml' if accept_xhtml else ''
1✔
87
    return json_response, mimetype
1✔
88

89

90
def parse_http_url(http_request) -> dict:
1✔
91
    """
92
    This function parses the request URL and extracts the following:
93
        default operation, process identifier, output_ids, default mimetype
94
        info that cannot be terminated from the URL will be None (default)
95

96
        The url is expected to be in the following format, all the levels are optional.
97
        [base_url]/[identifier]/[output_ids]
98

99
    :param http_request: the request URL
100
    :return: dict with the extracted info listed:
101
        base_url - [wps|processes|jobs|api/api_level]
102
        default_mimetype - determinate by the base_url part:
103
            XML - if the base url == 'wps',
104
            JSON - if the base URL in ['api'|'jobs'|'processes']
105
        operation - also determinate by the base_url part:
106
            ['api'|'jobs'] -> 'execute'
107
            processes -> 'describeprocess' or 'getcapabilities'
108
                'describeprocess' if identifier is present as the next item, 'getcapabilities' otherwise
109
        api - api level, only expected if base_url=='api'
110
        identifier - the process identifier
111
        output_ids - if exist then it selects raw output with the name output_ids
112
    """
113
    operation = api = identifier = output_ids = default_mimetype = base_url = None
1✔
114
    if http_request:
1✔
115
        parts = str(http_request.path[1:]).split('/')
1✔
116
        i = 0
1✔
117
        if len(parts) > i:
1✔
118
            base_url = parts[i].lower()
1✔
119
            if base_url == 'wps':
1✔
120
                default_mimetype = 'xml'
×
121
            elif base_url in ['api', 'processes', 'jobs']:
1✔
122
                default_mimetype = 'json'
×
123
            i += 1
1✔
124
            if base_url == 'api':
1✔
125
                api = parts[i]
×
126
                i += 1
×
127
            if len(parts) > i:
1✔
128
                identifier = parts[i]
×
129
                i += 1
×
130
                if len(parts) > i:
×
131
                    output_ids = parts[i]
×
132
                    if not output_ids:
×
133
                        output_ids = None
×
134
    if base_url in ['jobs', 'api']:
1✔
135
        operation = 'execute'
×
136
    elif base_url == 'processes':
1✔
137
        operation = 'describeprocess' if identifier else 'getcapabilities'
×
138
    d = {}
1✔
139
    if operation:
1✔
140
        d['operation'] = operation
×
141
    if identifier:
1✔
142
        d['identifier'] = identifier
×
143
    if output_ids:
1✔
144
        d['output_ids'] = output_ids
×
145
    if default_mimetype:
1✔
146
        d['default_mimetype'] = default_mimetype
×
147
    if api:
1✔
148
        d['api'] = api
×
149
    if base_url:
1✔
150
        d['base_url'] = base_url
×
151
    return d
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc