openest.generate.retrieve module

openest.generate.retrieve.any_from_url(url)[source]

Returns a model retrieved from the argument url

any_from_url is a wrapper around from_url(). It returns a model chosen by choose_model(). Therefore, the file reader returned by from_url() must have one of the allowed model types as the first four characters in the document.

Parameters:url (str) – URL of file to retrieve
Returns:Model chosen by choose_model()
Return type:object
openest.generate.retrieve.choose_model(fp, source=None)[source]

Reads a file object and returns a model based on file header

The file is converted into a BinModel, DDPModel, or SplineModel depending on the first four characters of the file.

To use choose_model, the first four characters of the file reader object must be one of the following:

  • bin1, in which case a BinModel will be returned,
  • ddp1 or ddp2, in which case a DDPModel will be returned, or
  • spp1, in which case a SplineModel will be returned.

If the model type is not one of the types listed above, a BaseException will be raised.

Todo

  • Change exception type - sublcassing BaseException is not PEP compliant.
    Custom exceptions should inherrit from Exception or other built-in exceptions. This is so that except Exception will catch all exceptions except for KeyboardInterrupt and SystemExit, which are not errors, but user-triggered events. See PEP-352.
Parameters:
  • fp (file reader object) – file reader object to be converted into a model.
  • source (str) – Meta-information about url the file was recovered from
Returns:

Model of class BinModel, DDPModel, or SplineModel.

Return type:

object

openest.generate.retrieve.ddp_from_url(url)[source]

Returns a DDPModel from the argument url

openest.generate.retrieve.from_url(url, create_func)[source]

Returns a StringIO.StringIO buffer with the contents of the response from url

Todo

  • response from urllib2.urlopen(req) is already a buffer. Is writing to a new buffer necessary?
openest.generate.retrieve.spline_from_url(url)[source]

Returns a SplineModel from the argument url