Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async def on_request(self, request: Request):
request.identity = User({'id': '001', 'name': 'Charlie Brown'}, 'JWTBearer')
User,
Optional[User],
Optional[Identity]
])
def test_identity_binder_by_param_type(annotation_type):
async def handler(param):
...
handler.__annotations__['param'] = annotation_type
binders = get_binders(Route(b'/', handler), {})
assert isinstance(binders[0], IdentityBinder)
async def index(self, request: Request, user: Optional[User]):
assert hasattr(request, 'identity')
assert isinstance(request.identity, User)
return text(request.identity.name)
if name in services:
return FromServices(name, services)
# 2B. do services contain a service with matching type?
if annotation in services:
return FromServices(annotation, services)
# 3. does route contain a parameter with matching name?
if route and name in route.param_names:
return FromRoute(annotation, name)
# 4. is simple type?
if annotation in _simple_types_handled_with_query:
return FromQuery(annotation, name, required=not is_optional)
if annotation is User or annotation is Identity:
return IdentityBinder()
# 5. from json body (last default)
return FromJson(annotation, required=not is_optional)