Coder Social home page Coder Social logo

Comments (4)

tomkralidis avatar tomkralidis commented on August 21, 2024

cc @kwilcox

@rsignell-usgs thanks for the info.

What about something like owslib.util.guess_format, which can then provide a hint to the caller on how to parse the response. In the end, it's either delimited, JSON, or XML (others)?

I would see something like this can be used by the entire codebase.


def guess_format(mime_type):
    if mime_type.find('xml') != -1:
        dformat = 'xml'  # parse with lxml.etree
    elif mime_type.find('csv') != -1:
        dformat = 'csv'  # parse with csv
    elif mime_type.find('tab-separated-values') != -1:
        dformat = 'tsv'  # parse with csv and tab delimiter
    elif mime_type.find('json') != -1:
        dformat = 'json'  # parse with simplejson
    return dformat


from owslib.

rsignell-usgs avatar rsignell-usgs commented on August 21, 2024

That sounds great to me.

from owslib.

kwilcox avatar kwilcox commented on August 21, 2024

Is it important for OWSLib to parse the response from a GetObservation request at all? Would we be more inline with the spec to just return the raw results and let the user do what they want with it? They already need to provide a responseFormat parameter to the get_observation method so would have a good idea of what the result mimeType should be.

We could wrap a test for ows:ExceptionReport in a try block and return the raw response if the request was successful.

Something like:

response = openURL(base_url, data, method, username=self.username, password=self.password).read()
try:
    tr = etree.fromstring(response)
    if tr.tag == nspath_eval("ows:ExceptionReport", namespaces):
        raise ows.ExceptionReport(tr)
except ows.ExceptionReport:
    raise
except BaseException:
    return response

@tomkralidis Thoughts?

from owslib.

tomkralidis avatar tomkralidis commented on August 21, 2024

@kwilcox I just realized that we return a string of the response, not an lxml.etree object of any kind.

In this case, agreed, forget the util.guess_format approach and +1 to your try/except block above.

from owslib.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.