partition
stringclasses
3 values
func_name
stringlengths
1
134
docstring
stringlengths
1
46.9k
path
stringlengths
4
223
original_string
stringlengths
75
104k
code
stringlengths
75
104k
docstring_tokens
listlengths
1
1.97k
repo
stringlengths
7
55
language
stringclasses
1 value
url
stringlengths
87
315
code_tokens
listlengths
19
28.4k
sha
stringlengths
40
40
train
_ArtifactoryFlavour.splitroot
Splits path string into drive, root and relative path Uses '/artifactory/' as a splitting point in URI. Everything before it, including '/artifactory/' itself is treated as drive. The next folder is treated as root, and everything else is taken for relative path.
artifactory.py
def splitroot(self, part, sep=sep): """ Splits path string into drive, root and relative path Uses '/artifactory/' as a splitting point in URI. Everything before it, including '/artifactory/' itself is treated as drive. The next folder is treated as root, and everything else is ...
def splitroot(self, part, sep=sep): """ Splits path string into drive, root and relative path Uses '/artifactory/' as a splitting point in URI. Everything before it, including '/artifactory/' itself is treated as drive. The next folder is treated as root, and everything else is ...
[ "Splits", "path", "string", "into", "drive", "root", "and", "relative", "path" ]
Parallels/artifactory
python
https://github.com/Parallels/artifactory/blob/09ddcc4ae15095eec2347d39774c3f8aca6c4654/artifactory.py#L316-L355
[ "def", "splitroot", "(", "self", ",", "part", ",", "sep", "=", "sep", ")", ":", "drv", "=", "''", "root", "=", "''", "base", "=", "get_global_base_url", "(", "part", ")", "if", "base", "and", "without_http_prefix", "(", "part", ")", ".", "startswith", ...
09ddcc4ae15095eec2347d39774c3f8aca6c4654
train
_ArtifactoryAccessor.rest_get
Perform a GET request to url with optional authentication
artifactory.py
def rest_get(self, url, params=None, headers=None, auth=None, verify=True, cert=None): """ Perform a GET request to url with optional authentication """ res = requests.get(url, params=params, headers=headers, auth=auth, verify=verify, cert=cert) return ...
def rest_get(self, url, params=None, headers=None, auth=None, verify=True, cert=None): """ Perform a GET request to url with optional authentication """ res = requests.get(url, params=params, headers=headers, auth=auth, verify=verify, cert=cert) return ...
[ "Perform", "a", "GET", "request", "to", "url", "with", "optional", "authentication" ]
Parallels/artifactory
python
https://github.com/Parallels/artifactory/blob/09ddcc4ae15095eec2347d39774c3f8aca6c4654/artifactory.py#L412-L418
[ "def", "rest_get", "(", "self", ",", "url", ",", "params", "=", "None", ",", "headers", "=", "None", ",", "auth", "=", "None", ",", "verify", "=", "True", ",", "cert", "=", "None", ")", ":", "res", "=", "requests", ".", "get", "(", "url", ",", ...
09ddcc4ae15095eec2347d39774c3f8aca6c4654
train
_ArtifactoryAccessor.rest_put
Perform a PUT request to url with optional authentication
artifactory.py
def rest_put(self, url, params=None, headers=None, auth=None, verify=True, cert=None): """ Perform a PUT request to url with optional authentication """ res = requests.put(url, params=params, headers=headers, auth=auth, verify=verify, cert=cert) return ...
def rest_put(self, url, params=None, headers=None, auth=None, verify=True, cert=None): """ Perform a PUT request to url with optional authentication """ res = requests.put(url, params=params, headers=headers, auth=auth, verify=verify, cert=cert) return ...
[ "Perform", "a", "PUT", "request", "to", "url", "with", "optional", "authentication" ]
Parallels/artifactory
python
https://github.com/Parallels/artifactory/blob/09ddcc4ae15095eec2347d39774c3f8aca6c4654/artifactory.py#L420-L426
[ "def", "rest_put", "(", "self", ",", "url", ",", "params", "=", "None", ",", "headers", "=", "None", ",", "auth", "=", "None", ",", "verify", "=", "True", ",", "cert", "=", "None", ")", ":", "res", "=", "requests", ".", "put", "(", "url", ",", ...
09ddcc4ae15095eec2347d39774c3f8aca6c4654
train
_ArtifactoryAccessor.rest_post
Perform a PUT request to url with optional authentication
artifactory.py
def rest_post(self, url, params=None, headers=None, auth=None, verify=True, cert=None): """ Perform a PUT request to url with optional authentication """ res = requests.post(url, params=params, headers=headers, auth=auth, verify=verify, cert=cert) retu...
def rest_post(self, url, params=None, headers=None, auth=None, verify=True, cert=None): """ Perform a PUT request to url with optional authentication """ res = requests.post(url, params=params, headers=headers, auth=auth, verify=verify, cert=cert) retu...
[ "Perform", "a", "PUT", "request", "to", "url", "with", "optional", "authentication" ]
Parallels/artifactory
python
https://github.com/Parallels/artifactory/blob/09ddcc4ae15095eec2347d39774c3f8aca6c4654/artifactory.py#L428-L434
[ "def", "rest_post", "(", "self", ",", "url", ",", "params", "=", "None", ",", "headers", "=", "None", ",", "auth", "=", "None", ",", "verify", "=", "True", ",", "cert", "=", "None", ")", ":", "res", "=", "requests", ".", "post", "(", "url", ",", ...
09ddcc4ae15095eec2347d39774c3f8aca6c4654
train
_ArtifactoryAccessor.rest_del
Perform a DELETE request to url with optional authentication
artifactory.py
def rest_del(self, url, params=None, auth=None, verify=True, cert=None): """ Perform a DELETE request to url with optional authentication """ res = requests.delete(url, params=params, auth=auth, verify=verify, cert=cert) return res.text, res.status_code
def rest_del(self, url, params=None, auth=None, verify=True, cert=None): """ Perform a DELETE request to url with optional authentication """ res = requests.delete(url, params=params, auth=auth, verify=verify, cert=cert) return res.text, res.status_code
[ "Perform", "a", "DELETE", "request", "to", "url", "with", "optional", "authentication" ]
Parallels/artifactory
python
https://github.com/Parallels/artifactory/blob/09ddcc4ae15095eec2347d39774c3f8aca6c4654/artifactory.py#L436-L441
[ "def", "rest_del", "(", "self", ",", "url", ",", "params", "=", "None", ",", "auth", "=", "None", ",", "verify", "=", "True", ",", "cert", "=", "None", ")", ":", "res", "=", "requests", ".", "delete", "(", "url", ",", "params", "=", "params", ","...
09ddcc4ae15095eec2347d39774c3f8aca6c4654
train
_ArtifactoryAccessor.rest_get_stream
Perform a chunked GET request to url with optional authentication This is specifically to download files.
artifactory.py
def rest_get_stream(self, url, auth=None, verify=True, cert=None): """ Perform a chunked GET request to url with optional authentication This is specifically to download files. """ res = requests.get(url, auth=auth, stream=True, verify=verify, cert=cert) return res.raw, r...
def rest_get_stream(self, url, auth=None, verify=True, cert=None): """ Perform a chunked GET request to url with optional authentication This is specifically to download files. """ res = requests.get(url, auth=auth, stream=True, verify=verify, cert=cert) return res.raw, r...
[ "Perform", "a", "chunked", "GET", "request", "to", "url", "with", "optional", "authentication", "This", "is", "specifically", "to", "download", "files", "." ]
Parallels/artifactory
python
https://github.com/Parallels/artifactory/blob/09ddcc4ae15095eec2347d39774c3f8aca6c4654/artifactory.py#L451-L457
[ "def", "rest_get_stream", "(", "self", ",", "url", ",", "auth", "=", "None", ",", "verify", "=", "True", ",", "cert", "=", "None", ")", ":", "res", "=", "requests", ".", "get", "(", "url", ",", "auth", "=", "auth", ",", "stream", "=", "True", ","...
09ddcc4ae15095eec2347d39774c3f8aca6c4654
train
_ArtifactoryAccessor.get_stat_json
Request remote file/directory status info Returns a json object as specified by Artifactory REST API
artifactory.py
def get_stat_json(self, pathobj): """ Request remote file/directory status info Returns a json object as specified by Artifactory REST API """ url = '/'.join([pathobj.drive, 'api/storage', str(pathobj.relative_to(pathobj.drive)).str...
def get_stat_json(self, pathobj): """ Request remote file/directory status info Returns a json object as specified by Artifactory REST API """ url = '/'.join([pathobj.drive, 'api/storage', str(pathobj.relative_to(pathobj.drive)).str...
[ "Request", "remote", "file", "/", "directory", "status", "info", "Returns", "a", "json", "object", "as", "specified", "by", "Artifactory", "REST", "API" ]
Parallels/artifactory
python
https://github.com/Parallels/artifactory/blob/09ddcc4ae15095eec2347d39774c3f8aca6c4654/artifactory.py#L459-L475
[ "def", "get_stat_json", "(", "self", ",", "pathobj", ")", ":", "url", "=", "'/'", ".", "join", "(", "[", "pathobj", ".", "drive", ",", "'api/storage'", ",", "str", "(", "pathobj", ".", "relative_to", "(", "pathobj", ".", "drive", ")", ")", ".", "stri...
09ddcc4ae15095eec2347d39774c3f8aca6c4654
train
_ArtifactoryAccessor.open
Opens the remote file and returns a file-like object HTTPResponse Given the nature of HTTP streaming, this object doesn't support seek()
artifactory.py
def open(self, pathobj): """ Opens the remote file and returns a file-like object HTTPResponse Given the nature of HTTP streaming, this object doesn't support seek() """ url = str(pathobj) raw, code = self.rest_get_stream(url, auth=pathobj.auth, verify=pathobj.ver...
def open(self, pathobj): """ Opens the remote file and returns a file-like object HTTPResponse Given the nature of HTTP streaming, this object doesn't support seek() """ url = str(pathobj) raw, code = self.rest_get_stream(url, auth=pathobj.auth, verify=pathobj.ver...
[ "Opens", "the", "remote", "file", "and", "returns", "a", "file", "-", "like", "object", "HTTPResponse", "Given", "the", "nature", "of", "HTTP", "streaming", "this", "object", "doesn", "t", "support", "seek", "()" ]
Parallels/artifactory
python
https://github.com/Parallels/artifactory/blob/09ddcc4ae15095eec2347d39774c3f8aca6c4654/artifactory.py#L649-L662
[ "def", "open", "(", "self", ",", "pathobj", ")", ":", "url", "=", "str", "(", "pathobj", ")", "raw", ",", "code", "=", "self", ".", "rest_get_stream", "(", "url", ",", "auth", "=", "pathobj", ".", "auth", ",", "verify", "=", "pathobj", ".", "verify...
09ddcc4ae15095eec2347d39774c3f8aca6c4654
train
_ArtifactoryAccessor.deploy
Uploads a given file-like object HTTP chunked encoding will be attempted
artifactory.py
def deploy(self, pathobj, fobj, md5=None, sha1=None, parameters=None): """ Uploads a given file-like object HTTP chunked encoding will be attempted """ if isinstance(fobj, urllib3.response.HTTPResponse): fobj = HTTPResponseWrapper(fobj) url = str(pathobj) ...
def deploy(self, pathobj, fobj, md5=None, sha1=None, parameters=None): """ Uploads a given file-like object HTTP chunked encoding will be attempted """ if isinstance(fobj, urllib3.response.HTTPResponse): fobj = HTTPResponseWrapper(fobj) url = str(pathobj) ...
[ "Uploads", "a", "given", "file", "-", "like", "object", "HTTP", "chunked", "encoding", "will", "be", "attempted" ]
Parallels/artifactory
python
https://github.com/Parallels/artifactory/blob/09ddcc4ae15095eec2347d39774c3f8aca6c4654/artifactory.py#L664-L692
[ "def", "deploy", "(", "self", ",", "pathobj", ",", "fobj", ",", "md5", "=", "None", ",", "sha1", "=", "None", ",", "parameters", "=", "None", ")", ":", "if", "isinstance", "(", "fobj", ",", "urllib3", ".", "response", ".", "HTTPResponse", ")", ":", ...
09ddcc4ae15095eec2347d39774c3f8aca6c4654
train
_ArtifactoryAccessor.move
Move artifact from src to dst
artifactory.py
def move(self, src, dst): """ Move artifact from src to dst """ url = '/'.join([src.drive, 'api/move', str(src.relative_to(src.drive)).rstrip('/')]) params = {'to': str(dst.relative_to(dst.drive)).rstrip('/')} text, code =...
def move(self, src, dst): """ Move artifact from src to dst """ url = '/'.join([src.drive, 'api/move', str(src.relative_to(src.drive)).rstrip('/')]) params = {'to': str(dst.relative_to(dst.drive)).rstrip('/')} text, code =...
[ "Move", "artifact", "from", "src", "to", "dst" ]
Parallels/artifactory
python
https://github.com/Parallels/artifactory/blob/09ddcc4ae15095eec2347d39774c3f8aca6c4654/artifactory.py#L714-L731
[ "def", "move", "(", "self", ",", "src", ",", "dst", ")", ":", "url", "=", "'/'", ".", "join", "(", "[", "src", ".", "drive", ",", "'api/move'", ",", "str", "(", "src", ".", "relative_to", "(", "src", ".", "drive", ")", ")", ".", "rstrip", "(", ...
09ddcc4ae15095eec2347d39774c3f8aca6c4654
train
_ArtifactoryAccessor.set_properties
Set artifact properties
artifactory.py
def set_properties(self, pathobj, props, recursive): """ Set artifact properties """ url = '/'.join([pathobj.drive, 'api/storage', str(pathobj.relative_to(pathobj.drive)).strip('/')]) params = {'properties': encode_properties(props...
def set_properties(self, pathobj, props, recursive): """ Set artifact properties """ url = '/'.join([pathobj.drive, 'api/storage', str(pathobj.relative_to(pathobj.drive)).strip('/')]) params = {'properties': encode_properties(props...
[ "Set", "artifact", "properties" ]
Parallels/artifactory
python
https://github.com/Parallels/artifactory/blob/09ddcc4ae15095eec2347d39774c3f8aca6c4654/artifactory.py#L758-L780
[ "def", "set_properties", "(", "self", ",", "pathobj", ",", "props", ",", "recursive", ")", ":", "url", "=", "'/'", ".", "join", "(", "[", "pathobj", ".", "drive", ",", "'api/storage'", ",", "str", "(", "pathobj", ".", "relative_to", "(", "pathobj", "."...
09ddcc4ae15095eec2347d39774c3f8aca6c4654
train
_ArtifactoryAccessor.del_properties
Delete artifact properties
artifactory.py
def del_properties(self, pathobj, props, recursive): """ Delete artifact properties """ if isinstance(props, str): props = (props,) url = '/'.join([pathobj.drive, 'api/storage', str(pathobj.relative_to(pathobj.drive)).s...
def del_properties(self, pathobj, props, recursive): """ Delete artifact properties """ if isinstance(props, str): props = (props,) url = '/'.join([pathobj.drive, 'api/storage', str(pathobj.relative_to(pathobj.drive)).s...
[ "Delete", "artifact", "properties" ]
Parallels/artifactory
python
https://github.com/Parallels/artifactory/blob/09ddcc4ae15095eec2347d39774c3f8aca6c4654/artifactory.py#L782-L807
[ "def", "del_properties", "(", "self", ",", "pathobj", ",", "props", ",", "recursive", ")", ":", "if", "isinstance", "(", "props", ",", "str", ")", ":", "props", "=", "(", "props", ",", ")", "url", "=", "'/'", ".", "join", "(", "[", "pathobj", ".", ...
09ddcc4ae15095eec2347d39774c3f8aca6c4654
train
ArtifactoryPath.relative_to
Return the relative path to another path identified by the passed arguments. If the operation is not possible (because this is not a subpath of the other path), raise ValueError.
artifactory.py
def relative_to(self, *other): """ Return the relative path to another path identified by the passed arguments. If the operation is not possible (because this is not a subpath of the other path), raise ValueError. """ obj = super(ArtifactoryPath, self).relative_to(*other...
def relative_to(self, *other): """ Return the relative path to another path identified by the passed arguments. If the operation is not possible (because this is not a subpath of the other path), raise ValueError. """ obj = super(ArtifactoryPath, self).relative_to(*other...
[ "Return", "the", "relative", "path", "to", "another", "path", "identified", "by", "the", "passed", "arguments", ".", "If", "the", "operation", "is", "not", "possible", "(", "because", "this", "is", "not", "a", "subpath", "of", "the", "other", "path", ")", ...
Parallels/artifactory
python
https://github.com/Parallels/artifactory/blob/09ddcc4ae15095eec2347d39774c3f8aca6c4654/artifactory.py#L923-L933
[ "def", "relative_to", "(", "self", ",", "*", "other", ")", ":", "obj", "=", "super", "(", "ArtifactoryPath", ",", "self", ")", ".", "relative_to", "(", "*", "other", ")", "obj", ".", "auth", "=", "self", ".", "auth", "obj", ".", "verify", "=", "sel...
09ddcc4ae15095eec2347d39774c3f8aca6c4654
train
ArtifactoryPath.set_properties
Adds new or modifies existing properties listed in properties properties - is a dict which contains the property names and values to set. Property values can be a list or tuple to set multiple values for a key. recursive - on folders property attachment is rec...
artifactory.py
def set_properties(self, properties, recursive=True): """ Adds new or modifies existing properties listed in properties properties - is a dict which contains the property names and values to set. Property values can be a list or tuple to set multiple values ...
def set_properties(self, properties, recursive=True): """ Adds new or modifies existing properties listed in properties properties - is a dict which contains the property names and values to set. Property values can be a list or tuple to set multiple values ...
[ "Adds", "new", "or", "modifies", "existing", "properties", "listed", "in", "properties" ]
Parallels/artifactory
python
https://github.com/Parallels/artifactory/blob/09ddcc4ae15095eec2347d39774c3f8aca6c4654/artifactory.py#L1234-L1247
[ "def", "set_properties", "(", "self", ",", "properties", ",", "recursive", "=", "True", ")", ":", "if", "not", "properties", ":", "return", "return", "self", ".", "_accessor", ".", "set_properties", "(", "self", ",", "properties", ",", "recursive", ")" ]
09ddcc4ae15095eec2347d39774c3f8aca6c4654
train
ALEInterface.getScreenDims
returns a tuple that contains (screen_width,screen_height)
ale_python_interface/ale_python_interface.py
def getScreenDims(self): """returns a tuple that contains (screen_width,screen_height) """ width = ale_lib.getScreenWidth(self.obj) height = ale_lib.getScreenHeight(self.obj) return (width,height)
def getScreenDims(self): """returns a tuple that contains (screen_width,screen_height) """ width = ale_lib.getScreenWidth(self.obj) height = ale_lib.getScreenHeight(self.obj) return (width,height)
[ "returns", "a", "tuple", "that", "contains", "(", "screen_width", "screen_height", ")" ]
bbitmaster/ale_python_interface
python
https://github.com/bbitmaster/ale_python_interface/blob/253062be8e07fb738ea25982387b20af3712b615/ale_python_interface/ale_python_interface.py#L67-L72
[ "def", "getScreenDims", "(", "self", ")", ":", "width", "=", "ale_lib", ".", "getScreenWidth", "(", "self", ".", "obj", ")", "height", "=", "ale_lib", ".", "getScreenHeight", "(", "self", ".", "obj", ")", "return", "(", "width", ",", "height", ")" ]
253062be8e07fb738ea25982387b20af3712b615
train
ALEInterface.getScreen
This function fills screen_data with the RAW Pixel data screen_data MUST be a numpy array of uint8/int8. This could be initialized like so: screen_data = np.array(w*h,dtype=np.uint8) Notice, it must be width*height in size also If it is None, then this function will initialize it ...
ale_python_interface/ale_python_interface.py
def getScreen(self,screen_data=None): """This function fills screen_data with the RAW Pixel data screen_data MUST be a numpy array of uint8/int8. This could be initialized like so: screen_data = np.array(w*h,dtype=np.uint8) Notice, it must be width*height in size also If it is No...
def getScreen(self,screen_data=None): """This function fills screen_data with the RAW Pixel data screen_data MUST be a numpy array of uint8/int8. This could be initialized like so: screen_data = np.array(w*h,dtype=np.uint8) Notice, it must be width*height in size also If it is No...
[ "This", "function", "fills", "screen_data", "with", "the", "RAW", "Pixel", "data", "screen_data", "MUST", "be", "a", "numpy", "array", "of", "uint8", "/", "int8", ".", "This", "could", "be", "initialized", "like", "so", ":", "screen_data", "=", "np", ".", ...
bbitmaster/ale_python_interface
python
https://github.com/bbitmaster/ale_python_interface/blob/253062be8e07fb738ea25982387b20af3712b615/ale_python_interface/ale_python_interface.py#L75-L88
[ "def", "getScreen", "(", "self", ",", "screen_data", "=", "None", ")", ":", "if", "(", "screen_data", "is", "None", ")", ":", "width", "=", "ale_lib", ".", "getScreenWidth", "(", "self", ".", "obj", ")", "height", "=", "ale_lib", ".", "getScreenWidth", ...
253062be8e07fb738ea25982387b20af3712b615
train
ALEInterface.getScreenRGB
This function fills screen_data with the data screen_data MUST be a numpy array of uint32/int32. This can be initialized like so: screen_data = np.array(w*h,dtype=np.uint32) Notice, it must be width*height in size also If it is None, then this function will initialize it
ale_python_interface/ale_python_interface.py
def getScreenRGB(self,screen_data=None): """This function fills screen_data with the data screen_data MUST be a numpy array of uint32/int32. This can be initialized like so: screen_data = np.array(w*h,dtype=np.uint32) Notice, it must be width*height in size also If it is None, th...
def getScreenRGB(self,screen_data=None): """This function fills screen_data with the data screen_data MUST be a numpy array of uint32/int32. This can be initialized like so: screen_data = np.array(w*h,dtype=np.uint32) Notice, it must be width*height in size also If it is None, th...
[ "This", "function", "fills", "screen_data", "with", "the", "data", "screen_data", "MUST", "be", "a", "numpy", "array", "of", "uint32", "/", "int32", ".", "This", "can", "be", "initialized", "like", "so", ":", "screen_data", "=", "np", ".", "array", "(", ...
bbitmaster/ale_python_interface
python
https://github.com/bbitmaster/ale_python_interface/blob/253062be8e07fb738ea25982387b20af3712b615/ale_python_interface/ale_python_interface.py#L90-L102
[ "def", "getScreenRGB", "(", "self", ",", "screen_data", "=", "None", ")", ":", "if", "(", "screen_data", "is", "None", ")", ":", "width", "=", "ale_lib", ".", "getScreenWidth", "(", "self", ".", "obj", ")", "height", "=", "ale_lib", ".", "getScreenWidth"...
253062be8e07fb738ea25982387b20af3712b615
train
ALEInterface.getRAM
This function grabs the atari RAM. ram MUST be a numpy array of uint8/int8. This can be initialized like so: ram = np.array(ram_size,dtype=uint8) Notice: It must be ram_size where ram_size can be retrieved via the getRAMSize function. If it is None, then this function will initialize it.
ale_python_interface/ale_python_interface.py
def getRAM(self,ram=None): """This function grabs the atari RAM. ram MUST be a numpy array of uint8/int8. This can be initialized like so: ram = np.array(ram_size,dtype=uint8) Notice: It must be ram_size where ram_size can be retrieved via the getRAMSize function. If it is None, ...
def getRAM(self,ram=None): """This function grabs the atari RAM. ram MUST be a numpy array of uint8/int8. This can be initialized like so: ram = np.array(ram_size,dtype=uint8) Notice: It must be ram_size where ram_size can be retrieved via the getRAMSize function. If it is None, ...
[ "This", "function", "grabs", "the", "atari", "RAM", ".", "ram", "MUST", "be", "a", "numpy", "array", "of", "uint8", "/", "int8", ".", "This", "can", "be", "initialized", "like", "so", ":", "ram", "=", "np", ".", "array", "(", "ram_size", "dtype", "="...
bbitmaster/ale_python_interface
python
https://github.com/bbitmaster/ale_python_interface/blob/253062be8e07fb738ea25982387b20af3712b615/ale_python_interface/ale_python_interface.py#L107-L117
[ "def", "getRAM", "(", "self", ",", "ram", "=", "None", ")", ":", "if", "(", "ram", "is", "None", ")", ":", "ram_size", "=", "ale_lib", ".", "getRAMSize", "(", "self", ".", "obj", ")", "ram", "=", "np", ".", "zeros", "(", "ram_size", ",", "dtype",...
253062be8e07fb738ea25982387b20af3712b615
train
lowstrip
Convert to lowercase and strip spaces
scripts/csvjoin.py
def lowstrip(term): """Convert to lowercase and strip spaces""" term = re.sub('\s+', ' ', term) term = term.lower() return term
def lowstrip(term): """Convert to lowercase and strip spaces""" term = re.sub('\s+', ' ', term) term = term.lower() return term
[ "Convert", "to", "lowercase", "and", "strip", "spaces" ]
gpoulter/python-ngram
python
https://github.com/gpoulter/python-ngram/blob/f8543bdc84a4d24ac60a48b36c4034f881664491/scripts/csvjoin.py#L16-L20
[ "def", "lowstrip", "(", "term", ")", ":", "term", "=", "re", ".", "sub", "(", "'\\s+'", ",", "' '", ",", "term", ")", "term", "=", "term", ".", "lower", "(", ")", "return", "term" ]
f8543bdc84a4d24ac60a48b36c4034f881664491
train
main
Perform the similarity join
scripts/csvjoin.py
def main(left_path, left_column, right_path, right_column, outfile, titles, join, minscore, count, warp): """Perform the similarity join""" right_file = csv.reader(open(right_path, 'r')) if titles: right_header = next(right_file) index = NGram((tuple(r) for r in right_file), ...
def main(left_path, left_column, right_path, right_column, outfile, titles, join, minscore, count, warp): """Perform the similarity join""" right_file = csv.reader(open(right_path, 'r')) if titles: right_header = next(right_file) index = NGram((tuple(r) for r in right_file), ...
[ "Perform", "the", "similarity", "join" ]
gpoulter/python-ngram
python
https://github.com/gpoulter/python-ngram/blob/f8543bdc84a4d24ac60a48b36c4034f881664491/scripts/csvjoin.py#L22-L46
[ "def", "main", "(", "left_path", ",", "left_column", ",", "right_path", ",", "right_column", ",", "outfile", ",", "titles", ",", "join", ",", "minscore", ",", "count", ",", "warp", ")", ":", "right_file", "=", "csv", ".", "reader", "(", "open", "(", "r...
f8543bdc84a4d24ac60a48b36c4034f881664491
train
console_main
Process command-line arguments.
scripts/csvjoin.py
def console_main(): """Process command-line arguments.""" from argparse import ArgumentParser parser = ArgumentParser(description=__doc__) parser.add_argument('-t', '--titles', action='store_true', help='input files have column titles') parser.add_argument( '-j', '--j...
def console_main(): """Process command-line arguments.""" from argparse import ArgumentParser parser = ArgumentParser(description=__doc__) parser.add_argument('-t', '--titles', action='store_true', help='input files have column titles') parser.add_argument( '-j', '--j...
[ "Process", "command", "-", "line", "arguments", "." ]
gpoulter/python-ngram
python
https://github.com/gpoulter/python-ngram/blob/f8543bdc84a4d24ac60a48b36c4034f881664491/scripts/csvjoin.py#L48-L84
[ "def", "console_main", "(", ")", ":", "from", "argparse", "import", "ArgumentParser", "parser", "=", "ArgumentParser", "(", "description", "=", "__doc__", ")", "parser", ".", "add_argument", "(", "'-t'", ",", "'--titles'", ",", "action", "=", "'store_true'", "...
f8543bdc84a4d24ac60a48b36c4034f881664491
train
NGram.copy
Return a new NGram object with the same settings, and referencing the same items. Copy is shallow in that each item is not recursively copied. Optionally specify alternate items to populate the copy. >>> from ngram import NGram >>> from copy import deepcopy >>> n = NG...
ngram.py
def copy(self, items=None): """Return a new NGram object with the same settings, and referencing the same items. Copy is shallow in that each item is not recursively copied. Optionally specify alternate items to populate the copy. >>> from ngram import NGram >>> from ...
def copy(self, items=None): """Return a new NGram object with the same settings, and referencing the same items. Copy is shallow in that each item is not recursively copied. Optionally specify alternate items to populate the copy. >>> from ngram import NGram >>> from ...
[ "Return", "a", "new", "NGram", "object", "with", "the", "same", "settings", "and", "referencing", "the", "same", "items", ".", "Copy", "is", "shallow", "in", "that", "each", "item", "is", "not", "recursively", "copied", ".", "Optionally", "specify", "alterna...
gpoulter/python-ngram
python
https://github.com/gpoulter/python-ngram/blob/f8543bdc84a4d24ac60a48b36c4034f881664491/ngram.py#L127-L148
[ "def", "copy", "(", "self", ",", "items", "=", "None", ")", ":", "return", "NGram", "(", "items", "if", "items", "is", "not", "None", "else", "self", ",", "self", ".", "threshold", ",", "self", ".", "warp", ",", "self", ".", "_key", ",", "self", ...
f8543bdc84a4d24ac60a48b36c4034f881664491
train
NGram._split
Iterates over the ngrams of a string (no padding). >>> from ngram import NGram >>> n = NGram() >>> list(n._split("hamegg")) ['ham', 'ame', 'meg', 'egg']
ngram.py
def _split(self, string): """Iterates over the ngrams of a string (no padding). >>> from ngram import NGram >>> n = NGram() >>> list(n._split("hamegg")) ['ham', 'ame', 'meg', 'egg'] """ for i in range(len(string) - self.N + 1): yield string[i:i + self...
def _split(self, string): """Iterates over the ngrams of a string (no padding). >>> from ngram import NGram >>> n = NGram() >>> list(n._split("hamegg")) ['ham', 'ame', 'meg', 'egg'] """ for i in range(len(string) - self.N + 1): yield string[i:i + self...
[ "Iterates", "over", "the", "ngrams", "of", "a", "string", "(", "no", "padding", ")", "." ]
gpoulter/python-ngram
python
https://github.com/gpoulter/python-ngram/blob/f8543bdc84a4d24ac60a48b36c4034f881664491/ngram.py#L170-L179
[ "def", "_split", "(", "self", ",", "string", ")", ":", "for", "i", "in", "range", "(", "len", "(", "string", ")", "-", "self", ".", "N", "+", "1", ")", ":", "yield", "string", "[", "i", ":", "i", "+", "self", ".", "N", "]" ]
f8543bdc84a4d24ac60a48b36c4034f881664491
train
NGram.add
Add an item to the N-gram index (if it has not already been added). >>> from ngram import NGram >>> n = NGram() >>> n.add("ham") >>> list(n) ['ham'] >>> n.add("spam") >>> sorted(list(n)) ['ham', 'spam']
ngram.py
def add(self, item): """Add an item to the N-gram index (if it has not already been added). >>> from ngram import NGram >>> n = NGram() >>> n.add("ham") >>> list(n) ['ham'] >>> n.add("spam") >>> sorted(list(n)) ['ham', 'spam'] """ ...
def add(self, item): """Add an item to the N-gram index (if it has not already been added). >>> from ngram import NGram >>> n = NGram() >>> n.add("ham") >>> list(n) ['ham'] >>> n.add("spam") >>> sorted(list(n)) ['ham', 'spam'] """ ...
[ "Add", "an", "item", "to", "the", "N", "-", "gram", "index", "(", "if", "it", "has", "not", "already", "been", "added", ")", "." ]
gpoulter/python-ngram
python
https://github.com/gpoulter/python-ngram/blob/f8543bdc84a4d24ac60a48b36c4034f881664491/ngram.py#L212-L234
[ "def", "add", "(", "self", ",", "item", ")", ":", "if", "item", "not", "in", "self", ":", "# Add the item to the base set", "super", "(", "NGram", ",", "self", ")", ".", "add", "(", "item", ")", "# Record length of padded string", "padded_item", "=", "self",...
f8543bdc84a4d24ac60a48b36c4034f881664491
train
NGram.items_sharing_ngrams
Retrieve the subset of items that share n-grams the query string. :param query: look up items that share N-grams with this string. :return: mapping from matched string to the number of shared N-grams. >>> from ngram import NGram >>> n = NGram(["ham","spam","eggs"]) >>> sorted(n...
ngram.py
def items_sharing_ngrams(self, query): """Retrieve the subset of items that share n-grams the query string. :param query: look up items that share N-grams with this string. :return: mapping from matched string to the number of shared N-grams. >>> from ngram import NGram >>> n =...
def items_sharing_ngrams(self, query): """Retrieve the subset of items that share n-grams the query string. :param query: look up items that share N-grams with this string. :return: mapping from matched string to the number of shared N-grams. >>> from ngram import NGram >>> n =...
[ "Retrieve", "the", "subset", "of", "items", "that", "share", "n", "-", "grams", "the", "query", "string", "." ]
gpoulter/python-ngram
python
https://github.com/gpoulter/python-ngram/blob/f8543bdc84a4d24ac60a48b36c4034f881664491/ngram.py#L267-L294
[ "def", "items_sharing_ngrams", "(", "self", ",", "query", ")", ":", "# From matched string to number of N-grams shared with query string", "shared", "=", "{", "}", "# Dictionary mapping n-gram to string to number of occurrences of that", "# ngram in the string that remain to be matched."...
f8543bdc84a4d24ac60a48b36c4034f881664491
train
NGram.searchitem
Search the index for items whose key exceeds the threshold similarity to the key of the given item. :return: list of pairs of (item, similarity) by decreasing similarity. >>> from ngram import NGram >>> n = NGram([(0, "SPAM"), (1, "SPAN"), (2, "EG"), ... (3, "SPANN")], key=lamb...
ngram.py
def searchitem(self, item, threshold=None): """Search the index for items whose key exceeds the threshold similarity to the key of the given item. :return: list of pairs of (item, similarity) by decreasing similarity. >>> from ngram import NGram >>> n = NGram([(0, "SPAM"), (1, ...
def searchitem(self, item, threshold=None): """Search the index for items whose key exceeds the threshold similarity to the key of the given item. :return: list of pairs of (item, similarity) by decreasing similarity. >>> from ngram import NGram >>> n = NGram([(0, "SPAM"), (1, ...
[ "Search", "the", "index", "for", "items", "whose", "key", "exceeds", "the", "threshold", "similarity", "to", "the", "key", "of", "the", "given", "item", "." ]
gpoulter/python-ngram
python
https://github.com/gpoulter/python-ngram/blob/f8543bdc84a4d24ac60a48b36c4034f881664491/ngram.py#L296-L308
[ "def", "searchitem", "(", "self", ",", "item", ",", "threshold", "=", "None", ")", ":", "return", "self", ".", "search", "(", "self", ".", "key", "(", "item", ")", ",", "threshold", ")" ]
f8543bdc84a4d24ac60a48b36c4034f881664491
train
NGram.search
Search the index for items whose key exceeds threshold similarity to the query string. :param query: returned items will have at least `threshold` \ similarity to the query string. :return: list of pairs of (item, similarity) by decreasing similarity. >>> from ngram import NGr...
ngram.py
def search(self, query, threshold=None): """Search the index for items whose key exceeds threshold similarity to the query string. :param query: returned items will have at least `threshold` \ similarity to the query string. :return: list of pairs of (item, similarity) by decre...
def search(self, query, threshold=None): """Search the index for items whose key exceeds threshold similarity to the query string. :param query: returned items will have at least `threshold` \ similarity to the query string. :return: list of pairs of (item, similarity) by decre...
[ "Search", "the", "index", "for", "items", "whose", "key", "exceeds", "threshold", "similarity", "to", "the", "query", "string", "." ]
gpoulter/python-ngram
python
https://github.com/gpoulter/python-ngram/blob/f8543bdc84a4d24ac60a48b36c4034f881664491/ngram.py#L310-L339
[ "def", "search", "(", "self", ",", "query", ",", "threshold", "=", "None", ")", ":", "threshold", "=", "threshold", "if", "threshold", "is", "not", "None", "else", "self", ".", "threshold", "results", "=", "[", "]", "# Identify possible results", "for", "m...
f8543bdc84a4d24ac60a48b36c4034f881664491
train
NGram.finditem
Return most similar item to the provided one, or None if nothing exceeds the threshold. >>> from ngram import NGram >>> n = NGram([(0, "Spam"), (1, "Ham"), (2, "Eggsy"), (3, "Egggsy")], ... key=lambda x:x[1].lower()) >>> n.finditem((3, 'Hom')) (1, 'Ham') >>> ...
ngram.py
def finditem(self, item, threshold=None): """Return most similar item to the provided one, or None if nothing exceeds the threshold. >>> from ngram import NGram >>> n = NGram([(0, "Spam"), (1, "Ham"), (2, "Eggsy"), (3, "Egggsy")], ... key=lambda x:x[1].lower()) >>> n...
def finditem(self, item, threshold=None): """Return most similar item to the provided one, or None if nothing exceeds the threshold. >>> from ngram import NGram >>> n = NGram([(0, "Spam"), (1, "Ham"), (2, "Eggsy"), (3, "Egggsy")], ... key=lambda x:x[1].lower()) >>> n...
[ "Return", "most", "similar", "item", "to", "the", "provided", "one", "or", "None", "if", "nothing", "exceeds", "the", "threshold", "." ]
gpoulter/python-ngram
python
https://github.com/gpoulter/python-ngram/blob/f8543bdc84a4d24ac60a48b36c4034f881664491/ngram.py#L341-L358
[ "def", "finditem", "(", "self", ",", "item", ",", "threshold", "=", "None", ")", ":", "results", "=", "self", ".", "searchitem", "(", "item", ",", "threshold", ")", "if", "results", ":", "return", "results", "[", "0", "]", "[", "0", "]", "else", ":...
f8543bdc84a4d24ac60a48b36c4034f881664491
train
NGram.find
Simply return the best match to the query, None on no match. >>> from ngram import NGram >>> n = NGram(["Spam","Eggs","Ham"], key=lambda x:x.lower(), N=1) >>> n.find('Hom') 'Ham' >>> n.find("Spom") 'Spam' >>> n.find("Spom", 0.8)
ngram.py
def find(self, query, threshold=None): """Simply return the best match to the query, None on no match. >>> from ngram import NGram >>> n = NGram(["Spam","Eggs","Ham"], key=lambda x:x.lower(), N=1) >>> n.find('Hom') 'Ham' >>> n.find("Spom") 'Spam' >>> n.fi...
def find(self, query, threshold=None): """Simply return the best match to the query, None on no match. >>> from ngram import NGram >>> n = NGram(["Spam","Eggs","Ham"], key=lambda x:x.lower(), N=1) >>> n.find('Hom') 'Ham' >>> n.find("Spom") 'Spam' >>> n.fi...
[ "Simply", "return", "the", "best", "match", "to", "the", "query", "None", "on", "no", "match", "." ]
gpoulter/python-ngram
python
https://github.com/gpoulter/python-ngram/blob/f8543bdc84a4d24ac60a48b36c4034f881664491/ngram.py#L360-L375
[ "def", "find", "(", "self", ",", "query", ",", "threshold", "=", "None", ")", ":", "results", "=", "self", ".", "search", "(", "query", ",", "threshold", ")", "if", "results", ":", "return", "results", "[", "0", "]", "[", "0", "]", "else", ":", "...
f8543bdc84a4d24ac60a48b36c4034f881664491
train
NGram.ngram_similarity
Similarity for two sets of n-grams. :note: ``similarity = (a**e - d**e)/a**e`` where `a` is \ "all n-grams", `d` is "different n-grams" and `e` is the warp. :param samegrams: number of n-grams shared by the two strings. :param allgrams: total of the distinct n-grams across the two str...
ngram.py
def ngram_similarity(samegrams, allgrams, warp=1.0): """Similarity for two sets of n-grams. :note: ``similarity = (a**e - d**e)/a**e`` where `a` is \ "all n-grams", `d` is "different n-grams" and `e` is the warp. :param samegrams: number of n-grams shared by the two strings. :...
def ngram_similarity(samegrams, allgrams, warp=1.0): """Similarity for two sets of n-grams. :note: ``similarity = (a**e - d**e)/a**e`` where `a` is \ "all n-grams", `d` is "different n-grams" and `e` is the warp. :param samegrams: number of n-grams shared by the two strings. :...
[ "Similarity", "for", "two", "sets", "of", "n", "-", "grams", "." ]
gpoulter/python-ngram
python
https://github.com/gpoulter/python-ngram/blob/f8543bdc84a4d24ac60a48b36c4034f881664491/ngram.py#L378-L407
[ "def", "ngram_similarity", "(", "samegrams", ",", "allgrams", ",", "warp", "=", "1.0", ")", ":", "if", "abs", "(", "warp", "-", "1.0", ")", "<", "1e-9", ":", "similarity", "=", "float", "(", "samegrams", ")", "/", "allgrams", "else", ":", "diffgrams", ...
f8543bdc84a4d24ac60a48b36c4034f881664491
train
NGram.compare
Compares two strings and returns their similarity. :param s1: first string :param s2: second string :param kwargs: additional keyword arguments passed to __init__. :return: similarity between 0.0 and 1.0. >>> from ngram import NGram >>> NGram.compare('spa', 'spam') ...
ngram.py
def compare(s1, s2, **kwargs): """Compares two strings and returns their similarity. :param s1: first string :param s2: second string :param kwargs: additional keyword arguments passed to __init__. :return: similarity between 0.0 and 1.0. >>> from ngram import NGram ...
def compare(s1, s2, **kwargs): """Compares two strings and returns their similarity. :param s1: first string :param s2: second string :param kwargs: additional keyword arguments passed to __init__. :return: similarity between 0.0 and 1.0. >>> from ngram import NGram ...
[ "Compares", "two", "strings", "and", "returns", "their", "similarity", "." ]
gpoulter/python-ngram
python
https://github.com/gpoulter/python-ngram/blob/f8543bdc84a4d24ac60a48b36c4034f881664491/ngram.py#L410-L435
[ "def", "compare", "(", "s1", ",", "s2", ",", "*", "*", "kwargs", ")", ":", "if", "s1", "is", "None", "or", "s2", "is", "None", ":", "if", "s1", "==", "s2", ":", "return", "1.0", "return", "0.0", "try", ":", "return", "NGram", "(", "[", "s1", ...
f8543bdc84a4d24ac60a48b36c4034f881664491
train
NGram.clear
Remove all elements from this set. >>> from ngram import NGram >>> n = NGram(['spam', 'eggs']) >>> sorted(list(n)) ['eggs', 'spam'] >>> n.clear() >>> list(n) []
ngram.py
def clear(self): """Remove all elements from this set. >>> from ngram import NGram >>> n = NGram(['spam', 'eggs']) >>> sorted(list(n)) ['eggs', 'spam'] >>> n.clear() >>> list(n) [] """ super(NGram, self).clear() self._grams = {} ...
def clear(self): """Remove all elements from this set. >>> from ngram import NGram >>> n = NGram(['spam', 'eggs']) >>> sorted(list(n)) ['eggs', 'spam'] >>> n.clear() >>> list(n) [] """ super(NGram, self).clear() self._grams = {} ...
[ "Remove", "all", "elements", "from", "this", "set", "." ]
gpoulter/python-ngram
python
https://github.com/gpoulter/python-ngram/blob/f8543bdc84a4d24ac60a48b36c4034f881664491/ngram.py#L466-L479
[ "def", "clear", "(", "self", ")", ":", "super", "(", "NGram", ",", "self", ")", ".", "clear", "(", ")", "self", ".", "_grams", "=", "{", "}", "self", ".", "length", "=", "{", "}" ]
f8543bdc84a4d24ac60a48b36c4034f881664491
train
NGram.union
Return the union of two or more sets as a new set. >>> from ngram import NGram >>> a = NGram(['spam', 'eggs']) >>> b = NGram(['spam', 'ham']) >>> sorted(list(a.union(b))) ['eggs', 'ham', 'spam']
ngram.py
def union(self, *others): """Return the union of two or more sets as a new set. >>> from ngram import NGram >>> a = NGram(['spam', 'eggs']) >>> b = NGram(['spam', 'ham']) >>> sorted(list(a.union(b))) ['eggs', 'ham', 'spam'] """ return self.copy(super(NGra...
def union(self, *others): """Return the union of two or more sets as a new set. >>> from ngram import NGram >>> a = NGram(['spam', 'eggs']) >>> b = NGram(['spam', 'ham']) >>> sorted(list(a.union(b))) ['eggs', 'ham', 'spam'] """ return self.copy(super(NGra...
[ "Return", "the", "union", "of", "two", "or", "more", "sets", "as", "a", "new", "set", "." ]
gpoulter/python-ngram
python
https://github.com/gpoulter/python-ngram/blob/f8543bdc84a4d24ac60a48b36c4034f881664491/ngram.py#L481-L490
[ "def", "union", "(", "self", ",", "*", "others", ")", ":", "return", "self", ".", "copy", "(", "super", "(", "NGram", ",", "self", ")", ".", "union", "(", "*", "others", ")", ")" ]
f8543bdc84a4d24ac60a48b36c4034f881664491
train
NGram.difference
Return the difference of two or more sets as a new set. >>> from ngram import NGram >>> a = NGram(['spam', 'eggs']) >>> b = NGram(['spam', 'ham']) >>> list(a.difference(b)) ['eggs']
ngram.py
def difference(self, *others): """Return the difference of two or more sets as a new set. >>> from ngram import NGram >>> a = NGram(['spam', 'eggs']) >>> b = NGram(['spam', 'ham']) >>> list(a.difference(b)) ['eggs'] """ return self.copy(super(NGram, self)...
def difference(self, *others): """Return the difference of two or more sets as a new set. >>> from ngram import NGram >>> a = NGram(['spam', 'eggs']) >>> b = NGram(['spam', 'ham']) >>> list(a.difference(b)) ['eggs'] """ return self.copy(super(NGram, self)...
[ "Return", "the", "difference", "of", "two", "or", "more", "sets", "as", "a", "new", "set", "." ]
gpoulter/python-ngram
python
https://github.com/gpoulter/python-ngram/blob/f8543bdc84a4d24ac60a48b36c4034f881664491/ngram.py#L492-L501
[ "def", "difference", "(", "self", ",", "*", "others", ")", ":", "return", "self", ".", "copy", "(", "super", "(", "NGram", ",", "self", ")", ".", "difference", "(", "*", "others", ")", ")" ]
f8543bdc84a4d24ac60a48b36c4034f881664491
train
NGram.intersection
Return the intersection of two or more sets as a new set. >>> from ngram import NGram >>> a = NGram(['spam', 'eggs']) >>> b = NGram(['spam', 'ham']) >>> list(a.intersection(b)) ['spam']
ngram.py
def intersection(self, *others): """Return the intersection of two or more sets as a new set. >>> from ngram import NGram >>> a = NGram(['spam', 'eggs']) >>> b = NGram(['spam', 'ham']) >>> list(a.intersection(b)) ['spam'] """ return self.copy(super(NGram,...
def intersection(self, *others): """Return the intersection of two or more sets as a new set. >>> from ngram import NGram >>> a = NGram(['spam', 'eggs']) >>> b = NGram(['spam', 'ham']) >>> list(a.intersection(b)) ['spam'] """ return self.copy(super(NGram,...
[ "Return", "the", "intersection", "of", "two", "or", "more", "sets", "as", "a", "new", "set", "." ]
gpoulter/python-ngram
python
https://github.com/gpoulter/python-ngram/blob/f8543bdc84a4d24ac60a48b36c4034f881664491/ngram.py#L516-L525
[ "def", "intersection", "(", "self", ",", "*", "others", ")", ":", "return", "self", ".", "copy", "(", "super", "(", "NGram", ",", "self", ")", ".", "intersection", "(", "*", "others", ")", ")" ]
f8543bdc84a4d24ac60a48b36c4034f881664491
train
NGram.intersection_update
Update the set with the intersection of itself and other sets. >>> from ngram import NGram >>> n = NGram(['spam', 'eggs']) >>> other = set(['spam', 'ham']) >>> n.intersection_update(other) >>> list(n) ['spam']
ngram.py
def intersection_update(self, *others): """Update the set with the intersection of itself and other sets. >>> from ngram import NGram >>> n = NGram(['spam', 'eggs']) >>> other = set(['spam', 'ham']) >>> n.intersection_update(other) >>> list(n) ['spam'] ""...
def intersection_update(self, *others): """Update the set with the intersection of itself and other sets. >>> from ngram import NGram >>> n = NGram(['spam', 'eggs']) >>> other = set(['spam', 'ham']) >>> n.intersection_update(other) >>> list(n) ['spam'] ""...
[ "Update", "the", "set", "with", "the", "intersection", "of", "itself", "and", "other", "sets", "." ]
gpoulter/python-ngram
python
https://github.com/gpoulter/python-ngram/blob/f8543bdc84a4d24ac60a48b36c4034f881664491/ngram.py#L527-L537
[ "def", "intersection_update", "(", "self", ",", "*", "others", ")", ":", "self", ".", "difference_update", "(", "super", "(", "NGram", ",", "self", ")", ".", "difference", "(", "*", "others", ")", ")" ]
f8543bdc84a4d24ac60a48b36c4034f881664491
train
NGram.symmetric_difference
Return the symmetric difference of two sets as a new set. >>> from ngram import NGram >>> a = NGram(['spam', 'eggs']) >>> b = NGram(['spam', 'ham']) >>> sorted(list(a.symmetric_difference(b))) ['eggs', 'ham']
ngram.py
def symmetric_difference(self, other): """Return the symmetric difference of two sets as a new set. >>> from ngram import NGram >>> a = NGram(['spam', 'eggs']) >>> b = NGram(['spam', 'ham']) >>> sorted(list(a.symmetric_difference(b))) ['eggs', 'ham'] """ ...
def symmetric_difference(self, other): """Return the symmetric difference of two sets as a new set. >>> from ngram import NGram >>> a = NGram(['spam', 'eggs']) >>> b = NGram(['spam', 'ham']) >>> sorted(list(a.symmetric_difference(b))) ['eggs', 'ham'] """ ...
[ "Return", "the", "symmetric", "difference", "of", "two", "sets", "as", "a", "new", "set", "." ]
gpoulter/python-ngram
python
https://github.com/gpoulter/python-ngram/blob/f8543bdc84a4d24ac60a48b36c4034f881664491/ngram.py#L539-L548
[ "def", "symmetric_difference", "(", "self", ",", "other", ")", ":", "return", "self", ".", "copy", "(", "super", "(", "NGram", ",", "self", ")", ".", "symmetric_difference", "(", "other", ")", ")" ]
f8543bdc84a4d24ac60a48b36c4034f881664491
train
NGram.symmetric_difference_update
Update the set with the symmetric difference of itself and `other`. >>> from ngram import NGram >>> n = NGram(['spam', 'eggs']) >>> other = set(['spam', 'ham']) >>> n.symmetric_difference_update(other) >>> sorted(list(n)) ['eggs', 'ham']
ngram.py
def symmetric_difference_update(self, other): """Update the set with the symmetric difference of itself and `other`. >>> from ngram import NGram >>> n = NGram(['spam', 'eggs']) >>> other = set(['spam', 'ham']) >>> n.symmetric_difference_update(other) >>> sorted(list(n)) ...
def symmetric_difference_update(self, other): """Update the set with the symmetric difference of itself and `other`. >>> from ngram import NGram >>> n = NGram(['spam', 'eggs']) >>> other = set(['spam', 'ham']) >>> n.symmetric_difference_update(other) >>> sorted(list(n)) ...
[ "Update", "the", "set", "with", "the", "symmetric", "difference", "of", "itself", "and", "other", "." ]
gpoulter/python-ngram
python
https://github.com/gpoulter/python-ngram/blob/f8543bdc84a4d24ac60a48b36c4034f881664491/ngram.py#L550-L562
[ "def", "symmetric_difference_update", "(", "self", ",", "other", ")", ":", "intersection", "=", "super", "(", "NGram", ",", "self", ")", ".", "intersection", "(", "other", ")", "self", ".", "update", "(", "other", ")", "# add items present in other", "self", ...
f8543bdc84a4d24ac60a48b36c4034f881664491
train
sub
Subtract the arg from the value.
mathfilters/templatetags/mathfilters.py
def sub(value, arg): """Subtract the arg from the value.""" try: nvalue, narg = handle_float_decimal_combinations( valid_numeric(value), valid_numeric(arg), '-') return nvalue - narg except (ValueError, TypeError): try: return value - arg except Except...
def sub(value, arg): """Subtract the arg from the value.""" try: nvalue, narg = handle_float_decimal_combinations( valid_numeric(value), valid_numeric(arg), '-') return nvalue - narg except (ValueError, TypeError): try: return value - arg except Except...
[ "Subtract", "the", "arg", "from", "the", "value", "." ]
dbrgn/django-mathfilters
python
https://github.com/dbrgn/django-mathfilters/blob/7f22f98e906d46bee487ce2d78fb995f74c1d568/mathfilters/templatetags/mathfilters.py#L37-L47
[ "def", "sub", "(", "value", ",", "arg", ")", ":", "try", ":", "nvalue", ",", "narg", "=", "handle_float_decimal_combinations", "(", "valid_numeric", "(", "value", ")", ",", "valid_numeric", "(", "arg", ")", ",", "'-'", ")", "return", "nvalue", "-", "narg...
7f22f98e906d46bee487ce2d78fb995f74c1d568
train
absolute
Return the absolute value.
mathfilters/templatetags/mathfilters.py
def absolute(value): """Return the absolute value.""" try: return abs(valid_numeric(value)) except (ValueError, TypeError): try: return abs(value) except Exception: return ''
def absolute(value): """Return the absolute value.""" try: return abs(valid_numeric(value)) except (ValueError, TypeError): try: return abs(value) except Exception: return ''
[ "Return", "the", "absolute", "value", "." ]
dbrgn/django-mathfilters
python
https://github.com/dbrgn/django-mathfilters/blob/7f22f98e906d46bee487ce2d78fb995f74c1d568/mathfilters/templatetags/mathfilters.py#L97-L105
[ "def", "absolute", "(", "value", ")", ":", "try", ":", "return", "abs", "(", "valid_numeric", "(", "value", ")", ")", "except", "(", "ValueError", ",", "TypeError", ")", ":", "try", ":", "return", "abs", "(", "value", ")", "except", "Exception", ":", ...
7f22f98e906d46bee487ce2d78fb995f74c1d568
train
cli
Create the cli command line.
pbs.py
def cli(config, server, api_key, all, credentials, project): """Create the cli command line.""" # Check first for the pybossa.rc file to configure server and api-key home = expanduser("~") if os.path.isfile(os.path.join(home, '.pybossa.cfg')): config.parser.read(os.path.join(home, '.pybossa.cfg'...
def cli(config, server, api_key, all, credentials, project): """Create the cli command line.""" # Check first for the pybossa.rc file to configure server and api-key home = expanduser("~") if os.path.isfile(os.path.join(home, '.pybossa.cfg')): config.parser.read(os.path.join(home, '.pybossa.cfg'...
[ "Create", "the", "cli", "command", "line", "." ]
Scifabric/pbs
python
https://github.com/Scifabric/pbs/blob/3e5d5f3f0f5d20f740eaacc4d6e872a0c9fb8b38/pbs.py#L65-L109
[ "def", "cli", "(", "config", ",", "server", ",", "api_key", ",", "all", ",", "credentials", ",", "project", ")", ":", "# Check first for the pybossa.rc file to configure server and api-key", "home", "=", "expanduser", "(", "\"~\"", ")", "if", "os", ".", "path", ...
3e5d5f3f0f5d20f740eaacc4d6e872a0c9fb8b38
train
version
Show pbs version.
pbs.py
def version(): """Show pbs version.""" try: import pkg_resources click.echo(pkg_resources.get_distribution('pybossa-pbs').version) except ImportError: click.echo("pybossa-pbs package not found!")
def version(): """Show pbs version.""" try: import pkg_resources click.echo(pkg_resources.get_distribution('pybossa-pbs').version) except ImportError: click.echo("pybossa-pbs package not found!")
[ "Show", "pbs", "version", "." ]
Scifabric/pbs
python
https://github.com/Scifabric/pbs/blob/3e5d5f3f0f5d20f740eaacc4d6e872a0c9fb8b38/pbs.py#L113-L119
[ "def", "version", "(", ")", ":", "try", ":", "import", "pkg_resources", "click", ".", "echo", "(", "pkg_resources", ".", "get_distribution", "(", "'pybossa-pbs'", ")", ".", "version", ")", "except", "ImportError", ":", "click", ".", "echo", "(", "\"pybossa-p...
3e5d5f3f0f5d20f740eaacc4d6e872a0c9fb8b38
train
update_project
Update project templates and information.
pbs.py
def update_project(config, task_presenter, results, long_description, tutorial, watch): # pragma: no cover """Update project templates and information.""" if watch: res = _update_project_watch(config, task_presenter, results, long_description, tutor...
def update_project(config, task_presenter, results, long_description, tutorial, watch): # pragma: no cover """Update project templates and information.""" if watch: res = _update_project_watch(config, task_presenter, results, long_description, tutor...
[ "Update", "project", "templates", "and", "information", "." ]
Scifabric/pbs
python
https://github.com/Scifabric/pbs/blob/3e5d5f3f0f5d20f740eaacc4d6e872a0c9fb8b38/pbs.py#L141-L150
[ "def", "update_project", "(", "config", ",", "task_presenter", ",", "results", ",", "long_description", ",", "tutorial", ",", "watch", ")", ":", "# pragma: no cover", "if", "watch", ":", "res", "=", "_update_project_watch", "(", "config", ",", "task_presenter", ...
3e5d5f3f0f5d20f740eaacc4d6e872a0c9fb8b38
train
add_tasks
Add tasks to a project.
pbs.py
def add_tasks(config, tasks_file, tasks_type, priority, redundancy): """Add tasks to a project.""" res = _add_tasks(config, tasks_file, tasks_type, priority, redundancy) click.echo(res)
def add_tasks(config, tasks_file, tasks_type, priority, redundancy): """Add tasks to a project.""" res = _add_tasks(config, tasks_file, tasks_type, priority, redundancy) click.echo(res)
[ "Add", "tasks", "to", "a", "project", "." ]
Scifabric/pbs
python
https://github.com/Scifabric/pbs/blob/3e5d5f3f0f5d20f740eaacc4d6e872a0c9fb8b38/pbs.py#L162-L165
[ "def", "add_tasks", "(", "config", ",", "tasks_file", ",", "tasks_type", ",", "priority", ",", "redundancy", ")", ":", "res", "=", "_add_tasks", "(", "config", ",", "tasks_file", ",", "tasks_type", ",", "priority", ",", "redundancy", ")", "click", ".", "ec...
3e5d5f3f0f5d20f740eaacc4d6e872a0c9fb8b38
train
add_helpingmaterials
Add helping materials to a project.
pbs.py
def add_helpingmaterials(config, helping_materials_file, helping_type): """Add helping materials to a project.""" res = _add_helpingmaterials(config, helping_materials_file, helping_type) click.echo(res)
def add_helpingmaterials(config, helping_materials_file, helping_type): """Add helping materials to a project.""" res = _add_helpingmaterials(config, helping_materials_file, helping_type) click.echo(res)
[ "Add", "helping", "materials", "to", "a", "project", "." ]
Scifabric/pbs
python
https://github.com/Scifabric/pbs/blob/3e5d5f3f0f5d20f740eaacc4d6e872a0c9fb8b38/pbs.py#L175-L178
[ "def", "add_helpingmaterials", "(", "config", ",", "helping_materials_file", ",", "helping_type", ")", ":", "res", "=", "_add_helpingmaterials", "(", "config", ",", "helping_materials_file", ",", "helping_type", ")", "click", ".", "echo", "(", "res", ")" ]
3e5d5f3f0f5d20f740eaacc4d6e872a0c9fb8b38
train
delete_tasks
Delete tasks from a project.
pbs.py
def delete_tasks(config, task_id): """Delete tasks from a project.""" if task_id is None: msg = ("Are you sure you want to delete all the tasks and associated task runs?") if click.confirm(msg): res = _delete_tasks(config, task_id) click.echo(res) else: ...
def delete_tasks(config, task_id): """Delete tasks from a project.""" if task_id is None: msg = ("Are you sure you want to delete all the tasks and associated task runs?") if click.confirm(msg): res = _delete_tasks(config, task_id) click.echo(res) else: ...
[ "Delete", "tasks", "from", "a", "project", "." ]
Scifabric/pbs
python
https://github.com/Scifabric/pbs/blob/3e5d5f3f0f5d20f740eaacc4d6e872a0c9fb8b38/pbs.py#L184-L196
[ "def", "delete_tasks", "(", "config", ",", "task_id", ")", ":", "if", "task_id", "is", "None", ":", "msg", "=", "(", "\"Are you sure you want to delete all the tasks and associated task runs?\"", ")", "if", "click", ".", "confirm", "(", "msg", ")", ":", "res", "...
3e5d5f3f0f5d20f740eaacc4d6e872a0c9fb8b38
train
update_task_redundancy
Update task redudancy for a project.
pbs.py
def update_task_redundancy(config, task_id, redundancy): """Update task redudancy for a project.""" if task_id is None: msg = ("Are you sure you want to update all the tasks redundancy?") if click.confirm(msg): res = _update_tasks_redundancy(config, task_id, redundancy) c...
def update_task_redundancy(config, task_id, redundancy): """Update task redudancy for a project.""" if task_id is None: msg = ("Are you sure you want to update all the tasks redundancy?") if click.confirm(msg): res = _update_tasks_redundancy(config, task_id, redundancy) c...
[ "Update", "task", "redudancy", "for", "a", "project", "." ]
Scifabric/pbs
python
https://github.com/Scifabric/pbs/blob/3e5d5f3f0f5d20f740eaacc4d6e872a0c9fb8b38/pbs.py#L202-L214
[ "def", "update_task_redundancy", "(", "config", ",", "task_id", ",", "redundancy", ")", ":", "if", "task_id", "is", "None", ":", "msg", "=", "(", "\"Are you sure you want to update all the tasks redundancy?\"", ")", "if", "click", ".", "confirm", "(", "msg", ")", ...
3e5d5f3f0f5d20f740eaacc4d6e872a0c9fb8b38
train
_create_project
Create a project in a PyBossa server.
helpers.py
def _create_project(config): """Create a project in a PyBossa server.""" try: response = config.pbclient.create_project(config.project['name'], config.project['short_name'], config.project['description'])...
def _create_project(config): """Create a project in a PyBossa server.""" try: response = config.pbclient.create_project(config.project['name'], config.project['short_name'], config.project['description'])...
[ "Create", "a", "project", "in", "a", "PyBossa", "server", "." ]
Scifabric/pbs
python
https://github.com/Scifabric/pbs/blob/3e5d5f3f0f5d20f740eaacc4d6e872a0c9fb8b38/helpers.py#L57-L68
[ "def", "_create_project", "(", "config", ")", ":", "try", ":", "response", "=", "config", ".", "pbclient", ".", "create_project", "(", "config", ".", "project", "[", "'name'", "]", ",", "config", ".", "project", "[", "'short_name'", "]", ",", "config", "...
3e5d5f3f0f5d20f740eaacc4d6e872a0c9fb8b38
train
_update_project_watch
Update a project in a loop.
helpers.py
def _update_project_watch(config, task_presenter, results, long_description, tutorial): # pragma: no cover """Update a project in a loop.""" logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(message)s', datefmt='%Y-%m-%d %H...
def _update_project_watch(config, task_presenter, results, long_description, tutorial): # pragma: no cover """Update a project in a loop.""" logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(message)s', datefmt='%Y-%m-%d %H...
[ "Update", "a", "project", "in", "a", "loop", "." ]
Scifabric/pbs
python
https://github.com/Scifabric/pbs/blob/3e5d5f3f0f5d20f740eaacc4d6e872a0c9fb8b38/helpers.py#L70-L88
[ "def", "_update_project_watch", "(", "config", ",", "task_presenter", ",", "results", ",", "long_description", ",", "tutorial", ")", ":", "# pragma: no cover", "logging", ".", "basicConfig", "(", "level", "=", "logging", ".", "INFO", ",", "format", "=", "'%(asct...
3e5d5f3f0f5d20f740eaacc4d6e872a0c9fb8b38
train
_update_task_presenter_bundle_js
Append to template a distribution bundle js.
helpers.py
def _update_task_presenter_bundle_js(project): """Append to template a distribution bundle js.""" if os.path.isfile ('bundle.min.js'): with open('bundle.min.js') as f: js = f.read() project.info['task_presenter'] += "<script>\n%s\n</script>" % js return if os.path.isfile...
def _update_task_presenter_bundle_js(project): """Append to template a distribution bundle js.""" if os.path.isfile ('bundle.min.js'): with open('bundle.min.js') as f: js = f.read() project.info['task_presenter'] += "<script>\n%s\n</script>" % js return if os.path.isfile...
[ "Append", "to", "template", "a", "distribution", "bundle", "js", "." ]
Scifabric/pbs
python
https://github.com/Scifabric/pbs/blob/3e5d5f3f0f5d20f740eaacc4d6e872a0c9fb8b38/helpers.py#L90-L101
[ "def", "_update_task_presenter_bundle_js", "(", "project", ")", ":", "if", "os", ".", "path", ".", "isfile", "(", "'bundle.min.js'", ")", ":", "with", "open", "(", "'bundle.min.js'", ")", "as", "f", ":", "js", "=", "f", ".", "read", "(", ")", "project", ...
3e5d5f3f0f5d20f740eaacc4d6e872a0c9fb8b38
train
_update_project
Update a project.
helpers.py
def _update_project(config, task_presenter, results, long_description, tutorial): """Update a project.""" try: # Get project project = find_project_by_short_name(config.project['short_name'], config.pbclient, ...
def _update_project(config, task_presenter, results, long_description, tutorial): """Update a project.""" try: # Get project project = find_project_by_short_name(config.project['short_name'], config.pbclient, ...
[ "Update", "a", "project", "." ]
Scifabric/pbs
python
https://github.com/Scifabric/pbs/blob/3e5d5f3f0f5d20f740eaacc4d6e872a0c9fb8b38/helpers.py#L103-L138
[ "def", "_update_project", "(", "config", ",", "task_presenter", ",", "results", ",", "long_description", ",", "tutorial", ")", ":", "try", ":", "# Get project", "project", "=", "find_project_by_short_name", "(", "config", ".", "project", "[", "'short_name'", "]", ...
3e5d5f3f0f5d20f740eaacc4d6e872a0c9fb8b38
train
_load_data
Load data from CSV, JSON, Excel, ..., formats.
helpers.py
def _load_data(data_file, data_type): """Load data from CSV, JSON, Excel, ..., formats.""" raw_data = data_file.read() if data_type is None: data_type = data_file.name.split('.')[-1] # Data list to process data = [] # JSON type if data_type == 'json': data = json.loads(raw_da...
def _load_data(data_file, data_type): """Load data from CSV, JSON, Excel, ..., formats.""" raw_data = data_file.read() if data_type is None: data_type = data_file.name.split('.')[-1] # Data list to process data = [] # JSON type if data_type == 'json': data = json.loads(raw_da...
[ "Load", "data", "from", "CSV", "JSON", "Excel", "...", "formats", "." ]
Scifabric/pbs
python
https://github.com/Scifabric/pbs/blob/3e5d5f3f0f5d20f740eaacc4d6e872a0c9fb8b38/helpers.py#L141-L194
[ "def", "_load_data", "(", "data_file", ",", "data_type", ")", ":", "raw_data", "=", "data_file", ".", "read", "(", ")", "if", "data_type", "is", "None", ":", "data_type", "=", "data_file", ".", "name", ".", "split", "(", "'.'", ")", "[", "-", "1", "]...
3e5d5f3f0f5d20f740eaacc4d6e872a0c9fb8b38
train
_add_tasks
Add tasks to a project.
helpers.py
def _add_tasks(config, tasks_file, tasks_type, priority, redundancy): """Add tasks to a project.""" try: project = find_project_by_short_name(config.project['short_name'], config.pbclient, config.all) data ...
def _add_tasks(config, tasks_file, tasks_type, priority, redundancy): """Add tasks to a project.""" try: project = find_project_by_short_name(config.project['short_name'], config.pbclient, config.all) data ...
[ "Add", "tasks", "to", "a", "project", "." ]
Scifabric/pbs
python
https://github.com/Scifabric/pbs/blob/3e5d5f3f0f5d20f740eaacc4d6e872a0c9fb8b38/helpers.py#L197-L230
[ "def", "_add_tasks", "(", "config", ",", "tasks_file", ",", "tasks_type", ",", "priority", ",", "redundancy", ")", ":", "try", ":", "project", "=", "find_project_by_short_name", "(", "config", ".", "project", "[", "'short_name'", "]", ",", "config", ".", "pb...
3e5d5f3f0f5d20f740eaacc4d6e872a0c9fb8b38
train
_add_helpingmaterials
Add helping materials to a project.
helpers.py
def _add_helpingmaterials(config, helping_file, helping_type): """Add helping materials to a project.""" try: project = find_project_by_short_name(config.project['short_name'], config.pbclient, config.all) ...
def _add_helpingmaterials(config, helping_file, helping_type): """Add helping materials to a project.""" try: project = find_project_by_short_name(config.project['short_name'], config.pbclient, config.all) ...
[ "Add", "helping", "materials", "to", "a", "project", "." ]
Scifabric/pbs
python
https://github.com/Scifabric/pbs/blob/3e5d5f3f0f5d20f740eaacc4d6e872a0c9fb8b38/helpers.py#L233-L277
[ "def", "_add_helpingmaterials", "(", "config", ",", "helping_file", ",", "helping_type", ")", ":", "try", ":", "project", "=", "find_project_by_short_name", "(", "config", ".", "project", "[", "'short_name'", "]", ",", "config", ".", "pbclient", ",", "config", ...
3e5d5f3f0f5d20f740eaacc4d6e872a0c9fb8b38
train
_delete_tasks
Delete tasks from a project.
helpers.py
def _delete_tasks(config, task_id, limit=100, offset=0): """Delete tasks from a project.""" try: project = find_project_by_short_name(config.project['short_name'], config.pbclient, config.all) if task_id: ...
def _delete_tasks(config, task_id, limit=100, offset=0): """Delete tasks from a project.""" try: project = find_project_by_short_name(config.project['short_name'], config.pbclient, config.all) if task_id: ...
[ "Delete", "tasks", "from", "a", "project", "." ]
Scifabric/pbs
python
https://github.com/Scifabric/pbs/blob/3e5d5f3f0f5d20f740eaacc4d6e872a0c9fb8b38/helpers.py#L281-L305
[ "def", "_delete_tasks", "(", "config", ",", "task_id", ",", "limit", "=", "100", ",", "offset", "=", "0", ")", ":", "try", ":", "project", "=", "find_project_by_short_name", "(", "config", ".", "project", "[", "'short_name'", "]", ",", "config", ".", "pb...
3e5d5f3f0f5d20f740eaacc4d6e872a0c9fb8b38
train
_update_tasks_redundancy
Update tasks redundancy from a project.
helpers.py
def _update_tasks_redundancy(config, task_id, redundancy, limit=300, offset=0): """Update tasks redundancy from a project.""" try: project = find_project_by_short_name(config.project['short_name'], config.pbclient, ...
def _update_tasks_redundancy(config, task_id, redundancy, limit=300, offset=0): """Update tasks redundancy from a project.""" try: project = find_project_by_short_name(config.project['short_name'], config.pbclient, ...
[ "Update", "tasks", "redundancy", "from", "a", "project", "." ]
Scifabric/pbs
python
https://github.com/Scifabric/pbs/blob/3e5d5f3f0f5d20f740eaacc4d6e872a0c9fb8b38/helpers.py#L308-L345
[ "def", "_update_tasks_redundancy", "(", "config", ",", "task_id", ",", "redundancy", ",", "limit", "=", "300", ",", "offset", "=", "0", ")", ":", "try", ":", "project", "=", "find_project_by_short_name", "(", "config", ".", "project", "[", "'short_name'", "]...
3e5d5f3f0f5d20f740eaacc4d6e872a0c9fb8b38
train
find_project_by_short_name
Return project by short_name.
helpers.py
def find_project_by_short_name(short_name, pbclient, all=None): """Return project by short_name.""" try: response = pbclient.find_project(short_name=short_name, all=all) check_api_error(response) if (len(response) == 0): msg = '%s not found! You can use the all=1 argument to ...
def find_project_by_short_name(short_name, pbclient, all=None): """Return project by short_name.""" try: response = pbclient.find_project(short_name=short_name, all=all) check_api_error(response) if (len(response) == 0): msg = '%s not found! You can use the all=1 argument to ...
[ "Return", "project", "by", "short_name", "." ]
Scifabric/pbs
python
https://github.com/Scifabric/pbs/blob/3e5d5f3f0f5d20f740eaacc4d6e872a0c9fb8b38/helpers.py#L348-L362
[ "def", "find_project_by_short_name", "(", "short_name", ",", "pbclient", ",", "all", "=", "None", ")", ":", "try", ":", "response", "=", "pbclient", ".", "find_project", "(", "short_name", "=", "short_name", ",", "all", "=", "all", ")", "check_api_error", "(...
3e5d5f3f0f5d20f740eaacc4d6e872a0c9fb8b38
train
check_api_error
Check if returned API response contains an error.
helpers.py
def check_api_error(api_response): print(api_response) """Check if returned API response contains an error.""" if type(api_response) == dict and 'code' in api_response and api_response['code'] <> 200: print("Server response code: %s" % api_response['code']) print("Server response: %s...
def check_api_error(api_response): print(api_response) """Check if returned API response contains an error.""" if type(api_response) == dict and 'code' in api_response and api_response['code'] <> 200: print("Server response code: %s" % api_response['code']) print("Server response: %s...
[ "Check", "if", "returned", "API", "response", "contains", "an", "error", "." ]
Scifabric/pbs
python
https://github.com/Scifabric/pbs/blob/3e5d5f3f0f5d20f740eaacc4d6e872a0c9fb8b38/helpers.py#L365-L388
[ "def", "check_api_error", "(", "api_response", ")", ":", "print", "(", "api_response", ")", "if", "type", "(", "api_response", ")", "==", "dict", "and", "'code'", "in", "api_response", "and", "api_response", "[", "'code'", "]", "<>", "200", ":", "print", "...
3e5d5f3f0f5d20f740eaacc4d6e872a0c9fb8b38
train
format_error
Format the error for the given module.
helpers.py
def format_error(module, error): """Format the error for the given module.""" logging.error(module) # Beautify JSON error print error.message print json.dumps(error.error, sort_keys=True, indent=4, separators=(',', ': ')) exit(1)
def format_error(module, error): """Format the error for the given module.""" logging.error(module) # Beautify JSON error print error.message print json.dumps(error.error, sort_keys=True, indent=4, separators=(',', ': ')) exit(1)
[ "Format", "the", "error", "for", "the", "given", "module", "." ]
Scifabric/pbs
python
https://github.com/Scifabric/pbs/blob/3e5d5f3f0f5d20f740eaacc4d6e872a0c9fb8b38/helpers.py#L391-L397
[ "def", "format_error", "(", "module", ",", "error", ")", ":", "logging", ".", "error", "(", "module", ")", "# Beautify JSON error", "print", "error", ".", "message", "print", "json", ".", "dumps", "(", "error", ".", "error", ",", "sort_keys", "=", "True", ...
3e5d5f3f0f5d20f740eaacc4d6e872a0c9fb8b38
train
create_task_info
Create task_info field.
helpers.py
def create_task_info(task): """Create task_info field.""" task_info = None if task.get('info'): task_info = task['info'] else: task_info = task return task_info
def create_task_info(task): """Create task_info field.""" task_info = None if task.get('info'): task_info = task['info'] else: task_info = task return task_info
[ "Create", "task_info", "field", "." ]
Scifabric/pbs
python
https://github.com/Scifabric/pbs/blob/3e5d5f3f0f5d20f740eaacc4d6e872a0c9fb8b38/helpers.py#L400-L407
[ "def", "create_task_info", "(", "task", ")", ":", "task_info", "=", "None", "if", "task", ".", "get", "(", "'info'", ")", ":", "task_info", "=", "task", "[", "'info'", "]", "else", ":", "task_info", "=", "task", "return", "task_info" ]
3e5d5f3f0f5d20f740eaacc4d6e872a0c9fb8b38
train
create_helping_material_info
Create helping_material_info field.
helpers.py
def create_helping_material_info(helping): """Create helping_material_info field.""" helping_info = None file_path = None if helping.get('info'): helping_info = helping['info'] else: helping_info = helping if helping_info.get('file_path'): file_path = helping_info.get('fi...
def create_helping_material_info(helping): """Create helping_material_info field.""" helping_info = None file_path = None if helping.get('info'): helping_info = helping['info'] else: helping_info = helping if helping_info.get('file_path'): file_path = helping_info.get('fi...
[ "Create", "helping_material_info", "field", "." ]
Scifabric/pbs
python
https://github.com/Scifabric/pbs/blob/3e5d5f3f0f5d20f740eaacc4d6e872a0c9fb8b38/helpers.py#L410-L421
[ "def", "create_helping_material_info", "(", "helping", ")", ":", "helping_info", "=", "None", "file_path", "=", "None", "if", "helping", ".", "get", "(", "'info'", ")", ":", "helping_info", "=", "helping", "[", "'info'", "]", "else", ":", "helping_info", "="...
3e5d5f3f0f5d20f740eaacc4d6e872a0c9fb8b38
train
TokenStore.fetch_by_code
Returns data belonging to an authorization code from redis or ``None`` if no data was found. See :class:`oauth2.store.AuthCodeStore`.
oauth2/store/redisdb.py
def fetch_by_code(self, code): """ Returns data belonging to an authorization code from redis or ``None`` if no data was found. See :class:`oauth2.store.AuthCodeStore`. """ code_data = self.read(code) if code_data is None: raise AuthCodeNotFound ...
def fetch_by_code(self, code): """ Returns data belonging to an authorization code from redis or ``None`` if no data was found. See :class:`oauth2.store.AuthCodeStore`. """ code_data = self.read(code) if code_data is None: raise AuthCodeNotFound ...
[ "Returns", "data", "belonging", "to", "an", "authorization", "code", "from", "redis", "or", "None", "if", "no", "data", "was", "found", "." ]
wndhydrnt/python-oauth2
python
https://github.com/wndhydrnt/python-oauth2/blob/abe3bf5f27bda2ff737cab387b040e2e6e85c2e2/oauth2/store/redisdb.py#L61-L74
[ "def", "fetch_by_code", "(", "self", ",", "code", ")", ":", "code_data", "=", "self", ".", "read", "(", "code", ")", "if", "code_data", "is", "None", ":", "raise", "AuthCodeNotFound", "return", "AuthorizationCode", "(", "*", "*", "code_data", ")" ]
abe3bf5f27bda2ff737cab387b040e2e6e85c2e2
train
TokenStore.save_code
Stores the data belonging to an authorization code token in redis. See :class:`oauth2.store.AuthCodeStore`.
oauth2/store/redisdb.py
def save_code(self, authorization_code): """ Stores the data belonging to an authorization code token in redis. See :class:`oauth2.store.AuthCodeStore`. """ self.write(authorization_code.code, {"client_id": authorization_code.client_id, "c...
def save_code(self, authorization_code): """ Stores the data belonging to an authorization code token in redis. See :class:`oauth2.store.AuthCodeStore`. """ self.write(authorization_code.code, {"client_id": authorization_code.client_id, "c...
[ "Stores", "the", "data", "belonging", "to", "an", "authorization", "code", "token", "in", "redis", "." ]
wndhydrnt/python-oauth2
python
https://github.com/wndhydrnt/python-oauth2/blob/abe3bf5f27bda2ff737cab387b040e2e6e85c2e2/oauth2/store/redisdb.py#L76-L90
[ "def", "save_code", "(", "self", ",", "authorization_code", ")", ":", "self", ".", "write", "(", "authorization_code", ".", "code", ",", "{", "\"client_id\"", ":", "authorization_code", ".", "client_id", ",", "\"code\"", ":", "authorization_code", ".", "code", ...
abe3bf5f27bda2ff737cab387b040e2e6e85c2e2
train
TokenStore.save_token
Stores the access token and additional data in redis. See :class:`oauth2.store.AccessTokenStore`.
oauth2/store/redisdb.py
def save_token(self, access_token): """ Stores the access token and additional data in redis. See :class:`oauth2.store.AccessTokenStore`. """ self.write(access_token.token, access_token.__dict__) unique_token_key = self._unique_token_key(access_token.client_id, ...
def save_token(self, access_token): """ Stores the access token and additional data in redis. See :class:`oauth2.store.AccessTokenStore`. """ self.write(access_token.token, access_token.__dict__) unique_token_key = self._unique_token_key(access_token.client_id, ...
[ "Stores", "the", "access", "token", "and", "additional", "data", "in", "redis", "." ]
wndhydrnt/python-oauth2
python
https://github.com/wndhydrnt/python-oauth2/blob/abe3bf5f27bda2ff737cab387b040e2e6e85c2e2/oauth2/store/redisdb.py#L99-L114
[ "def", "save_token", "(", "self", ",", "access_token", ")", ":", "self", ".", "write", "(", "access_token", ".", "token", ",", "access_token", ".", "__dict__", ")", "unique_token_key", "=", "self", ".", "_unique_token_key", "(", "access_token", ".", "client_id...
abe3bf5f27bda2ff737cab387b040e2e6e85c2e2
train
TokenStore.delete_refresh_token
Deletes a refresh token after use :param refresh_token: The refresh token to delete.
oauth2/store/redisdb.py
def delete_refresh_token(self, refresh_token): """ Deletes a refresh token after use :param refresh_token: The refresh token to delete. """ access_token = self.fetch_by_refresh_token(refresh_token) self.delete(access_token.token)
def delete_refresh_token(self, refresh_token): """ Deletes a refresh token after use :param refresh_token: The refresh token to delete. """ access_token = self.fetch_by_refresh_token(refresh_token) self.delete(access_token.token)
[ "Deletes", "a", "refresh", "token", "after", "use", ":", "param", "refresh_token", ":", "The", "refresh", "token", "to", "delete", "." ]
wndhydrnt/python-oauth2
python
https://github.com/wndhydrnt/python-oauth2/blob/abe3bf5f27bda2ff737cab387b040e2e6e85c2e2/oauth2/store/redisdb.py#L116-L123
[ "def", "delete_refresh_token", "(", "self", ",", "refresh_token", ")", ":", "access_token", "=", "self", ".", "fetch_by_refresh_token", "(", "refresh_token", ")", "self", ".", "delete", "(", "access_token", ".", "token", ")" ]
abe3bf5f27bda2ff737cab387b040e2e6e85c2e2
train
ClientStore.add_client
Add a client app. :param client_id: Identifier of the client app. :param client_secret: Secret the client app uses for authentication against the OAuth 2.0 provider. :param redirect_uris: A ``list`` of URIs to redirect to.
oauth2/store/redisdb.py
def add_client(self, client_id, client_secret, redirect_uris, authorized_grants=None, authorized_response_types=None): """ Add a client app. :param client_id: Identifier of the client app. :param client_secret: Secret the client app uses for authentication ...
def add_client(self, client_id, client_secret, redirect_uris, authorized_grants=None, authorized_response_types=None): """ Add a client app. :param client_id: Identifier of the client app. :param client_secret: Secret the client app uses for authentication ...
[ "Add", "a", "client", "app", "." ]
wndhydrnt/python-oauth2
python
https://github.com/wndhydrnt/python-oauth2/blob/abe3bf5f27bda2ff737cab387b040e2e6e85c2e2/oauth2/store/redisdb.py#L149-L167
[ "def", "add_client", "(", "self", ",", "client_id", ",", "client_secret", ",", "redirect_uris", ",", "authorized_grants", "=", "None", ",", "authorized_response_types", "=", "None", ")", ":", "self", ".", "write", "(", "client_id", ",", "{", "\"identifier\"", ...
abe3bf5f27bda2ff737cab387b040e2e6e85c2e2
train
TokenGenerator.create_access_token_data
Create data needed by an access token. :param grant_type: :type grant_type: str :return: A ``dict`` containing he ``access_token`` and the ``token_type``. If the value of ``TokenGenerator.expires_in`` is larger than 0, a ``refresh_token`` will be generated too...
oauth2/tokengenerator.py
def create_access_token_data(self, grant_type): """ Create data needed by an access token. :param grant_type: :type grant_type: str :return: A ``dict`` containing he ``access_token`` and the ``token_type``. If the value of ``TokenGenerator.expires_in`` ...
def create_access_token_data(self, grant_type): """ Create data needed by an access token. :param grant_type: :type grant_type: str :return: A ``dict`` containing he ``access_token`` and the ``token_type``. If the value of ``TokenGenerator.expires_in`` ...
[ "Create", "data", "needed", "by", "an", "access", "token", "." ]
wndhydrnt/python-oauth2
python
https://github.com/wndhydrnt/python-oauth2/blob/abe3bf5f27bda2ff737cab387b040e2e6e85c2e2/oauth2/tokengenerator.py#L22-L41
[ "def", "create_access_token_data", "(", "self", ",", "grant_type", ")", ":", "result", "=", "{", "\"access_token\"", ":", "self", ".", "generate", "(", ")", ",", "\"token_type\"", ":", "\"Bearer\"", "}", "if", "self", ".", "expires_in", ".", "get", "(", "g...
abe3bf5f27bda2ff737cab387b040e2e6e85c2e2
train
URandomTokenGenerator.generate
:return: A new token :rtype: str
oauth2/tokengenerator.py
def generate(self): """ :return: A new token :rtype: str """ random_data = os.urandom(100) hash_gen = hashlib.new("sha512") hash_gen.update(random_data) return hash_gen.hexdigest()[:self.token_length]
def generate(self): """ :return: A new token :rtype: str """ random_data = os.urandom(100) hash_gen = hashlib.new("sha512") hash_gen.update(random_data) return hash_gen.hexdigest()[:self.token_length]
[ ":", "return", ":", "A", "new", "token", ":", "rtype", ":", "str" ]
wndhydrnt/python-oauth2
python
https://github.com/wndhydrnt/python-oauth2/blob/abe3bf5f27bda2ff737cab387b040e2e6e85c2e2/oauth2/tokengenerator.py#L60-L70
[ "def", "generate", "(", "self", ")", ":", "random_data", "=", "os", ".", "urandom", "(", "100", ")", "hash_gen", "=", "hashlib", ".", "new", "(", "\"sha512\"", ")", "hash_gen", ".", "update", "(", "random_data", ")", "return", "hash_gen", ".", "hexdigest...
abe3bf5f27bda2ff737cab387b040e2e6e85c2e2
train
ClientApplication._display_token
Display token information or redirect to login prompt if none is available.
docs/examples/resource_owner_grant.py
def _display_token(self): """ Display token information or redirect to login prompt if none is available. """ if self.token is None: return "301 Moved", "", {"Location": "/login"} return ("200 OK", self.TOKEN_TEMPLATE.format( ...
def _display_token(self): """ Display token information or redirect to login prompt if none is available. """ if self.token is None: return "301 Moved", "", {"Location": "/login"} return ("200 OK", self.TOKEN_TEMPLATE.format( ...
[ "Display", "token", "information", "or", "redirect", "to", "login", "prompt", "if", "none", "is", "available", "." ]
wndhydrnt/python-oauth2
python
https://github.com/wndhydrnt/python-oauth2/blob/abe3bf5f27bda2ff737cab387b040e2e6e85c2e2/docs/examples/resource_owner_grant.py#L95-L106
[ "def", "_display_token", "(", "self", ")", ":", "if", "self", ".", "token", "is", "None", ":", "return", "\"301 Moved\"", ",", "\"\"", ",", "{", "\"Location\"", ":", "\"/login\"", "}", "return", "(", "\"200 OK\"", ",", "self", ".", "TOKEN_TEMPLATE", ".", ...
abe3bf5f27bda2ff737cab387b040e2e6e85c2e2
train
ClientApplication._login
Login prompt
docs/examples/resource_owner_grant.py
def _login(self, failed=False): """ Login prompt """ if failed: content = self.LOGIN_TEMPLATE.format(failed_message="Login failed") else: content = self.LOGIN_TEMPLATE.format(failed_message="") return "200 OK", content, {"Content-Type": "text/html"...
def _login(self, failed=False): """ Login prompt """ if failed: content = self.LOGIN_TEMPLATE.format(failed_message="Login failed") else: content = self.LOGIN_TEMPLATE.format(failed_message="") return "200 OK", content, {"Content-Type": "text/html"...
[ "Login", "prompt" ]
wndhydrnt/python-oauth2
python
https://github.com/wndhydrnt/python-oauth2/blob/abe3bf5f27bda2ff737cab387b040e2e6e85c2e2/docs/examples/resource_owner_grant.py#L108-L116
[ "def", "_login", "(", "self", ",", "failed", "=", "False", ")", ":", "if", "failed", ":", "content", "=", "self", ".", "LOGIN_TEMPLATE", ".", "format", "(", "failed_message", "=", "\"Login failed\"", ")", "else", ":", "content", "=", "self", ".", "LOGIN_...
abe3bf5f27bda2ff737cab387b040e2e6e85c2e2
train
ClientApplication._request_token
Retrieves a new access token from the OAuth2 server.
docs/examples/resource_owner_grant.py
def _request_token(self, env): """ Retrieves a new access token from the OAuth2 server. """ params = {} content = env['wsgi.input'].read(int(env['CONTENT_LENGTH'])) post_params = parse_qs(content) # Convert to dict for easier access for param, value in po...
def _request_token(self, env): """ Retrieves a new access token from the OAuth2 server. """ params = {} content = env['wsgi.input'].read(int(env['CONTENT_LENGTH'])) post_params = parse_qs(content) # Convert to dict for easier access for param, value in po...
[ "Retrieves", "a", "new", "access", "token", "from", "the", "OAuth2", "server", "." ]
wndhydrnt/python-oauth2
python
https://github.com/wndhydrnt/python-oauth2/blob/abe3bf5f27bda2ff737cab387b040e2e6e85c2e2/docs/examples/resource_owner_grant.py#L118-L151
[ "def", "_request_token", "(", "self", ",", "env", ")", ":", "params", "=", "{", "}", "content", "=", "env", "[", "'wsgi.input'", "]", ".", "read", "(", "int", "(", "env", "[", "'CONTENT_LENGTH'", "]", ")", ")", "post_params", "=", "parse_qs", "(", "c...
abe3bf5f27bda2ff737cab387b040e2e6e85c2e2
train
ClientStore.add_client
Add a client app. :param client_id: Identifier of the client app. :param client_secret: Secret the client app uses for authentication against the OAuth 2.0 provider. :param redirect_uris: A ``list`` of URIs to redirect to.
oauth2/store/memory.py
def add_client(self, client_id, client_secret, redirect_uris, authorized_grants=None, authorized_response_types=None): """ Add a client app. :param client_id: Identifier of the client app. :param client_secret: Secret the client app uses for authentication ...
def add_client(self, client_id, client_secret, redirect_uris, authorized_grants=None, authorized_response_types=None): """ Add a client app. :param client_id: Identifier of the client app. :param client_secret: Secret the client app uses for authentication ...
[ "Add", "a", "client", "app", "." ]
wndhydrnt/python-oauth2
python
https://github.com/wndhydrnt/python-oauth2/blob/abe3bf5f27bda2ff737cab387b040e2e6e85c2e2/oauth2/store/memory.py#L21-L39
[ "def", "add_client", "(", "self", ",", "client_id", ",", "client_secret", ",", "redirect_uris", ",", "authorized_grants", "=", "None", ",", "authorized_response_types", "=", "None", ")", ":", "self", ".", "clients", "[", "client_id", "]", "=", "Client", "(", ...
abe3bf5f27bda2ff737cab387b040e2e6e85c2e2
train
ClientStore.fetch_by_client_id
Retrieve a client by its identifier. :param client_id: Identifier of a client app. :return: An instance of :class:`oauth2.Client`. :raises: ClientNotFoundError
oauth2/store/memory.py
def fetch_by_client_id(self, client_id): """ Retrieve a client by its identifier. :param client_id: Identifier of a client app. :return: An instance of :class:`oauth2.Client`. :raises: ClientNotFoundError """ if client_id not in self.clients: raise C...
def fetch_by_client_id(self, client_id): """ Retrieve a client by its identifier. :param client_id: Identifier of a client app. :return: An instance of :class:`oauth2.Client`. :raises: ClientNotFoundError """ if client_id not in self.clients: raise C...
[ "Retrieve", "a", "client", "by", "its", "identifier", "." ]
wndhydrnt/python-oauth2
python
https://github.com/wndhydrnt/python-oauth2/blob/abe3bf5f27bda2ff737cab387b040e2e6e85c2e2/oauth2/store/memory.py#L41-L53
[ "def", "fetch_by_client_id", "(", "self", ",", "client_id", ")", ":", "if", "client_id", "not", "in", "self", ".", "clients", ":", "raise", "ClientNotFoundError", "return", "self", ".", "clients", "[", "client_id", "]" ]
abe3bf5f27bda2ff737cab387b040e2e6e85c2e2
train
TokenStore.fetch_by_code
Returns an AuthorizationCode. :param code: The authorization code. :return: An instance of :class:`oauth2.datatype.AuthorizationCode`. :raises: :class:`AuthCodeNotFound` if no data could be retrieved for given code.
oauth2/store/memory.py
def fetch_by_code(self, code): """ Returns an AuthorizationCode. :param code: The authorization code. :return: An instance of :class:`oauth2.datatype.AuthorizationCode`. :raises: :class:`AuthCodeNotFound` if no data could be retrieved for given code. ""...
def fetch_by_code(self, code): """ Returns an AuthorizationCode. :param code: The authorization code. :return: An instance of :class:`oauth2.datatype.AuthorizationCode`. :raises: :class:`AuthCodeNotFound` if no data could be retrieved for given code. ""...
[ "Returns", "an", "AuthorizationCode", "." ]
wndhydrnt/python-oauth2
python
https://github.com/wndhydrnt/python-oauth2/blob/abe3bf5f27bda2ff737cab387b040e2e6e85c2e2/oauth2/store/memory.py#L69-L82
[ "def", "fetch_by_code", "(", "self", ",", "code", ")", ":", "if", "code", "not", "in", "self", ".", "auth_codes", ":", "raise", "AuthCodeNotFound", "return", "self", ".", "auth_codes", "[", "code", "]" ]
abe3bf5f27bda2ff737cab387b040e2e6e85c2e2
train
TokenStore.save_token
Stores an access token and additional data in memory. :param access_token: An instance of :class:`oauth2.datatype.AccessToken`.
oauth2/store/memory.py
def save_token(self, access_token): """ Stores an access token and additional data in memory. :param access_token: An instance of :class:`oauth2.datatype.AccessToken`. """ self.access_tokens[access_token.token] = access_token unique_token_key = self._unique_token_key(ac...
def save_token(self, access_token): """ Stores an access token and additional data in memory. :param access_token: An instance of :class:`oauth2.datatype.AccessToken`. """ self.access_tokens[access_token.token] = access_token unique_token_key = self._unique_token_key(ac...
[ "Stores", "an", "access", "token", "and", "additional", "data", "in", "memory", "." ]
wndhydrnt/python-oauth2
python
https://github.com/wndhydrnt/python-oauth2/blob/abe3bf5f27bda2ff737cab387b040e2e6e85c2e2/oauth2/store/memory.py#L96-L113
[ "def", "save_token", "(", "self", ",", "access_token", ")", ":", "self", ".", "access_tokens", "[", "access_token", ".", "token", "]", "=", "access_token", "unique_token_key", "=", "self", ".", "_unique_token_key", "(", "access_token", ".", "client_id", ",", "...
abe3bf5f27bda2ff737cab387b040e2e6e85c2e2
train
TokenStore.fetch_by_refresh_token
Find an access token by its refresh token. :param refresh_token: The refresh token that was assigned to an ``AccessToken``. :return: The :class:`oauth2.datatype.AccessToken`. :raises: :class:`oauth2.error.AccessTokenNotFound`
oauth2/store/memory.py
def fetch_by_refresh_token(self, refresh_token): """ Find an access token by its refresh token. :param refresh_token: The refresh token that was assigned to an ``AccessToken``. :return: The :class:`oauth2.datatype.AccessToken`. :raises: :class:`oaut...
def fetch_by_refresh_token(self, refresh_token): """ Find an access token by its refresh token. :param refresh_token: The refresh token that was assigned to an ``AccessToken``. :return: The :class:`oauth2.datatype.AccessToken`. :raises: :class:`oaut...
[ "Find", "an", "access", "token", "by", "its", "refresh", "token", "." ]
wndhydrnt/python-oauth2
python
https://github.com/wndhydrnt/python-oauth2/blob/abe3bf5f27bda2ff737cab387b040e2e6e85c2e2/oauth2/store/memory.py#L131-L143
[ "def", "fetch_by_refresh_token", "(", "self", ",", "refresh_token", ")", ":", "if", "refresh_token", "not", "in", "self", ".", "refresh_tokens", ":", "raise", "AccessTokenNotFound", "return", "self", ".", "refresh_tokens", "[", "refresh_token", "]" ]
abe3bf5f27bda2ff737cab387b040e2e6e85c2e2
train
Provider.add_grant
Adds a Grant that the provider should support. :param grant: An instance of a class that extends :class:`oauth2.grant.GrantHandlerFactory` :type grant: oauth2.grant.GrantHandlerFactory
oauth2/__init__.py
def add_grant(self, grant): """ Adds a Grant that the provider should support. :param grant: An instance of a class that extends :class:`oauth2.grant.GrantHandlerFactory` :type grant: oauth2.grant.GrantHandlerFactory """ if hasattr(grant, "expires_i...
def add_grant(self, grant): """ Adds a Grant that the provider should support. :param grant: An instance of a class that extends :class:`oauth2.grant.GrantHandlerFactory` :type grant: oauth2.grant.GrantHandlerFactory """ if hasattr(grant, "expires_i...
[ "Adds", "a", "Grant", "that", "the", "provider", "should", "support", "." ]
wndhydrnt/python-oauth2
python
https://github.com/wndhydrnt/python-oauth2/blob/abe3bf5f27bda2ff737cab387b040e2e6e85c2e2/oauth2/__init__.py#L83-L97
[ "def", "add_grant", "(", "self", ",", "grant", ")", ":", "if", "hasattr", "(", "grant", ",", "\"expires_in\"", ")", ":", "self", ".", "token_generator", ".", "expires_in", "[", "grant", ".", "grant_type", "]", "=", "grant", ".", "expires_in", "if", "hasa...
abe3bf5f27bda2ff737cab387b040e2e6e85c2e2
train
Provider.dispatch
Checks which Grant supports the current request and dispatches to it. :param request: The incoming request. :type request: :class:`oauth2.web.Request` :param environ: Dict containing variables of the environment. :type environ: dict :return: An instance of ``oauth2.web.Response...
oauth2/__init__.py
def dispatch(self, request, environ): """ Checks which Grant supports the current request and dispatches to it. :param request: The incoming request. :type request: :class:`oauth2.web.Request` :param environ: Dict containing variables of the environment. :type environ: d...
def dispatch(self, request, environ): """ Checks which Grant supports the current request and dispatches to it. :param request: The incoming request. :type request: :class:`oauth2.web.Request` :param environ: Dict containing variables of the environment. :type environ: d...
[ "Checks", "which", "Grant", "supports", "the", "current", "request", "and", "dispatches", "to", "it", "." ]
wndhydrnt/python-oauth2
python
https://github.com/wndhydrnt/python-oauth2/blob/abe3bf5f27bda2ff737cab387b040e2e6e85c2e2/oauth2/__init__.py#L99-L147
[ "def", "dispatch", "(", "self", ",", "request", ",", "environ", ")", ":", "try", ":", "grant_type", "=", "self", ".", "_determine_grant_type", "(", "request", ")", "response", "=", "self", ".", "response_class", "(", ")", "grant_type", ".", "read_validate_pa...
abe3bf5f27bda2ff737cab387b040e2e6e85c2e2
train
Provider.enable_unique_tokens
Enable the use of unique access tokens on all grant types that support this option.
oauth2/__init__.py
def enable_unique_tokens(self): """ Enable the use of unique access tokens on all grant types that support this option. """ for grant_type in self.grant_types: if hasattr(grant_type, "unique_token"): grant_type.unique_token = True
def enable_unique_tokens(self): """ Enable the use of unique access tokens on all grant types that support this option. """ for grant_type in self.grant_types: if hasattr(grant_type, "unique_token"): grant_type.unique_token = True
[ "Enable", "the", "use", "of", "unique", "access", "tokens", "on", "all", "grant", "types", "that", "support", "this", "option", "." ]
wndhydrnt/python-oauth2
python
https://github.com/wndhydrnt/python-oauth2/blob/abe3bf5f27bda2ff737cab387b040e2e6e85c2e2/oauth2/__init__.py#L149-L156
[ "def", "enable_unique_tokens", "(", "self", ")", ":", "for", "grant_type", "in", "self", ".", "grant_types", ":", "if", "hasattr", "(", "grant_type", ",", "\"unique_token\"", ")", ":", "grant_type", ".", "unique_token", "=", "True" ]
abe3bf5f27bda2ff737cab387b040e2e6e85c2e2
train
Request.header
Returns the value of the HTTP header identified by `name`.
oauth2/web/wsgi.py
def header(self, name, default=None): """ Returns the value of the HTTP header identified by `name`. """ wsgi_header = "HTTP_{0}".format(name.upper()) try: return self.env_raw[wsgi_header] except KeyError: return default
def header(self, name, default=None): """ Returns the value of the HTTP header identified by `name`. """ wsgi_header = "HTTP_{0}".format(name.upper()) try: return self.env_raw[wsgi_header] except KeyError: return default
[ "Returns", "the", "value", "of", "the", "HTTP", "header", "identified", "by", "name", "." ]
wndhydrnt/python-oauth2
python
https://github.com/wndhydrnt/python-oauth2/blob/abe3bf5f27bda2ff737cab387b040e2e6e85c2e2/oauth2/web/wsgi.py#L61-L70
[ "def", "header", "(", "self", ",", "name", ",", "default", "=", "None", ")", ":", "wsgi_header", "=", "\"HTTP_{0}\"", ".", "format", "(", "name", ".", "upper", "(", ")", ")", "try", ":", "return", "self", ".", "env_raw", "[", "wsgi_header", "]", "exc...
abe3bf5f27bda2ff737cab387b040e2e6e85c2e2
train
request_body
Extracts the credentials of a client from the *application/x-www-form-urlencoded* body of a request. Expects the client_id to be the value of the ``client_id`` parameter and the client_secret to be the value of the ``client_secret`` parameter. :param request: The incoming request :type request: oa...
oauth2/client_authenticator.py
def request_body(request): """ Extracts the credentials of a client from the *application/x-www-form-urlencoded* body of a request. Expects the client_id to be the value of the ``client_id`` parameter and the client_secret to be the value of the ``client_secret`` parameter. :param request: The...
def request_body(request): """ Extracts the credentials of a client from the *application/x-www-form-urlencoded* body of a request. Expects the client_id to be the value of the ``client_id`` parameter and the client_secret to be the value of the ``client_secret`` parameter. :param request: The...
[ "Extracts", "the", "credentials", "of", "a", "client", "from", "the", "*", "application", "/", "x", "-", "www", "-", "form", "-", "urlencoded", "*", "body", "of", "a", "request", "." ]
wndhydrnt/python-oauth2
python
https://github.com/wndhydrnt/python-oauth2/blob/abe3bf5f27bda2ff737cab387b040e2e6e85c2e2/oauth2/client_authenticator.py#L96-L120
[ "def", "request_body", "(", "request", ")", ":", "client_id", "=", "request", ".", "post_param", "(", "\"client_id\"", ")", "if", "client_id", "is", "None", ":", "raise", "OAuthInvalidError", "(", "error", "=", "\"invalid_request\"", ",", "explanation", "=", "...
abe3bf5f27bda2ff737cab387b040e2e6e85c2e2
train
http_basic_auth
Extracts the credentials of a client using HTTP Basic Auth. Expects the ``client_id`` to be the username and the ``client_secret`` to be the password part of the Authorization header. :param request: The incoming request :type request: oauth2.web.Request :return: A tuple in the format of (<CLIENT...
oauth2/client_authenticator.py
def http_basic_auth(request): """ Extracts the credentials of a client using HTTP Basic Auth. Expects the ``client_id`` to be the username and the ``client_secret`` to be the password part of the Authorization header. :param request: The incoming request :type request: oauth2.web.Request ...
def http_basic_auth(request): """ Extracts the credentials of a client using HTTP Basic Auth. Expects the ``client_id`` to be the username and the ``client_secret`` to be the password part of the Authorization header. :param request: The incoming request :type request: oauth2.web.Request ...
[ "Extracts", "the", "credentials", "of", "a", "client", "using", "HTTP", "Basic", "Auth", "." ]
wndhydrnt/python-oauth2
python
https://github.com/wndhydrnt/python-oauth2/blob/abe3bf5f27bda2ff737cab387b040e2e6e85c2e2/oauth2/client_authenticator.py#L123-L151
[ "def", "http_basic_auth", "(", "request", ")", ":", "auth_header", "=", "request", ".", "header", "(", "\"authorization\"", ")", "if", "auth_header", "is", "None", ":", "raise", "OAuthInvalidError", "(", "error", "=", "\"invalid_request\"", ",", "explanation", "...
abe3bf5f27bda2ff737cab387b040e2e6e85c2e2
train
ClientAuthenticator.by_identifier
Authenticates a client by its identifier. :param request: The incoming request :type request: oauth2.web.Request :return: The identified client :rtype: oauth2.datatype.Client :raises: :class OAuthInvalidNoRedirectError:
oauth2/client_authenticator.py
def by_identifier(self, request): """ Authenticates a client by its identifier. :param request: The incoming request :type request: oauth2.web.Request :return: The identified client :rtype: oauth2.datatype.Client :raises: :class OAuthInvalidNoRedirectError: ...
def by_identifier(self, request): """ Authenticates a client by its identifier. :param request: The incoming request :type request: oauth2.web.Request :return: The identified client :rtype: oauth2.datatype.Client :raises: :class OAuthInvalidNoRedirectError: ...
[ "Authenticates", "a", "client", "by", "its", "identifier", "." ]
wndhydrnt/python-oauth2
python
https://github.com/wndhydrnt/python-oauth2/blob/abe3bf5f27bda2ff737cab387b040e2e6e85c2e2/oauth2/client_authenticator.py#L29-L59
[ "def", "by_identifier", "(", "self", ",", "request", ")", ":", "client_id", "=", "request", ".", "get_param", "(", "\"client_id\"", ")", "if", "client_id", "is", "None", ":", "raise", "OAuthInvalidNoRedirectError", "(", "error", "=", "\"missing_client_id\"", ")"...
abe3bf5f27bda2ff737cab387b040e2e6e85c2e2
train
ClientAuthenticator.by_identifier_secret
Authenticates a client by its identifier and secret (aka password). :param request: The incoming request :type request: oauth2.web.Request :return: The identified client :rtype: oauth2.datatype.Client :raises OAuthInvalidError: If the client could not be found, is not ...
oauth2/client_authenticator.py
def by_identifier_secret(self, request): """ Authenticates a client by its identifier and secret (aka password). :param request: The incoming request :type request: oauth2.web.Request :return: The identified client :rtype: oauth2.datatype.Client :raises OAuthIn...
def by_identifier_secret(self, request): """ Authenticates a client by its identifier and secret (aka password). :param request: The incoming request :type request: oauth2.web.Request :return: The identified client :rtype: oauth2.datatype.Client :raises OAuthIn...
[ "Authenticates", "a", "client", "by", "its", "identifier", "and", "secret", "(", "aka", "password", ")", "." ]
wndhydrnt/python-oauth2
python
https://github.com/wndhydrnt/python-oauth2/blob/abe3bf5f27bda2ff737cab387b040e2e6e85c2e2/oauth2/client_authenticator.py#L61-L93
[ "def", "by_identifier_secret", "(", "self", ",", "request", ")", ":", "client_id", ",", "client_secret", "=", "self", ".", "source", "(", "request", "=", "request", ")", "try", ":", "client", "=", "self", ".", "client_store", ".", "fetch_by_client_id", "(", ...
abe3bf5f27bda2ff737cab387b040e2e6e85c2e2
train
AccessToken.expires_in
Returns the time until the token expires. :return: The remaining time until expiration in seconds or 0 if the token has expired.
oauth2/datatype.py
def expires_in(self): """ Returns the time until the token expires. :return: The remaining time until expiration in seconds or 0 if the token has expired. """ time_left = self.expires_at - int(time.time()) if time_left > 0: return time_left ...
def expires_in(self): """ Returns the time until the token expires. :return: The remaining time until expiration in seconds or 0 if the token has expired. """ time_left = self.expires_at - int(time.time()) if time_left > 0: return time_left ...
[ "Returns", "the", "time", "until", "the", "token", "expires", "." ]
wndhydrnt/python-oauth2
python
https://github.com/wndhydrnt/python-oauth2/blob/abe3bf5f27bda2ff737cab387b040e2e6e85c2e2/oauth2/datatype.py#L28-L39
[ "def", "expires_in", "(", "self", ")", ":", "time_left", "=", "self", ".", "expires_at", "-", "int", "(", "time", ".", "time", "(", ")", ")", "if", "time_left", ">", "0", ":", "return", "time_left", "return", "0" ]
abe3bf5f27bda2ff737cab387b040e2e6e85c2e2
train
DatabaseStore.execute
Executes a query and returns the identifier of the modified row. :param query: The query to be executed as a `str`. :param params: A `tuple` of parameters that will be replaced for placeholders in the query. :return: A `long` identifying the last altered row.
oauth2/store/dbapi/__init__.py
def execute(self, query, *params): """ Executes a query and returns the identifier of the modified row. :param query: The query to be executed as a `str`. :param params: A `tuple` of parameters that will be replaced for placeholders in the query. :return: ...
def execute(self, query, *params): """ Executes a query and returns the identifier of the modified row. :param query: The query to be executed as a `str`. :param params: A `tuple` of parameters that will be replaced for placeholders in the query. :return: ...
[ "Executes", "a", "query", "and", "returns", "the", "identifier", "of", "the", "modified", "row", "." ]
wndhydrnt/python-oauth2
python
https://github.com/wndhydrnt/python-oauth2/blob/abe3bf5f27bda2ff737cab387b040e2e6e85c2e2/oauth2/store/dbapi/__init__.py#L25-L43
[ "def", "execute", "(", "self", ",", "query", ",", "*", "params", ")", ":", "cursor", "=", "self", ".", "connection", ".", "cursor", "(", ")", "try", ":", "cursor", ".", "execute", "(", "query", ",", "params", ")", "self", ".", "connection", ".", "c...
abe3bf5f27bda2ff737cab387b040e2e6e85c2e2
train
DatabaseStore.fetchone
Returns the first result of the given query. :param query: The query to be executed as a `str`. :param params: A `tuple` of parameters that will be replaced for placeholders in the query. :return: The retrieved row with each field being one element in a `...
oauth2/store/dbapi/__init__.py
def fetchone(self, query, *args): """ Returns the first result of the given query. :param query: The query to be executed as a `str`. :param params: A `tuple` of parameters that will be replaced for placeholders in the query. :return: The retrieved row wit...
def fetchone(self, query, *args): """ Returns the first result of the given query. :param query: The query to be executed as a `str`. :param params: A `tuple` of parameters that will be replaced for placeholders in the query. :return: The retrieved row wit...
[ "Returns", "the", "first", "result", "of", "the", "given", "query", "." ]
wndhydrnt/python-oauth2
python
https://github.com/wndhydrnt/python-oauth2/blob/abe3bf5f27bda2ff737cab387b040e2e6e85c2e2/oauth2/store/dbapi/__init__.py#L45-L62
[ "def", "fetchone", "(", "self", ",", "query", ",", "*", "args", ")", ":", "cursor", "=", "self", ".", "connection", ".", "cursor", "(", ")", "try", ":", "cursor", ".", "execute", "(", "query", ",", "args", ")", "return", "cursor", ".", "fetchone", ...
abe3bf5f27bda2ff737cab387b040e2e6e85c2e2
train
DatabaseStore.fetchall
Returns all results of the given query. :param query: The query to be executed as a `str`. :param params: A `tuple` of parameters that will be replaced for placeholders in the query. :return: A `list` of `tuple`s with each field being one element in the `...
oauth2/store/dbapi/__init__.py
def fetchall(self, query, *args): """ Returns all results of the given query. :param query: The query to be executed as a `str`. :param params: A `tuple` of parameters that will be replaced for placeholders in the query. :return: A `list` of `tuple`s with ...
def fetchall(self, query, *args): """ Returns all results of the given query. :param query: The query to be executed as a `str`. :param params: A `tuple` of parameters that will be replaced for placeholders in the query. :return: A `list` of `tuple`s with ...
[ "Returns", "all", "results", "of", "the", "given", "query", "." ]
wndhydrnt/python-oauth2
python
https://github.com/wndhydrnt/python-oauth2/blob/abe3bf5f27bda2ff737cab387b040e2e6e85c2e2/oauth2/store/dbapi/__init__.py#L64-L81
[ "def", "fetchall", "(", "self", ",", "query", ",", "*", "args", ")", ":", "cursor", "=", "self", ".", "connection", ".", "cursor", "(", ")", "try", ":", "cursor", ".", "execute", "(", "query", ",", "args", ")", "return", "cursor", ".", "fetchall", ...
abe3bf5f27bda2ff737cab387b040e2e6e85c2e2
train
DbApiAccessTokenStore.fetch_by_refresh_token
Retrieves an access token by its refresh token. :param refresh_token: The refresh token of an access token as a `str`. :return: An instance of :class:`oauth2.datatype.AccessToken`. :raises: :class:`oauth2.error.AccessTokenNotFound` if not access token could be retrieved.
oauth2/store/dbapi/__init__.py
def fetch_by_refresh_token(self, refresh_token): """ Retrieves an access token by its refresh token. :param refresh_token: The refresh token of an access token as a `str`. :return: An instance of :class:`oauth2.datatype.AccessToken`. :raises: :class:`oauth2.error.AccessTokenNo...
def fetch_by_refresh_token(self, refresh_token): """ Retrieves an access token by its refresh token. :param refresh_token: The refresh token of an access token as a `str`. :return: An instance of :class:`oauth2.datatype.AccessToken`. :raises: :class:`oauth2.error.AccessTokenNo...
[ "Retrieves", "an", "access", "token", "by", "its", "refresh", "token", "." ]
wndhydrnt/python-oauth2
python
https://github.com/wndhydrnt/python-oauth2/blob/abe3bf5f27bda2ff737cab387b040e2e6e85c2e2/oauth2/store/dbapi/__init__.py#L118-L138
[ "def", "fetch_by_refresh_token", "(", "self", ",", "refresh_token", ")", ":", "row", "=", "self", ".", "fetchone", "(", "self", ".", "fetch_by_refresh_token_query", ",", "refresh_token", ")", "if", "row", "is", "None", ":", "raise", "AccessTokenNotFound", "scope...
abe3bf5f27bda2ff737cab387b040e2e6e85c2e2
train
DbApiAccessTokenStore.fetch_existing_token_of_user
Retrieve an access token issued to a client and user for a specific grant. :param client_id: The identifier of a client as a `str`. :param grant_type: The type of grant. :param user_id: The identifier of the user the access token has been issued to. :ret...
oauth2/store/dbapi/__init__.py
def fetch_existing_token_of_user(self, client_id, grant_type, user_id): """ Retrieve an access token issued to a client and user for a specific grant. :param client_id: The identifier of a client as a `str`. :param grant_type: The type of grant. :param user_id: The ident...
def fetch_existing_token_of_user(self, client_id, grant_type, user_id): """ Retrieve an access token issued to a client and user for a specific grant. :param client_id: The identifier of a client as a `str`. :param grant_type: The type of grant. :param user_id: The ident...
[ "Retrieve", "an", "access", "token", "issued", "to", "a", "client", "and", "user", "for", "a", "specific", "grant", "." ]
wndhydrnt/python-oauth2
python
https://github.com/wndhydrnt/python-oauth2/blob/abe3bf5f27bda2ff737cab387b040e2e6e85c2e2/oauth2/store/dbapi/__init__.py#L140-L165
[ "def", "fetch_existing_token_of_user", "(", "self", ",", "client_id", ",", "grant_type", ",", "user_id", ")", ":", "token_data", "=", "self", ".", "fetchone", "(", "self", ".", "fetch_existing_token_of_user_query", ",", "client_id", ",", "grant_type", ",", "user_i...
abe3bf5f27bda2ff737cab387b040e2e6e85c2e2
train
DbApiAccessTokenStore.save_token
Creates a new entry for an access token in the database. :param access_token: An instance of :class:`oauth2.datatype.AccessToken`. :return: `True`.
oauth2/store/dbapi/__init__.py
def save_token(self, access_token): """ Creates a new entry for an access token in the database. :param access_token: An instance of :class:`oauth2.datatype.AccessToken`. :return: `True`. """ access_token_id = self.execute(self.create_acces...
def save_token(self, access_token): """ Creates a new entry for an access token in the database. :param access_token: An instance of :class:`oauth2.datatype.AccessToken`. :return: `True`. """ access_token_id = self.execute(self.create_acces...
[ "Creates", "a", "new", "entry", "for", "an", "access", "token", "in", "the", "database", "." ]
wndhydrnt/python-oauth2
python
https://github.com/wndhydrnt/python-oauth2/blob/abe3bf5f27bda2ff737cab387b040e2e6e85c2e2/oauth2/store/dbapi/__init__.py#L167-L192
[ "def", "save_token", "(", "self", ",", "access_token", ")", ":", "access_token_id", "=", "self", ".", "execute", "(", "self", ".", "create_access_token_query", ",", "access_token", ".", "client_id", ",", "access_token", ".", "grant_type", ",", "access_token", "....
abe3bf5f27bda2ff737cab387b040e2e6e85c2e2
train
DbApiAuthCodeStore.fetch_by_code
Retrieves an auth code by its code. :param code: The code of an auth code. :return: An instance of :class:`oauth2.datatype.AuthorizationCode`. :raises: :class:`oauth2.error.AuthCodeNotFound` if no auth code could be retrieved.
oauth2/store/dbapi/__init__.py
def fetch_by_code(self, code): """ Retrieves an auth code by its code. :param code: The code of an auth code. :return: An instance of :class:`oauth2.datatype.AuthorizationCode`. :raises: :class:`oauth2.error.AuthCodeNotFound` if no auth code could be retrieved...
def fetch_by_code(self, code): """ Retrieves an auth code by its code. :param code: The code of an auth code. :return: An instance of :class:`oauth2.datatype.AuthorizationCode`. :raises: :class:`oauth2.error.AuthCodeNotFound` if no auth code could be retrieved...
[ "Retrieves", "an", "auth", "code", "by", "its", "code", "." ]
wndhydrnt/python-oauth2
python
https://github.com/wndhydrnt/python-oauth2/blob/abe3bf5f27bda2ff737cab387b040e2e6e85c2e2/oauth2/store/dbapi/__init__.py#L250-L284
[ "def", "fetch_by_code", "(", "self", ",", "code", ")", ":", "auth_code_data", "=", "self", ".", "fetchone", "(", "self", ".", "fetch_code_query", ",", "code", ")", "if", "auth_code_data", "is", "None", ":", "raise", "AuthCodeNotFound", "data", "=", "dict", ...
abe3bf5f27bda2ff737cab387b040e2e6e85c2e2
train
DbApiAuthCodeStore.save_code
Creates a new entry of an auth code in the database. :param authorization_code: An instance of :class:`oauth2.datatype.AuthorizationCode`. :return: `True` if everything went fine.
oauth2/store/dbapi/__init__.py
def save_code(self, authorization_code): """ Creates a new entry of an auth code in the database. :param authorization_code: An instance of :class:`oauth2.datatype.AuthorizationCode`. :return: `True` if everything went fine. """ auth_c...
def save_code(self, authorization_code): """ Creates a new entry of an auth code in the database. :param authorization_code: An instance of :class:`oauth2.datatype.AuthorizationCode`. :return: `True` if everything went fine. """ auth_c...
[ "Creates", "a", "new", "entry", "of", "an", "auth", "code", "in", "the", "database", "." ]
wndhydrnt/python-oauth2
python
https://github.com/wndhydrnt/python-oauth2/blob/abe3bf5f27bda2ff737cab387b040e2e6e85c2e2/oauth2/store/dbapi/__init__.py#L286-L308
[ "def", "save_code", "(", "self", ",", "authorization_code", ")", ":", "auth_code_id", "=", "self", ".", "execute", "(", "self", ".", "create_auth_code_query", ",", "authorization_code", ".", "client_id", ",", "authorization_code", ".", "code", ",", "authorization_...
abe3bf5f27bda2ff737cab387b040e2e6e85c2e2
train
DbApiClientStore.fetch_by_client_id
Retrieves a client by its identifier. :param client_id: The identifier of a client. :return: An instance of :class:`oauth2.datatype.Client`. :raises: :class:`oauth2.error.ClientError` if no client could be retrieved.
oauth2/store/dbapi/__init__.py
def fetch_by_client_id(self, client_id): """ Retrieves a client by its identifier. :param client_id: The identifier of a client. :return: An instance of :class:`oauth2.datatype.Client`. :raises: :class:`oauth2.error.ClientError` if no client could be retrieved...
def fetch_by_client_id(self, client_id): """ Retrieves a client by its identifier. :param client_id: The identifier of a client. :return: An instance of :class:`oauth2.datatype.Client`. :raises: :class:`oauth2.error.ClientError` if no client could be retrieved...
[ "Retrieves", "a", "client", "by", "its", "identifier", "." ]
wndhydrnt/python-oauth2
python
https://github.com/wndhydrnt/python-oauth2/blob/abe3bf5f27bda2ff737cab387b040e2e6e85c2e2/oauth2/store/dbapi/__init__.py#L327-L370
[ "def", "fetch_by_client_id", "(", "self", ",", "client_id", ")", ":", "grants", "=", "None", "redirect_uris", "=", "None", "response_types", "=", "None", "client_data", "=", "self", ".", "fetchone", "(", "self", ".", "fetch_client_query", ",", "client_id", ")"...
abe3bf5f27bda2ff737cab387b040e2e6e85c2e2
train
TokenStore.fetch_by_code
Returns data belonging to an authorization code from memcache or ``None`` if no data was found. See :class:`oauth2.store.AuthCodeStore`.
oauth2/store/memcache.py
def fetch_by_code(self, code): """ Returns data belonging to an authorization code from memcache or ``None`` if no data was found. See :class:`oauth2.store.AuthCodeStore`. """ code_data = self.mc.get(self._generate_cache_key(code)) if code_data is None: ...
def fetch_by_code(self, code): """ Returns data belonging to an authorization code from memcache or ``None`` if no data was found. See :class:`oauth2.store.AuthCodeStore`. """ code_data = self.mc.get(self._generate_cache_key(code)) if code_data is None: ...
[ "Returns", "data", "belonging", "to", "an", "authorization", "code", "from", "memcache", "or", "None", "if", "no", "data", "was", "found", "." ]
wndhydrnt/python-oauth2
python
https://github.com/wndhydrnt/python-oauth2/blob/abe3bf5f27bda2ff737cab387b040e2e6e85c2e2/oauth2/store/memcache.py#L39-L52
[ "def", "fetch_by_code", "(", "self", ",", "code", ")", ":", "code_data", "=", "self", ".", "mc", ".", "get", "(", "self", ".", "_generate_cache_key", "(", "code", ")", ")", "if", "code_data", "is", "None", ":", "raise", "AuthCodeNotFound", "return", "Aut...
abe3bf5f27bda2ff737cab387b040e2e6e85c2e2
train
TokenStore.save_code
Stores the data belonging to an authorization code token in memcache. See :class:`oauth2.store.AuthCodeStore`.
oauth2/store/memcache.py
def save_code(self, authorization_code): """ Stores the data belonging to an authorization code token in memcache. See :class:`oauth2.store.AuthCodeStore`. """ key = self._generate_cache_key(authorization_code.code) self.mc.set(key, {"client_id": authorization_code.cli...
def save_code(self, authorization_code): """ Stores the data belonging to an authorization code token in memcache. See :class:`oauth2.store.AuthCodeStore`. """ key = self._generate_cache_key(authorization_code.code) self.mc.set(key, {"client_id": authorization_code.cli...
[ "Stores", "the", "data", "belonging", "to", "an", "authorization", "code", "token", "in", "memcache", "." ]
wndhydrnt/python-oauth2
python
https://github.com/wndhydrnt/python-oauth2/blob/abe3bf5f27bda2ff737cab387b040e2e6e85c2e2/oauth2/store/memcache.py#L54-L69
[ "def", "save_code", "(", "self", ",", "authorization_code", ")", ":", "key", "=", "self", ".", "_generate_cache_key", "(", "authorization_code", ".", "code", ")", "self", ".", "mc", ".", "set", "(", "key", ",", "{", "\"client_id\"", ":", "authorization_code"...
abe3bf5f27bda2ff737cab387b040e2e6e85c2e2
train
TokenStore.save_token
Stores the access token and additional data in memcache. See :class:`oauth2.store.AccessTokenStore`.
oauth2/store/memcache.py
def save_token(self, access_token): """ Stores the access token and additional data in memcache. See :class:`oauth2.store.AccessTokenStore`. """ key = self._generate_cache_key(access_token.token) self.mc.set(key, access_token.__dict__) unique_token_key = self._...
def save_token(self, access_token): """ Stores the access token and additional data in memcache. See :class:`oauth2.store.AccessTokenStore`. """ key = self._generate_cache_key(access_token.token) self.mc.set(key, access_token.__dict__) unique_token_key = self._...
[ "Stores", "the", "access", "token", "and", "additional", "data", "in", "memcache", "." ]
wndhydrnt/python-oauth2
python
https://github.com/wndhydrnt/python-oauth2/blob/abe3bf5f27bda2ff737cab387b040e2e6e85c2e2/oauth2/store/memcache.py#L78-L96
[ "def", "save_token", "(", "self", ",", "access_token", ")", ":", "key", "=", "self", ".", "_generate_cache_key", "(", "access_token", ".", "token", ")", "self", ".", "mc", ".", "set", "(", "key", ",", "access_token", ".", "__dict__", ")", "unique_token_key...
abe3bf5f27bda2ff737cab387b040e2e6e85c2e2
train
TokenStore.delete_refresh_token
Deletes a refresh token after use :param refresh_token: The refresh token to delete.
oauth2/store/memcache.py
def delete_refresh_token(self, refresh_token): """ Deletes a refresh token after use :param refresh_token: The refresh token to delete. """ access_token = self.fetch_by_refresh_token(refresh_token) self.mc.delete(self._generate_cache_key(access_token.token)) self....
def delete_refresh_token(self, refresh_token): """ Deletes a refresh token after use :param refresh_token: The refresh token to delete. """ access_token = self.fetch_by_refresh_token(refresh_token) self.mc.delete(self._generate_cache_key(access_token.token)) self....
[ "Deletes", "a", "refresh", "token", "after", "use", ":", "param", "refresh_token", ":", "The", "refresh", "token", "to", "delete", "." ]
wndhydrnt/python-oauth2
python
https://github.com/wndhydrnt/python-oauth2/blob/abe3bf5f27bda2ff737cab387b040e2e6e85c2e2/oauth2/store/memcache.py#L98-L105
[ "def", "delete_refresh_token", "(", "self", ",", "refresh_token", ")", ":", "access_token", "=", "self", ".", "fetch_by_refresh_token", "(", "refresh_token", ")", "self", ".", "mc", ".", "delete", "(", "self", ".", "_generate_cache_key", "(", "access_token", "."...
abe3bf5f27bda2ff737cab387b040e2e6e85c2e2
train
encode_scopes
Creates a string out of a list of scopes. :param scopes: A list of scopes :param use_quote: Boolean flag indicating whether the string should be quoted :return: Scopes as a string
oauth2/grant.py
def encode_scopes(scopes, use_quote=False): """ Creates a string out of a list of scopes. :param scopes: A list of scopes :param use_quote: Boolean flag indicating whether the string should be quoted :return: Scopes as a string """ scopes_as_string = Scope.separator.join(scopes) if use...
def encode_scopes(scopes, use_quote=False): """ Creates a string out of a list of scopes. :param scopes: A list of scopes :param use_quote: Boolean flag indicating whether the string should be quoted :return: Scopes as a string """ scopes_as_string = Scope.separator.join(scopes) if use...
[ "Creates", "a", "string", "out", "of", "a", "list", "of", "scopes", "." ]
wndhydrnt/python-oauth2
python
https://github.com/wndhydrnt/python-oauth2/blob/abe3bf5f27bda2ff737cab387b040e2e6e85c2e2/oauth2/grant.py#L41-L53
[ "def", "encode_scopes", "(", "scopes", ",", "use_quote", "=", "False", ")", ":", "scopes_as_string", "=", "Scope", ".", "separator", ".", "join", "(", "scopes", ")", "if", "use_quote", ":", "return", "quote", "(", "scopes_as_string", ")", "return", "scopes_a...
abe3bf5f27bda2ff737cab387b040e2e6e85c2e2
train
json_error_response
Formats an error as a response containing a JSON body.
oauth2/grant.py
def json_error_response(error, response, status_code=400): """ Formats an error as a response containing a JSON body. """ msg = {"error": error.error, "error_description": error.explanation} response.status_code = status_code response.add_header("Content-Type", "application/json") response....
def json_error_response(error, response, status_code=400): """ Formats an error as a response containing a JSON body. """ msg = {"error": error.error, "error_description": error.explanation} response.status_code = status_code response.add_header("Content-Type", "application/json") response....
[ "Formats", "an", "error", "as", "a", "response", "containing", "a", "JSON", "body", "." ]
wndhydrnt/python-oauth2
python
https://github.com/wndhydrnt/python-oauth2/blob/abe3bf5f27bda2ff737cab387b040e2e6e85c2e2/oauth2/grant.py#L56-L66
[ "def", "json_error_response", "(", "error", ",", "response", ",", "status_code", "=", "400", ")", ":", "msg", "=", "{", "\"error\"", ":", "error", ".", "error", ",", "\"error_description\"", ":", "error", ".", "explanation", "}", "response", ".", "status_cod...
abe3bf5f27bda2ff737cab387b040e2e6e85c2e2