Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
from twisted.python.components import Componentized
from zope.interface import implementer
from zope.interface.interfaces import IInterface
from klein.interfaces import (
ISession,
ISessionStore,
NoSuchSession,
SessionMechanism,
)
_authCB = Callable[[IInterface, ISession, Componentized], Any]
@implementer(ISession) # type: ignore[misc]
@attr.s
class MemorySession(object):
"""
An in-memory session.
"""
identifier = attr.ib(type=Text)
isConfidential = attr.ib(type=bool)
authenticatedBy = attr.ib(type=SessionMechanism)
_authorizationCallback = attr.ib(type=_authCB) # type: ignore[misc]
_components = attr.ib(default=Factory(Componentized), type=Componentized)
def authorize(self, interfaces):
# type: (List[IInterface]) -> Deferred
"""
Authorize each interface by calling back to the session store's
@requirer.prerequisite([ISession])
def procurer(request):
return SessionProcurer(sessions).procureSession(request)
from attr import Factory
from twisted.internet.defer import Deferred, fail, succeed
from twisted.python.components import Componentized
from zope.interface import implementer
from zope.interface.interfaces import IInterface
from klein.interfaces import (
ISession,
ISessionStore,
NoSuchSession,
SessionMechanism,
)
_authCB = Callable[[IInterface, ISession, Componentized], Any]
@implementer(ISession) # type: ignore[misc]
@attr.s
class MemorySession(object):
"""
An in-memory session.
"""
identifier = attr.ib(type=Text)
isConfidential = attr.ib(type=bool)
authenticatedBy = attr.ib(type=SessionMechanism)
_authorizationCallback = attr.ib(type=_authCB) # type: ignore[misc]
_components = attr.ib(default=Factory(Componentized), type=Componentized)
def authorize(self, interfaces):
session=RequestComponent(ISession),
)
@inlineCallbacks
def sessions(binding, form, session):
# type: (ISimpleAccountBinding, Form, ISession) -> Deferred
if binding is None:
returnValue({"sessions": []})
else:
dump = {
"sessions": [
oneSession.widget(
session_info, form, session.identifier == session_info.id
)
for session_info in (yield binding.boundSessionInformation())
]
}
returnValue(dump)
@requirer.prerequisite([ISession])
def getSessionProcurer(request):
# type: (IRequest) -> ISessionProcurer
return procurer.procureSession(request)