INSTRUCTION stringlengths 1 8.43k | RESPONSE stringlengths 75 104k |
|---|---|
Removes itself from the cache | def delete(self):
"""Removes itself from the cache
Note: This is required by the oauthlib
"""
log.debug(
"Deleting grant %s for client %s" % (self.code, self.client_id)
)
self._cache.delete(self.key)
return None |
Determines which method of getting the query object for use | def query(self):
"""Determines which method of getting the query object for use"""
if hasattr(self.model, 'query'):
return self.model.query
else:
return self.session.query(self.model) |
Returns the User object | def get(self, username, password, *args, **kwargs):
"""Returns the User object
Returns None if the user isn't found or the passwords don't match
:param username: username of the user
:param password: password of the user
"""
user = self.query.filter_by(username=username... |
returns a Token object with the given access token or refresh token | def get(self, access_token=None, refresh_token=None):
"""returns a Token object with the given access token or refresh token
:param access_token: User's access token
:param refresh_token: User's refresh token
"""
if access_token:
return self.query.filter_by(access_to... |
Creates a Token object and removes all expired tokens that belong to the user | def set(self, token, request, *args, **kwargs):
"""Creates a Token object and removes all expired tokens that belong
to the user
:param token: token object
:param request: OAuthlib request object
"""
if hasattr(request, 'user') and request.user:
user = reques... |
Creates Grant object with the given params | def set(self, client_id, code, request, *args, **kwargs):
"""Creates Grant object with the given params
:param client_id: ID of the client
:param code:
:param request: OAuthlib request object
"""
expires = datetime.utcnow() + timedelta(seconds=100)
grant = self.m... |
Get the Grant object with the given client ID and code | def get(self, client_id, code):
"""Get the Grant object with the given client ID and code
:param client_id: ID of the client
:param code:
"""
return self.query.filter_by(client_id=client_id, code=code).first() |
Parse the response returned by: meth: OAuthRemoteApp. http_request. | def parse_response(resp, content, strict=False, content_type=None):
"""Parse the response returned by :meth:`OAuthRemoteApp.http_request`.
:param resp: response of http_request
:param content: content of the response
:param strict: strict mode for form urlencoded content
:param content_type: assign... |
Make request parameters right. | def prepare_request(uri, headers=None, data=None, method=None):
"""Make request parameters right."""
if headers is None:
headers = {}
if data and not method:
method = 'POST'
elif not method:
method = 'GET'
if method == 'GET' and data:
uri = add_params_to_uri(uri, da... |
Init app with Flask instance. | def init_app(self, app):
"""Init app with Flask instance.
You can also pass the instance of Flask later::
oauth = OAuth()
oauth.init_app(app)
"""
self.app = app
app.extensions = getattr(app, 'extensions', {})
app.extensions[self.state_key] = self |
Registers a new remote application. | def remote_app(self, name, register=True, **kwargs):
"""Registers a new remote application.
:param name: the name of the remote application
:param register: whether the remote app will be registered
Find more parameters from :class:`OAuthRemoteApp`.
"""
remote = OAuthRe... |
Sends a request to the remote server with OAuth tokens attached. | def request(self, url, data=None, headers=None, format='urlencoded',
method='GET', content_type=None, token=None):
"""
Sends a request to the remote server with OAuth tokens attached.
:param data: the data to be sent to the server.
:param headers: an optional dictionary ... |
Returns a redirect response to the remote authorization URL with the signed callback given. | def authorize(self, callback=None, state=None, **kwargs):
"""
Returns a redirect response to the remote authorization URL with
the signed callback given.
:param callback: a redirect url for the callback
:param state: an optional value to embed in the OAuth request.
... |
Handles an oauth1 authorization response. | def handle_oauth1_response(self, args):
"""Handles an oauth1 authorization response."""
client = self.make_client()
client.verifier = args.get('oauth_verifier')
tup = session.get('%s_oauthtok' % self.name)
if not tup:
raise OAuthException(
'Token not f... |
Handles an oauth2 authorization response. | def handle_oauth2_response(self, args):
"""Handles an oauth2 authorization response."""
client = self.make_client()
remote_args = {
'code': args.get('code'),
'client_secret': self.consumer_secret,
'redirect_uri': session.get('%s_oauthredir' % self.name)
... |
Handles authorization response smartly. | def authorized_response(self, args=None):
"""Handles authorization response smartly."""
if args is None:
args = request.args
if 'oauth_verifier' in args:
data = self.handle_oauth1_response(args)
elif 'code' in args:
data = self.handle_oauth2_response(a... |
Handles an OAuth callback. | def authorized_handler(self, f):
"""Handles an OAuth callback.
.. versionchanged:: 0.7
@authorized_handler is deprecated in favor of authorized_response.
"""
@wraps(f)
def decorated(*args, **kwargs):
log.warn(
'@authorized_handler is deprec... |
Creates a hashable object for given token then we could use it as a dictionary key. | def _hash_token(application, token):
"""Creates a hashable object for given token then we could use it as a
dictionary key.
"""
if isinstance(token, dict):
hashed_token = tuple(sorted(token.items()))
elif isinstance(token, tuple):
hashed_token = token
else:
raise TypeErro... |
The lazy - created OAuth session with the return value of: meth: tokengetter. | def client(self):
"""The lazy-created OAuth session with the return value of
:meth:`tokengetter`.
:returns: The OAuth session instance or ``None`` while token missing.
"""
token = self.obtain_token()
if token is None:
raise AccessTokenNotFound
return ... |
Uses cached client or create new one with specific token. | def _make_client_with_token(self, token):
"""Uses cached client or create new one with specific token."""
cached_clients = getattr(self, 'clients', None)
hashed_token = _hash_token(self, token)
if cached_clients and hashed_token in cached_clients:
return cached_clients[hashe... |
Creates a client with specific access token pair. | def make_client(self, token):
"""Creates a client with specific access token pair.
:param token: a tuple of access token pair ``(token, token_secret)``
or a dictionary of access token response.
:returns: a :class:`requests_oauthlib.oauth1_session.OAuth1Session`
... |
Creates a context to enable the oauthlib environment variable in order to debug with insecure transport. | def insecure_transport(self):
"""Creates a context to enable the oauthlib environment variable in
order to debug with insecure transport.
"""
origin = os.environ.get('OAUTHLIB_INSECURE_TRANSPORT')
if current_app.debug or current_app.testing:
try:
os.en... |
All in one endpoints. This property is created automaticly if you have implemented all the getters and setters. | def server(self):
"""
All in one endpoints. This property is created automaticly
if you have implemented all the getters and setters.
"""
if hasattr(self, '_validator'):
return Server(self._validator)
if hasattr(self, '_clientgetter') and \
hasattr... |
Authorization handler decorator. | def authorize_handler(self, f):
"""Authorization handler decorator.
This decorator will sort the parameters and headers out, and
pre validate everything::
@app.route('/oauth/authorize', methods=['GET', 'POST'])
@oauth.authorize_handler
def authorize(*args, *... |
When consumer confirm the authrozation. | def confirm_authorization_request(self):
"""When consumer confirm the authrozation."""
server = self.server
uri, http_method, body, headers = extract_params()
try:
realms, credentials = server.get_realms_and_credentials(
uri, http_method=http_method, body=bod... |
Request token handler decorator. | def request_token_handler(self, f):
"""Request token handler decorator.
The decorated function should return an dictionary or None as
the extra credentials for creating the token response.
If you don't need to add any extra credentials, it could be as
simple as::
@... |
Protect resource with specified scopes. | def require_oauth(self, *realms, **kwargs):
"""Protect resource with specified scopes."""
def wrapper(f):
@wraps(f)
def decorated(*args, **kwargs):
for func in self._before_request_funcs:
func()
if hasattr(request, 'oauth') and... |
Get client secret. | def get_client_secret(self, client_key, request):
"""Get client secret.
The client object must has ``client_secret`` attribute.
"""
log.debug('Get client secret of %r', client_key)
if not request.client:
request.client = self._clientgetter(client_key=client_key)
... |
Get request token secret. | def get_request_token_secret(self, client_key, token, request):
"""Get request token secret.
The request token object should a ``secret`` attribute.
"""
log.debug('Get request token secret of %r for %r',
token, client_key)
tok = request.request_token or self._g... |
Get access token secret. | def get_access_token_secret(self, client_key, token, request):
"""Get access token secret.
The access token object should a ``secret`` attribute.
"""
log.debug('Get access token secret of %r for %r',
token, client_key)
tok = request.access_token or self._tokeng... |
Default realms of the client. | def get_default_realms(self, client_key, request):
"""Default realms of the client."""
log.debug('Get realms for %r', client_key)
if not request.client:
request.client = self._clientgetter(client_key=client_key)
client = request.client
if hasattr(client, 'default_re... |
Realms for this request token. | def get_realms(self, token, request):
"""Realms for this request token."""
log.debug('Get realms of %r', token)
tok = request.request_token or self._grantgetter(token=token)
if not tok:
return []
request.request_token = tok
if hasattr(tok, 'realms'):
... |
Redirect uri for this request token. | def get_redirect_uri(self, token, request):
"""Redirect uri for this request token."""
log.debug('Get redirect uri of %r', token)
tok = request.request_token or self._grantgetter(token=token)
return tok.redirect_uri |
Retrieves a previously stored client provided RSA key. | def get_rsa_key(self, client_key, request):
"""Retrieves a previously stored client provided RSA key."""
if not request.client:
request.client = self._clientgetter(client_key=client_key)
if hasattr(request.client, 'rsa_key'):
return request.client.rsa_key
return N... |
Validates that supplied client key. | def validate_client_key(self, client_key, request):
"""Validates that supplied client key."""
log.debug('Validate client key for %r', client_key)
if not request.client:
request.client = self._clientgetter(client_key=client_key)
if request.client:
return True
... |
Validates request token is available for client. | def validate_request_token(self, client_key, token, request):
"""Validates request token is available for client."""
log.debug('Validate request token %r for %r',
token, client_key)
tok = request.request_token or self._grantgetter(token=token)
if tok and tok.client_key ... |
Validates access token is available for client. | def validate_access_token(self, client_key, token, request):
"""Validates access token is available for client."""
log.debug('Validate access token %r for %r',
token, client_key)
tok = request.access_token or self._tokengetter(
client_key=client_key,
tok... |
Validate the timestamp and nonce is used or not. | def validate_timestamp_and_nonce(self, client_key, timestamp, nonce,
request, request_token=None,
access_token=None):
"""Validate the timestamp and nonce is used or not."""
log.debug('Validate timestamp and nonce %r', client_key)
... |
Validate if the redirect_uri is allowed by the client. | def validate_redirect_uri(self, client_key, redirect_uri, request):
"""Validate if the redirect_uri is allowed by the client."""
log.debug('Validate redirect_uri %r for %r', redirect_uri, client_key)
if not request.client:
request.client = self._clientgetter(client_key=client_key)
... |
Check if the token has permission on those realms. | def validate_realms(self, client_key, token, request, uri=None,
realms=None):
"""Check if the token has permission on those realms."""
log.debug('Validate realms %r for %r', realms, client_key)
if request.access_token:
tok = request.access_token
else:
... |
Validate verifier exists. | def validate_verifier(self, client_key, token, verifier, request):
"""Validate verifier exists."""
log.debug('Validate verifier %r for %r', verifier, client_key)
data = self._verifiergetter(verifier=verifier, token=token)
if not data:
return False
if not hasattr(data,... |
Verify if the request token is existed. | def verify_request_token(self, token, request):
"""Verify if the request token is existed."""
log.debug('Verify request token %r', token)
tok = request.request_token or self._grantgetter(token=token)
if tok:
request.request_token = tok
return True
return F... |
Verify if the realms match the requested realms. | def verify_realms(self, token, realms, request):
"""Verify if the realms match the requested realms."""
log.debug('Verify realms %r', realms)
tok = request.request_token or self._grantgetter(token=token)
if not tok:
return False
request.request_token = tok
if... |
Save access token to database. | def save_access_token(self, token, request):
"""Save access token to database.
A tokensetter is required, which accepts a token and request
parameters::
def tokensetter(token, request):
access_token = Token(
client=request.client,
... |
Save request token to database. | def save_request_token(self, token, request):
"""Save request token to database.
A grantsetter is required, which accepts a token and request
parameters::
def grantsetter(token, request):
grant = Grant(
token=token['oauth_token'],
... |
Save verifier to database. | def save_verifier(self, token, verifier, request):
"""Save verifier to database.
A verifiersetter is required. It would be better to combine request
token and verifier together::
def verifiersetter(token, verifier, request):
tok = Grant.query.filter_by(token=token).... |
The error page URI. | def error_uri(self):
"""The error page URI.
When something turns error, it will redirect to this error page.
You can configure the error page URI with Flask config::
OAUTH2_PROVIDER_ERROR_URI = '/error'
You can also define the error page by a named endpoint::
... |
All in one endpoints. This property is created automaticly if you have implemented all the getters and setters. | def server(self):
"""
All in one endpoints. This property is created automaticly
if you have implemented all the getters and setters.
However, if you are not satisfied with the getter and setter,
you can create a validator with :class:`OAuth2RequestValidator`::
clas... |
Authorization handler decorator. | def authorize_handler(self, f):
"""Authorization handler decorator.
This decorator will sort the parameters and headers out, and
pre validate everything::
@app.route('/oauth/authorize', methods=['GET', 'POST'])
@oauth.authorize_handler
def authorize(*args, *... |
When consumer confirm the authorization. | def confirm_authorization_request(self):
"""When consumer confirm the authorization."""
server = self.server
scope = request.values.get('scope') or ''
scopes = scope.split()
credentials = dict(
client_id=request.values.get('client_id'),
redirect_uri=reques... |
Verify current request get the oauth data. | def verify_request(self, scopes):
"""Verify current request, get the oauth data.
If you can't use the ``require_oauth`` decorator, you can fetch
the data in your request body::
def your_handler():
valid, req = oauth.verify_request(['email'])
if valid... |
Access/ refresh token handler decorator. | def token_handler(self, f):
"""Access/refresh token handler decorator.
The decorated function should return an dictionary or None as
the extra credentials for creating the token response.
You can control the access method with standard flask route mechanism.
If you only allow t... |
Access/ refresh token revoke decorator. | def revoke_handler(self, f):
"""Access/refresh token revoke decorator.
Any return value by the decorated function will get discarded as
defined in [`RFC7009`_].
You can control the access method with the standard flask routing
mechanism, as per [`RFC7009`_] it is recommended to... |
Protect resource with specified scopes. | def require_oauth(self, *scopes):
"""Protect resource with specified scopes."""
def wrapper(f):
@wraps(f)
def decorated(*args, **kwargs):
for func in self._before_request_funcs:
func()
if hasattr(request, 'oauth') and request.o... |
Return client credentials based on the current request. | def _get_client_creds_from_request(self, request):
"""Return client credentials based on the current request.
According to the rfc6749, client MAY use the HTTP Basic authentication
scheme as defined in [RFC2617] to authenticate with the authorization
server. The client identifier is enc... |
Determine if client authentication is required for current request. | def client_authentication_required(self, request, *args, **kwargs):
"""Determine if client authentication is required for current request.
According to the rfc6749, client authentication is required in the
following cases:
Resource Owner Password Credentials Grant: see `Section 4.3.2`_... |
Authenticate itself in other means. | def authenticate_client(self, request, *args, **kwargs):
"""Authenticate itself in other means.
Other means means is described in `Section 3.2.1`_.
.. _`Section 3.2.1`: http://tools.ietf.org/html/rfc6749#section-3.2.1
"""
client_id, client_secret = self._get_client_creds_from_r... |
Authenticate a non - confidential client. | def authenticate_client_id(self, client_id, request, *args, **kwargs):
"""Authenticate a non-confidential client.
:param client_id: Client ID of the non-confidential client
:param request: The Request object passed by oauthlib
"""
if client_id is None:
client_id, _ =... |
Ensure client is authorized to redirect to the redirect_uri. | def confirm_redirect_uri(self, client_id, code, redirect_uri, client,
*args, **kwargs):
"""Ensure client is authorized to redirect to the redirect_uri.
This method is used in the authorization code grant flow. It will
compare redirect_uri and the one in grant token ... |
Get the list of scopes associated with the refresh token. | def get_original_scopes(self, refresh_token, request, *args, **kwargs):
"""Get the list of scopes associated with the refresh token.
This method is used in the refresh token grant flow. We return
the scope of the token to be refreshed so it can be applied to the
new access token.
... |
Ensures the requested scope matches the scope originally granted by the resource owner. If the scope is omitted it is treated as equal to the scope originally granted by the resource owner. | def confirm_scopes(self, refresh_token, scopes, request, *args, **kwargs):
"""Ensures the requested scope matches the scope originally granted
by the resource owner. If the scope is omitted it is treated as equal
to the scope originally granted by the resource owner.
DEPRECATION NOTE: T... |
Default redirect_uri for the given client. | def get_default_redirect_uri(self, client_id, request, *args, **kwargs):
"""Default redirect_uri for the given client."""
request.client = request.client or self._clientgetter(client_id)
redirect_uri = request.client.default_redirect_uri
log.debug('Found default redirect uri %r', redirec... |
Default scopes for the given client. | def get_default_scopes(self, client_id, request, *args, **kwargs):
"""Default scopes for the given client."""
request.client = request.client or self._clientgetter(client_id)
scopes = request.client.default_scopes
log.debug('Found default scopes %r', scopes)
return scopes |
Invalidate an authorization code after use. | def invalidate_authorization_code(self, client_id, code, request,
*args, **kwargs):
"""Invalidate an authorization code after use.
We keep the temporary code in a grant, which has a `delete`
function to destroy itself.
"""
log.debug('Destroy... |
Persist the authorization code. | def save_authorization_code(self, client_id, code, request,
*args, **kwargs):
"""Persist the authorization code."""
log.debug(
'Persist authorization code %r for client %r',
code, client_id
)
request.client = request.client or self.... |
Persist the Bearer token. | def save_bearer_token(self, token, request, *args, **kwargs):
"""Persist the Bearer token."""
log.debug('Save bearer token %r', token)
self._tokensetter(token, request, *args, **kwargs)
return request.client.default_redirect_uri |
Validate access token. | def validate_bearer_token(self, token, scopes, request):
"""Validate access token.
:param token: A string of random characters
:param scopes: A list of scopes
:param request: The Request object passed by oauthlib
The validation validates:
1) if the token is availab... |
Ensure client_id belong to a valid and active client. | def validate_client_id(self, client_id, request, *args, **kwargs):
"""Ensure client_id belong to a valid and active client."""
log.debug('Validate client %r', client_id)
client = request.client or self._clientgetter(client_id)
if client:
# attach client to request object
... |
Ensure the grant code is valid. | def validate_code(self, client_id, code, client, request, *args, **kwargs):
"""Ensure the grant code is valid."""
client = client or self._clientgetter(client_id)
log.debug(
'Validate code for client %r and code %r', client.client_id, code
)
grant = self._grantgetter(... |
Ensure the client is authorized to use the grant type requested. | def validate_grant_type(self, client_id, grant_type, client, request,
*args, **kwargs):
"""Ensure the client is authorized to use the grant type requested.
It will allow any of the four grant types (`authorization_code`,
`password`, `client_credentials`, `refresh_tok... |
Ensure client is authorized to redirect to the redirect_uri. | def validate_redirect_uri(self, client_id, redirect_uri, request,
*args, **kwargs):
"""Ensure client is authorized to redirect to the redirect_uri.
This method is used in the authorization code grant flow and also
in implicit grant flow. It will detect if redirect_... |
Ensure the token is valid and belongs to the client | def validate_refresh_token(self, refresh_token, client, request,
*args, **kwargs):
"""Ensure the token is valid and belongs to the client
This method is used by the authorization code grant indirectly by
issuing refresh tokens, resource owner password credentials ... |
Ensure client is authorized to use the response type requested. | def validate_response_type(self, client_id, response_type, client, request,
*args, **kwargs):
"""Ensure client is authorized to use the response type requested.
It will allow any of the two (`code`, `token`) response types by
default. Implemented `allowed_response... |
Ensure the client is authorized access to requested scopes. | def validate_scopes(self, client_id, scopes, client, request,
*args, **kwargs):
"""Ensure the client is authorized access to requested scopes."""
if hasattr(client, 'validate_scopes'):
return client.validate_scopes(scopes)
return set(client.default_scopes).iss... |
Ensure the username and password is valid. | def validate_user(self, username, password, client, request,
*args, **kwargs):
"""Ensure the username and password is valid.
Attach user object on request for later using.
"""
log.debug('Validating username %r and its password', username)
if self._usergette... |
Revoke an access or refresh token. | def revoke_token(self, token, token_type_hint, request, *args, **kwargs):
"""Revoke an access or refresh token.
"""
if token_type_hint:
tok = self._tokengetter(**{token_type_hint: token})
else:
tok = self._tokengetter(access_token=token)
if not tok:
... |
OAuthResponse class can t parse the JSON data with content - type - text/ html and because of a rubbish api we can t just tell flask - oauthlib to treat it as json. | def json_to_dict(x):
'''OAuthResponse class can't parse the JSON data with content-type
- text/html and because of a rubbish api, we can't just tell flask-oauthlib to treat it as json.'''
if x.find(b'callback') > -1:
# the rubbish api (https://graph.qq.com/oauth2.0/authorize) is handled here as speci... |
Update some required parameters for OAuth2. 0 API calls | def update_qq_api_request_data(data={}):
'''Update some required parameters for OAuth2.0 API calls'''
defaults = {
'openid': session.get('qq_openid'),
'access_token': session.get('qq_token')[0],
'oauth_consumer_key': QQ_APP_ID,
}
defaults.update(data)
return defaults |
Recursively converts dictionary keys to strings. | def convert_keys_to_string(dictionary):
'''Recursively converts dictionary keys to strings.'''
if not isinstance(dictionary, dict):
return dictionary
return dict((str(k), convert_keys_to_string(v)) for k, v in dictionary.items()) |
Since weibo is a rubbish server it does not follow the standard we need to change the authorization header for it. | def change_weibo_header(uri, headers, body):
"""Since weibo is a rubbish server, it does not follow the standard,
we need to change the authorization header for it."""
auth = headers.get('Authorization')
if auth:
auth = auth.replace('Bearer', 'OAuth2')
headers['Authorization'] = auth
... |
Creates a remote app and registers it. | def register_to(self, oauth, name=None, **kwargs):
"""Creates a remote app and registers it."""
kwargs = self._process_kwargs(
name=(name or self.default_name), **kwargs)
return oauth.remote_app(**kwargs) |
Creates a remote app only. | def create(self, oauth, **kwargs):
"""Creates a remote app only."""
kwargs = self._process_kwargs(
name=self.default_name, register=False, **kwargs)
return oauth.remote_app(**kwargs) |
The uri returned from request. uri is not properly urlencoded ( sometimes it s partially urldecoded ) This is a weird hack to get werkzeug to return the proper urlencoded string uri | def _get_uri_from_request(request):
"""
The uri returned from request.uri is not properly urlencoded
(sometimes it's partially urldecoded) This is a weird hack to get
werkzeug to return the proper urlencoded string uri
"""
uri = request.base_url
if request.query_string:
uri += '?' + ... |
Extract request params. | def extract_params():
"""Extract request params."""
uri = _get_uri_from_request(request)
http_method = request.method
headers = dict(request.headers)
if 'wsgi.input' in headers:
del headers['wsgi.input']
if 'wsgi.errors' in headers:
del headers['wsgi.errors']
# Werkzeug, and... |
Make sure text is bytes type. | def to_bytes(text, encoding='utf-8'):
"""Make sure text is bytes type."""
if not text:
return text
if not isinstance(text, bytes_type):
text = text.encode(encoding)
return text |
Decode base64 string. | def decode_base64(text, encoding='utf-8'):
"""Decode base64 string."""
text = to_bytes(text, encoding)
return to_unicode(base64.b64decode(text), encoding) |
Create response class for Flask. | def create_response(headers, body, status):
"""Create response class for Flask."""
response = Response(body or '')
for k, v in headers.items():
response.headers[str(k)] = v
response.status_code = status
return response |
Returns a: class: SimpleCache instance | def _simple(self, **kwargs):
"""Returns a :class:`SimpleCache` instance
.. warning::
This cache system might not be thread safe. Use with caution.
"""
kwargs.update(dict(threshold=self._config('threshold', 500)))
return SimpleCache(**kwargs) |
Returns a: class: MemcachedCache instance | def _memcache(self, **kwargs):
"""Returns a :class:`MemcachedCache` instance"""
kwargs.update(dict(
servers=self._config('MEMCACHED_SERVERS', None),
key_prefix=self._config('key_prefix', None),
))
return MemcachedCache(**kwargs) |
Returns a: class: RedisCache instance | def _redis(self, **kwargs):
"""Returns a :class:`RedisCache` instance"""
kwargs.update(dict(
host=self._config('REDIS_HOST', 'localhost'),
port=self._config('REDIS_PORT', 6379),
password=self._config('REDIS_PASSWORD', None),
db=self._config('REDIS_DB', 0),... |
Returns a: class: FileSystemCache instance | def _filesystem(self, **kwargs):
"""Returns a :class:`FileSystemCache` instance"""
kwargs.update(dict(
threshold=self._config('threshold', 500),
))
return FileSystemCache(self._config('dir', None), **kwargs) |
Gets the cached clients dictionary in current context. | def get_cached_clients():
"""Gets the cached clients dictionary in current context."""
if OAuth.state_key not in current_app.extensions:
raise RuntimeError('%r is not initialized.' % current_app)
state = current_app.extensions[OAuth.state_key]
return state.cached_clients |
Adds remote application and applies custom attributes on it. | def add_remote_app(self, remote_app, name=None, **kwargs):
"""Adds remote application and applies custom attributes on it.
If the application instance's name is different from the argument
provided name, or the keyword arguments is not empty, then the
application instance will not be mo... |
Creates and adds new remote application. | def remote_app(self, name, version=None, **kwargs):
"""Creates and adds new remote application.
:param name: the remote application's name.
:param version: '1' or '2', the version code of OAuth protocol.
:param kwargs: the attributes of remote application.
"""
if version... |
Call the method repeatedly such that it will raise an exception. | def check_exception(self):
"""
Call the method repeatedly such that it will raise an exception.
"""
for i in xrange(self.iterations):
cert = X509()
try:
cert.get_pubkey()
except Error:
pass |
Call the method repeatedly such that it will return a PKey object. | def check_success(self):
"""
Call the method repeatedly such that it will return a PKey object.
"""
small = xrange(3)
for i in xrange(self.iterations):
key = PKey()
key.generate_key(TYPE_DSA, 256)
for i in small:
cert = X509()
... |
Call the function with an encrypted PEM and a passphrase callback. | def check_load_privatekey_callback(self):
"""
Call the function with an encrypted PEM and a passphrase callback.
"""
for i in xrange(self.iterations * 10):
load_privatekey(
FILETYPE_PEM, self.ENCRYPTED_PEM, lambda *args: "hello, secret") |
Call the function with an encrypted PEM and a passphrase callback which returns the wrong passphrase. | def check_load_privatekey_callback_incorrect(self):
"""
Call the function with an encrypted PEM and a passphrase callback which
returns the wrong passphrase.
"""
for i in xrange(self.iterations * 10):
try:
load_privatekey(
FILETYPE_... |
Call the function with an encrypted PEM and a passphrase callback which returns a non - string. | def check_load_privatekey_callback_wrong_type(self):
"""
Call the function with an encrypted PEM and a passphrase callback which
returns a non-string.
"""
for i in xrange(self.iterations * 10):
try:
load_privatekey(
FILETYPE_PEM, se... |
Create a CRL object with 100 Revoked objects then call the get_revoked method repeatedly. | def check_get_revoked(self):
"""
Create a CRL object with 100 Revoked objects, then call the
get_revoked method repeatedly.
"""
crl = CRL()
for i in xrange(100):
crl.add_revoked(Revoked())
for i in xrange(self.iterations):
crl.get_revoked() |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.