Exemple #1
0
def from_str(
  type_: Type[T],
  value: str,
  field_metadata: Optional[FieldMetadata] = None,
  registry: Optional[Registry] = None,
) -> T:
  return _json.from_json(type_, loads(value), field_metadata, registry or globals()['registry'])
Exemple #2
0
def from_stream(
    type_: Type[T],
    stream: TextIO,
    field_metadata: FieldMetadata = None,
    registry: Registry = None,
    Loader: Type[yaml.composer.Composer] = yaml.SafeLoader,
) -> T:
    return _json.from_json(type_, yaml.load(stream, Loader=Loader),
                           field_metadata, registry)
Exemple #3
0
def from_str(
    type_: Type[T],
    value: str,
    field_metadata: FieldMetadata = None,
    registry: Registry = None,
    Loader: Type[yaml.composer.Composer] = yaml.SafeLoader,
) -> T:
    return _json.from_json(type_, yaml.load(value, Loader=Loader),
                           field_metadata, registry)
Exemple #4
0
 def from_response(response: requests.Response) -> 'AccessTokenResponse':
   raise_for_response(response)
   content_type = response.headers.get('Content-Type', '').partition(';')[0]
   if content_type == 'application/json':
     raw = response.json()
   elif content_type == 'application/x-www-form-urlencoded':
     raw = dict(parse_qsl(response.text))
   else:
     raise RuntimeError(f'unsupported Content-Type: {content_type!r}')
   return from_json(AccessTokenResponse, raw)
Exemple #5
0
 def authorize(self) -> flask.Response:
     code = flask.request.args['code']
     state = flask.request.args['state']
     data = self.context.state_recorder.get_state(state, consume=True)
     session = OAuth2Session(from_json(OAuth2SessionData, data['session']),
                             self.oauth2)
     access_data = session.get_token(code)
     redirect_uri = data['redirect_uri'] or self.context.redirect_uri
     user = self.finalize_login(access_data)
     self.context.state_recorder.login(user)
     return flask.redirect(redirect_uri)
Exemple #6
0
    def get_device_code(
        self,
        scope: t.Optional[str] = None,
        session: t.Optional[requests.Session] = None,
    ) -> DeviceCodeResponse:

        parameters = {'client_id': self.client_id}
        if scope or self.scope:
            parameters['scope'] = t.cast(str, scope or self.scope)

        session = session or self.session or get_default_session()
        response = session.post(self.device_code_uri, data=parameters)
        raise_for_response(response)
        return from_json(DeviceCodeResponse, response.json())
Exemple #7
0
 def load(self) -> BaseTask:
   module_name, member_name = self.class_name.split(':')
   module = importlib.import_module(module_name)
   type_ = getattr(module, member_name)
   return from_json(type_, self.args)
Exemple #8
0
 def load(cls, file: Path) -> 'Config':
     raw = toml.load(file)
     return from_json(cls, raw)
Exemple #9
0
 def read_query(self, request, annotated_type, value):
     return from_json(annotated_type, value, registry=self.json_registry)
Exemple #10
0
 def read_body(self, request, annotated_type):
     return from_json(annotated_type,
                      request.json,
                      registry=self.json_registry)