magpie.adapter¶
Package Contents¶
-
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 callsParameters: - 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)¶
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.ServiceStoreInterfaceRegistry 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
namefrom magpie.
-
fetch_by_url(self, url, request=None)¶ Gets service for given
urlfrom mongodb storage.
-
clear_services(self, request=None)¶ Magpie store is read-only, use magpie api to delete services.
-
-
magpie.adapter.get_tm_session(session_factory, transaction_manager)[source]¶ Get a
sqlalchemy.orm.Sessioninstance 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_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.
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 viarequest.unauthenticated_userid()withinget_user()to provide additional logging.See also
pyramid.authentication.AuthTktCookieHelperpyramid.authentication.AuthTktAuthenticationPolicy
-
class
magpie.adapter._Singleton[source]¶ Bases:
typeA metaclass that creates a Singleton base class when called.
-
class
magpie.adapter.Singleton[source]¶ Bases:
magpie.adapter._Singleton
-
class
magpie.adapter.MagpieAdapter(container)[source]¶ Bases:
magpie.definitions.twitcher_definitions.AdapterInterface,magpie.adapter.Singleton