geopython / pywps

PyWPS is an implementation of the Web Processing Service standard from the Open Geospatial Consortium. PyWPS is written in Python.
https://pywps.org
MIT License
178 stars 117 forks source link

convert_anyURI uses pywps._compat.urlparse as a module #486

Closed corrado9999 closed 4 years ago

corrado9999 commented 5 years ago

Description

convert_anyURI calls pywps._compat.urlparse.urlparse instead of pywps._compat.urlparse

Environment

Steps to Reproduce

>>> pywps.inout.literaltypes as lt
>>> convert_anyURI("https://github.com")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/opt/miniconda/envs/emage/lib/python2.7/site-packages/pywps/inout/literaltypes.py", line 241, in convert_anyURI
    components = urlparse.urlparse(inpt)
AttributeError: 'function' object has no attribute 'urlparse'

Additional Information

The fix is very easy (change urlparse.urlparse to urlparse), not sure if you would like a pull request. Anyway, I noticed that tests/test_literaltypes.py does not test such data type. Perhaps something like

self.assertEqual(convert_anyURI("http://username:password@hostname.dom:port/deep/path/;params?query#fragment"),
                 ('http', 'username:password@hostname.dom:port', '/deep/path/', 'params', 'k=v', 'fragment')
                )
self.assertEqual(convert_anyURI("file:///very/very/very/deep/path"),
                 ('file', '', '/very/very/very/deep/path', '', '', '')
                )

may be enough?

cehbrecht commented 5 years ago

@corrado9999 Thanks for reporting. Would you like to add a PR? You can also update the tests.

corrado9999 commented 5 years ago

When "testing the test" I got an unexpected error due to this test

if components[0] and components[1]:
    return components
else:
    raise InvalidParameterValue(
        'The value "{}" does not seem to be of type anyURI'.format(inpt))

because, with a "file" schema, the netloc part of the URL (components[1] in the code) is always empty. Does it make sense to explicitly check for this schema and avoid to test the second component for it? Are there other schemas like that?

cehbrecht commented 5 years ago

@corrado9999 I would handle the file URL separate ... not sure if there are more cases.