Search is not available for this dataset
identifier
stringlengths
1
155
parameters
stringlengths
2
6.09k
docstring
stringlengths
11
63.4k
docstring_summary
stringlengths
0
63.4k
function
stringlengths
29
99.8k
function_tokens
list
start_point
list
end_point
list
language
stringclasses
1 value
docstring_language
stringlengths
2
7
docstring_language_predictions
stringlengths
18
23
is_langid_reliable
stringclasses
2 values
Storage.get
(self)
Retrieve credential. The Storage lock must *not* be held when this is called. Returns: oauth2client.client.Credentials
Retrieve credential.
def get(self): """Retrieve credential. The Storage lock must *not* be held when this is called. Returns: oauth2client.client.Credentials """ self.acquire_lock() try: return self.locked_get() finally: self.release_lock()
[ "def", "get", "(", "self", ")", ":", "self", ".", "acquire_lock", "(", ")", "try", ":", "return", "self", ".", "locked_get", "(", ")", "finally", ":", "self", ".", "release_lock", "(", ")" ]
[ 396, 4 ]
[ 408, 31 ]
python
en
['en', 'pt', 'en']
False
Storage.put
(self, credentials)
Write a credential. The Storage lock must be held when this is called. Args: credentials: Credentials, the credentials to store.
Write a credential.
def put(self, credentials): """Write a credential. The Storage lock must be held when this is called. Args: credentials: Credentials, the credentials to store. """ self.acquire_lock() try: self.locked_put(credentials) finally: ...
[ "def", "put", "(", "self", ",", "credentials", ")", ":", "self", ".", "acquire_lock", "(", ")", "try", ":", "self", ".", "locked_put", "(", "credentials", ")", "finally", ":", "self", ".", "release_lock", "(", ")" ]
[ 410, 4 ]
[ 422, 31 ]
python
en
['es', 'pt', 'en']
False
Storage.delete
(self)
Delete credential. Frees any resources associated with storing the credential. The Storage lock must *not* be held when this is called. Returns: None
Delete credential.
def delete(self): """Delete credential. Frees any resources associated with storing the credential. The Storage lock must *not* be held when this is called. Returns: None """ self.acquire_lock() try: return self.locked_delete() fi...
[ "def", "delete", "(", "self", ")", ":", "self", ".", "acquire_lock", "(", ")", "try", ":", "return", "self", ".", "locked_delete", "(", ")", "finally", ":", "self", ".", "release_lock", "(", ")" ]
[ 424, 4 ]
[ 437, 31 ]
python
en
['en', 'la', 'en']
False
OAuth2Credentials.__init__
(self, access_token, client_id, client_secret, refresh_token, token_expiry, token_uri, user_agent, revoke_uri=None, id_token=None, token_response=None, scopes=None, token_info_uri=None, id_token_jwt=None)
Create an instance of OAuth2Credentials. This constructor is not usually called by the user, instead OAuth2Credentials objects are instantiated by the OAuth2WebServerFlow. Args: access_token: string, access token. client_id: string, client identifier. client...
Create an instance of OAuth2Credentials.
def __init__(self, access_token, client_id, client_secret, refresh_token, token_expiry, token_uri, user_agent, revoke_uri=None, id_token=None, token_response=None, scopes=None, token_info_uri=None, id_token_jwt=None): """Create an instance of OAuth2Credentials....
[ "def", "__init__", "(", "self", ",", "access_token", ",", "client_id", ",", "client_secret", ",", "refresh_token", ",", "token_expiry", ",", "token_uri", ",", "user_agent", ",", "revoke_uri", "=", "None", ",", "id_token", "=", "None", ",", "token_response", "=...
[ 450, 4 ]
[ 505, 28 ]
python
en
['en', 'en', 'en']
True
OAuth2Credentials.authorize
(self, http)
Authorize an httplib2.Http instance with these credentials. The modified http.request method will add authentication headers to each request and will refresh access_tokens when a 401 is received on a request. In addition the http.request method has a credentials property, http.request.c...
Authorize an httplib2.Http instance with these credentials.
def authorize(self, http): """Authorize an httplib2.Http instance with these credentials. The modified http.request method will add authentication headers to each request and will refresh access_tokens when a 401 is received on a request. In addition the http.request method has a creden...
[ "def", "authorize", "(", "self", ",", "http", ")", ":", "transport", ".", "wrap_http_for_auth", "(", "self", ",", "http", ")", "return", "http" ]
[ 507, 4 ]
[ 535, 19 ]
python
en
['en', 'en', 'en']
True
OAuth2Credentials.refresh
(self, http)
Forces a refresh of the access_token. Args: http: httplib2.Http, an http object to be used to make the refresh request.
Forces a refresh of the access_token.
def refresh(self, http): """Forces a refresh of the access_token. Args: http: httplib2.Http, an http object to be used to make the refresh request. """ self._refresh(http)
[ "def", "refresh", "(", "self", ",", "http", ")", ":", "self", ".", "_refresh", "(", "http", ")" ]
[ 537, 4 ]
[ 544, 27 ]
python
en
['en', 'en', 'en']
True
OAuth2Credentials.revoke
(self, http)
Revokes a refresh_token and makes the credentials void. Args: http: httplib2.Http, an http object to be used to make the revoke request.
Revokes a refresh_token and makes the credentials void.
def revoke(self, http): """Revokes a refresh_token and makes the credentials void. Args: http: httplib2.Http, an http object to be used to make the revoke request. """ self._revoke(http)
[ "def", "revoke", "(", "self", ",", "http", ")", ":", "self", ".", "_revoke", "(", "http", ")" ]
[ 546, 4 ]
[ 553, 26 ]
python
en
['en', 'en', 'en']
True
OAuth2Credentials.apply
(self, headers)
Add the authorization to the headers. Args: headers: dict, the headers to add the Authorization header to.
Add the authorization to the headers.
def apply(self, headers): """Add the authorization to the headers. Args: headers: dict, the headers to add the Authorization header to. """ headers['Authorization'] = 'Bearer ' + self.access_token
[ "def", "apply", "(", "self", ",", "headers", ")", ":", "headers", "[", "'Authorization'", "]", "=", "'Bearer '", "+", "self", ".", "access_token" ]
[ 555, 4 ]
[ 561, 64 ]
python
en
['en', 'en', 'en']
True
OAuth2Credentials.has_scopes
(self, scopes)
Verify that the credentials are authorized for the given scopes. Returns True if the credentials authorized scopes contain all of the scopes given. Args: scopes: list or string, the scopes to check. Notes: There are cases where the credentials are unaware of wh...
Verify that the credentials are authorized for the given scopes.
def has_scopes(self, scopes): """Verify that the credentials are authorized for the given scopes. Returns True if the credentials authorized scopes contain all of the scopes given. Args: scopes: list or string, the scopes to check. Notes: There are case...
[ "def", "has_scopes", "(", "self", ",", "scopes", ")", ":", "scopes", "=", "_helpers", ".", "string_to_scopes", "(", "scopes", ")", "return", "set", "(", "scopes", ")", ".", "issubset", "(", "self", ".", "scopes", ")" ]
[ 563, 4 ]
[ 580, 48 ]
python
en
['en', 'en', 'en']
True
OAuth2Credentials.retrieve_scopes
(self, http)
Retrieves the canonical list of scopes for this access token. Gets the scopes from the OAuth2 provider. Args: http: httplib2.Http, an http object to be used to make the refresh request. Returns: A set of strings containing the canonical list of scopes...
Retrieves the canonical list of scopes for this access token.
def retrieve_scopes(self, http): """Retrieves the canonical list of scopes for this access token. Gets the scopes from the OAuth2 provider. Args: http: httplib2.Http, an http object to be used to make the refresh request. Returns: A set of str...
[ "def", "retrieve_scopes", "(", "self", ",", "http", ")", ":", "self", ".", "_retrieve_scopes", "(", "http", ")", "return", "self", ".", "scopes" ]
[ 582, 4 ]
[ 595, 26 ]
python
en
['en', 'en', 'en']
True
OAuth2Credentials.from_json
(cls, json_data)
Instantiate a Credentials object from a JSON description of it. The JSON should have been produced by calling .to_json() on the object. Args: json_data: string or bytes, JSON to deserialize. Returns: An instance of a Credentials subclass.
Instantiate a Credentials object from a JSON description of it.
def from_json(cls, json_data): """Instantiate a Credentials object from a JSON description of it. The JSON should have been produced by calling .to_json() on the object. Args: json_data: string or bytes, JSON to deserialize. Returns: An instance of a Credential...
[ "def", "from_json", "(", "cls", ",", "json_data", ")", ":", "data", "=", "json", ".", "loads", "(", "_helpers", ".", "_from_bytes", "(", "json_data", ")", ")", "if", "(", "data", ".", "get", "(", "'token_expiry'", ")", "and", "not", "isinstance", "(", ...
[ 598, 4 ]
[ 632, 21 ]
python
en
['en', 'en', 'en']
True
OAuth2Credentials.access_token_expired
(self)
True if the credential is expired or invalid. If the token_expiry isn't set, we assume the token doesn't expire.
True if the credential is expired or invalid.
def access_token_expired(self): """True if the credential is expired or invalid. If the token_expiry isn't set, we assume the token doesn't expire. """ if self.invalid: return True if not self.token_expiry: return False now = _UTCNOW() i...
[ "def", "access_token_expired", "(", "self", ")", ":", "if", "self", ".", "invalid", ":", "return", "True", "if", "not", "self", ".", "token_expiry", ":", "return", "False", "now", "=", "_UTCNOW", "(", ")", "if", "now", ">=", "self", ".", "token_expiry", ...
[ 635, 4 ]
[ 651, 20 ]
python
en
['en', 'en', 'en']
True
OAuth2Credentials.get_access_token
(self, http=None)
Return the access token and its expiration information. If the token does not exist, get one. If the token expired, refresh it.
Return the access token and its expiration information.
def get_access_token(self, http=None): """Return the access token and its expiration information. If the token does not exist, get one. If the token expired, refresh it. """ if not self.access_token or self.access_token_expired: if not http: http = tr...
[ "def", "get_access_token", "(", "self", ",", "http", "=", "None", ")", ":", "if", "not", "self", ".", "access_token", "or", "self", ".", "access_token_expired", ":", "if", "not", "http", ":", "http", "=", "transport", ".", "get_http_object", "(", ")", "s...
[ 653, 4 ]
[ 664, 61 ]
python
en
['en', 'en', 'en']
True
OAuth2Credentials.set_store
(self, store)
Set the Storage for the credential. Args: store: Storage, an implementation of Storage object. This is needed to store the latest access_token if it has expired and been refreshed. This implementation uses locking to check for updates before ...
Set the Storage for the credential.
def set_store(self, store): """Set the Storage for the credential. Args: store: Storage, an implementation of Storage object. This is needed to store the latest access_token if it has expired and been refreshed. This implementation uses ...
[ "def", "set_store", "(", "self", ",", "store", ")", ":", "self", ".", "store", "=", "store" ]
[ 666, 4 ]
[ 676, 26 ]
python
en
['en', 'en', 'en']
True
OAuth2Credentials._expires_in
(self)
Return the number of seconds until this token expires. If token_expiry is in the past, this method will return 0, meaning the token has already expired. If token_expiry is None, this method will return None. Note that returning 0 in such a case would not be fair: the token may still be...
Return the number of seconds until this token expires.
def _expires_in(self): """Return the number of seconds until this token expires. If token_expiry is in the past, this method will return 0, meaning the token has already expired. If token_expiry is None, this method will return None. Note that returning 0 in such a case would n...
[ "def", "_expires_in", "(", "self", ")", ":", "if", "self", ".", "token_expiry", ":", "now", "=", "_UTCNOW", "(", ")", "if", "self", ".", "token_expiry", ">", "now", ":", "time_delta", "=", "self", ".", "token_expiry", "-", "now", "# TODO(orestica): return ...
[ 678, 4 ]
[ 696, 24 ]
python
en
['en', 'en', 'en']
True
OAuth2Credentials._updateFromCredential
(self, other)
Update this Credential from another instance.
Update this Credential from another instance.
def _updateFromCredential(self, other): """Update this Credential from another instance.""" self.__dict__.update(other.__getstate__())
[ "def", "_updateFromCredential", "(", "self", ",", "other", ")", ":", "self", ".", "__dict__", ".", "update", "(", "other", ".", "__getstate__", "(", ")", ")" ]
[ 698, 4 ]
[ 700, 50 ]
python
en
['en', 'en', 'en']
True
OAuth2Credentials.__getstate__
(self)
Trim the state down to something that can be pickled.
Trim the state down to something that can be pickled.
def __getstate__(self): """Trim the state down to something that can be pickled.""" d = copy.copy(self.__dict__) del d['store'] return d
[ "def", "__getstate__", "(", "self", ")", ":", "d", "=", "copy", ".", "copy", "(", "self", ".", "__dict__", ")", "del", "d", "[", "'store'", "]", "return", "d" ]
[ 702, 4 ]
[ 706, 16 ]
python
en
['en', 'en', 'en']
True
OAuth2Credentials.__setstate__
(self, state)
Reconstitute the state of the object from being pickled.
Reconstitute the state of the object from being pickled.
def __setstate__(self, state): """Reconstitute the state of the object from being pickled.""" self.__dict__.update(state) self.store = None
[ "def", "__setstate__", "(", "self", ",", "state", ")", ":", "self", ".", "__dict__", ".", "update", "(", "state", ")", "self", ".", "store", "=", "None" ]
[ 708, 4 ]
[ 711, 25 ]
python
en
['en', 'en', 'en']
True
OAuth2Credentials._generate_refresh_request_body
(self)
Generate the body that will be used in the refresh request.
Generate the body that will be used in the refresh request.
def _generate_refresh_request_body(self): """Generate the body that will be used in the refresh request.""" body = urllib.parse.urlencode({ 'grant_type': 'refresh_token', 'client_id': self.client_id, 'client_secret': self.client_secret, 'refresh_token': se...
[ "def", "_generate_refresh_request_body", "(", "self", ")", ":", "body", "=", "urllib", ".", "parse", ".", "urlencode", "(", "{", "'grant_type'", ":", "'refresh_token'", ",", "'client_id'", ":", "self", ".", "client_id", ",", "'client_secret'", ":", "self", "."...
[ 713, 4 ]
[ 721, 19 ]
python
en
['en', 'en', 'en']
True
OAuth2Credentials._generate_refresh_request_headers
(self)
Generate the headers that will be used in the refresh request.
Generate the headers that will be used in the refresh request.
def _generate_refresh_request_headers(self): """Generate the headers that will be used in the refresh request.""" headers = { 'content-type': 'application/x-www-form-urlencoded', } if self.user_agent is not None: headers['user-agent'] = self.user_agent r...
[ "def", "_generate_refresh_request_headers", "(", "self", ")", ":", "headers", "=", "{", "'content-type'", ":", "'application/x-www-form-urlencoded'", ",", "}", "if", "self", ".", "user_agent", "is", "not", "None", ":", "headers", "[", "'user-agent'", "]", "=", "...
[ 723, 4 ]
[ 732, 22 ]
python
en
['en', 'en', 'en']
True
OAuth2Credentials._refresh
(self, http)
Refreshes the access_token. This method first checks by reading the Storage object if available. If a refresh is still needed, it holds the Storage lock until the refresh is completed. Args: http: an object to be used to make HTTP requests. Raises: Http...
Refreshes the access_token.
def _refresh(self, http): """Refreshes the access_token. This method first checks by reading the Storage object if available. If a refresh is still needed, it holds the Storage lock until the refresh is completed. Args: http: an object to be used to make HTTP reques...
[ "def", "_refresh", "(", "self", ",", "http", ")", ":", "if", "not", "self", ".", "store", ":", "self", ".", "_do_refresh_request", "(", "http", ")", "else", ":", "self", ".", "store", ".", "acquire_lock", "(", ")", "try", ":", "new_cred", "=", "self"...
[ 734, 4 ]
[ 762, 41 ]
python
en
['en', 'en', 'en']
True
OAuth2Credentials._do_refresh_request
(self, http)
Refresh the access_token using the refresh_token. Args: http: an object to be used to make HTTP requests. Raises: HttpAccessTokenRefreshError: When the refresh fails.
Refresh the access_token using the refresh_token.
def _do_refresh_request(self, http): """Refresh the access_token using the refresh_token. Args: http: an object to be used to make HTTP requests. Raises: HttpAccessTokenRefreshError: When the refresh fails. """ body = self._generate_refresh_request_body(...
[ "def", "_do_refresh_request", "(", "self", ",", "http", ")", ":", "body", "=", "self", ".", "_generate_refresh_request_body", "(", ")", "headers", "=", "self", ".", "_generate_refresh_request_headers", "(", ")", "logger", ".", "info", "(", "'Refreshing access_toke...
[ 764, 4 ]
[ 818, 76 ]
python
en
['en', 'gl', 'en']
True
OAuth2Credentials._revoke
(self, http)
Revokes this credential and deletes the stored copy (if it exists). Args: http: an object to be used to make HTTP requests.
Revokes this credential and deletes the stored copy (if it exists).
def _revoke(self, http): """Revokes this credential and deletes the stored copy (if it exists). Args: http: an object to be used to make HTTP requests. """ self._do_revoke(http, self.refresh_token or self.access_token)
[ "def", "_revoke", "(", "self", ",", "http", ")", ":", "self", ".", "_do_revoke", "(", "http", ",", "self", ".", "refresh_token", "or", "self", ".", "access_token", ")" ]
[ 820, 4 ]
[ 826, 70 ]
python
en
['en', 'en', 'en']
True
OAuth2Credentials._do_revoke
(self, http, token)
Revokes this credential and deletes the stored copy (if it exists). Args: http: an object to be used to make HTTP requests. token: A string used as the token to be revoked. Can be either an access_token or refresh_token. Raises: TokenRevokeError: ...
Revokes this credential and deletes the stored copy (if it exists).
def _do_revoke(self, http, token): """Revokes this credential and deletes the stored copy (if it exists). Args: http: an object to be used to make HTTP requests. token: A string used as the token to be revoked. Can be either an access_token or refresh_token. ...
[ "def", "_do_revoke", "(", "self", ",", "http", ",", "token", ")", ":", "logger", ".", "info", "(", "'Revoking token'", ")", "query_params", "=", "{", "'token'", ":", "token", "}", "token_revoke_uri", "=", "_helpers", ".", "update_query_params", "(", "self", ...
[ 828, 4 ]
[ 862, 31 ]
python
en
['en', 'en', 'en']
True
OAuth2Credentials._retrieve_scopes
(self, http)
Retrieves the list of authorized scopes from the OAuth2 provider. Args: http: an object to be used to make HTTP requests.
Retrieves the list of authorized scopes from the OAuth2 provider.
def _retrieve_scopes(self, http): """Retrieves the list of authorized scopes from the OAuth2 provider. Args: http: an object to be used to make HTTP requests. """ self._do_retrieve_scopes(http, self.access_token)
[ "def", "_retrieve_scopes", "(", "self", ",", "http", ")", ":", "self", ".", "_do_retrieve_scopes", "(", "http", ",", "self", ".", "access_token", ")" ]
[ 864, 4 ]
[ 870, 57 ]
python
en
['en', 'en', 'en']
True
OAuth2Credentials._do_retrieve_scopes
(self, http, token)
Retrieves the list of authorized scopes from the OAuth2 provider. Args: http: an object to be used to make HTTP requests. token: A string used as the token to identify the credentials to the provider. Raises: Error: When refresh fails, indicating ...
Retrieves the list of authorized scopes from the OAuth2 provider.
def _do_retrieve_scopes(self, http, token): """Retrieves the list of authorized scopes from the OAuth2 provider. Args: http: an object to be used to make HTTP requests. token: A string used as the token to identify the credentials to the provider. Rai...
[ "def", "_do_retrieve_scopes", "(", "self", ",", "http", ",", "token", ")", ":", "logger", ".", "info", "(", "'Refreshing scopes'", ")", "query_params", "=", "{", "'access_token'", ":", "token", ",", "'fields'", ":", "'scope'", "}", "token_info_uri", "=", "_h...
[ 872, 4 ]
[ 901, 34 ]
python
en
['en', 'en', 'en']
True
AccessTokenCredentials.__init__
(self, access_token, user_agent, revoke_uri=None)
Create an instance of OAuth2Credentials This is one of the few types if Credentials that you should contrust, Credentials objects are usually instantiated by a Flow. Args: access_token: string, access token. user_agent: string, The HTTP User-Agent to provide for this ...
Create an instance of OAuth2Credentials
def __init__(self, access_token, user_agent, revoke_uri=None): """Create an instance of OAuth2Credentials This is one of the few types if Credentials that you should contrust, Credentials objects are usually instantiated by a Flow. Args: access_token: string, access token. ...
[ "def", "__init__", "(", "self", ",", "access_token", ",", "user_agent", ",", "revoke_uri", "=", "None", ")", ":", "super", "(", "AccessTokenCredentials", ",", "self", ")", ".", "__init__", "(", "access_token", ",", "None", ",", "None", ",", "None", ",", ...
[ 930, 4 ]
[ 951, 34 ]
python
en
['en', 'en', 'en']
True
AccessTokenCredentials._refresh
(self, http)
Refreshes the access token. Args: http: unused HTTP object. Raises: AccessTokenCredentialsError: always
Refreshes the access token.
def _refresh(self, http): """Refreshes the access token. Args: http: unused HTTP object. Raises: AccessTokenCredentialsError: always """ raise AccessTokenCredentialsError( 'The access_token is expired or invalid and can\'t be refreshed.')
[ "def", "_refresh", "(", "self", ",", "http", ")", ":", "raise", "AccessTokenCredentialsError", "(", "'The access_token is expired or invalid and can\\'t be refreshed.'", ")" ]
[ 961, 4 ]
[ 971, 78 ]
python
en
['en', 'en', 'en']
True
AccessTokenCredentials._revoke
(self, http)
Revokes the access_token and deletes the store if available. Args: http: an object to be used to make HTTP requests.
Revokes the access_token and deletes the store if available.
def _revoke(self, http): """Revokes the access_token and deletes the store if available. Args: http: an object to be used to make HTTP requests. """ self._do_revoke(http, self.access_token)
[ "def", "_revoke", "(", "self", ",", "http", ")", ":", "self", ".", "_do_revoke", "(", "http", ",", "self", ".", "access_token", ")" ]
[ 973, 4 ]
[ 979, 48 ]
python
en
['en', 'en', 'en']
True
GoogleCredentials.__init__
(self, access_token, client_id, client_secret, refresh_token, token_expiry, token_uri, user_agent, revoke_uri=oauth2client.GOOGLE_REVOKE_URI)
Create an instance of GoogleCredentials. This constructor is not usually called by the user, instead GoogleCredentials objects are instantiated by GoogleCredentials.from_stream() or GoogleCredentials.get_application_default(). Args: access_token: string, access toke...
Create an instance of GoogleCredentials.
def __init__(self, access_token, client_id, client_secret, refresh_token, token_expiry, token_uri, user_agent, revoke_uri=oauth2client.GOOGLE_REVOKE_URI): """Create an instance of GoogleCredentials. This constructor is not usually called by the user, instead Go...
[ "def", "__init__", "(", "self", ",", "access_token", ",", "client_id", ",", "client_secret", ",", "refresh_token", ",", "token_expiry", ",", "token_uri", ",", "user_agent", ",", "revoke_uri", "=", "oauth2client", ".", "GOOGLE_REVOKE_URI", ")", ":", "super", "(",...
[ 1077, 4 ]
[ 1102, 71 ]
python
en
['en', 'de', 'en']
True
GoogleCredentials.create_scoped_required
(self)
Whether this Credentials object is scopeless. create_scoped(scopes) method needs to be called in order to create a Credentials object for API calls.
Whether this Credentials object is scopeless.
def create_scoped_required(self): """Whether this Credentials object is scopeless. create_scoped(scopes) method needs to be called in order to create a Credentials object for API calls. """ return False
[ "def", "create_scoped_required", "(", "self", ")", ":", "return", "False" ]
[ 1104, 4 ]
[ 1110, 20 ]
python
en
['en', 'en', 'en']
True
GoogleCredentials.create_scoped
(self, scopes)
Create a Credentials object for the given scopes. The Credentials type is preserved.
Create a Credentials object for the given scopes.
def create_scoped(self, scopes): """Create a Credentials object for the given scopes. The Credentials type is preserved. """ return self
[ "def", "create_scoped", "(", "self", ",", "scopes", ")", ":", "return", "self" ]
[ 1112, 4 ]
[ 1117, 19 ]
python
en
['en', 'en', 'en']
True
GoogleCredentials.serialization_data
(self)
Get the fields and values identifying the current credentials.
Get the fields and values identifying the current credentials.
def serialization_data(self): """Get the fields and values identifying the current credentials.""" return { 'type': 'authorized_user', 'client_id': self.client_id, 'client_secret': self.client_secret, 'refresh_token': self.refresh_token }
[ "def", "serialization_data", "(", "self", ")", ":", "return", "{", "'type'", ":", "'authorized_user'", ",", "'client_id'", ":", "self", ".", "client_id", ",", "'client_secret'", ":", "self", ".", "client_secret", ",", "'refresh_token'", ":", "self", ".", "refr...
[ 1149, 4 ]
[ 1156, 9 ]
python
en
['en', 'en', 'en']
True
GoogleCredentials._implicit_credentials_from_gae
()
Attempts to get implicit credentials in Google App Engine env. If the current environment is not detected as App Engine, returns None, indicating no Google App Engine credentials can be detected from the current environment. Returns: None, if not in GAE, else an appengine.A...
Attempts to get implicit credentials in Google App Engine env.
def _implicit_credentials_from_gae(): """Attempts to get implicit credentials in Google App Engine env. If the current environment is not detected as App Engine, returns None, indicating no Google App Engine credentials can be detected from the current environment. Returns: ...
[ "def", "_implicit_credentials_from_gae", "(", ")", ":", "if", "not", "_in_gae_environment", "(", ")", ":", "return", "None", "return", "_get_application_default_credential_GAE", "(", ")" ]
[ 1159, 4 ]
[ 1173, 56 ]
python
en
['en', 'en', 'en']
True
GoogleCredentials._implicit_credentials_from_gce
()
Attempts to get implicit credentials in Google Compute Engine env. If the current environment is not detected as Compute Engine, returns None, indicating no Google Compute Engine credentials can be detected from the current environment. Returns: None, if not in GCE, else a ...
Attempts to get implicit credentials in Google Compute Engine env.
def _implicit_credentials_from_gce(): """Attempts to get implicit credentials in Google Compute Engine env. If the current environment is not detected as Compute Engine, returns None, indicating no Google Compute Engine credentials can be detected from the current environment. ...
[ "def", "_implicit_credentials_from_gce", "(", ")", ":", "if", "not", "_in_gce_environment", "(", ")", ":", "return", "None", "return", "_get_application_default_credential_GCE", "(", ")" ]
[ 1176, 4 ]
[ 1189, 56 ]
python
en
['en', 'en', 'en']
True
GoogleCredentials._implicit_credentials_from_files
()
Attempts to get implicit credentials from local credential files. First checks if the environment variable GOOGLE_APPLICATION_CREDENTIALS is set with a filename and then falls back to a configuration file (the "well known" file) associated with the 'gcloud' command line tool. Returns: ...
Attempts to get implicit credentials from local credential files.
def _implicit_credentials_from_files(): """Attempts to get implicit credentials from local credential files. First checks if the environment variable GOOGLE_APPLICATION_CREDENTIALS is set with a filename and then falls back to a configuration file (the "well known" file) associated with...
[ "def", "_implicit_credentials_from_files", "(", ")", ":", "credentials_filename", "=", "_get_environment_variable_file", "(", ")", "if", "not", "credentials_filename", ":", "credentials_filename", "=", "_get_well_known_file", "(", ")", "if", "os", ".", "path", ".", "i...
[ 1192, 4 ]
[ 1230, 64 ]
python
en
['en', 'en', 'en']
True
GoogleCredentials._get_implicit_credentials
(cls)
Gets credentials implicitly from the environment. Checks environment in order of precedence: - Environment variable GOOGLE_APPLICATION_CREDENTIALS pointing to a file with stored credentials information. - Stored "well known" file associated with `gcloud` command line tool. - G...
Gets credentials implicitly from the environment.
def _get_implicit_credentials(cls): """Gets credentials implicitly from the environment. Checks environment in order of precedence: - Environment variable GOOGLE_APPLICATION_CREDENTIALS pointing to a file with stored credentials information. - Stored "well known" file associat...
[ "def", "_get_implicit_credentials", "(", "cls", ")", ":", "# Environ checks (in order).", "environ_checkers", "=", "[", "cls", ".", "_implicit_credentials_from_files", ",", "cls", ".", "_implicit_credentials_from_gae", ",", "cls", ".", "_implicit_credentials_from_gce", ",",...
[ 1233, 4 ]
[ 1260, 62 ]
python
en
['en', 'en', 'en']
True
GoogleCredentials.get_application_default
()
Get the Application Default Credentials for the current environment. Raises: ApplicationDefaultCredentialsError: raised when the credentials fail to be retrieved.
Get the Application Default Credentials for the current environment.
def get_application_default(): """Get the Application Default Credentials for the current environment. Raises: ApplicationDefaultCredentialsError: raised when the credentials fail to be retrieved. """ return GoogleCredentials._...
[ "def", "get_application_default", "(", ")", ":", "return", "GoogleCredentials", ".", "_get_implicit_credentials", "(", ")" ]
[ 1263, 4 ]
[ 1270, 60 ]
python
en
['en', 'en', 'en']
True
GoogleCredentials.from_stream
(credential_filename)
Create a Credentials object by reading information from a file. It returns an object of type GoogleCredentials. Args: credential_filename: the path to the file from where the credentials are to be read Raises: ApplicationDefaultCredenti...
Create a Credentials object by reading information from a file.
def from_stream(credential_filename): """Create a Credentials object by reading information from a file. It returns an object of type GoogleCredentials. Args: credential_filename: the path to the file from where the credentials are to be read ...
[ "def", "from_stream", "(", "credential_filename", ")", ":", "if", "credential_filename", "and", "os", ".", "path", ".", "isfile", "(", "credential_filename", ")", ":", "try", ":", "return", "_get_application_default_credential_from_file", "(", "credential_filename", "...
[ 1273, 4 ]
[ 1299, 49 ]
python
en
['en', 'en', 'en']
True
AssertionCredentials.__init__
(self, assertion_type, user_agent=None, token_uri=oauth2client.GOOGLE_TOKEN_URI, revoke_uri=oauth2client.GOOGLE_REVOKE_URI, **unused_kwargs)
Constructor for AssertionFlowCredentials. Args: assertion_type: string, assertion type that will be declared to the auth server user_agent: string, The HTTP User-Agent to provide for this application. token_uri: string, URI...
Constructor for AssertionFlowCredentials.
def __init__(self, assertion_type, user_agent=None, token_uri=oauth2client.GOOGLE_TOKEN_URI, revoke_uri=oauth2client.GOOGLE_REVOKE_URI, **unused_kwargs): """Constructor for AssertionFlowCredentials. Args: assertion_type: string, assertion t...
[ "def", "__init__", "(", "self", ",", "assertion_type", ",", "user_agent", "=", "None", ",", "token_uri", "=", "oauth2client", ".", "GOOGLE_TOKEN_URI", ",", "revoke_uri", "=", "oauth2client", ".", "GOOGLE_REVOKE_URI", ",", "*", "*", "unused_kwargs", ")", ":", "...
[ 1455, 4 ]
[ 1480, 44 ]
python
en
['da', 'en', 'en']
True
AssertionCredentials._generate_assertion
(self)
Generate assertion string to be used in the access token request.
Generate assertion string to be used in the access token request.
def _generate_assertion(self): """Generate assertion string to be used in the access token request.""" raise NotImplementedError
[ "def", "_generate_assertion", "(", "self", ")", ":", "raise", "NotImplementedError" ]
[ 1492, 4 ]
[ 1494, 33 ]
python
en
['en', 'en', 'en']
True
AssertionCredentials._revoke
(self, http)
Revokes the access_token and deletes the store if available. Args: http: an object to be used to make HTTP requests.
Revokes the access_token and deletes the store if available.
def _revoke(self, http): """Revokes the access_token and deletes the store if available. Args: http: an object to be used to make HTTP requests. """ self._do_revoke(http, self.access_token)
[ "def", "_revoke", "(", "self", ",", "http", ")", ":", "self", ".", "_do_revoke", "(", "http", ",", "self", ".", "access_token", ")" ]
[ 1496, 4 ]
[ 1502, 48 ]
python
en
['en', 'en', 'en']
True
AssertionCredentials.sign_blob
(self, blob)
Cryptographically sign a blob (of bytes). Args: blob: bytes, Message to be signed. Returns: tuple, A pair of the private key ID used to sign the blob and the signed contents.
Cryptographically sign a blob (of bytes).
def sign_blob(self, blob): """Cryptographically sign a blob (of bytes). Args: blob: bytes, Message to be signed. Returns: tuple, A pair of the private key ID used to sign the blob and the signed contents. """ raise NotImplementedError('This m...
[ "def", "sign_blob", "(", "self", ",", "blob", ")", ":", "raise", "NotImplementedError", "(", "'This method is abstract.'", ")" ]
[ 1504, 4 ]
[ 1514, 61 ]
python
en
['en', 'en', 'en']
True
DeviceFlowInfo.FromResponse
(cls, response)
Create a DeviceFlowInfo from a server response. The response should be a dict containing entries as described here: http://tools.ietf.org/html/draft-ietf-oauth-v2-05#section-3.7.1
Create a DeviceFlowInfo from a server response.
def FromResponse(cls, response): """Create a DeviceFlowInfo from a server response. The response should be a dict containing entries as described here: http://tools.ietf.org/html/draft-ietf-oauth-v2-05#section-3.7.1 """ # device_code, user_code, and verification_url are require...
[ "def", "FromResponse", "(", "cls", ",", "response", ")", ":", "# device_code, user_code, and verification_url are required.", "kwargs", "=", "{", "'device_code'", ":", "response", "[", "'device_code'", "]", ",", "'user_code'", ":", "response", "[", "'user_code'", "]",...
[ 1745, 4 ]
[ 1774, 28 ]
python
en
['en', 'en', 'en']
True
OAuth2WebServerFlow.__init__
(self, client_id, client_secret=None, scope=None, redirect_uri=None, user_agent=None, auth_uri=oauth2client.GOOGLE_AUTH_URI, token_uri=oauth2client.GOOGLE_TOKEN_URI, revoke_uri=oauth2client.GOOGLE_REVO...
Constructor for OAuth2WebServerFlow. The kwargs argument is used to set extra query parameters on the auth_uri. For example, the access_type and prompt query parameters can be set via kwargs. Args: client_id: string, client identifier. client_secret: string clie...
Constructor for OAuth2WebServerFlow.
def __init__(self, client_id, client_secret=None, scope=None, redirect_uri=None, user_agent=None, auth_uri=oauth2client.GOOGLE_AUTH_URI, token_uri=oauth2client.GOOGLE_TOKEN_URI, revoke_uri=oauth2client...
[ "def", "__init__", "(", "self", ",", "client_id", ",", "client_secret", "=", "None", ",", "scope", "=", "None", ",", "redirect_uri", "=", "None", ",", "user_agent", "=", "None", ",", "auth_uri", "=", "oauth2client", ".", "GOOGLE_AUTH_URI", ",", "token_uri", ...
[ 1811, 4 ]
[ 1892, 60 ]
python
en
['da', 'en', 'en']
True
OAuth2WebServerFlow.step1_get_authorize_url
(self, redirect_uri=None, state=None)
Returns a URI to redirect to the provider. Args: redirect_uri: string, Either the string 'urn:ietf:wg:oauth:2.0:oob' for a non-web-based application, or a URI that handles the callback from the authorization server. This ...
Returns a URI to redirect to the provider.
def step1_get_authorize_url(self, redirect_uri=None, state=None): """Returns a URI to redirect to the provider. Args: redirect_uri: string, Either the string 'urn:ietf:wg:oauth:2.0:oob' for a non-web-based application, or a URI that handle...
[ "def", "step1_get_authorize_url", "(", "self", ",", "redirect_uri", "=", "None", ",", "state", "=", "None", ")", ":", "if", "redirect_uri", "is", "not", "None", ":", "logger", ".", "warning", "(", "(", "'The redirect_uri parameter for '", "'OAuth2WebServerFlow.ste...
[ 1895, 4 ]
[ 1940, 72 ]
python
en
['en', 'en', 'en']
True
OAuth2WebServerFlow.step1_get_device_and_user_codes
(self, http=None)
Returns a user code and the verification URL where to enter it Returns: A user code as a string for the user to authorize the application An URL as a string where the user has to enter the code
Returns a user code and the verification URL where to enter it
def step1_get_device_and_user_codes(self, http=None): """Returns a user code and the verification URL where to enter it Returns: A user code as a string for the user to authorize the application An URL as a string where the user has to enter the code """ if self....
[ "def", "step1_get_device_and_user_codes", "(", "self", ",", "http", "=", "None", ")", ":", "if", "self", ".", "device_uri", "is", "None", ":", "raise", "ValueError", "(", "'The value of device_uri must not be None.'", ")", "body", "=", "urllib", ".", "parse", "....
[ 1943, 4 ]
[ 1988, 50 ]
python
en
['en', 'en', 'en']
True
OAuth2WebServerFlow.step2_exchange
(self, code=None, http=None, device_flow_info=None)
Exchanges a code for OAuth2Credentials. Args: code: string, a dict-like object, or None. For a non-device flow, this is either the response code as a string, or a dictionary of query parameters to the redirect_uri. For a device flow, this should...
Exchanges a code for OAuth2Credentials.
def step2_exchange(self, code=None, http=None, device_flow_info=None): """Exchanges a code for OAuth2Credentials. Args: code: string, a dict-like object, or None. For a non-device flow, this is either the response code as a string, or a dictionary of quer...
[ "def", "step2_exchange", "(", "self", ",", "code", "=", "None", ",", "http", "=", "None", ",", "device_flow_info", "=", "None", ")", ":", "if", "code", "is", "None", "and", "device_flow_info", "is", "None", ":", "raise", "ValueError", "(", "'No code or dev...
[ 1991, 4 ]
[ 2088, 46 ]
python
en
['en', 'en', 'en']
True
parse_html
(html)
Take a string that contains HTML and turn it into a Python object structure that can be easily compared against other HTML on semantic equivalence. Syntactical differences like which quotation is used on arguments will be ignored.
Take a string that contains HTML and turn it into a Python object structure that can be easily compared against other HTML on semantic equivalence. Syntactical differences like which quotation is used on arguments will be ignored.
def parse_html(html): """ Take a string that contains HTML and turn it into a Python object structure that can be easily compared against other HTML on semantic equivalence. Syntactical differences like which quotation is used on arguments will be ignored. """ parser = Parser() parser.fe...
[ "def", "parse_html", "(", "html", ")", ":", "parser", "=", "Parser", "(", ")", "parser", ".", "feed", "(", "html", ")", "parser", ".", "close", "(", ")", "document", "=", "parser", ".", "root", "document", ".", "finalize", "(", ")", "# Removing ROOT el...
[ 225, 0 ]
[ 240, 19 ]
python
en
['en', 'error', 'th']
False
cache_page
(timeout, *, cache=None, key_prefix=None)
Decorator for views that tries getting the page from the cache and populates the cache if the page isn't in the cache yet. The cache is keyed by the URL and some data from the headers. Additionally there is the key prefix that is used to distinguish different cache areas in a multi-site setup. You...
Decorator for views that tries getting the page from the cache and populates the cache if the page isn't in the cache yet.
def cache_page(timeout, *, cache=None, key_prefix=None): """ Decorator for views that tries getting the page from the cache and populates the cache if the page isn't in the cache yet. The cache is keyed by the URL and some data from the headers. Additionally there is the key prefix that is used to ...
[ "def", "cache_page", "(", "timeout", ",", "*", ",", "cache", "=", "None", ",", "key_prefix", "=", "None", ")", ":", "return", "decorator_from_middleware_with_args", "(", "CacheMiddleware", ")", "(", "page_timeout", "=", "timeout", ",", "cache_alias", "=", "cac...
[ 7, 0 ]
[ 23, 5 ]
python
en
['en', 'error', 'th']
False
never_cache
(view_func)
Decorator that adds headers to a response so that it will never be cached.
Decorator that adds headers to a response so that it will never be cached.
def never_cache(view_func): """ Decorator that adds headers to a response so that it will never be cached. """ @wraps(view_func) def _wrapped_view_func(request, *args, **kwargs): response = view_func(request, *args, **kwargs) add_never_cache_headers(response) return response ...
[ "def", "never_cache", "(", "view_func", ")", ":", "@", "wraps", "(", "view_func", ")", "def", "_wrapped_view_func", "(", "request", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "response", "=", "view_func", "(", "request", ",", "*", "args", ","...
[ 37, 0 ]
[ 46, 29 ]
python
en
['en', 'error', 'th']
False
blankout
(src, char)
Change every non-whitespace character to the given char. Used in the templatize function.
Change every non-whitespace character to the given char. Used in the templatize function.
def blankout(src, char): """ Change every non-whitespace character to the given char. Used in the templatize function. """ return dot_re.sub(char, src)
[ "def", "blankout", "(", "src", ",", "char", ")", ":", "return", "dot_re", ".", "sub", "(", "char", ",", "src", ")" ]
[ 11, 0 ]
[ 16, 32 ]
python
en
['en', 'error', 'th']
False
templatize
(src, origin=None)
Turn a Django template into something that is understood by xgettext. It does so by translating the Django translation tags into standard gettext function invocations.
Turn a Django template into something that is understood by xgettext. It does so by translating the Django translation tags into standard gettext function invocations.
def templatize(src, origin=None): """ Turn a Django template into something that is understood by xgettext. It does so by translating the Django translation tags into standard gettext function invocations. """ out = StringIO('') message_context = None intrans = False inplural = False...
[ "def", "templatize", "(", "src", ",", "origin", "=", "None", ")", ":", "out", "=", "StringIO", "(", "''", ")", "message_context", "=", "None", "intrans", "=", "False", "inplural", "=", "False", "trimmed", "=", "False", "singular", "=", "[", "]", "plura...
[ 34, 0 ]
[ 226, 25 ]
python
en
['en', 'error', 'th']
False
get_fixed_timezone
(offset)
Return a tzinfo instance with a fixed offset from UTC.
Return a tzinfo instance with a fixed offset from UTC.
def get_fixed_timezone(offset): """Return a tzinfo instance with a fixed offset from UTC.""" if isinstance(offset, timedelta): offset = offset.total_seconds() // 60 sign = '-' if offset < 0 else '+' hhmm = '%02d%02d' % divmod(abs(offset), 60) name = sign + hhmm return timezone(timedelta(...
[ "def", "get_fixed_timezone", "(", "offset", ")", ":", "if", "isinstance", "(", "offset", ",", "timedelta", ")", ":", "offset", "=", "offset", ".", "total_seconds", "(", ")", "//", "60", "sign", "=", "'-'", "if", "offset", "<", "0", "else", "'+'", "hhmm...
[ 32, 0 ]
[ 39, 52 ]
python
en
['en', 'en', 'en']
True
get_default_timezone
()
Return the default time zone as a tzinfo instance. This is the time zone defined by settings.TIME_ZONE.
Return the default time zone as a tzinfo instance.
def get_default_timezone(): """ Return the default time zone as a tzinfo instance. This is the time zone defined by settings.TIME_ZONE. """ return pytz.timezone(settings.TIME_ZONE)
[ "def", "get_default_timezone", "(", ")", ":", "return", "pytz", ".", "timezone", "(", "settings", ".", "TIME_ZONE", ")" ]
[ 45, 0 ]
[ 51, 44 ]
python
en
['en', 'error', 'th']
False
get_default_timezone_name
()
Return the name of the default time zone.
Return the name of the default time zone.
def get_default_timezone_name(): """Return the name of the default time zone.""" return _get_timezone_name(get_default_timezone())
[ "def", "get_default_timezone_name", "(", ")", ":", "return", "_get_timezone_name", "(", "get_default_timezone", "(", ")", ")" ]
[ 55, 0 ]
[ 57, 53 ]
python
en
['en', 'en', 'en']
True
get_current_timezone
()
Return the currently active time zone as a tzinfo instance.
Return the currently active time zone as a tzinfo instance.
def get_current_timezone(): """Return the currently active time zone as a tzinfo instance.""" return getattr(_active, "value", get_default_timezone())
[ "def", "get_current_timezone", "(", ")", ":", "return", "getattr", "(", "_active", ",", "\"value\"", ",", "get_default_timezone", "(", ")", ")" ]
[ 63, 0 ]
[ 65, 60 ]
python
en
['en', 'en', 'en']
True
get_current_timezone_name
()
Return the name of the currently active time zone.
Return the name of the currently active time zone.
def get_current_timezone_name(): """Return the name of the currently active time zone.""" return _get_timezone_name(get_current_timezone())
[ "def", "get_current_timezone_name", "(", ")", ":", "return", "_get_timezone_name", "(", "get_current_timezone", "(", ")", ")" ]
[ 68, 0 ]
[ 70, 53 ]
python
en
['en', 'en', 'en']
True
_get_timezone_name
(timezone)
Return the offset for fixed offset timezones, or the name of timezone if not set.
Return the offset for fixed offset timezones, or the name of timezone if not set.
def _get_timezone_name(timezone): """ Return the offset for fixed offset timezones, or the name of timezone if not set. """ return timezone.tzname(None) or str(timezone)
[ "def", "_get_timezone_name", "(", "timezone", ")", ":", "return", "timezone", ".", "tzname", "(", "None", ")", "or", "str", "(", "timezone", ")" ]
[ 73, 0 ]
[ 78, 49 ]
python
en
['en', 'error', 'th']
False
activate
(timezone)
Set the time zone for the current thread. The ``timezone`` argument must be an instance of a tzinfo subclass or a time zone name.
Set the time zone for the current thread.
def activate(timezone): """ Set the time zone for the current thread. The ``timezone`` argument must be an instance of a tzinfo subclass or a time zone name. """ if isinstance(timezone, tzinfo): _active.value = timezone elif isinstance(timezone, str): _active.value = pytz.ti...
[ "def", "activate", "(", "timezone", ")", ":", "if", "isinstance", "(", "timezone", ",", "tzinfo", ")", ":", "_active", ".", "value", "=", "timezone", "elif", "isinstance", "(", "timezone", ",", "str", ")", ":", "_active", ".", "value", "=", "pytz", "."...
[ 86, 0 ]
[ 98, 59 ]
python
en
['en', 'error', 'th']
False
deactivate
()
Unset the time zone for the current thread. Django will then use the time zone defined by settings.TIME_ZONE.
Unset the time zone for the current thread.
def deactivate(): """ Unset the time zone for the current thread. Django will then use the time zone defined by settings.TIME_ZONE. """ if hasattr(_active, "value"): del _active.value
[ "def", "deactivate", "(", ")", ":", "if", "hasattr", "(", "_active", ",", "\"value\"", ")", ":", "del", "_active", ".", "value" ]
[ 101, 0 ]
[ 108, 25 ]
python
en
['en', 'error', 'th']
False
template_localtime
(value, use_tz=None)
Check if value is a datetime and converts it to local time if necessary. If use_tz is provided and is not None, that will force the value to be converted (or not), overriding the value of settings.USE_TZ. This function is designed for use by the template engine.
Check if value is a datetime and converts it to local time if necessary.
def template_localtime(value, use_tz=None): """ Check if value is a datetime and converts it to local time if necessary. If use_tz is provided and is not None, that will force the value to be converted (or not), overriding the value of settings.USE_TZ. This function is designed for use by the temp...
[ "def", "template_localtime", "(", "value", ",", "use_tz", "=", "None", ")", ":", "should_convert", "=", "(", "isinstance", "(", "value", ",", "datetime", ")", "and", "(", "settings", ".", "USE_TZ", "if", "use_tz", "is", "None", "else", "use_tz", ")", "an...
[ 142, 0 ]
[ 157, 56 ]
python
en
['en', 'error', 'th']
False
localtime
(value=None, timezone=None)
Convert an aware datetime.datetime to local time. Only aware datetimes are allowed. When value is omitted, it defaults to now(). Local time is defined by the current time zone, unless another time zone is specified.
Convert an aware datetime.datetime to local time.
def localtime(value=None, timezone=None): """ Convert an aware datetime.datetime to local time. Only aware datetimes are allowed. When value is omitted, it defaults to now(). Local time is defined by the current time zone, unless another time zone is specified. """ if value is None: ...
[ "def", "localtime", "(", "value", "=", "None", ",", "timezone", "=", "None", ")", ":", "if", "value", "is", "None", ":", "value", "=", "now", "(", ")", "if", "timezone", "is", "None", ":", "timezone", "=", "get_current_timezone", "(", ")", "# Emulate t...
[ 162, 0 ]
[ 179, 37 ]
python
en
['en', 'error', 'th']
False
localdate
(value=None, timezone=None)
Convert an aware datetime to local time and return the value's date. Only aware datetimes are allowed. When value is omitted, it defaults to now(). Local time is defined by the current time zone, unless another time zone is specified.
Convert an aware datetime to local time and return the value's date.
def localdate(value=None, timezone=None): """ Convert an aware datetime to local time and return the value's date. Only aware datetimes are allowed. When value is omitted, it defaults to now(). Local time is defined by the current time zone, unless another time zone is specified. """ r...
[ "def", "localdate", "(", "value", "=", "None", ",", "timezone", "=", "None", ")", ":", "return", "localtime", "(", "value", ",", "timezone", ")", ".", "date", "(", ")" ]
[ 182, 0 ]
[ 192, 44 ]
python
en
['en', 'error', 'th']
False
now
()
Return an aware or naive datetime.datetime, depending on settings.USE_TZ.
Return an aware or naive datetime.datetime, depending on settings.USE_TZ.
def now(): """ Return an aware or naive datetime.datetime, depending on settings.USE_TZ. """ if settings.USE_TZ: # timeit shows that datetime.now(tz=utc) is 24% slower return datetime.utcnow().replace(tzinfo=utc) else: return datetime.now()
[ "def", "now", "(", ")", ":", "if", "settings", ".", "USE_TZ", ":", "# timeit shows that datetime.now(tz=utc) is 24% slower", "return", "datetime", ".", "utcnow", "(", ")", ".", "replace", "(", "tzinfo", "=", "utc", ")", "else", ":", "return", "datetime", ".", ...
[ 195, 0 ]
[ 203, 29 ]
python
en
['en', 'error', 'th']
False
is_aware
(value)
Determine if a given datetime.datetime is aware. The concept is defined in Python's docs: https://docs.python.org/library/datetime.html#datetime.tzinfo Assuming value.tzinfo is either None or a proper datetime.tzinfo, value.utcoffset() implements the appropriate logic.
Determine if a given datetime.datetime is aware.
def is_aware(value): """ Determine if a given datetime.datetime is aware. The concept is defined in Python's docs: https://docs.python.org/library/datetime.html#datetime.tzinfo Assuming value.tzinfo is either None or a proper datetime.tzinfo, value.utcoffset() implements the appropriate logic....
[ "def", "is_aware", "(", "value", ")", ":", "return", "value", ".", "utcoffset", "(", ")", "is", "not", "None" ]
[ 209, 0 ]
[ 219, 40 ]
python
en
['en', 'error', 'th']
False
is_naive
(value)
Determine if a given datetime.datetime is naive. The concept is defined in Python's docs: https://docs.python.org/library/datetime.html#datetime.tzinfo Assuming value.tzinfo is either None or a proper datetime.tzinfo, value.utcoffset() implements the appropriate logic.
Determine if a given datetime.datetime is naive.
def is_naive(value): """ Determine if a given datetime.datetime is naive. The concept is defined in Python's docs: https://docs.python.org/library/datetime.html#datetime.tzinfo Assuming value.tzinfo is either None or a proper datetime.tzinfo, value.utcoffset() implements the appropriate logic....
[ "def", "is_naive", "(", "value", ")", ":", "return", "value", ".", "utcoffset", "(", ")", "is", "None" ]
[ 222, 0 ]
[ 232, 36 ]
python
en
['en', 'error', 'th']
False
make_aware
(value, timezone=None, is_dst=None)
Make a naive datetime.datetime in a given time zone aware.
Make a naive datetime.datetime in a given time zone aware.
def make_aware(value, timezone=None, is_dst=None): """Make a naive datetime.datetime in a given time zone aware.""" if timezone is None: timezone = get_current_timezone() if _is_pytz_zone(timezone): # This method is available for pytz time zones. return timezone.localize(value, is_ds...
[ "def", "make_aware", "(", "value", ",", "timezone", "=", "None", ",", "is_dst", "=", "None", ")", ":", "if", "timezone", "is", "None", ":", "timezone", "=", "get_current_timezone", "(", ")", "if", "_is_pytz_zone", "(", "timezone", ")", ":", "# This method ...
[ 235, 0 ]
[ 248, 45 ]
python
en
['en', 'en', 'en']
True
make_naive
(value, timezone=None)
Make an aware datetime.datetime naive in a given time zone.
Make an aware datetime.datetime naive in a given time zone.
def make_naive(value, timezone=None): """Make an aware datetime.datetime naive in a given time zone.""" if timezone is None: timezone = get_current_timezone() # Emulate the behavior of astimezone() on Python < 3.6. if is_naive(value): raise ValueError("make_naive() cannot be applied to a...
[ "def", "make_naive", "(", "value", ",", "timezone", "=", "None", ")", ":", "if", "timezone", "is", "None", ":", "timezone", "=", "get_current_timezone", "(", ")", "# Emulate the behavior of astimezone() on Python < 3.6.", "if", "is_naive", "(", "value", ")", ":", ...
[ 251, 0 ]
[ 258, 58 ]
python
en
['en', 'en', 'en']
True
_is_pytz_zone
(tz)
Checks if a zone is a pytz zone.
Checks if a zone is a pytz zone.
def _is_pytz_zone(tz): """Checks if a zone is a pytz zone.""" return isinstance(tz, _PYTZ_BASE_CLASSES)
[ "def", "_is_pytz_zone", "(", "tz", ")", ":", "return", "isinstance", "(", "tz", ",", "_PYTZ_BASE_CLASSES", ")" ]
[ 261, 0 ]
[ 263, 45 ]
python
en
['en', 'en', 'en']
True
pkcs12_key_as_pem
(private_key_bytes, private_key_password)
Convert the contents of a PKCS#12 key to PEM using pyOpenSSL. Args: private_key_bytes: Bytes. PKCS#12 key in DER format. private_key_password: String. Password for PKCS#12 key. Returns: String. PEM contents of ``private_key_bytes``.
Convert the contents of a PKCS#12 key to PEM using pyOpenSSL.
def pkcs12_key_as_pem(private_key_bytes, private_key_password): """Convert the contents of a PKCS#12 key to PEM using pyOpenSSL. Args: private_key_bytes: Bytes. PKCS#12 key in DER format. private_key_password: String. Password for PKCS#12 key. Returns: String. PEM contents of ``pri...
[ "def", "pkcs12_key_as_pem", "(", "private_key_bytes", ",", "private_key_password", ")", ":", "private_key_password", "=", "_helpers", ".", "_to_bytes", "(", "private_key_password", ")", "pkcs12", "=", "crypto", ".", "load_pkcs12", "(", "private_key_bytes", ",", "priva...
[ 122, 0 ]
[ 135, 58 ]
python
en
['en', 'fr', 'en']
True
OpenSSLVerifier.__init__
(self, pubkey)
Constructor. Args: pubkey: OpenSSL.crypto.PKey, The public key to verify with.
Constructor.
def __init__(self, pubkey): """Constructor. Args: pubkey: OpenSSL.crypto.PKey, The public key to verify with. """ self._pubkey = pubkey
[ "def", "__init__", "(", "self", ",", "pubkey", ")", ":", "self", ".", "_pubkey", "=", "pubkey" ]
[ 23, 4 ]
[ 29, 29 ]
python
en
['en', 'en', 'en']
False
OpenSSLVerifier.verify
(self, message, signature)
Verifies a message against a signature. Args: message: string or bytes, The message to verify. If string, will be encoded to bytes as utf-8. signature: string or bytes, The signature on the message. If string, will be encoded to bytes as utf-8. Retur...
Verifies a message against a signature.
def verify(self, message, signature): """Verifies a message against a signature. Args: message: string or bytes, The message to verify. If string, will be encoded to bytes as utf-8. signature: string or bytes, The signature on the message. If string, ...
[ "def", "verify", "(", "self", ",", "message", ",", "signature", ")", ":", "message", "=", "_helpers", ".", "_to_bytes", "(", "message", ",", "encoding", "=", "'utf-8'", ")", "signature", "=", "_helpers", ".", "_to_bytes", "(", "signature", ",", "encoding",...
[ 31, 4 ]
[ 50, 24 ]
python
en
['en', 'fr', 'en']
True
OpenSSLVerifier.from_string
(key_pem, is_x509_cert)
Construct a Verified instance from a string. Args: key_pem: string, public key in PEM format. is_x509_cert: bool, True if key_pem is an X509 cert, otherwise it is expected to be an RSA key in PEM format. Returns: Verifier instance. ...
Construct a Verified instance from a string.
def from_string(key_pem, is_x509_cert): """Construct a Verified instance from a string. Args: key_pem: string, public key in PEM format. is_x509_cert: bool, True if key_pem is an X509 cert, otherwise it is expected to be an RSA key in PEM format. ...
[ "def", "from_string", "(", "key_pem", ",", "is_x509_cert", ")", ":", "key_pem", "=", "_helpers", ".", "_to_bytes", "(", "key_pem", ")", "if", "is_x509_cert", ":", "pubkey", "=", "crypto", ".", "load_certificate", "(", "crypto", ".", "FILETYPE_PEM", ",", "key...
[ 53, 4 ]
[ 72, 38 ]
python
en
['en', 'en', 'en']
True
OpenSSLSigner.__init__
(self, pkey)
Constructor. Args: pkey: OpenSSL.crypto.PKey (or equiv), The private key to sign with.
Constructor.
def __init__(self, pkey): """Constructor. Args: pkey: OpenSSL.crypto.PKey (or equiv), The private key to sign with. """ self._key = pkey
[ "def", "__init__", "(", "self", ",", "pkey", ")", ":", "self", ".", "_key", "=", "pkey" ]
[ 78, 4 ]
[ 84, 24 ]
python
en
['en', 'en', 'en']
False
OpenSSLSigner.sign
(self, message)
Signs a message. Args: message: bytes, Message to be signed. Returns: string, The signature of the message for the given key.
Signs a message.
def sign(self, message): """Signs a message. Args: message: bytes, Message to be signed. Returns: string, The signature of the message for the given key. """ message = _helpers._to_bytes(message, encoding='utf-8') return crypto.sign(self._key, me...
[ "def", "sign", "(", "self", ",", "message", ")", ":", "message", "=", "_helpers", ".", "_to_bytes", "(", "message", ",", "encoding", "=", "'utf-8'", ")", "return", "crypto", ".", "sign", "(", "self", ".", "_key", ",", "message", ",", "'sha256'", ")" ]
[ 86, 4 ]
[ 96, 56 ]
python
en
['en', 'en', 'en']
True
OpenSSLSigner.from_string
(key, password=b'notasecret')
Construct a Signer instance from a string. Args: key: string, private key in PKCS12 or PEM format. password: string, password for the private key file. Returns: Signer instance. Raises: OpenSSL.crypto.Error if the key can't be parsed.
Construct a Signer instance from a string.
def from_string(key, password=b'notasecret'): """Construct a Signer instance from a string. Args: key: string, private key in PKCS12 or PEM format. password: string, password for the private key file. Returns: Signer instance. Raises: Op...
[ "def", "from_string", "(", "key", ",", "password", "=", "b'notasecret'", ")", ":", "key", "=", "_helpers", ".", "_to_bytes", "(", "key", ")", "parsed_pem_key", "=", "_helpers", ".", "_parse_pem_key", "(", "key", ")", "if", "parsed_pem_key", ":", "pkey", "=...
[ 99, 4 ]
[ 119, 34 ]
python
en
['en', 'en', 'en']
True
uninstall_if_needed
(setting, value, enter, **kwargs)
Undo the effects of PostgresConfig.ready() when django.contrib.postgres is "uninstalled" by override_settings().
Undo the effects of PostgresConfig.ready() when django.contrib.postgres is "uninstalled" by override_settings().
def uninstall_if_needed(setting, value, enter, **kwargs): """ Undo the effects of PostgresConfig.ready() when django.contrib.postgres is "uninstalled" by override_settings(). """ if not enter and setting == 'INSTALLED_APPS' and 'django.contrib.postgres' not in set(value): connection_created....
[ "def", "uninstall_if_needed", "(", "setting", ",", "value", ",", "enter", ",", "*", "*", "kwargs", ")", ":", "if", "not", "enter", "and", "setting", "==", "'INSTALLED_APPS'", "and", "'django.contrib.postgres'", "not", "in", "set", "(", "value", ")", ":", "...
[ 22, 0 ]
[ 39, 58 ]
python
en
['en', 'error', 'th']
False
CommandQueue.flush
(self)
Flushes out the queue by setting the property to an empty list :return:
Flushes out the queue by setting the property to an empty list :return:
def flush(self) -> None: """ Flushes out the queue by setting the property to an empty list :return: """ self.queue = list()
[ "def", "flush", "(", "self", ")", "->", "None", ":", "self", ".", "queue", "=", "list", "(", ")" ]
[ 62, 4 ]
[ 67, 27 ]
python
en
['en', 'error', 'th']
False
CommandQueue.__len__
(self)
:return: int length of self.queue
:return: int length of self.queue
def __len__(self) -> int: """ :return: int length of self.queue """ return len(self.queue)
[ "def", "__len__", "(", "self", ")", "->", "int", ":", "return", "len", "(", "self", ".", "queue", ")" ]
[ 69, 4 ]
[ 73, 30 ]
python
en
['en', 'error', 'th']
False
register_serializer
(format, serializer_module, serializers=None)
Register a new serializer. ``serializer_module`` should be the fully qualified module name for the serializer. If ``serializers`` is provided, the registration will be added to the provided dictionary. If ``serializers`` is not provided, the registration will be made directly into the global ...
Register a new serializer.
def register_serializer(format, serializer_module, serializers=None): """Register a new serializer. ``serializer_module`` should be the fully qualified module name for the serializer. If ``serializers`` is provided, the registration will be added to the provided dictionary. If ``serializers``...
[ "def", "register_serializer", "(", "format", ",", "serializer_module", ",", "serializers", "=", "None", ")", ":", "if", "serializers", "is", "None", "and", "not", "_serializers", ":", "_load_serializers", "(", ")", "try", ":", "module", "=", "importlib", ".", ...
[ 53, 0 ]
[ 82, 36 ]
python
en
['en', 'en', 'en']
True
unregister_serializer
(format)
Unregister a given serializer. This is not a thread-safe operation.
Unregister a given serializer. This is not a thread-safe operation.
def unregister_serializer(format): "Unregister a given serializer. This is not a thread-safe operation." if not _serializers: _load_serializers() if format not in _serializers: raise SerializerDoesNotExist(format) del _serializers[format]
[ "def", "unregister_serializer", "(", "format", ")", ":", "if", "not", "_serializers", ":", "_load_serializers", "(", ")", "if", "format", "not", "in", "_serializers", ":", "raise", "SerializerDoesNotExist", "(", "format", ")", "del", "_serializers", "[", "format...
[ 85, 0 ]
[ 91, 28 ]
python
en
['en', 'en', 'en']
True
serialize
(format, queryset, **options)
Serialize a queryset (or any iterator that returns database objects) using a certain serializer.
Serialize a queryset (or any iterator that returns database objects) using a certain serializer.
def serialize(format, queryset, **options): """ Serialize a queryset (or any iterator that returns database objects) using a certain serializer. """ s = get_serializer(format)() s.serialize(queryset, **options) return s.getvalue()
[ "def", "serialize", "(", "format", ",", "queryset", ",", "*", "*", "options", ")", ":", "s", "=", "get_serializer", "(", "format", ")", "(", ")", "s", ".", "serialize", "(", "queryset", ",", "*", "*", "options", ")", "return", "s", ".", "getvalue", ...
[ 122, 0 ]
[ 129, 23 ]
python
en
['en', 'error', 'th']
False
deserialize
(format, stream_or_string, **options)
Deserialize a stream or a string. Return an iterator that yields ``(obj, m2m_relation_dict)``, where ``obj`` is an instantiated -- but *unsaved* -- object, and ``m2m_relation_dict`` is a dictionary of ``{m2m_field_name : list_of_related_objects}``.
Deserialize a stream or a string. Return an iterator that yields ``(obj, m2m_relation_dict)``, where ``obj`` is an instantiated -- but *unsaved* -- object, and ``m2m_relation_dict`` is a dictionary of ``{m2m_field_name : list_of_related_objects}``.
def deserialize(format, stream_or_string, **options): """ Deserialize a stream or a string. Return an iterator that yields ``(obj, m2m_relation_dict)``, where ``obj`` is an instantiated -- but *unsaved* -- object, and ``m2m_relation_dict`` is a dictionary of ``{m2m_field_name : list_of_related_objec...
[ "def", "deserialize", "(", "format", ",", "stream_or_string", ",", "*", "*", "options", ")", ":", "d", "=", "get_deserializer", "(", "format", ")", "return", "d", "(", "stream_or_string", ",", "*", "*", "options", ")" ]
[ 132, 0 ]
[ 140, 41 ]
python
en
['en', 'error', 'th']
False
_load_serializers
()
Register built-in and settings-defined serializers. This is done lazily so that user code has a chance to (e.g.) set up custom settings without needing to be careful of import order.
Register built-in and settings-defined serializers. This is done lazily so that user code has a chance to (e.g.) set up custom settings without needing to be careful of import order.
def _load_serializers(): """ Register built-in and settings-defined serializers. This is done lazily so that user code has a chance to (e.g.) set up custom settings without needing to be careful of import order. """ global _serializers serializers = {} for format in BUILTIN_SERIALIZERS: ...
[ "def", "_load_serializers", "(", ")", ":", "global", "_serializers", "serializers", "=", "{", "}", "for", "format", "in", "BUILTIN_SERIALIZERS", ":", "register_serializer", "(", "format", ",", "BUILTIN_SERIALIZERS", "[", "format", "]", ",", "serializers", ")", "...
[ 143, 0 ]
[ 156, 30 ]
python
en
['en', 'error', 'th']
False
sort_dependencies
(app_list, allow_cycles=False)
Sort a list of (app_config, models) pairs into a single list of models. The single list of models is sorted so that any model with a natural key is serialized before a normal model, and any model with a natural key dependency has it's dependencies serialized first. If allow_cycles is True, return the ...
Sort a list of (app_config, models) pairs into a single list of models.
def sort_dependencies(app_list, allow_cycles=False): """Sort a list of (app_config, models) pairs into a single list of models. The single list of models is sorted so that any model with a natural key is serialized before a normal model, and any model with a natural key dependency has it's dependencies...
[ "def", "sort_dependencies", "(", "app_list", ",", "allow_cycles", "=", "False", ")", ":", "# Process the list of models, and get the list of dependencies", "model_dependencies", "=", "[", "]", "models", "=", "set", "(", ")", "for", "app_config", ",", "model_list", "in...
[ 159, 0 ]
[ 244, 21 ]
python
en
['en', 'en', 'en']
True
WhereNode.split_having
(self, negated=False)
Return two possibly None nodes: one for those parts of self that should be included in the WHERE clause and one for those parts of self that must be included in the HAVING clause.
Return two possibly None nodes: one for those parts of self that should be included in the WHERE clause and one for those parts of self that must be included in the HAVING clause.
def split_having(self, negated=False): """ Return two possibly None nodes: one for those parts of self that should be included in the WHERE clause and one for those parts of self that must be included in the HAVING clause. """ if not self.contains_aggregate: r...
[ "def", "split_having", "(", "self", ",", "negated", "=", "False", ")", ":", "if", "not", "self", ".", "contains_aggregate", ":", "return", "self", ",", "None", "in_negated", "=", "negated", "^", "self", ".", "negated", "# If the effective connector is OR and thi...
[ 31, 4 ]
[ 62, 38 ]
python
en
['en', 'error', 'th']
False
WhereNode.as_sql
(self, compiler, connection)
Return the SQL version of the where clause and the value to be substituted in. Return '', [] if this node matches everything, None, [] if this node is empty, and raise EmptyResultSet if this node can't match anything.
Return the SQL version of the where clause and the value to be substituted in. Return '', [] if this node matches everything, None, [] if this node is empty, and raise EmptyResultSet if this node can't match anything.
def as_sql(self, compiler, connection): """ Return the SQL version of the where clause and the value to be substituted in. Return '', [] if this node matches everything, None, [] if this node is empty, and raise EmptyResultSet if this node can't match anything. """ ...
[ "def", "as_sql", "(", "self", ",", "compiler", ",", "connection", ")", ":", "result", "=", "[", "]", "result_params", "=", "[", "]", "if", "self", ".", "connector", "==", "AND", ":", "full_needed", ",", "empty_needed", "=", "len", "(", "self", ".", "...
[ 64, 4 ]
[ 114, 40 ]
python
en
['en', 'error', 'th']
False
WhereNode.relabel_aliases
(self, change_map)
Relabel the alias values of any children. 'change_map' is a dictionary mapping old (current) alias values to the new values.
Relabel the alias values of any children. 'change_map' is a dictionary mapping old (current) alias values to the new values.
def relabel_aliases(self, change_map): """ Relabel the alias values of any children. 'change_map' is a dictionary mapping old (current) alias values to the new values. """ for pos, child in enumerate(self.children): if hasattr(child, 'relabel_aliases'): ...
[ "def", "relabel_aliases", "(", "self", ",", "change_map", ")", ":", "for", "pos", ",", "child", "in", "enumerate", "(", "self", ".", "children", ")", ":", "if", "hasattr", "(", "child", ",", "'relabel_aliases'", ")", ":", "# For example another WhereNode", "...
[ 129, 4 ]
[ 139, 70 ]
python
en
['en', 'error', 'th']
False
WhereNode.clone
(self)
Create a clone of the tree. Must only be called on root nodes (nodes with empty subtree_parents). Childs must be either (Constraint, lookup, value) tuples, or objects supporting .clone().
Create a clone of the tree. Must only be called on root nodes (nodes with empty subtree_parents). Childs must be either (Constraint, lookup, value) tuples, or objects supporting .clone().
def clone(self): """ Create a clone of the tree. Must only be called on root nodes (nodes with empty subtree_parents). Childs must be either (Constraint, lookup, value) tuples, or objects supporting .clone(). """ clone = self.__class__._new_instance( children=...
[ "def", "clone", "(", "self", ")", ":", "clone", "=", "self", ".", "__class__", ".", "_new_instance", "(", "children", "=", "[", "]", ",", "connector", "=", "self", ".", "connector", ",", "negated", "=", "self", ".", "negated", ")", "for", "child", "i...
[ 141, 4 ]
[ 154, 20 ]
python
en
['en', 'error', 'th']
False
_get_related_models
(m)
Return all models that have a direct relationship to the given model.
Return all models that have a direct relationship to the given model.
def _get_related_models(m): """Return all models that have a direct relationship to the given model.""" related_models = [ subclass for subclass in m.__subclasses__() if issubclass(subclass, models.Model) ] related_fields_models = set() for f in m._meta.get_fields(include_parents=Tru...
[ "def", "_get_related_models", "(", "m", ")", ":", "related_models", "=", "[", "subclass", "for", "subclass", "in", "m", ".", "__subclasses__", "(", ")", "if", "issubclass", "(", "subclass", ",", "models", ".", "Model", ")", "]", "related_fields_models", "=",...
[ 25, 0 ]
[ 41, 25 ]
python
en
['en', 'en', 'en']
True
get_related_models_tuples
(model)
Return a list of typical (app_label, model_name) tuples for all related models for the given model.
Return a list of typical (app_label, model_name) tuples for all related models for the given model.
def get_related_models_tuples(model): """ Return a list of typical (app_label, model_name) tuples for all related models for the given model. """ return { (rel_mod._meta.app_label, rel_mod._meta.model_name) for rel_mod in _get_related_models(model) }
[ "def", "get_related_models_tuples", "(", "model", ")", ":", "return", "{", "(", "rel_mod", ".", "_meta", ".", "app_label", ",", "rel_mod", ".", "_meta", ".", "model_name", ")", "for", "rel_mod", "in", "_get_related_models", "(", "model", ")", "}" ]
[ 44, 0 ]
[ 52, 5 ]
python
en
['en', 'error', 'th']
False
get_related_models_recursive
(model)
Return all models that have a direct or indirect relationship to the given model. Relationships are either defined by explicit relational fields, like ForeignKey, ManyToManyField or OneToOneField, or by inheriting from another model (a superclass is related to its subclasses, but not vice versa). ...
Return all models that have a direct or indirect relationship to the given model.
def get_related_models_recursive(model): """ Return all models that have a direct or indirect relationship to the given model. Relationships are either defined by explicit relational fields, like ForeignKey, ManyToManyField or OneToOneField, or by inheriting from another model (a superclass is ...
[ "def", "get_related_models_recursive", "(", "model", ")", ":", "seen", "=", "set", "(", ")", "queue", "=", "_get_related_models", "(", "model", ")", "for", "rel_mod", "in", "queue", ":", "rel_app_label", ",", "rel_model_name", "=", "rel_mod", ".", "_meta", "...
[ 55, 0 ]
[ 74, 67 ]
python
en
['en', 'error', 'th']
False
ProjectState.clone
(self)
Return an exact copy of this ProjectState.
Return an exact copy of this ProjectState.
def clone(self): """Return an exact copy of this ProjectState.""" new_state = ProjectState( models={k: v.clone() for k, v in self.models.items()}, real_apps=self.real_apps, ) if 'apps' in self.__dict__: new_state.apps = self.apps.clone() new_st...
[ "def", "clone", "(", "self", ")", ":", "new_state", "=", "ProjectState", "(", "models", "=", "{", "k", ":", "v", ".", "clone", "(", ")", "for", "k", ",", "v", "in", "self", ".", "models", ".", "items", "(", ")", "}", ",", "real_apps", "=", "sel...
[ 190, 4 ]
[ 199, 24 ]
python
en
['en', 'en', 'en']
True
ProjectState.from_apps
(cls, apps)
Take an Apps and return a ProjectState matching it.
Take an Apps and return a ProjectState matching it.
def from_apps(cls, apps): """Take an Apps and return a ProjectState matching it.""" app_models = {} for model in apps.get_models(include_swapped=True): model_state = ModelState.from_model(model) app_models[(model_state.app_label, model_state.name_lower)] = model_state ...
[ "def", "from_apps", "(", "cls", ",", "apps", ")", ":", "app_models", "=", "{", "}", "for", "model", "in", "apps", ".", "get_models", "(", "include_swapped", "=", "True", ")", ":", "model_state", "=", "ModelState", ".", "from_model", "(", "model", ")", ...
[ 215, 4 ]
[ 221, 30 ]
python
en
['en', 'en', 'en']
True
StateApps.clone
(self)
Return a clone of this registry.
Return a clone of this registry.
def clone(self): """Return a clone of this registry.""" clone = StateApps([], {}) clone.all_models = copy.deepcopy(self.all_models) clone.app_configs = copy.deepcopy(self.app_configs) # Set the pointer to the correct app registry. for app_config in clone.app_configs.value...
[ "def", "clone", "(", "self", ")", ":", "clone", "=", "StateApps", "(", "[", "]", ",", "{", "}", ")", "clone", ".", "all_models", "=", "copy", ".", "deepcopy", "(", "self", ".", "all_models", ")", "clone", ".", "app_configs", "=", "copy", ".", "deep...
[ 316, 4 ]
[ 326, 20 ]
python
en
['en', 'en', 'en']
True
ModelState.from_model
(cls, model, exclude_rels=False)
Given a model, return a ModelState representing it.
Given a model, return a ModelState representing it.
def from_model(cls, model, exclude_rels=False): """Given a model, return a ModelState representing it.""" # Deconstruct the fields fields = [] for field in model._meta.local_fields: if getattr(field, "remote_field", None) and exclude_rels: continue ...
[ "def", "from_model", "(", "cls", ",", "model", ",", "exclude_rels", "=", "False", ")", ":", "# Deconstruct the fields", "fields", "=", "[", "]", "for", "field", "in", "model", ".", "_meta", ".", "local_fields", ":", "if", "getattr", "(", "field", ",", "\...
[ 395, 4 ]
[ 521, 9 ]
python
en
['en', 'en', 'en']
True
ModelState.construct_managers
(self)
Deep-clone the managers using deconstruction.
Deep-clone the managers using deconstruction.
def construct_managers(self): """Deep-clone the managers using deconstruction.""" # Sort all managers by their creation counter sorted_managers = sorted(self.managers, key=lambda v: v[1].creation_counter) for mgr_name, manager in sorted_managers: as_manager, manager_path, qs_...
[ "def", "construct_managers", "(", "self", ")", ":", "# Sort all managers by their creation counter", "sorted_managers", "=", "sorted", "(", "self", ".", "managers", ",", "key", "=", "lambda", "v", ":", "v", "[", "1", "]", ".", "creation_counter", ")", "for", "...
[ 523, 4 ]
[ 534, 62 ]
python
en
['en', 'en', 'en']
True
ModelState.clone
(self)
Return an exact copy of this ModelState.
Return an exact copy of this ModelState.
def clone(self): """Return an exact copy of this ModelState.""" return self.__class__( app_label=self.app_label, name=self.name, fields=dict(self.fields), # Since options are shallow-copied here, operations such as # AddIndex must replace their...
[ "def", "clone", "(", "self", ")", ":", "return", "self", ".", "__class__", "(", "app_label", "=", "self", ".", "app_label", ",", "name", "=", "self", ".", "name", ",", "fields", "=", "dict", "(", "self", ".", "fields", ")", ",", "# Since options are sh...
[ 536, 4 ]
[ 548, 9 ]
python
en
['en', 'en', 'en']
True
ModelState.render
(self, apps)
Create a Model object from our current state into the given apps.
Create a Model object from our current state into the given apps.
def render(self, apps): """Create a Model object from our current state into the given apps.""" # First, make a Meta object meta_contents = {'app_label': self.app_label, 'apps': apps, **self.options} meta = type("Meta", (), meta_contents) # Then, work out our bases try: ...
[ "def", "render", "(", "self", ",", "apps", ")", ":", "# First, make a Meta object", "meta_contents", "=", "{", "'app_label'", ":", "self", ".", "app_label", ",", "'apps'", ":", "apps", ",", "*", "*", "self", ".", "options", "}", "meta", "=", "type", "(",...
[ 550, 4 ]
[ 571, 43 ]
python
en
['en', 'en', 'en']
True