magpie.adapter

Package Contents

magpie.adapter.SigninAPI[source]
magpie.adapter.valid_http(httpSuccess=HTTPOk, httpKWArgs=None, detail='', content=None, contentType=CONTENT_TYPE_JSON) → HTTPException[source]

Returns successful HTTP with standardized information formatted with content type. (see :function:`raise_http` for HTTP error calls)

Parameters:
  • httpSuccess – any derived class from base HTTPSuccessful (default: HTTPOk)
  • httpKWArgs – additional keyword arguments to pass to httpSuccess when called
  • detail – additional message information (default: empty)
  • content – json formatted content to include
  • contentType – format in which to return the exception (one of magpie.common.SUPPORTED_CONTENT_TYPES)
Return HTTPSuccessfulHTTPSuccessful:
 

formatted successful with additional details and HTTP code

magpie.adapter.raise_http(httpError=HTTPInternalServerError, httpKWArgs=None, detail='', content=None, contentType=CONTENT_TYPE_JSON, nothrow=False) → Optional[HTTPException][source]

Raises error HTTP with standardized information formatted with content type.

The content contains the corresponding http error code, the provided message as detail and optional specified additional json content (kwarg dict).

See also

valid_http() for HTTP successful calls

Parameters:
  • httpError – any derived class from base HTTPError (default: HTTPInternalServerError)
  • httpKWArgs – additional keyword arguments to pass to httpError if called in case of HTTP exception
  • detail – additional message information (default: empty)
  • content – json formatted content to include
  • contentType – format in which to return the exception (one of magpie.common.SUPPORTED_CONTENT_TYPES)
  • nothrow – returns the error response instead of raising it automatically, but still handles execution errors
Raises:

HTTPError – formatted raised exception with additional details and HTTP code

Returns:

HTTPError formatted exception with additional details and HTTP code only if nothrow is True

class magpie.adapter.MagpieOWSSecurity(request)[source]

Bases: magpie.definitions.twitcher_definitions.OWSSecurityInterface

check_request(self, request)
update_request_cookies(self, request)

Ensure login of the user and update the request cookies if Twitcher is in a special configuration.

Only update if MAGPIE_COOKIE_NAME is missing and is retrievable from access_token in Authorization header. Counter-validate the login procedure by calling Magpie’s /session which should indicated a logged user.

class magpie.adapter.MagpieServiceStore(request)[source]

Bases: magpie.definitions.twitcher_definitions.ServiceStoreInterface

Registry for OWS services.

Uses magpie to fetch service url and attributes.

save_service(self, service, overwrite=True, request=None)

Magpie store is read-only, use magpie api to add services.

delete_service(self, name, request=None)

Magpie store is read-only, use magpie api to delete services.

list_services(self, request=None)

Lists all services registered in magpie.

fetch_by_name(self, name, visibility=None, request=None)

Gets service for given name from magpie.

fetch_by_url(self, url, request=None)

Gets service for given url from mongodb storage.

clear_services(self, request=None)

Magpie store is read-only, use magpie api to delete services.

magpie.adapter.get_auth_config(container)[source]
magpie.adapter.get_session_factory(engine)[source]
magpie.adapter.get_tm_session(session_factory, transaction_manager)[source]

Get a sqlalchemy.orm.Session instance backed by a transaction.

This function will hook the session to the transaction manager which will take care of committing any changes.

  • When using pyramid_tm it will automatically be committed or aborted depending on whether an exception is raised.

  • When using scripts you should wrap the session in a manager yourself. For example:

    import transaction
    
    engine = get_engine(settings)
    session_factory = get_session_factory(engine)
    with transaction.manager:
        db_session = get_tm_session(session_factory, transaction.manager)
    
magpie.adapter.get_engine(container=None, prefix='sqlalchemy.', **kwargs) → Engine[source]
magpie.adapter.get_logger(name, level=None)[source]

Immediately sets the logger level to avoid duplicate log outputs from the root logger and this logger when level is NOTSET.

magpie.adapter.get_settings(container) → SettingsType[source]
magpie.adapter.get_magpie_url(container=None) → Str[source]
magpie.adapter.CONTENT_TYPE_JSON = application/json[source]
magpie.adapter.LOGGER[source]

Logs debug information about request cookie.

Warning

This function is intended for debugging purposes only. It reveals sensible configuration information.

Re-implements basic functionality of pyramid.AuthTktAuthenticationPolicy.cookie.identify() called via request.unauthenticated_userid() within get_user() to provide additional logging.

See also

  • pyramid.authentication.AuthTktCookieHelper
  • pyramid.authentication.AuthTktAuthenticationPolicy
magpie.adapter.get_user(request)[source]
magpie.adapter.verify_user(request)[source]
class magpie.adapter._Singleton[source]

Bases: type

A metaclass that creates a Singleton base class when called.

_instances[source]
__call__(cls, *args, **kwargs)[source]
class magpie.adapter.Singleton[source]

Bases: magpie.adapter._Singleton

class magpie.adapter.MagpieAdapter(container)[source]

Bases: magpie.definitions.twitcher_definitions.AdapterInterface, magpie.adapter.Singleton

describe_adapter(self)[source]
servicestore_factory(self, request, headers=None)[source]
owssecurity_factory(self, request)[source]
owsproxy_config(self, container)[source]
configurator_factory(self, container)[source]