repository_name stringlengths 7 55 | func_path_in_repository stringlengths 4 223 | func_name stringlengths 1 134 | whole_func_string stringlengths 75 104k | language stringclasses 1
value | func_code_string stringlengths 75 104k | func_code_tokens listlengths 19 28.4k | func_documentation_string stringlengths 1 46.9k | func_documentation_tokens listlengths 1 1.97k | split_name stringclasses 1
value | func_code_url stringlengths 87 315 |
|---|---|---|---|---|---|---|---|---|---|---|
secure-systems-lab/securesystemslib | securesystemslib/formats.py | unix_timestamp_to_datetime | def unix_timestamp_to_datetime(unix_timestamp):
"""
<Purpose>
Convert 'unix_timestamp' (i.e., POSIX time, in UNIX_TIMESTAMP_SCHEMA format)
to a datetime.datetime() object. 'unix_timestamp' is the number of seconds
since the epoch (January 1, 1970.)
>>> datetime_object = unix_timestamp_to_datetime(... | python | def unix_timestamp_to_datetime(unix_timestamp):
"""
<Purpose>
Convert 'unix_timestamp' (i.e., POSIX time, in UNIX_TIMESTAMP_SCHEMA format)
to a datetime.datetime() object. 'unix_timestamp' is the number of seconds
since the epoch (January 1, 1970.)
>>> datetime_object = unix_timestamp_to_datetime(... | [
"def",
"unix_timestamp_to_datetime",
"(",
"unix_timestamp",
")",
":",
"# Is 'unix_timestamp' properly formatted?",
"# Raise 'securesystemslib.exceptions.FormatError' if there is a mismatch.",
"securesystemslib",
".",
"formats",
".",
"UNIX_TIMESTAMP_SCHEMA",
".",
"check_match",
"(",
"... | <Purpose>
Convert 'unix_timestamp' (i.e., POSIX time, in UNIX_TIMESTAMP_SCHEMA format)
to a datetime.datetime() object. 'unix_timestamp' is the number of seconds
since the epoch (January 1, 1970.)
>>> datetime_object = unix_timestamp_to_datetime(1445455680)
>>> datetime_object
datetime.datetim... | [
"<Purpose",
">",
"Convert",
"unix_timestamp",
"(",
"i",
".",
"e",
".",
"POSIX",
"time",
"in",
"UNIX_TIMESTAMP_SCHEMA",
"format",
")",
"to",
"a",
"datetime",
".",
"datetime",
"()",
"object",
".",
"unix_timestamp",
"is",
"the",
"number",
"of",
"seconds",
"sinc... | train | https://github.com/secure-systems-lab/securesystemslib/blob/beb3109d5bb462e5a60eed88fb40ed1167bd354e/securesystemslib/formats.py#L573-L613 |
secure-systems-lab/securesystemslib | securesystemslib/formats.py | format_base64 | def format_base64(data):
"""
<Purpose>
Return the base64 encoding of 'data' with whitespace and '=' signs omitted.
<Arguments>
data:
Binary or buffer of data to convert.
<Exceptions>
securesystemslib.exceptions.FormatError, if the base64 encoding fails or the
argument is invalid.
<Sid... | python | def format_base64(data):
"""
<Purpose>
Return the base64 encoding of 'data' with whitespace and '=' signs omitted.
<Arguments>
data:
Binary or buffer of data to convert.
<Exceptions>
securesystemslib.exceptions.FormatError, if the base64 encoding fails or the
argument is invalid.
<Sid... | [
"def",
"format_base64",
"(",
"data",
")",
":",
"try",
":",
"return",
"binascii",
".",
"b2a_base64",
"(",
"data",
")",
".",
"decode",
"(",
"'utf-8'",
")",
".",
"rstrip",
"(",
"'=\\n '",
")",
"except",
"(",
"TypeError",
",",
"binascii",
".",
"Error",
")"... | <Purpose>
Return the base64 encoding of 'data' with whitespace and '=' signs omitted.
<Arguments>
data:
Binary or buffer of data to convert.
<Exceptions>
securesystemslib.exceptions.FormatError, if the base64 encoding fails or the
argument is invalid.
<Side Effects>
None.
<Returns>... | [
"<Purpose",
">",
"Return",
"the",
"base64",
"encoding",
"of",
"data",
"with",
"whitespace",
"and",
"=",
"signs",
"omitted",
"."
] | train | https://github.com/secure-systems-lab/securesystemslib/blob/beb3109d5bb462e5a60eed88fb40ed1167bd354e/securesystemslib/formats.py#L618-L643 |
secure-systems-lab/securesystemslib | securesystemslib/formats.py | parse_base64 | def parse_base64(base64_string):
"""
<Purpose>
Parse a base64 encoding with whitespace and '=' signs omitted.
<Arguments>
base64_string:
A string holding a base64 value.
<Exceptions>
securesystemslib.exceptions.FormatError, if 'base64_string' cannot be parsed
due to an invalid base64 enc... | python | def parse_base64(base64_string):
"""
<Purpose>
Parse a base64 encoding with whitespace and '=' signs omitted.
<Arguments>
base64_string:
A string holding a base64 value.
<Exceptions>
securesystemslib.exceptions.FormatError, if 'base64_string' cannot be parsed
due to an invalid base64 enc... | [
"def",
"parse_base64",
"(",
"base64_string",
")",
":",
"if",
"not",
"isinstance",
"(",
"base64_string",
",",
"six",
".",
"string_types",
")",
":",
"message",
"=",
"'Invalid argument: '",
"+",
"repr",
"(",
"base64_string",
")",
"raise",
"securesystemslib",
".",
... | <Purpose>
Parse a base64 encoding with whitespace and '=' signs omitted.
<Arguments>
base64_string:
A string holding a base64 value.
<Exceptions>
securesystemslib.exceptions.FormatError, if 'base64_string' cannot be parsed
due to an invalid base64 encoding.
<Side Effects>
None.
<Re... | [
"<Purpose",
">",
"Parse",
"a",
"base64",
"encoding",
"with",
"whitespace",
"and",
"=",
"signs",
"omitted",
"."
] | train | https://github.com/secure-systems-lab/securesystemslib/blob/beb3109d5bb462e5a60eed88fb40ed1167bd354e/securesystemslib/formats.py#L648-L683 |
secure-systems-lab/securesystemslib | securesystemslib/formats.py | encode_canonical | def encode_canonical(object, output_function=None):
"""
<Purpose>
Encode 'object' in canonical JSON form, as specified at
http://wiki.laptop.org/go/Canonical_JSON . It's a restricted
dialect of JSON in which keys are always lexically sorted,
there is no whitespace, floats aren't allowed, and only q... | python | def encode_canonical(object, output_function=None):
"""
<Purpose>
Encode 'object' in canonical JSON form, as specified at
http://wiki.laptop.org/go/Canonical_JSON . It's a restricted
dialect of JSON in which keys are always lexically sorted,
there is no whitespace, floats aren't allowed, and only q... | [
"def",
"encode_canonical",
"(",
"object",
",",
"output_function",
"=",
"None",
")",
":",
"result",
"=",
"None",
"# If 'output_function' is unset, treat it as",
"# appending to a list.",
"if",
"output_function",
"is",
"None",
":",
"result",
"=",
"[",
"]",
"output_funct... | <Purpose>
Encode 'object' in canonical JSON form, as specified at
http://wiki.laptop.org/go/Canonical_JSON . It's a restricted
dialect of JSON in which keys are always lexically sorted,
there is no whitespace, floats aren't allowed, and only quote
and backslash get escaped. The result is encoded i... | [
"<Purpose",
">",
"Encode",
"object",
"in",
"canonical",
"JSON",
"form",
"as",
"specified",
"at",
"http",
":",
"//",
"wiki",
".",
"laptop",
".",
"org",
"/",
"go",
"/",
"Canonical_JSON",
".",
"It",
"s",
"a",
"restricted",
"dialect",
"of",
"JSON",
"in",
"... | train | https://github.com/secure-systems-lab/securesystemslib/blob/beb3109d5bb462e5a60eed88fb40ed1167bd354e/securesystemslib/formats.py#L752-L820 |
HEPData/hepdata-converter | hepdata_converter/writers/array_writer.py | ArrayWriter.process_error_labels | def process_error_labels(value):
""" Process the error labels of a dependent variable 'value' to ensure uniqueness. """
observed_error_labels = {}
for error in value.get('errors', []):
label = error.get('label', 'error')
if label not in observed_error_labels:
... | python | def process_error_labels(value):
""" Process the error labels of a dependent variable 'value' to ensure uniqueness. """
observed_error_labels = {}
for error in value.get('errors', []):
label = error.get('label', 'error')
if label not in observed_error_labels:
... | [
"def",
"process_error_labels",
"(",
"value",
")",
":",
"observed_error_labels",
"=",
"{",
"}",
"for",
"error",
"in",
"value",
".",
"get",
"(",
"'errors'",
",",
"[",
"]",
")",
":",
"label",
"=",
"error",
".",
"get",
"(",
"'label'",
",",
"'error'",
")",
... | Process the error labels of a dependent variable 'value' to ensure uniqueness. | [
"Process",
"the",
"error",
"labels",
"of",
"a",
"dependent",
"variable",
"value",
"to",
"ensure",
"uniqueness",
"."
] | train | https://github.com/HEPData/hepdata-converter/blob/354271448980efba86f2f3d27b99d818e75fd90d/hepdata_converter/writers/array_writer.py#L140-L160 |
boolangery/py-lua-parser | luaparser/printers.py | raw | def raw(text):
"""Returns a raw string representation of text"""
new_string = ''
for char in text:
try:
new_string += escape_dict[char]
except KeyError:
new_string += char
return new_string | python | def raw(text):
"""Returns a raw string representation of text"""
new_string = ''
for char in text:
try:
new_string += escape_dict[char]
except KeyError:
new_string += char
return new_string | [
"def",
"raw",
"(",
"text",
")",
":",
"new_string",
"=",
"''",
"for",
"char",
"in",
"text",
":",
"try",
":",
"new_string",
"+=",
"escape_dict",
"[",
"char",
"]",
"except",
"KeyError",
":",
"new_string",
"+=",
"char",
"return",
"new_string"
] | Returns a raw string representation of text | [
"Returns",
"a",
"raw",
"string",
"representation",
"of",
"text"
] | train | https://github.com/boolangery/py-lua-parser/blob/578f2bf75f6f84c4b52c2affba56a4ec569d7ce7/luaparser/printers.py#L139-L147 |
indranilsinharoy/pyzos | pyzos/ddeclient.py | get_winfunc | def get_winfunc(libname, funcname, restype=None, argtypes=(), _libcache={}):
"""Retrieve a function from a library/DLL, and set the data types."""
if libname not in _libcache:
_libcache[libname] = windll.LoadLibrary(libname)
func = getattr(_libcache[libname], funcname)
func.argtypes = argtypes
... | python | def get_winfunc(libname, funcname, restype=None, argtypes=(), _libcache={}):
"""Retrieve a function from a library/DLL, and set the data types."""
if libname not in _libcache:
_libcache[libname] = windll.LoadLibrary(libname)
func = getattr(_libcache[libname], funcname)
func.argtypes = argtypes
... | [
"def",
"get_winfunc",
"(",
"libname",
",",
"funcname",
",",
"restype",
"=",
"None",
",",
"argtypes",
"=",
"(",
")",
",",
"_libcache",
"=",
"{",
"}",
")",
":",
"if",
"libname",
"not",
"in",
"_libcache",
":",
"_libcache",
"[",
"libname",
"]",
"=",
"win... | Retrieve a function from a library/DLL, and set the data types. | [
"Retrieve",
"a",
"function",
"from",
"a",
"library",
"/",
"DLL",
"and",
"set",
"the",
"data",
"types",
"."
] | train | https://github.com/indranilsinharoy/pyzos/blob/da6bf3296b0154ccee44ad9a4286055ae031ecc7/pyzos/ddeclient.py#L237-L244 |
indranilsinharoy/pyzos | pyzos/ddeclient.py | WinMSGLoop | def WinMSGLoop():
"""Run the main windows message loop."""
LPMSG = POINTER(MSG)
LRESULT = c_ulong
GetMessage = get_winfunc("user32", "GetMessageW", BOOL, (LPMSG, HWND, UINT, UINT))
TranslateMessage = get_winfunc("user32", "TranslateMessage", BOOL, (LPMSG,))
# restype = LRESULT
DispatchMessag... | python | def WinMSGLoop():
"""Run the main windows message loop."""
LPMSG = POINTER(MSG)
LRESULT = c_ulong
GetMessage = get_winfunc("user32", "GetMessageW", BOOL, (LPMSG, HWND, UINT, UINT))
TranslateMessage = get_winfunc("user32", "TranslateMessage", BOOL, (LPMSG,))
# restype = LRESULT
DispatchMessag... | [
"def",
"WinMSGLoop",
"(",
")",
":",
"LPMSG",
"=",
"POINTER",
"(",
"MSG",
")",
"LRESULT",
"=",
"c_ulong",
"GetMessage",
"=",
"get_winfunc",
"(",
"\"user32\"",
",",
"\"GetMessageW\"",
",",
"BOOL",
",",
"(",
"LPMSG",
",",
"HWND",
",",
"UINT",
",",
"UINT",
... | Run the main windows message loop. | [
"Run",
"the",
"main",
"windows",
"message",
"loop",
"."
] | train | https://github.com/indranilsinharoy/pyzos/blob/da6bf3296b0154ccee44ad9a4286055ae031ecc7/pyzos/ddeclient.py#L384-L397 |
indranilsinharoy/pyzos | pyzos/ddeclient.py | CreateConversation.ConnectTo | def ConnectTo(self, appName, data=None):
"""Exceptional error is handled in zdde Init() method, so the exception
must be re-raised"""
global number_of_apps_communicating
self.ddeServerName = appName
try:
self.ddec = DDEClient(self.ddeServerName, self.ddeClientName) # ... | python | def ConnectTo(self, appName, data=None):
"""Exceptional error is handled in zdde Init() method, so the exception
must be re-raised"""
global number_of_apps_communicating
self.ddeServerName = appName
try:
self.ddec = DDEClient(self.ddeServerName, self.ddeClientName) # ... | [
"def",
"ConnectTo",
"(",
"self",
",",
"appName",
",",
"data",
"=",
"None",
")",
":",
"global",
"number_of_apps_communicating",
"self",
".",
"ddeServerName",
"=",
"appName",
"try",
":",
"self",
".",
"ddec",
"=",
"DDEClient",
"(",
"self",
".",
"ddeServerName",... | Exceptional error is handled in zdde Init() method, so the exception
must be re-raised | [
"Exceptional",
"error",
"is",
"handled",
"in",
"zdde",
"Init",
"()",
"method",
"so",
"the",
"exception",
"must",
"be",
"re",
"-",
"raised"
] | train | https://github.com/indranilsinharoy/pyzos/blob/da6bf3296b0154ccee44ad9a4286055ae031ecc7/pyzos/ddeclient.py#L191-L201 |
indranilsinharoy/pyzos | pyzos/ddeclient.py | CreateConversation.Request | def Request(self, item, timeout=None):
"""Request DDE client
timeout in seconds
Note ... handle the exception within this function.
"""
if not timeout:
timeout = self.ddetimeout
try:
reply = self.ddec.request(item, int(timeout*1000)) # convert time... | python | def Request(self, item, timeout=None):
"""Request DDE client
timeout in seconds
Note ... handle the exception within this function.
"""
if not timeout:
timeout = self.ddetimeout
try:
reply = self.ddec.request(item, int(timeout*1000)) # convert time... | [
"def",
"Request",
"(",
"self",
",",
"item",
",",
"timeout",
"=",
"None",
")",
":",
"if",
"not",
"timeout",
":",
"timeout",
"=",
"self",
".",
"ddetimeout",
"try",
":",
"reply",
"=",
"self",
".",
"ddec",
".",
"request",
"(",
"item",
",",
"int",
"(",
... | Request DDE client
timeout in seconds
Note ... handle the exception within this function. | [
"Request",
"DDE",
"client",
"timeout",
"in",
"seconds",
"Note",
"...",
"handle",
"the",
"exception",
"within",
"this",
"function",
"."
] | train | https://github.com/indranilsinharoy/pyzos/blob/da6bf3296b0154ccee44ad9a4286055ae031ecc7/pyzos/ddeclient.py#L204-L222 |
indranilsinharoy/pyzos | pyzos/ddeclient.py | DDEClient.advise | def advise(self, item, stop=False):
"""Request updates when DDE data changes."""
hszItem = DDE.CreateStringHandle(self._idInst, item, CP_WINUNICODE)
hDdeData = DDE.ClientTransaction(LPBYTE(), 0, self._hConv, hszItem, CF_TEXT, XTYP_ADVSTOP if stop else XTYP_ADVSTART, TIMEOUT_ASYNC, LPDWORD())
... | python | def advise(self, item, stop=False):
"""Request updates when DDE data changes."""
hszItem = DDE.CreateStringHandle(self._idInst, item, CP_WINUNICODE)
hDdeData = DDE.ClientTransaction(LPBYTE(), 0, self._hConv, hszItem, CF_TEXT, XTYP_ADVSTOP if stop else XTYP_ADVSTART, TIMEOUT_ASYNC, LPDWORD())
... | [
"def",
"advise",
"(",
"self",
",",
"item",
",",
"stop",
"=",
"False",
")",
":",
"hszItem",
"=",
"DDE",
".",
"CreateStringHandle",
"(",
"self",
".",
"_idInst",
",",
"item",
",",
"CP_WINUNICODE",
")",
"hDdeData",
"=",
"DDE",
".",
"ClientTransaction",
"(",
... | Request updates when DDE data changes. | [
"Request",
"updates",
"when",
"DDE",
"data",
"changes",
"."
] | train | https://github.com/indranilsinharoy/pyzos/blob/da6bf3296b0154ccee44ad9a4286055ae031ecc7/pyzos/ddeclient.py#L305-L312 |
indranilsinharoy/pyzos | pyzos/ddeclient.py | DDEClient.execute | def execute(self, command):
"""Execute a DDE command."""
pData = c_char_p(command)
cbData = DWORD(len(command) + 1)
hDdeData = DDE.ClientTransaction(pData, cbData, self._hConv, HSZ(), CF_TEXT, XTYP_EXECUTE, TIMEOUT_ASYNC, LPDWORD())
if not hDdeData:
raise DDEError("Un... | python | def execute(self, command):
"""Execute a DDE command."""
pData = c_char_p(command)
cbData = DWORD(len(command) + 1)
hDdeData = DDE.ClientTransaction(pData, cbData, self._hConv, HSZ(), CF_TEXT, XTYP_EXECUTE, TIMEOUT_ASYNC, LPDWORD())
if not hDdeData:
raise DDEError("Un... | [
"def",
"execute",
"(",
"self",
",",
"command",
")",
":",
"pData",
"=",
"c_char_p",
"(",
"command",
")",
"cbData",
"=",
"DWORD",
"(",
"len",
"(",
"command",
")",
"+",
"1",
")",
"hDdeData",
"=",
"DDE",
".",
"ClientTransaction",
"(",
"pData",
",",
"cbDa... | Execute a DDE command. | [
"Execute",
"a",
"DDE",
"command",
"."
] | train | https://github.com/indranilsinharoy/pyzos/blob/da6bf3296b0154ccee44ad9a4286055ae031ecc7/pyzos/ddeclient.py#L314-L321 |
indranilsinharoy/pyzos | pyzos/ddeclient.py | DDEClient.request | def request(self, item, timeout=5000):
"""Request data from DDE service."""
hszItem = DDE.CreateStringHandle(self._idInst, item, CP_WINUNICODE)
#hDdeData = DDE.ClientTransaction(LPBYTE(), 0, self._hConv, hszItem, CF_TEXT, XTYP_REQUEST, timeout, LPDWORD())
pdwResult = DWORD(0)
hDd... | python | def request(self, item, timeout=5000):
"""Request data from DDE service."""
hszItem = DDE.CreateStringHandle(self._idInst, item, CP_WINUNICODE)
#hDdeData = DDE.ClientTransaction(LPBYTE(), 0, self._hConv, hszItem, CF_TEXT, XTYP_REQUEST, timeout, LPDWORD())
pdwResult = DWORD(0)
hDd... | [
"def",
"request",
"(",
"self",
",",
"item",
",",
"timeout",
"=",
"5000",
")",
":",
"hszItem",
"=",
"DDE",
".",
"CreateStringHandle",
"(",
"self",
".",
"_idInst",
",",
"item",
",",
"CP_WINUNICODE",
")",
"#hDdeData = DDE.ClientTransaction(LPBYTE(), 0, self._hConv, h... | Request data from DDE service. | [
"Request",
"data",
"from",
"DDE",
"service",
"."
] | train | https://github.com/indranilsinharoy/pyzos/blob/da6bf3296b0154ccee44ad9a4286055ae031ecc7/pyzos/ddeclient.py#L323-L343 |
indranilsinharoy/pyzos | pyzos/ddeclient.py | DDEClient._callback | def _callback(self, wType, uFmt, hConv, hsz1, hsz2, hDdeData, dwData1, dwData2):
"""DdeCallback callback function for processing Dynamic Data Exchange (DDE)
transactions sent by DDEML in response to DDE events
Parameters
----------
wType : transaction type (UINT)
uFmt... | python | def _callback(self, wType, uFmt, hConv, hsz1, hsz2, hDdeData, dwData1, dwData2):
"""DdeCallback callback function for processing Dynamic Data Exchange (DDE)
transactions sent by DDEML in response to DDE events
Parameters
----------
wType : transaction type (UINT)
uFmt... | [
"def",
"_callback",
"(",
"self",
",",
"wType",
",",
"uFmt",
",",
"hConv",
",",
"hsz1",
",",
"hsz2",
",",
"hDdeData",
",",
"dwData1",
",",
"dwData2",
")",
":",
"if",
"wType",
"==",
"XTYP_ADVDATA",
":",
"# value of the data item has changed [hsz1 = topic; hsz2 = i... | DdeCallback callback function for processing Dynamic Data Exchange (DDE)
transactions sent by DDEML in response to DDE events
Parameters
----------
wType : transaction type (UINT)
uFmt : clipboard data format (UINT)
hConv : handle to conversation (HCONV)
... | [
"DdeCallback",
"callback",
"function",
"for",
"processing",
"Dynamic",
"Data",
"Exchange",
"(",
"DDE",
")",
"transactions",
"sent",
"by",
"DDEML",
"in",
"response",
"to",
"DDE",
"events"
] | train | https://github.com/indranilsinharoy/pyzos/blob/da6bf3296b0154ccee44ad9a4286055ae031ecc7/pyzos/ddeclient.py#L349-L382 |
HEPData/hepdata-converter | hepdata_converter/parsers/yaml_parser.py | YAML.parse | def parse(self, data_in, *args, **kwargs):
"""
:param data_in: path to submission.yaml
:param args:
:param kwargs:
:raise ValueError:
"""
if not os.path.exists(data_in):
raise ValueError("File / Directory does not exist: %s" % data_in)
if os.p... | python | def parse(self, data_in, *args, **kwargs):
"""
:param data_in: path to submission.yaml
:param args:
:param kwargs:
:raise ValueError:
"""
if not os.path.exists(data_in):
raise ValueError("File / Directory does not exist: %s" % data_in)
if os.p... | [
"def",
"parse",
"(",
"self",
",",
"data_in",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"not",
"os",
".",
"path",
".",
"exists",
"(",
"data_in",
")",
":",
"raise",
"ValueError",
"(",
"\"File / Directory does not exist: %s\"",
"%",
"data_i... | :param data_in: path to submission.yaml
:param args:
:param kwargs:
:raise ValueError: | [
":",
"param",
"data_in",
":",
"path",
"to",
"submission",
".",
"yaml",
":",
"param",
"args",
":",
":",
"param",
"kwargs",
":",
":",
"raise",
"ValueError",
":"
] | train | https://github.com/HEPData/hepdata-converter/blob/354271448980efba86f2f3d27b99d818e75fd90d/hepdata_converter/parsers/yaml_parser.py#L42-L109 |
jay-johnson/antinex-client | antinex_client/generate_ai_request.py | generate_ai_request | def generate_ai_request(
predict_rows,
req_dict=None,
req_file=ANTINEX_PUBLISH_REQUEST_FILE,
features=ANTINEX_FEATURES_TO_PROCESS,
ignore_features=ANTINEX_IGNORE_FEATURES,
sort_values=ANTINEX_SORT_VALUES,
ml_type=ANTINEX_ML_TYPE,
use_model_name=ANTINEX_USE... | python | def generate_ai_request(
predict_rows,
req_dict=None,
req_file=ANTINEX_PUBLISH_REQUEST_FILE,
features=ANTINEX_FEATURES_TO_PROCESS,
ignore_features=ANTINEX_IGNORE_FEATURES,
sort_values=ANTINEX_SORT_VALUES,
ml_type=ANTINEX_ML_TYPE,
use_model_name=ANTINEX_USE... | [
"def",
"generate_ai_request",
"(",
"predict_rows",
",",
"req_dict",
"=",
"None",
",",
"req_file",
"=",
"ANTINEX_PUBLISH_REQUEST_FILE",
",",
"features",
"=",
"ANTINEX_FEATURES_TO_PROCESS",
",",
"ignore_features",
"=",
"ANTINEX_IGNORE_FEATURES",
",",
"sort_values",
"=",
"... | generate_ai_request
:param predict_rows: list of predict rows to build into the request
:param req_dict: request dictionary to update - for long-running clients
:param req_file: file holding a request dict to update - one-off tests
:param features: features to process in the data
:param ignore_feat... | [
"generate_ai_request"
] | train | https://github.com/jay-johnson/antinex-client/blob/850ba2a2fe21c836e071def618dcecc9caf5d59c/antinex_client/generate_ai_request.py#L44-L256 |
jay-johnson/antinex-client | antinex_client/scripts/ai_get_job.py | get_ml_job | def get_ml_job():
"""get_ml_job
Get an ``MLJob`` by database id.
"""
parser = argparse.ArgumentParser(
description=("Python client get AI Job by ID"))
parser.add_argument(
"-u",
help="username",
required=False,
dest="user")
parser.add_argument(
... | python | def get_ml_job():
"""get_ml_job
Get an ``MLJob`` by database id.
"""
parser = argparse.ArgumentParser(
description=("Python client get AI Job by ID"))
parser.add_argument(
"-u",
help="username",
required=False,
dest="user")
parser.add_argument(
... | [
"def",
"get_ml_job",
"(",
")",
":",
"parser",
"=",
"argparse",
".",
"ArgumentParser",
"(",
"description",
"=",
"(",
"\"Python client get AI Job by ID\"",
")",
")",
"parser",
".",
"add_argument",
"(",
"\"-u\"",
",",
"help",
"=",
"\"username\"",
",",
"required",
... | get_ml_job
Get an ``MLJob`` by database id. | [
"get_ml_job"
] | train | https://github.com/jay-johnson/antinex-client/blob/850ba2a2fe21c836e071def618dcecc9caf5d59c/antinex_client/scripts/ai_get_job.py#L20-L251 |
praekeltfoundation/molo.commenting | molo/commenting/templatetags/molo_commenting_tags.py | get_molo_comments | def get_molo_comments(parser, token):
"""
Get a limited set of comments for a given object.
Defaults to a limit of 5. Setting the limit to -1 disables limiting.
Set the amount of comments to
usage:
{% get_molo_comments for object as variable_name %}
{% get_molo_comments for object ... | python | def get_molo_comments(parser, token):
"""
Get a limited set of comments for a given object.
Defaults to a limit of 5. Setting the limit to -1 disables limiting.
Set the amount of comments to
usage:
{% get_molo_comments for object as variable_name %}
{% get_molo_comments for object ... | [
"def",
"get_molo_comments",
"(",
"parser",
",",
"token",
")",
":",
"keywords",
"=",
"token",
".",
"contents",
".",
"split",
"(",
")",
"if",
"len",
"(",
"keywords",
")",
"!=",
"5",
"and",
"len",
"(",
"keywords",
")",
"!=",
"7",
"and",
"len",
"(",
"k... | Get a limited set of comments for a given object.
Defaults to a limit of 5. Setting the limit to -1 disables limiting.
Set the amount of comments to
usage:
{% get_molo_comments for object as variable_name %}
{% get_molo_comments for object as variable_name limit amount %}
{% get_mo... | [
"Get",
"a",
"limited",
"set",
"of",
"comments",
"for",
"a",
"given",
"object",
".",
"Defaults",
"to",
"a",
"limit",
"of",
"5",
".",
"Setting",
"the",
"limit",
"to",
"-",
"1",
"disables",
"limiting",
".",
"Set",
"the",
"amount",
"of",
"comments",
"to"
] | train | https://github.com/praekeltfoundation/molo.commenting/blob/94549bd75e4a5c5b3db43149e32d636330b3969c/molo/commenting/templatetags/molo_commenting_tags.py#L13-L48 |
praekeltfoundation/molo.commenting | molo/commenting/templatetags/molo_commenting_tags.py | get_comments_content_object | def get_comments_content_object(parser, token):
"""
Get a limited set of comments for a given object.
Defaults to a limit of 5. Setting the limit to -1 disables limiting.
usage:
{% get_comments_content_object for form_object as variable_name %}
"""
keywords = token.contents.split()
... | python | def get_comments_content_object(parser, token):
"""
Get a limited set of comments for a given object.
Defaults to a limit of 5. Setting the limit to -1 disables limiting.
usage:
{% get_comments_content_object for form_object as variable_name %}
"""
keywords = token.contents.split()
... | [
"def",
"get_comments_content_object",
"(",
"parser",
",",
"token",
")",
":",
"keywords",
"=",
"token",
".",
"contents",
".",
"split",
"(",
")",
"if",
"len",
"(",
"keywords",
")",
"!=",
"5",
":",
"raise",
"template",
".",
"TemplateSyntaxError",
"(",
"\"'%s'... | Get a limited set of comments for a given object.
Defaults to a limit of 5. Setting the limit to -1 disables limiting.
usage:
{% get_comments_content_object for form_object as variable_name %} | [
"Get",
"a",
"limited",
"set",
"of",
"comments",
"for",
"a",
"given",
"object",
".",
"Defaults",
"to",
"a",
"limit",
"of",
"5",
".",
"Setting",
"the",
"limit",
"to",
"-",
"1",
"disables",
"limiting",
"."
] | train | https://github.com/praekeltfoundation/molo.commenting/blob/94549bd75e4a5c5b3db43149e32d636330b3969c/molo/commenting/templatetags/molo_commenting_tags.py#L75-L95 |
praekeltfoundation/molo.commenting | molo/commenting/views.py | report | def report(request, comment_id):
"""
Flags a comment on GET.
Redirects to whatever is provided in request.REQUEST['next'].
"""
comment = get_object_or_404(
django_comments.get_model(), pk=comment_id, site__pk=settings.SITE_ID)
if comment.parent is not None:
messages.info(reques... | python | def report(request, comment_id):
"""
Flags a comment on GET.
Redirects to whatever is provided in request.REQUEST['next'].
"""
comment = get_object_or_404(
django_comments.get_model(), pk=comment_id, site__pk=settings.SITE_ID)
if comment.parent is not None:
messages.info(reques... | [
"def",
"report",
"(",
"request",
",",
"comment_id",
")",
":",
"comment",
"=",
"get_object_or_404",
"(",
"django_comments",
".",
"get_model",
"(",
")",
",",
"pk",
"=",
"comment_id",
",",
"site__pk",
"=",
"settings",
".",
"SITE_ID",
")",
"if",
"comment",
"."... | Flags a comment on GET.
Redirects to whatever is provided in request.REQUEST['next']. | [
"Flags",
"a",
"comment",
"on",
"GET",
"."
] | train | https://github.com/praekeltfoundation/molo.commenting/blob/94549bd75e4a5c5b3db43149e32d636330b3969c/molo/commenting/views.py#L21-L37 |
praekeltfoundation/molo.commenting | molo/commenting/views.py | post_molo_comment | def post_molo_comment(request, next=None, using=None):
"""
Allows for posting of a Molo Comment, this allows comments to
be set with the "user_name" as "Anonymous"
"""
data = request.POST.copy()
if 'submit_anonymously' in data:
data['name'] = 'Anonymous'
# replace with our changed PO... | python | def post_molo_comment(request, next=None, using=None):
"""
Allows for posting of a Molo Comment, this allows comments to
be set with the "user_name" as "Anonymous"
"""
data = request.POST.copy()
if 'submit_anonymously' in data:
data['name'] = 'Anonymous'
# replace with our changed PO... | [
"def",
"post_molo_comment",
"(",
"request",
",",
"next",
"=",
"None",
",",
"using",
"=",
"None",
")",
":",
"data",
"=",
"request",
".",
"POST",
".",
"copy",
"(",
")",
"if",
"'submit_anonymously'",
"in",
"data",
":",
"data",
"[",
"'name'",
"]",
"=",
"... | Allows for posting of a Molo Comment, this allows comments to
be set with the "user_name" as "Anonymous" | [
"Allows",
"for",
"posting",
"of",
"a",
"Molo",
"Comment",
"this",
"allows",
"comments",
"to",
"be",
"set",
"with",
"the",
"user_name",
"as",
"Anonymous"
] | train | https://github.com/praekeltfoundation/molo.commenting/blob/94549bd75e4a5c5b3db43149e32d636330b3969c/molo/commenting/views.py#L41-L55 |
jay-johnson/antinex-client | antinex_client/build_ai_client_from_env.py | build_ai_client_from_env | def build_ai_client_from_env(
verbose=ANTINEX_CLIENT_VERBOSE,
debug=ANTINEX_CLIENT_DEBUG,
ca_dir=None,
cert_file=None,
key_file=None):
"""build_ai_client_from_env
Use environment variables to build a client
:param verbose: verbose logging
:param debug: debug int... | python | def build_ai_client_from_env(
verbose=ANTINEX_CLIENT_VERBOSE,
debug=ANTINEX_CLIENT_DEBUG,
ca_dir=None,
cert_file=None,
key_file=None):
"""build_ai_client_from_env
Use environment variables to build a client
:param verbose: verbose logging
:param debug: debug int... | [
"def",
"build_ai_client_from_env",
"(",
"verbose",
"=",
"ANTINEX_CLIENT_VERBOSE",
",",
"debug",
"=",
"ANTINEX_CLIENT_DEBUG",
",",
"ca_dir",
"=",
"None",
",",
"cert_file",
"=",
"None",
",",
"key_file",
"=",
"None",
")",
":",
"if",
"not",
"ANTINEX_PUBLISH_ENABLED",
... | build_ai_client_from_env
Use environment variables to build a client
:param verbose: verbose logging
:param debug: debug internal client calls
:param ca_dir: optional path to CA bundle dir
:param cert_file: optional path to x509 ssl cert file
:param key_file: optional path to x509 ssl key file | [
"build_ai_client_from_env"
] | train | https://github.com/jay-johnson/antinex-client/blob/850ba2a2fe21c836e071def618dcecc9caf5d59c/antinex_client/build_ai_client_from_env.py#L19-L78 |
jay-johnson/antinex-client | antinex_client/scripts/ai_train_dnn.py | train_new_deep_neural_network | def train_new_deep_neural_network():
"""train_new_deep_neural_network
Train a new deep neural network and store the results as a new:
``MLJob`` and ``MLJobResult`` database records.
"""
parser = argparse.ArgumentParser(
description=(
"Python client to Train a Deep Neural Netwo... | python | def train_new_deep_neural_network():
"""train_new_deep_neural_network
Train a new deep neural network and store the results as a new:
``MLJob`` and ``MLJobResult`` database records.
"""
parser = argparse.ArgumentParser(
description=(
"Python client to Train a Deep Neural Netwo... | [
"def",
"train_new_deep_neural_network",
"(",
")",
":",
"parser",
"=",
"argparse",
".",
"ArgumentParser",
"(",
"description",
"=",
"(",
"\"Python client to Train a Deep Neural Network \"",
"\"with AntiNex Django Rest Framework\"",
")",
")",
"parser",
".",
"add_argument",
"("... | train_new_deep_neural_network
Train a new deep neural network and store the results as a new:
``MLJob`` and ``MLJobResult`` database records. | [
"train_new_deep_neural_network"
] | train | https://github.com/jay-johnson/antinex-client/blob/850ba2a2fe21c836e071def618dcecc9caf5d59c/antinex_client/scripts/ai_train_dnn.py#L22-L329 |
jay-johnson/antinex-client | antinex_client/scripts/ai_prepare_dataset.py | prepare_new_dataset | def prepare_new_dataset():
"""prepare_new_dataset
Prepare a new ``MLPrepare`` record and dataset files on disk.
"""
parser = argparse.ArgumentParser(
description=(
"Python client to Prepare a dataset"))
parser.add_argument(
"-u",
help="username",
requir... | python | def prepare_new_dataset():
"""prepare_new_dataset
Prepare a new ``MLPrepare`` record and dataset files on disk.
"""
parser = argparse.ArgumentParser(
description=(
"Python client to Prepare a dataset"))
parser.add_argument(
"-u",
help="username",
requir... | [
"def",
"prepare_new_dataset",
"(",
")",
":",
"parser",
"=",
"argparse",
".",
"ArgumentParser",
"(",
"description",
"=",
"(",
"\"Python client to Prepare a dataset\"",
")",
")",
"parser",
".",
"add_argument",
"(",
"\"-u\"",
",",
"help",
"=",
"\"username\"",
",",
... | prepare_new_dataset
Prepare a new ``MLPrepare`` record and dataset files on disk. | [
"prepare_new_dataset"
] | train | https://github.com/jay-johnson/antinex-client/blob/850ba2a2fe21c836e071def618dcecc9caf5d59c/antinex_client/scripts/ai_prepare_dataset.py#L21-L276 |
mrahnis/drapery | drapery/ops/sample.py | drape | def drape(raster, feature):
"""Convert a 2D feature to a 3D feature by sampling a raster
Parameters:
raster (rasterio): raster to provide the z coordinate
feature (dict): fiona feature record to convert
Returns:
result (Point or Linestring): shapely Point or LineString of xyz coord... | python | def drape(raster, feature):
"""Convert a 2D feature to a 3D feature by sampling a raster
Parameters:
raster (rasterio): raster to provide the z coordinate
feature (dict): fiona feature record to convert
Returns:
result (Point or Linestring): shapely Point or LineString of xyz coord... | [
"def",
"drape",
"(",
"raster",
",",
"feature",
")",
":",
"coords",
"=",
"feature",
"[",
"'geometry'",
"]",
"[",
"'coordinates'",
"]",
"geom_type",
"=",
"feature",
"[",
"'geometry'",
"]",
"[",
"'type'",
"]",
"if",
"geom_type",
"==",
"'Point'",
":",
"xyz",... | Convert a 2D feature to a 3D feature by sampling a raster
Parameters:
raster (rasterio): raster to provide the z coordinate
feature (dict): fiona feature record to convert
Returns:
result (Point or Linestring): shapely Point or LineString of xyz coordinate triples | [
"Convert",
"a",
"2D",
"feature",
"to",
"a",
"3D",
"feature",
"by",
"sampling",
"a",
"raster"
] | train | https://github.com/mrahnis/drapery/blob/c0c0906fb5ff846cf591cb9fe8a9eaee68e8820c/drapery/ops/sample.py#L6-L30 |
mrahnis/drapery | drapery/ops/sample.py | sample | def sample(raster, coords):
"""Sample a raster at given coordinates
Given a list of coordinates, return a list of x,y,z triples with z coordinates sampled from an input raster
Parameters:
raster (rasterio): raster dataset to sample
coords: array of tuples containing coordinate pairs (x,y) ... | python | def sample(raster, coords):
"""Sample a raster at given coordinates
Given a list of coordinates, return a list of x,y,z triples with z coordinates sampled from an input raster
Parameters:
raster (rasterio): raster dataset to sample
coords: array of tuples containing coordinate pairs (x,y) ... | [
"def",
"sample",
"(",
"raster",
",",
"coords",
")",
":",
"if",
"len",
"(",
"coords",
"[",
"0",
"]",
")",
"==",
"3",
":",
"logging",
".",
"info",
"(",
"'Input is a 3D geometry, z coordinate will be updated.'",
")",
"z",
"=",
"raster",
".",
"sample",
"(",
... | Sample a raster at given coordinates
Given a list of coordinates, return a list of x,y,z triples with z coordinates sampled from an input raster
Parameters:
raster (rasterio): raster dataset to sample
coords: array of tuples containing coordinate pairs (x,y) or triples (x,y,z)
Returns:
... | [
"Sample",
"a",
"raster",
"at",
"given",
"coordinates"
] | train | https://github.com/mrahnis/drapery/blob/c0c0906fb5ff846cf591cb9fe8a9eaee68e8820c/drapery/ops/sample.py#L32-L53 |
jay-johnson/antinex-client | antinex_client/log/setup_logging.py | setup_logging | def setup_logging(
default_level=logging.INFO,
default_path="{}/logging.json".format(
os.getenv(
"LOG_DIR",
os.path.dirname(os.path.realpath(__file__)))),
env_key="LOG_CFG",
config_name=None):
"""setup_logging
Setup logging configurati... | python | def setup_logging(
default_level=logging.INFO,
default_path="{}/logging.json".format(
os.getenv(
"LOG_DIR",
os.path.dirname(os.path.realpath(__file__)))),
env_key="LOG_CFG",
config_name=None):
"""setup_logging
Setup logging configurati... | [
"def",
"setup_logging",
"(",
"default_level",
"=",
"logging",
".",
"INFO",
",",
"default_path",
"=",
"\"{}/logging.json\"",
".",
"format",
"(",
"os",
".",
"getenv",
"(",
"\"LOG_DIR\"",
",",
"os",
".",
"path",
".",
"dirname",
"(",
"os",
".",
"path",
".",
... | setup_logging
Setup logging configuration
:param default_level: level to log
:param default_path: path to config (optional)
:param env_key: path to config in this env var
:param config_name: filename for config | [
"setup_logging"
] | train | https://github.com/jay-johnson/antinex-client/blob/850ba2a2fe21c836e071def618dcecc9caf5d59c/antinex_client/log/setup_logging.py#L6-L59 |
jay-johnson/antinex-client | antinex_client/log/setup_logging.py | build_logger | def build_logger(
name=os.getenv(
"LOG_NAME",
"client"),
config="logging.json",
log_level=logging.INFO,
log_config_path="{}/logging.json".format(
os.getenv(
"LOG_CFG",
os.path.dirname(os.path.realpath(__file__))))):
"""build_logger
:param name: na... | python | def build_logger(
name=os.getenv(
"LOG_NAME",
"client"),
config="logging.json",
log_level=logging.INFO,
log_config_path="{}/logging.json".format(
os.getenv(
"LOG_CFG",
os.path.dirname(os.path.realpath(__file__))))):
"""build_logger
:param name: na... | [
"def",
"build_logger",
"(",
"name",
"=",
"os",
".",
"getenv",
"(",
"\"LOG_NAME\"",
",",
"\"client\"",
")",
",",
"config",
"=",
"\"logging.json\"",
",",
"log_level",
"=",
"logging",
".",
"INFO",
",",
"log_config_path",
"=",
"\"{}/logging.json\"",
".",
"format",... | build_logger
:param name: name that shows in the logger
:param config: name of the config file
:param log_level: level to log
:param log_config_path: path to log config file | [
"build_logger"
] | train | https://github.com/jay-johnson/antinex-client/blob/850ba2a2fe21c836e071def618dcecc9caf5d59c/antinex_client/log/setup_logging.py#L63-L94 |
jay-johnson/antinex-client | antinex_client/log/setup_logging.py | build_colorized_logger | def build_colorized_logger(
name=os.getenv(
"LOG_NAME",
"client"),
config="colors-logging.json",
log_level=logging.INFO,
log_config_path="{}/logging.json".format(
os.getenv(
"LOG_CFG",
os.path.dirname(os.path.realpath(__file__))))):
"""build_colorized_... | python | def build_colorized_logger(
name=os.getenv(
"LOG_NAME",
"client"),
config="colors-logging.json",
log_level=logging.INFO,
log_config_path="{}/logging.json".format(
os.getenv(
"LOG_CFG",
os.path.dirname(os.path.realpath(__file__))))):
"""build_colorized_... | [
"def",
"build_colorized_logger",
"(",
"name",
"=",
"os",
".",
"getenv",
"(",
"\"LOG_NAME\"",
",",
"\"client\"",
")",
",",
"config",
"=",
"\"colors-logging.json\"",
",",
"log_level",
"=",
"logging",
".",
"INFO",
",",
"log_config_path",
"=",
"\"{}/logging.json\"",
... | build_colorized_logger
:param name: name that shows in the logger
:param config: name of the config file
:param log_level: level to log
:param log_config_path: path to log config file | [
"build_colorized_logger"
] | train | https://github.com/jay-johnson/antinex-client/blob/850ba2a2fe21c836e071def618dcecc9caf5d59c/antinex_client/log/setup_logging.py#L98-L169 |
feliphebueno/Rinzler | rinzler/auth/base_auth_service.py | BaseAuthService.authenticate | def authenticate(self, request: HttpRequest, auth_route: str, actual_params: dict) -> bool:
"""
Your AuhtService should override this method for request authentication, otherwise means no authentication.
:param request: HttpRequest Django's HttpRequest object
:param auth_route: str User'... | python | def authenticate(self, request: HttpRequest, auth_route: str, actual_params: dict) -> bool:
"""
Your AuhtService should override this method for request authentication, otherwise means no authentication.
:param request: HttpRequest Django's HttpRequest object
:param auth_route: str User'... | [
"def",
"authenticate",
"(",
"self",
",",
"request",
":",
"HttpRequest",
",",
"auth_route",
":",
"str",
",",
"actual_params",
":",
"dict",
")",
"->",
"bool",
":",
"if",
"auth_route",
"and",
"actual_params",
":",
"self",
".",
"auth_data",
"=",
"{",
"}",
"r... | Your AuhtService should override this method for request authentication, otherwise means no authentication.
:param request: HttpRequest Django's HttpRequest object
:param auth_route: str User's resqueted route
:param actual_params: User's url parameters
:return: bool | [
"Your",
"AuhtService",
"should",
"override",
"this",
"method",
"for",
"request",
"authentication",
"otherwise",
"means",
"no",
"authentication",
".",
":",
"param",
"request",
":",
"HttpRequest",
"Django",
"s",
"HttpRequest",
"object",
":",
"param",
"auth_route",
"... | train | https://github.com/feliphebueno/Rinzler/blob/7f6d5445b5662cba2e8938bb82c7f3ef94e5ded8/rinzler/auth/base_auth_service.py#L13-L23 |
mrahnis/drapery | drapery/cli/drape.py | cli | def cli(source_f, raster_f, output, verbose):
"""
Converts 2D geometries to 3D using GEOS sample through fiona.
\b
Example:
drape point.shp elevation.tif -o point_z.shp
"""
with fiona.open(source_f, 'r') as source:
source_driver = source.driver
source_crs = source.crs
... | python | def cli(source_f, raster_f, output, verbose):
"""
Converts 2D geometries to 3D using GEOS sample through fiona.
\b
Example:
drape point.shp elevation.tif -o point_z.shp
"""
with fiona.open(source_f, 'r') as source:
source_driver = source.driver
source_crs = source.crs
... | [
"def",
"cli",
"(",
"source_f",
",",
"raster_f",
",",
"output",
",",
"verbose",
")",
":",
"with",
"fiona",
".",
"open",
"(",
"source_f",
",",
"'r'",
")",
"as",
"source",
":",
"source_driver",
"=",
"source",
".",
"driver",
"source_crs",
"=",
"source",
".... | Converts 2D geometries to 3D using GEOS sample through fiona.
\b
Example:
drape point.shp elevation.tif -o point_z.shp | [
"Converts",
"2D",
"geometries",
"to",
"3D",
"using",
"GEOS",
"sample",
"through",
"fiona",
"."
] | train | https://github.com/mrahnis/drapery/blob/c0c0906fb5ff846cf591cb9fe8a9eaee68e8820c/drapery/cli/drape.py#L21-L67 |
praekeltfoundation/molo.commenting | molo/commenting/managers.py | MoloCommentManager.for_model | def for_model(self, model):
"""
QuerySet for all comments for a particular model (either an instance or
a class).
"""
ct = ContentType.objects.get_for_model(model)
qs = self.get_queryset().filter(content_type=ct)
if isinstance(model, models.Model):
qs ... | python | def for_model(self, model):
"""
QuerySet for all comments for a particular model (either an instance or
a class).
"""
ct = ContentType.objects.get_for_model(model)
qs = self.get_queryset().filter(content_type=ct)
if isinstance(model, models.Model):
qs ... | [
"def",
"for_model",
"(",
"self",
",",
"model",
")",
":",
"ct",
"=",
"ContentType",
".",
"objects",
".",
"get_for_model",
"(",
"model",
")",
"qs",
"=",
"self",
".",
"get_queryset",
"(",
")",
".",
"filter",
"(",
"content_type",
"=",
"ct",
")",
"if",
"i... | QuerySet for all comments for a particular model (either an instance or
a class). | [
"QuerySet",
"for",
"all",
"comments",
"for",
"a",
"particular",
"model",
"(",
"either",
"an",
"instance",
"or",
"a",
"class",
")",
"."
] | train | https://github.com/praekeltfoundation/molo.commenting/blob/94549bd75e4a5c5b3db43149e32d636330b3969c/molo/commenting/managers.py#L9-L18 |
oksome/Skink | skink/remote.py | RemotePage.eval | def eval(self, command):
'Blocking call, returns the value of the execution in JS'
event = threading.Event()
# TODO: Add event to server
#job_id = str(id(command))
import random
job_id = str(random.random())
server.EVALUATIONS[job_id] = event
message = '?... | python | def eval(self, command):
'Blocking call, returns the value of the execution in JS'
event = threading.Event()
# TODO: Add event to server
#job_id = str(id(command))
import random
job_id = str(random.random())
server.EVALUATIONS[job_id] = event
message = '?... | [
"def",
"eval",
"(",
"self",
",",
"command",
")",
":",
"event",
"=",
"threading",
".",
"Event",
"(",
")",
"# TODO: Add event to server",
"#job_id = str(id(command))",
"import",
"random",
"job_id",
"=",
"str",
"(",
"random",
".",
"random",
"(",
")",
")",
"serv... | Blocking call, returns the value of the execution in JS | [
"Blocking",
"call",
"returns",
"the",
"value",
"of",
"the",
"execution",
"in",
"JS"
] | train | https://github.com/oksome/Skink/blob/77560fb92749c1a21924cbd0017b8481a727be3e/skink/remote.py#L132-L158 |
oksome/Skink | skink/remote.py | RemotePage.register | def register(self, callback, name):
'Register a callback on server and on connected clients.'
server.CALLBACKS[name] = callback
self.run('''
window.skink.%s = function(args=[]) {
window.skink.call("%s", args);
}''' % (name, name)) | python | def register(self, callback, name):
'Register a callback on server and on connected clients.'
server.CALLBACKS[name] = callback
self.run('''
window.skink.%s = function(args=[]) {
window.skink.call("%s", args);
}''' % (name, name)) | [
"def",
"register",
"(",
"self",
",",
"callback",
",",
"name",
")",
":",
"server",
".",
"CALLBACKS",
"[",
"name",
"]",
"=",
"callback",
"self",
".",
"run",
"(",
"'''\n window.skink.%s = function(args=[]) {\n window.skink.call(\"%s\", args);\n ... | Register a callback on server and on connected clients. | [
"Register",
"a",
"callback",
"on",
"server",
"and",
"on",
"connected",
"clients",
"."
] | train | https://github.com/oksome/Skink/blob/77560fb92749c1a21924cbd0017b8481a727be3e/skink/remote.py#L160-L166 |
oksome/Skink | skink/server.py | launch_exception | def launch_exception(message):
"""
Launch a Python exception from an error that took place in the browser.
messsage format:
- name: str
- description: str
"""
error_name = message['name']
error_descr = message['description']
mapping = {
'ReferenceError': Name... | python | def launch_exception(message):
"""
Launch a Python exception from an error that took place in the browser.
messsage format:
- name: str
- description: str
"""
error_name = message['name']
error_descr = message['description']
mapping = {
'ReferenceError': Name... | [
"def",
"launch_exception",
"(",
"message",
")",
":",
"error_name",
"=",
"message",
"[",
"'name'",
"]",
"error_descr",
"=",
"message",
"[",
"'description'",
"]",
"mapping",
"=",
"{",
"'ReferenceError'",
":",
"NameError",
",",
"}",
"if",
"message",
"[",
"'name... | Launch a Python exception from an error that took place in the browser.
messsage format:
- name: str
- description: str | [
"Launch",
"a",
"Python",
"exception",
"from",
"an",
"error",
"that",
"took",
"place",
"in",
"the",
"browser",
"."
] | train | https://github.com/oksome/Skink/blob/77560fb92749c1a21924cbd0017b8481a727be3e/skink/server.py#L42-L58 |
jay-johnson/antinex-client | antinex_client/scripts/ai_env_predict.py | start_predictions | def start_predictions():
"""start_predictions
Using environment variables, create an AntiNex AI Client.
You can also use command line args if you want.
This can train a new deep neural network if it does not
exist or it can use an existing pre-trained deep neural
network within the AntiNex Cor... | python | def start_predictions():
"""start_predictions
Using environment variables, create an AntiNex AI Client.
You can also use command line args if you want.
This can train a new deep neural network if it does not
exist or it can use an existing pre-trained deep neural
network within the AntiNex Cor... | [
"def",
"start_predictions",
"(",
")",
":",
"parser",
"=",
"argparse",
".",
"ArgumentParser",
"(",
"description",
"=",
"(",
"\"Python client to make Predictions \"",
"\"using a Pre-trained Deep Neural Network \"",
"\"with AntiNex Django Rest Framework\"",
")",
")",
"parser",
"... | start_predictions
Using environment variables, create an AntiNex AI Client.
You can also use command line args if you want.
This can train a new deep neural network if it does not
exist or it can use an existing pre-trained deep neural
network within the AntiNex Core to make new predictions. | [
"start_predictions"
] | train | https://github.com/jay-johnson/antinex-client/blob/850ba2a2fe21c836e071def618dcecc9caf5d59c/antinex_client/scripts/ai_env_predict.py#L23-L288 |
jay-johnson/antinex-client | antinex_client/ai_client.py | AIClient.login | def login(
self):
"""login"""
auth_url = self.api_urls["login"]
if self.verbose:
log.info(("log in user={} url={} ca_dir={} cert={}")
.format(
self.user,
auth_url,
self.ca_dir,
... | python | def login(
self):
"""login"""
auth_url = self.api_urls["login"]
if self.verbose:
log.info(("log in user={} url={} ca_dir={} cert={}")
.format(
self.user,
auth_url,
self.ca_dir,
... | [
"def",
"login",
"(",
"self",
")",
":",
"auth_url",
"=",
"self",
".",
"api_urls",
"[",
"\"login\"",
"]",
"if",
"self",
".",
"verbose",
":",
"log",
".",
"info",
"(",
"(",
"\"log in user={} url={} ca_dir={} cert={}\"",
")",
".",
"format",
"(",
"self",
".",
... | login | [
"login"
] | train | https://github.com/jay-johnson/antinex-client/blob/850ba2a2fe21c836e071def618dcecc9caf5d59c/antinex_client/ai_client.py#L121-L186 |
jay-johnson/antinex-client | antinex_client/ai_client.py | AIClient.build_response | def build_response(
self,
status=NOT_SET,
error="",
data=None):
"""build_response
:param status: status code
:param error: error message
:param data: dictionary to send back
"""
res_node = {
"status": status,
... | python | def build_response(
self,
status=NOT_SET,
error="",
data=None):
"""build_response
:param status: status code
:param error: error message
:param data: dictionary to send back
"""
res_node = {
"status": status,
... | [
"def",
"build_response",
"(",
"self",
",",
"status",
"=",
"NOT_SET",
",",
"error",
"=",
"\"\"",
",",
"data",
"=",
"None",
")",
":",
"res_node",
"=",
"{",
"\"status\"",
":",
"status",
",",
"\"error\"",
":",
"error",
",",
"\"data\"",
":",
"data",
"}",
... | build_response
:param status: status code
:param error: error message
:param data: dictionary to send back | [
"build_response"
] | train | https://github.com/jay-johnson/antinex-client/blob/850ba2a2fe21c836e071def618dcecc9caf5d59c/antinex_client/ai_client.py#L211-L228 |
jay-johnson/antinex-client | antinex_client/ai_client.py | AIClient.retry_login | def retry_login(
self):
"""retry_login"""
if not self.user or not self.password:
return self.build_response(
status=ERROR,
error="please set the user and password")
retry = 0
not_done = True
while not_done:
if ... | python | def retry_login(
self):
"""retry_login"""
if not self.user or not self.password:
return self.build_response(
status=ERROR,
error="please set the user and password")
retry = 0
not_done = True
while not_done:
if ... | [
"def",
"retry_login",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"user",
"or",
"not",
"self",
".",
"password",
":",
"return",
"self",
".",
"build_response",
"(",
"status",
"=",
"ERROR",
",",
"error",
"=",
"\"please set the user and password\"",
")",
... | retry_login | [
"retry_login"
] | train | https://github.com/jay-johnson/antinex-client/blob/850ba2a2fe21c836e071def618dcecc9caf5d59c/antinex_client/ai_client.py#L231-L273 |
jay-johnson/antinex-client | antinex_client/ai_client.py | AIClient.get_prepare_by_id | def get_prepare_by_id(
self,
prepare_id=None):
"""get_prepare_by_id
:param prepare_id: MLJob.id in the database
"""
if not prepare_id:
log.error("missing prepare_id for get_prepare_by_id")
return self.build_response(
statu... | python | def get_prepare_by_id(
self,
prepare_id=None):
"""get_prepare_by_id
:param prepare_id: MLJob.id in the database
"""
if not prepare_id:
log.error("missing prepare_id for get_prepare_by_id")
return self.build_response(
statu... | [
"def",
"get_prepare_by_id",
"(",
"self",
",",
"prepare_id",
"=",
"None",
")",
":",
"if",
"not",
"prepare_id",
":",
"log",
".",
"error",
"(",
"\"missing prepare_id for get_prepare_by_id\"",
")",
"return",
"self",
".",
"build_response",
"(",
"status",
"=",
"ERROR"... | get_prepare_by_id
:param prepare_id: MLJob.id in the database | [
"get_prepare_by_id"
] | train | https://github.com/jay-johnson/antinex-client/blob/850ba2a2fe21c836e071def618dcecc9caf5d59c/antinex_client/ai_client.py#L276-L377 |
jay-johnson/antinex-client | antinex_client/ai_client.py | AIClient.wait_for_job_to_finish | def wait_for_job_to_finish(
self,
job_id,
sec_to_sleep=5.0,
max_retries=100000):
"""wait_for_job_to_finish
:param job_id: MLJob.id to wait on
:param sec_to_sleep: seconds to sleep during polling
:param max_retries: max retires until stoppi... | python | def wait_for_job_to_finish(
self,
job_id,
sec_to_sleep=5.0,
max_retries=100000):
"""wait_for_job_to_finish
:param job_id: MLJob.id to wait on
:param sec_to_sleep: seconds to sleep during polling
:param max_retries: max retires until stoppi... | [
"def",
"wait_for_job_to_finish",
"(",
"self",
",",
"job_id",
",",
"sec_to_sleep",
"=",
"5.0",
",",
"max_retries",
"=",
"100000",
")",
":",
"not_done",
"=",
"True",
"retry_attempt",
"=",
"1",
"while",
"not_done",
":",
"if",
"self",
".",
"debug",
":",
"log",... | wait_for_job_to_finish
:param job_id: MLJob.id to wait on
:param sec_to_sleep: seconds to sleep during polling
:param max_retries: max retires until stopping | [
"wait_for_job_to_finish"
] | train | https://github.com/jay-johnson/antinex-client/blob/850ba2a2fe21c836e071def618dcecc9caf5d59c/antinex_client/ai_client.py#L726-L870 |
jay-johnson/antinex-client | antinex_client/ai_client.py | AIClient.wait_for_prepare_to_finish | def wait_for_prepare_to_finish(
self,
prepare_id,
sec_to_sleep=5.0,
max_retries=100000):
"""wait_for_prepare_to_finish
:param prepare_id: MLPrepare.id to wait on
:param sec_to_sleep: seconds to sleep during polling
:param max_retries: max ... | python | def wait_for_prepare_to_finish(
self,
prepare_id,
sec_to_sleep=5.0,
max_retries=100000):
"""wait_for_prepare_to_finish
:param prepare_id: MLPrepare.id to wait on
:param sec_to_sleep: seconds to sleep during polling
:param max_retries: max ... | [
"def",
"wait_for_prepare_to_finish",
"(",
"self",
",",
"prepare_id",
",",
"sec_to_sleep",
"=",
"5.0",
",",
"max_retries",
"=",
"100000",
")",
":",
"not_done",
"=",
"True",
"retry_attempt",
"=",
"1",
"while",
"not_done",
":",
"if",
"self",
".",
"debug",
":",
... | wait_for_prepare_to_finish
:param prepare_id: MLPrepare.id to wait on
:param sec_to_sleep: seconds to sleep during polling
:param max_retries: max retires until stopping | [
"wait_for_prepare_to_finish"
] | train | https://github.com/jay-johnson/antinex-client/blob/850ba2a2fe21c836e071def618dcecc9caf5d59c/antinex_client/ai_client.py#L985-L1065 |
praekeltfoundation/molo.commenting | molo/commenting/forms.py | MoloCommentForm.get_comment_object | def get_comment_object(self):
"""
NB: Overridden to remove dupe comment check for admins (necessary for
canned responses)
Return a new (unsaved) comment object based on the information in this
form. Assumes that the form is already validated and will throw a
ValueError i... | python | def get_comment_object(self):
"""
NB: Overridden to remove dupe comment check for admins (necessary for
canned responses)
Return a new (unsaved) comment object based on the information in this
form. Assumes that the form is already validated and will throw a
ValueError i... | [
"def",
"get_comment_object",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"is_valid",
"(",
")",
":",
"raise",
"ValueError",
"(",
"\"get_comment_object may only be called on valid forms\"",
")",
"CommentModel",
"=",
"self",
".",
"get_comment_model",
"(",
")",
"... | NB: Overridden to remove dupe comment check for admins (necessary for
canned responses)
Return a new (unsaved) comment object based on the information in this
form. Assumes that the form is already validated and will throw a
ValueError if not.
Does not set any of the fields tha... | [
"NB",
":",
"Overridden",
"to",
"remove",
"dupe",
"comment",
"check",
"for",
"admins",
"(",
"necessary",
"for",
"canned",
"responses",
")"
] | train | https://github.com/praekeltfoundation/molo.commenting/blob/94549bd75e4a5c5b3db43149e32d636330b3969c/molo/commenting/forms.py#L31-L59 |
feliphebueno/Rinzler | rinzler/__init__.py | boot | def boot(app_name) -> Rinzler:
"""
Start Rinzler App
:param app_name: str Application's identifier
:return: dict
"""
app = Rinzler(app_name)
app.log.info("App booted =)")
return app | python | def boot(app_name) -> Rinzler:
"""
Start Rinzler App
:param app_name: str Application's identifier
:return: dict
"""
app = Rinzler(app_name)
app.log.info("App booted =)")
return app | [
"def",
"boot",
"(",
"app_name",
")",
"->",
"Rinzler",
":",
"app",
"=",
"Rinzler",
"(",
"app_name",
")",
"app",
".",
"log",
".",
"info",
"(",
"\"App booted =)\"",
")",
"return",
"app"
] | Start Rinzler App
:param app_name: str Application's identifier
:return: dict | [
"Start",
"Rinzler",
"App",
":",
"param",
"app_name",
":",
"str",
"Application",
"s",
"identifier",
":",
"return",
":",
"dict"
] | train | https://github.com/feliphebueno/Rinzler/blob/7f6d5445b5662cba2e8938bb82c7f3ef94e5ded8/rinzler/__init__.py#L391-L400 |
feliphebueno/Rinzler | rinzler/__init__.py | Rinzler.mount | def mount(self, route: str, controller: callable) -> url:
"""
Maps a route namespace with the given params and point it's requests to the especified controller.
:param route: str Namespace route to be mapped
:param controller: callback Controller callable to map end-points
:rtype... | python | def mount(self, route: str, controller: callable) -> url:
"""
Maps a route namespace with the given params and point it's requests to the especified controller.
:param route: str Namespace route to be mapped
:param controller: callback Controller callable to map end-points
:rtype... | [
"def",
"mount",
"(",
"self",
",",
"route",
":",
"str",
",",
"controller",
":",
"callable",
")",
"->",
"url",
":",
"if",
"issubclass",
"(",
"controller",
",",
"TemplateView",
")",
":",
"return",
"url",
"(",
"r\"%s\"",
"%",
"route",
",",
"Router",
"(",
... | Maps a route namespace with the given params and point it's requests to the especified controller.
:param route: str Namespace route to be mapped
:param controller: callback Controller callable to map end-points
:rtype: url | [
"Maps",
"a",
"route",
"namespace",
"with",
"the",
"given",
"params",
"and",
"point",
"it",
"s",
"requests",
"to",
"the",
"especified",
"controller",
".",
":",
"param",
"route",
":",
"str",
"Namespace",
"route",
"to",
"be",
"mapped",
":",
"param",
"controll... | train | https://github.com/feliphebueno/Rinzler/blob/7f6d5445b5662cba2e8938bb82c7f3ef94e5ded8/rinzler/__init__.py#L52-L68 |
feliphebueno/Rinzler | rinzler/__init__.py | Rinzler.set_auth_service | def set_auth_service(self, auth_service: BaseAuthService):
"""
Sets the authentication service
:param auth_service: BaseAuthService Authentication service
:raises: TypeError If the auth_service object is not a subclass of rinzler.auth.BaseAuthService
:rtype: Rinzler
"""
... | python | def set_auth_service(self, auth_service: BaseAuthService):
"""
Sets the authentication service
:param auth_service: BaseAuthService Authentication service
:raises: TypeError If the auth_service object is not a subclass of rinzler.auth.BaseAuthService
:rtype: Rinzler
"""
... | [
"def",
"set_auth_service",
"(",
"self",
",",
"auth_service",
":",
"BaseAuthService",
")",
":",
"if",
"issubclass",
"(",
"auth_service",
".",
"__class__",
",",
"BaseAuthService",
")",
":",
"self",
".",
"auth_service",
"=",
"auth_service",
"return",
"self",
"else"... | Sets the authentication service
:param auth_service: BaseAuthService Authentication service
:raises: TypeError If the auth_service object is not a subclass of rinzler.auth.BaseAuthService
:rtype: Rinzler | [
"Sets",
"the",
"authentication",
"service",
":",
"param",
"auth_service",
":",
"BaseAuthService",
"Authentication",
"service",
":",
"raises",
":",
"TypeError",
"If",
"the",
"auth_service",
"object",
"is",
"not",
"a",
"subclass",
"of",
"rinzler",
".",
"auth",
"."... | train | https://github.com/feliphebueno/Rinzler/blob/7f6d5445b5662cba2e8938bb82c7f3ef94e5ded8/rinzler/__init__.py#L88-L99 |
feliphebueno/Rinzler | rinzler/__init__.py | Router.handle | def handle(self, request: HttpRequest) -> HttpResponse:
"""
Prepares for the CallBackResolver and handles the response and exceptions
:param request HttpRequest
:rtype: HttpResponse
"""
self.__request_start = datetime.now()
self.__request = request
self.__... | python | def handle(self, request: HttpRequest) -> HttpResponse:
"""
Prepares for the CallBackResolver and handles the response and exceptions
:param request HttpRequest
:rtype: HttpResponse
"""
self.__request_start = datetime.now()
self.__request = request
self.__... | [
"def",
"handle",
"(",
"self",
",",
"request",
":",
"HttpRequest",
")",
"->",
"HttpResponse",
":",
"self",
".",
"__request_start",
"=",
"datetime",
".",
"now",
"(",
")",
"self",
".",
"__request",
"=",
"request",
"self",
".",
"__uri",
"=",
"request",
".",
... | Prepares for the CallBackResolver and handles the response and exceptions
:param request HttpRequest
:rtype: HttpResponse | [
"Prepares",
"for",
"the",
"CallBackResolver",
"and",
"handles",
"the",
"response",
"and",
"exceptions",
":",
"param",
"request",
"HttpRequest",
":",
"rtype",
":",
"HttpResponse"
] | train | https://github.com/feliphebueno/Rinzler/blob/7f6d5445b5662cba2e8938bb82c7f3ef94e5ded8/rinzler/__init__.py#L125-L165 |
feliphebueno/Rinzler | rinzler/__init__.py | Router.exec_route_callback | def exec_route_callback(self) -> Response or object:
"""
Executes the resolved end-point callback, or its fallback
:rtype: Response or object
"""
if self.__method.lower() in self.__end_points:
for bound in self.__end_points[self.__method.lower()]:
rou... | python | def exec_route_callback(self) -> Response or object:
"""
Executes the resolved end-point callback, or its fallback
:rtype: Response or object
"""
if self.__method.lower() in self.__end_points:
for bound in self.__end_points[self.__method.lower()]:
rou... | [
"def",
"exec_route_callback",
"(",
"self",
")",
"->",
"Response",
"or",
"object",
":",
"if",
"self",
".",
"__method",
".",
"lower",
"(",
")",
"in",
"self",
".",
"__end_points",
":",
"for",
"bound",
"in",
"self",
".",
"__end_points",
"[",
"self",
".",
"... | Executes the resolved end-point callback, or its fallback
:rtype: Response or object | [
"Executes",
"the",
"resolved",
"end",
"-",
"point",
"callback",
"or",
"its",
"fallback",
":",
"rtype",
":",
"Response",
"or",
"object"
] | train | https://github.com/feliphebueno/Rinzler/blob/7f6d5445b5662cba2e8938bb82c7f3ef94e5ded8/rinzler/__init__.py#L167-L201 |
feliphebueno/Rinzler | rinzler/__init__.py | Router.request_matches_route | def request_matches_route(self, actual_route: str, expected_route: str):
"""
Determines whether a route matches the actual requested route or not
:param actual_route str
:param expected_route
:rtype: Boolean
"""
expected_params = self.get_url_params(expected_route... | python | def request_matches_route(self, actual_route: str, expected_route: str):
"""
Determines whether a route matches the actual requested route or not
:param actual_route str
:param expected_route
:rtype: Boolean
"""
expected_params = self.get_url_params(expected_route... | [
"def",
"request_matches_route",
"(",
"self",
",",
"actual_route",
":",
"str",
",",
"expected_route",
":",
"str",
")",
":",
"expected_params",
"=",
"self",
".",
"get_url_params",
"(",
"expected_route",
")",
"actual_params",
"=",
"self",
".",
"get_url_params",
"("... | Determines whether a route matches the actual requested route or not
:param actual_route str
:param expected_route
:rtype: Boolean | [
"Determines",
"whether",
"a",
"route",
"matches",
"the",
"actual",
"requested",
"route",
"or",
"not",
":",
"param",
"actual_route",
"str",
":",
"param",
"expected_route",
":",
"rtype",
":",
"Boolean"
] | train | https://github.com/feliphebueno/Rinzler/blob/7f6d5445b5662cba2e8938bb82c7f3ef94e5ded8/rinzler/__init__.py#L203-L223 |
feliphebueno/Rinzler | rinzler/__init__.py | Router.authenticate | def authenticate(self, bound_route, actual_params) -> bool:
"""
Runs the pre-defined authenticaton service
:param bound_route str route matched
:param actual_params dict actual url parameters
:rtype: bool
"""
if self.__auth_service is not None:
auth_ro... | python | def authenticate(self, bound_route, actual_params) -> bool:
"""
Runs the pre-defined authenticaton service
:param bound_route str route matched
:param actual_params dict actual url parameters
:rtype: bool
"""
if self.__auth_service is not None:
auth_ro... | [
"def",
"authenticate",
"(",
"self",
",",
"bound_route",
",",
"actual_params",
")",
"->",
"bool",
":",
"if",
"self",
".",
"__auth_service",
"is",
"not",
"None",
":",
"auth_route",
"=",
"\"{0}_{1}{2}\"",
".",
"format",
"(",
"self",
".",
"__method",
",",
"sel... | Runs the pre-defined authenticaton service
:param bound_route str route matched
:param actual_params dict actual url parameters
:rtype: bool | [
"Runs",
"the",
"pre",
"-",
"defined",
"authenticaton",
"service",
":",
"param",
"bound_route",
"str",
"route",
"matched",
":",
"param",
"actual_params",
"dict",
"actual",
"url",
"parameters",
":",
"rtype",
":",
"bool"
] | train | https://github.com/feliphebueno/Rinzler/blob/7f6d5445b5662cba2e8938bb82c7f3ef94e5ded8/rinzler/__init__.py#L225-L240 |
feliphebueno/Rinzler | rinzler/__init__.py | Router.get_callback_pattern | def get_callback_pattern(expected_params, actual_params):
"""
Assembles a dictionary whith the parameters schema defined for this route
:param expected_params dict parameters schema defined for this route
:param actual_params dict actual url parameters
:rtype: dict
"""
... | python | def get_callback_pattern(expected_params, actual_params):
"""
Assembles a dictionary whith the parameters schema defined for this route
:param expected_params dict parameters schema defined for this route
:param actual_params dict actual url parameters
:rtype: dict
"""
... | [
"def",
"get_callback_pattern",
"(",
"expected_params",
",",
"actual_params",
")",
":",
"pattern",
"=",
"dict",
"(",
")",
"key",
"=",
"0",
"for",
"exp_param",
"in",
"expected_params",
":",
"if",
"exp_param",
"[",
"0",
"]",
"==",
"'{'",
"and",
"exp_param",
"... | Assembles a dictionary whith the parameters schema defined for this route
:param expected_params dict parameters schema defined for this route
:param actual_params dict actual url parameters
:rtype: dict | [
"Assembles",
"a",
"dictionary",
"whith",
"the",
"parameters",
"schema",
"defined",
"for",
"this",
"route",
":",
"param",
"expected_params",
"dict",
"parameters",
"schema",
"defined",
"for",
"this",
"route",
":",
"param",
"actual_params",
"dict",
"actual",
"url",
... | train | https://github.com/feliphebueno/Rinzler/blob/7f6d5445b5662cba2e8938bb82c7f3ef94e5ded8/rinzler/__init__.py#L243-L256 |
feliphebueno/Rinzler | rinzler/__init__.py | Router.get_url_params | def get_url_params(end_point: str) -> list:
"""
Gets route parameters as dictionary
:param end_point str target route
:rtype: list
"""
var_params = end_point.split('/')
if len(var_params) == 1 and var_params[0] == '':
return []
elif len(var_p... | python | def get_url_params(end_point: str) -> list:
"""
Gets route parameters as dictionary
:param end_point str target route
:rtype: list
"""
var_params = end_point.split('/')
if len(var_params) == 1 and var_params[0] == '':
return []
elif len(var_p... | [
"def",
"get_url_params",
"(",
"end_point",
":",
"str",
")",
"->",
"list",
":",
"var_params",
"=",
"end_point",
".",
"split",
"(",
"'/'",
")",
"if",
"len",
"(",
"var_params",
")",
"==",
"1",
"and",
"var_params",
"[",
"0",
"]",
"==",
"''",
":",
"return... | Gets route parameters as dictionary
:param end_point str target route
:rtype: list | [
"Gets",
"route",
"parameters",
"as",
"dictionary",
":",
"param",
"end_point",
"str",
"target",
"route",
":",
"rtype",
":",
"list"
] | train | https://github.com/feliphebueno/Rinzler/blob/7f6d5445b5662cba2e8938bb82c7f3ef94e5ded8/rinzler/__init__.py#L259-L277 |
feliphebueno/Rinzler | rinzler/__init__.py | Router.set_end_point_uri | def set_end_point_uri(self) -> bool:
"""
Extracts the route from the accessed URL and sets it to __end_point_uri
:rtype: bool
"""
expected_parts = self.__route.split("/")
actual_parts = self.__uri.split("/")
i = 0
for part in expected_parts:
i... | python | def set_end_point_uri(self) -> bool:
"""
Extracts the route from the accessed URL and sets it to __end_point_uri
:rtype: bool
"""
expected_parts = self.__route.split("/")
actual_parts = self.__uri.split("/")
i = 0
for part in expected_parts:
i... | [
"def",
"set_end_point_uri",
"(",
"self",
")",
"->",
"bool",
":",
"expected_parts",
"=",
"self",
".",
"__route",
".",
"split",
"(",
"\"/\"",
")",
"actual_parts",
"=",
"self",
".",
"__uri",
".",
"split",
"(",
"\"/\"",
")",
"i",
"=",
"0",
"for",
"part",
... | Extracts the route from the accessed URL and sets it to __end_point_uri
:rtype: bool | [
"Extracts",
"the",
"route",
"from",
"the",
"accessed",
"URL",
"and",
"sets",
"it",
"to",
"__end_point_uri",
":",
"rtype",
":",
"bool"
] | train | https://github.com/feliphebueno/Rinzler/blob/7f6d5445b5662cba2e8938bb82c7f3ef94e5ded8/rinzler/__init__.py#L286-L302 |
feliphebueno/Rinzler | rinzler/__init__.py | Router.no_route_found | def no_route_found(self, request):
"""
Default callback for route not found
:param request HttpRequest
:rtype: Response
"""
response_obj = OrderedDict()
response_obj["status"] = False
response_obj["exceptions"] = {
"message": "No route found fo... | python | def no_route_found(self, request):
"""
Default callback for route not found
:param request HttpRequest
:rtype: Response
"""
response_obj = OrderedDict()
response_obj["status"] = False
response_obj["exceptions"] = {
"message": "No route found fo... | [
"def",
"no_route_found",
"(",
"self",
",",
"request",
")",
":",
"response_obj",
"=",
"OrderedDict",
"(",
")",
"response_obj",
"[",
"\"status\"",
"]",
"=",
"False",
"response_obj",
"[",
"\"exceptions\"",
"]",
"=",
"{",
"\"message\"",
":",
"\"No route found for {0... | Default callback for route not found
:param request HttpRequest
:rtype: Response | [
"Default",
"callback",
"for",
"route",
"not",
"found",
":",
"param",
"request",
"HttpRequest",
":",
"rtype",
":",
"Response"
] | train | https://github.com/feliphebueno/Rinzler/blob/7f6d5445b5662cba2e8938bb82c7f3ef94e5ded8/rinzler/__init__.py#L304-L322 |
feliphebueno/Rinzler | rinzler/__init__.py | Router.welcome_page | def welcome_page(self):
"""
Defaulf welcome page when the route / is note mapped yet
:rtype: HttpResponse
"""
message = "HTTP/1.1 200 OK RINZLER FRAMEWORK"
return HttpResponse(
"<center><h1>{0}({1})</h1></center>".format(message, self.app.app_name),
... | python | def welcome_page(self):
"""
Defaulf welcome page when the route / is note mapped yet
:rtype: HttpResponse
"""
message = "HTTP/1.1 200 OK RINZLER FRAMEWORK"
return HttpResponse(
"<center><h1>{0}({1})</h1></center>".format(message, self.app.app_name),
... | [
"def",
"welcome_page",
"(",
"self",
")",
":",
"message",
"=",
"\"HTTP/1.1 200 OK RINZLER FRAMEWORK\"",
"return",
"HttpResponse",
"(",
"\"<center><h1>{0}({1})</h1></center>\"",
".",
"format",
"(",
"message",
",",
"self",
".",
"app",
".",
"app_name",
")",
",",
"conten... | Defaulf welcome page when the route / is note mapped yet
:rtype: HttpResponse | [
"Defaulf",
"welcome",
"page",
"when",
"the",
"route",
"/",
"is",
"note",
"mapped",
"yet",
":",
"rtype",
":",
"HttpResponse"
] | train | https://github.com/feliphebueno/Rinzler/blob/7f6d5445b5662cba2e8938bb82c7f3ef94e5ded8/rinzler/__init__.py#L324-L333 |
feliphebueno/Rinzler | rinzler/__init__.py | Router.default_route_options | def default_route_options():
"""
Default callback for OPTIONS request
:rtype: Response
"""
response_obj = OrderedDict()
response_obj["status"] = True
response_obj["data"] = "Ok"
return Response(response_obj, content_type="application/json", charset="utf-... | python | def default_route_options():
"""
Default callback for OPTIONS request
:rtype: Response
"""
response_obj = OrderedDict()
response_obj["status"] = True
response_obj["data"] = "Ok"
return Response(response_obj, content_type="application/json", charset="utf-... | [
"def",
"default_route_options",
"(",
")",
":",
"response_obj",
"=",
"OrderedDict",
"(",
")",
"response_obj",
"[",
"\"status\"",
"]",
"=",
"True",
"response_obj",
"[",
"\"data\"",
"]",
"=",
"\"Ok\"",
"return",
"Response",
"(",
"response_obj",
",",
"content_type",... | Default callback for OPTIONS request
:rtype: Response | [
"Default",
"callback",
"for",
"OPTIONS",
"request",
":",
"rtype",
":",
"Response"
] | train | https://github.com/feliphebueno/Rinzler/blob/7f6d5445b5662cba2e8938bb82c7f3ef94e5ded8/rinzler/__init__.py#L336-L346 |
feliphebueno/Rinzler | rinzler/__init__.py | Router.set_response_headers | def set_response_headers(self, response: HttpResponse) -> HttpResponse:
"""
Appends default headers to every response returned by the API
:param response HttpResponse
:rtype: HttpResponse
"""
public_name = os.environ.get('SERVER_PUBLIC_NAME')
response_headers = {
... | python | def set_response_headers(self, response: HttpResponse) -> HttpResponse:
"""
Appends default headers to every response returned by the API
:param response HttpResponse
:rtype: HttpResponse
"""
public_name = os.environ.get('SERVER_PUBLIC_NAME')
response_headers = {
... | [
"def",
"set_response_headers",
"(",
"self",
",",
"response",
":",
"HttpResponse",
")",
"->",
"HttpResponse",
":",
"public_name",
"=",
"os",
".",
"environ",
".",
"get",
"(",
"'SERVER_PUBLIC_NAME'",
")",
"response_headers",
"=",
"{",
"'access-control-allow-headers'",
... | Appends default headers to every response returned by the API
:param response HttpResponse
:rtype: HttpResponse | [
"Appends",
"default",
"headers",
"to",
"every",
"response",
"returned",
"by",
"the",
"API",
":",
"param",
"response",
"HttpResponse",
":",
"rtype",
":",
"HttpResponse"
] | train | https://github.com/feliphebueno/Rinzler/blob/7f6d5445b5662cba2e8938bb82c7f3ef94e5ded8/rinzler/__init__.py#L348-L374 |
feliphebueno/Rinzler | rinzler/__init__.py | Router.get_json_ident | def get_json_ident(request_headers: dict) -> int:
"""
Defines whether the JSON response will be indented or not
:param request_headers: dict
:return: self
"""
if 'HTTP_USER_AGENT' in request_headers:
indent = 2 if re.match("[Mozilla]{7}", request_headers['HTTP... | python | def get_json_ident(request_headers: dict) -> int:
"""
Defines whether the JSON response will be indented or not
:param request_headers: dict
:return: self
"""
if 'HTTP_USER_AGENT' in request_headers:
indent = 2 if re.match("[Mozilla]{7}", request_headers['HTTP... | [
"def",
"get_json_ident",
"(",
"request_headers",
":",
"dict",
")",
"->",
"int",
":",
"if",
"'HTTP_USER_AGENT'",
"in",
"request_headers",
":",
"indent",
"=",
"2",
"if",
"re",
".",
"match",
"(",
"\"[Mozilla]{7}\"",
",",
"request_headers",
"[",
"'HTTP_USER_AGENT'",... | Defines whether the JSON response will be indented or not
:param request_headers: dict
:return: self | [
"Defines",
"whether",
"the",
"JSON",
"response",
"will",
"be",
"indented",
"or",
"not",
":",
"param",
"request_headers",
":",
"dict",
":",
"return",
":",
"self"
] | train | https://github.com/feliphebueno/Rinzler/blob/7f6d5445b5662cba2e8938bb82c7f3ef94e5ded8/rinzler/__init__.py#L377-L388 |
calocan/rescape-python-helpers | rescape_python_helpers/functional/ramda.py | prop | def prop(key, dct_or_obj):
"""
Implementation of prop (get_item) that also supports object attributes
:param key:
:param dct_or_obj:
:return:
"""
# Note that hasattr is a builtin and getattr is a ramda function, hence the different arg position
if isinstance(dict, dct_or_obj):
... | python | def prop(key, dct_or_obj):
"""
Implementation of prop (get_item) that also supports object attributes
:param key:
:param dct_or_obj:
:return:
"""
# Note that hasattr is a builtin and getattr is a ramda function, hence the different arg position
if isinstance(dict, dct_or_obj):
... | [
"def",
"prop",
"(",
"key",
",",
"dct_or_obj",
")",
":",
"# Note that hasattr is a builtin and getattr is a ramda function, hence the different arg position",
"if",
"isinstance",
"(",
"dict",
",",
"dct_or_obj",
")",
":",
"if",
"has",
"(",
"key",
",",
"dct_or_obj",
")",
... | Implementation of prop (get_item) that also supports object attributes
:param key:
:param dct_or_obj:
:return: | [
"Implementation",
"of",
"prop",
"(",
"get_item",
")",
"that",
"also",
"supports",
"object",
"attributes",
":",
"param",
"key",
":",
":",
"param",
"dct_or_obj",
":",
":",
"return",
":"
] | train | https://github.com/calocan/rescape-python-helpers/blob/91a1724f062ee40a25aa60fc96b2d7acadd99618/rescape_python_helpers/functional/ramda.py#L12-L36 |
calocan/rescape-python-helpers | rescape_python_helpers/functional/ramda.py | all_pass_dict | def all_pass_dict(f, dct):
"""
Returns true if all dct values pass f
:param f: binary lambda predicate
:param dct:
:return: True or false
"""
return all(map_with_obj_to_values(
lambda key, value: f(key, value),
dct
)) | python | def all_pass_dict(f, dct):
"""
Returns true if all dct values pass f
:param f: binary lambda predicate
:param dct:
:return: True or false
"""
return all(map_with_obj_to_values(
lambda key, value: f(key, value),
dct
)) | [
"def",
"all_pass_dict",
"(",
"f",
",",
"dct",
")",
":",
"return",
"all",
"(",
"map_with_obj_to_values",
"(",
"lambda",
"key",
",",
"value",
":",
"f",
"(",
"key",
",",
"value",
")",
",",
"dct",
")",
")"
] | Returns true if all dct values pass f
:param f: binary lambda predicate
:param dct:
:return: True or false | [
"Returns",
"true",
"if",
"all",
"dct",
"values",
"pass",
"f",
":",
"param",
"f",
":",
"binary",
"lambda",
"predicate",
":",
"param",
"dct",
":",
":",
"return",
":",
"True",
"or",
"false"
] | train | https://github.com/calocan/rescape-python-helpers/blob/91a1724f062ee40a25aa60fc96b2d7acadd99618/rescape_python_helpers/functional/ramda.py#L50-L60 |
calocan/rescape-python-helpers | rescape_python_helpers/functional/ramda.py | prop_or | def prop_or(default, key, dct_or_obj):
"""
Ramda propOr implementation. This also resolves object attributes, so key
can be a dict prop or an attribute of dct_or_obj
:param default: Value if dct_or_obj doesn't have key_or_prop or the resolved value is null
:param key:
:param dct_or_obj:
... | python | def prop_or(default, key, dct_or_obj):
"""
Ramda propOr implementation. This also resolves object attributes, so key
can be a dict prop or an attribute of dct_or_obj
:param default: Value if dct_or_obj doesn't have key_or_prop or the resolved value is null
:param key:
:param dct_or_obj:
... | [
"def",
"prop_or",
"(",
"default",
",",
"key",
",",
"dct_or_obj",
")",
":",
"# Note that hasattr is a builtin and getattr is a ramda function, hence the different arg position",
"if",
"isinstance",
"(",
"dict",
",",
"dct_or_obj",
")",
":",
"value",
"=",
"dct_or_obj",
"[",
... | Ramda propOr implementation. This also resolves object attributes, so key
can be a dict prop or an attribute of dct_or_obj
:param default: Value if dct_or_obj doesn't have key_or_prop or the resolved value is null
:param key:
:param dct_or_obj:
:return: | [
"Ramda",
"propOr",
"implementation",
".",
"This",
"also",
"resolves",
"object",
"attributes",
"so",
"key",
"can",
"be",
"a",
"dict",
"prop",
"or",
"an",
"attribute",
"of",
"dct_or_obj",
":",
"param",
"default",
":",
"Value",
"if",
"dct_or_obj",
"doesn",
"t",... | train | https://github.com/calocan/rescape-python-helpers/blob/91a1724f062ee40a25aa60fc96b2d7acadd99618/rescape_python_helpers/functional/ramda.py#L82-L101 |
calocan/rescape-python-helpers | rescape_python_helpers/functional/ramda.py | prop_eq_or | def prop_eq_or(default, key, value, dct):
"""
Ramda propEq plus propOr implementation
:param default:
:param key:
:param value:
:param dct:
:return:
"""
return dct[key] and dct[key] == value if key in dct else default | python | def prop_eq_or(default, key, value, dct):
"""
Ramda propEq plus propOr implementation
:param default:
:param key:
:param value:
:param dct:
:return:
"""
return dct[key] and dct[key] == value if key in dct else default | [
"def",
"prop_eq_or",
"(",
"default",
",",
"key",
",",
"value",
",",
"dct",
")",
":",
"return",
"dct",
"[",
"key",
"]",
"and",
"dct",
"[",
"key",
"]",
"==",
"value",
"if",
"key",
"in",
"dct",
"else",
"default"
] | Ramda propEq plus propOr implementation
:param default:
:param key:
:param value:
:param dct:
:return: | [
"Ramda",
"propEq",
"plus",
"propOr",
"implementation",
":",
"param",
"default",
":",
":",
"param",
"key",
":",
":",
"param",
"value",
":",
":",
"param",
"dct",
":",
":",
"return",
":"
] | train | https://github.com/calocan/rescape-python-helpers/blob/91a1724f062ee40a25aa60fc96b2d7acadd99618/rescape_python_helpers/functional/ramda.py#L117-L126 |
calocan/rescape-python-helpers | rescape_python_helpers/functional/ramda.py | prop_eq_or_in_or | def prop_eq_or_in_or(default, key, value, dct):
"""
Ramda propEq/propIn plus propOr
:param default:
:param key:
:param value:
:param dct:
:return:
"""
return has(key, dct) and \
(dct[key] == value if key in dct else (
dct[key] in value if isinstance((lis... | python | def prop_eq_or_in_or(default, key, value, dct):
"""
Ramda propEq/propIn plus propOr
:param default:
:param key:
:param value:
:param dct:
:return:
"""
return has(key, dct) and \
(dct[key] == value if key in dct else (
dct[key] in value if isinstance((lis... | [
"def",
"prop_eq_or_in_or",
"(",
"default",
",",
"key",
",",
"value",
",",
"dct",
")",
":",
"return",
"has",
"(",
"key",
",",
"dct",
")",
"and",
"(",
"dct",
"[",
"key",
"]",
"==",
"value",
"if",
"key",
"in",
"dct",
"else",
"(",
"dct",
"[",
"key",
... | Ramda propEq/propIn plus propOr
:param default:
:param key:
:param value:
:param dct:
:return: | [
"Ramda",
"propEq",
"/",
"propIn",
"plus",
"propOr",
":",
"param",
"default",
":",
":",
"param",
"key",
":",
":",
"param",
"value",
":",
":",
"param",
"dct",
":",
":",
"return",
":"
] | train | https://github.com/calocan/rescape-python-helpers/blob/91a1724f062ee40a25aa60fc96b2d7acadd99618/rescape_python_helpers/functional/ramda.py#L142-L155 |
calocan/rescape-python-helpers | rescape_python_helpers/functional/ramda.py | item_path_or | def item_path_or(default, keys, dict_or_obj):
"""
Optional version of item_path with a default value. keys can be dict keys or object attributes, or a combination
:param default:
:param keys: List of keys or dot-separated string
:param dict_or_obj: A dict or obj
:return:
"""
if not keys:... | python | def item_path_or(default, keys, dict_or_obj):
"""
Optional version of item_path with a default value. keys can be dict keys or object attributes, or a combination
:param default:
:param keys: List of keys or dot-separated string
:param dict_or_obj: A dict or obj
:return:
"""
if not keys:... | [
"def",
"item_path_or",
"(",
"default",
",",
"keys",
",",
"dict_or_obj",
")",
":",
"if",
"not",
"keys",
":",
"raise",
"ValueError",
"(",
"\"Expected at least one key, got {0}\"",
".",
"format",
"(",
"keys",
")",
")",
"resolved_keys",
"=",
"keys",
".",
"split",
... | Optional version of item_path with a default value. keys can be dict keys or object attributes, or a combination
:param default:
:param keys: List of keys or dot-separated string
:param dict_or_obj: A dict or obj
:return: | [
"Optional",
"version",
"of",
"item_path",
"with",
"a",
"default",
"value",
".",
"keys",
"can",
"be",
"dict",
"keys",
"or",
"object",
"attributes",
"or",
"a",
"combination",
":",
"param",
"default",
":",
":",
"param",
"keys",
":",
"List",
"of",
"keys",
"o... | train | https://github.com/calocan/rescape-python-helpers/blob/91a1724f062ee40a25aa60fc96b2d7acadd99618/rescape_python_helpers/functional/ramda.py#L170-L184 |
calocan/rescape-python-helpers | rescape_python_helpers/functional/ramda.py | item_str_path | def item_str_path(keys, dct):
"""
Given a string of path segments separated by ., splits them into an array. Int strings are converted
to numbers to serve as an array index
:param keys: e.g. 'foo.bar.1.goo'
:param dct: e.g. dict(foo=dict(bar=[dict(goo='a'), dict(goo='b')])
:return: The r... | python | def item_str_path(keys, dct):
"""
Given a string of path segments separated by ., splits them into an array. Int strings are converted
to numbers to serve as an array index
:param keys: e.g. 'foo.bar.1.goo'
:param dct: e.g. dict(foo=dict(bar=[dict(goo='a'), dict(goo='b')])
:return: The r... | [
"def",
"item_str_path",
"(",
"keys",
",",
"dct",
")",
":",
"return",
"item_path",
"(",
"map",
"(",
"lambda",
"segment",
":",
"int",
"(",
"segment",
")",
"if",
"isint",
"(",
"segment",
")",
"else",
"segment",
",",
"keys",
".",
"split",
"(",
"'.'",
")"... | Given a string of path segments separated by ., splits them into an array. Int strings are converted
to numbers to serve as an array index
:param keys: e.g. 'foo.bar.1.goo'
:param dct: e.g. dict(foo=dict(bar=[dict(goo='a'), dict(goo='b')])
:return: The resolved value or an error. E.g. for above the ... | [
"Given",
"a",
"string",
"of",
"path",
"segments",
"separated",
"by",
".",
"splits",
"them",
"into",
"an",
"array",
".",
"Int",
"strings",
"are",
"converted",
"to",
"numbers",
"to",
"serve",
"as",
"an",
"array",
"index",
":",
"param",
"keys",
":",
"e",
... | train | https://github.com/calocan/rescape-python-helpers/blob/91a1724f062ee40a25aa60fc96b2d7acadd99618/rescape_python_helpers/functional/ramda.py#L212-L220 |
calocan/rescape-python-helpers | rescape_python_helpers/functional/ramda.py | item_str_path_or | def item_str_path_or(default, keys, dct):
"""
Given a string of path segments separated by ., splits them into an array. Int strings are converted
to numbers to serve as an array index
:param default: Value if any part yields None or undefined
:param keys: e.g. 'foo.bar.1.goo'
:param dct... | python | def item_str_path_or(default, keys, dct):
"""
Given a string of path segments separated by ., splits them into an array. Int strings are converted
to numbers to serve as an array index
:param default: Value if any part yields None or undefined
:param keys: e.g. 'foo.bar.1.goo'
:param dct... | [
"def",
"item_str_path_or",
"(",
"default",
",",
"keys",
",",
"dct",
")",
":",
"return",
"item_path_or",
"(",
"default",
",",
"map",
"(",
"lambda",
"segment",
":",
"int",
"(",
"segment",
")",
"if",
"isint",
"(",
"segment",
")",
"else",
"segment",
",",
"... | Given a string of path segments separated by ., splits them into an array. Int strings are converted
to numbers to serve as an array index
:param default: Value if any part yields None or undefined
:param keys: e.g. 'foo.bar.1.goo'
:param dct: e.g. dict(foo=dict(bar=[dict(goo='a'), dict(goo='b')])
... | [
"Given",
"a",
"string",
"of",
"path",
"segments",
"separated",
"by",
".",
"splits",
"them",
"into",
"an",
"array",
".",
"Int",
"strings",
"are",
"converted",
"to",
"numbers",
"to",
"serve",
"as",
"an",
"array",
"index",
":",
"param",
"default",
":",
"Val... | train | https://github.com/calocan/rescape-python-helpers/blob/91a1724f062ee40a25aa60fc96b2d7acadd99618/rescape_python_helpers/functional/ramda.py#L224-L233 |
calocan/rescape-python-helpers | rescape_python_helpers/functional/ramda.py | has | def has(prop, object_or_dct):
"""
Implementation of ramda has
:param prop:
:param object_or_dct:
:return:
"""
return prop in object_or_dct if isinstance(dict, object_or_dct) else hasattr(object_or_dct, prop) | python | def has(prop, object_or_dct):
"""
Implementation of ramda has
:param prop:
:param object_or_dct:
:return:
"""
return prop in object_or_dct if isinstance(dict, object_or_dct) else hasattr(object_or_dct, prop) | [
"def",
"has",
"(",
"prop",
",",
"object_or_dct",
")",
":",
"return",
"prop",
"in",
"object_or_dct",
"if",
"isinstance",
"(",
"dict",
",",
"object_or_dct",
")",
"else",
"hasattr",
"(",
"object_or_dct",
",",
"prop",
")"
] | Implementation of ramda has
:param prop:
:param object_or_dct:
:return: | [
"Implementation",
"of",
"ramda",
"has",
":",
"param",
"prop",
":",
":",
"param",
"object_or_dct",
":",
":",
"return",
":"
] | train | https://github.com/calocan/rescape-python-helpers/blob/91a1724f062ee40a25aa60fc96b2d7acadd99618/rescape_python_helpers/functional/ramda.py#L237-L244 |
calocan/rescape-python-helpers | rescape_python_helpers/functional/ramda.py | omit_deep | def omit_deep(omit_props, dct):
"""
Implementation of omit that recurses. This tests the same keys at every level of dict and in lists
:param omit_props:
:param dct:
:return:
"""
omit_partial = omit_deep(omit_props)
if isinstance(dict, dct):
# Filter out keys and then recurse o... | python | def omit_deep(omit_props, dct):
"""
Implementation of omit that recurses. This tests the same keys at every level of dict and in lists
:param omit_props:
:param dct:
:return:
"""
omit_partial = omit_deep(omit_props)
if isinstance(dict, dct):
# Filter out keys and then recurse o... | [
"def",
"omit_deep",
"(",
"omit_props",
",",
"dct",
")",
":",
"omit_partial",
"=",
"omit_deep",
"(",
"omit_props",
")",
"if",
"isinstance",
"(",
"dict",
",",
"dct",
")",
":",
"# Filter out keys and then recurse on each value that wasn't filtered out",
"return",
"map_di... | Implementation of omit that recurses. This tests the same keys at every level of dict and in lists
:param omit_props:
:param dct:
:return: | [
"Implementation",
"of",
"omit",
"that",
"recurses",
".",
"This",
"tests",
"the",
"same",
"keys",
"at",
"every",
"level",
"of",
"dict",
"and",
"in",
"lists",
":",
"param",
"omit_props",
":",
":",
"param",
"dct",
":",
":",
"return",
":"
] | train | https://github.com/calocan/rescape-python-helpers/blob/91a1724f062ee40a25aa60fc96b2d7acadd99618/rescape_python_helpers/functional/ramda.py#L259-L276 |
calocan/rescape-python-helpers | rescape_python_helpers/functional/ramda.py | pick_deep | def pick_deep(pick_dct, dct):
"""
Implementation of pick that recurses. This tests the same keys at every level of dict and in lists
:param pick_dct: Deep dict matching some portion of dct.
:param dct: Dct to filter. Any key matching pick_dct pass through. It doesn't matter what the pick_dct value
i... | python | def pick_deep(pick_dct, dct):
"""
Implementation of pick that recurses. This tests the same keys at every level of dict and in lists
:param pick_dct: Deep dict matching some portion of dct.
:param dct: Dct to filter. Any key matching pick_dct pass through. It doesn't matter what the pick_dct value
i... | [
"def",
"pick_deep",
"(",
"pick_dct",
",",
"dct",
")",
":",
"if",
"isinstance",
"(",
"dict",
",",
"dct",
")",
":",
"# Filter out keys and then recurse on each value that wasn't filtered out",
"return",
"map_with_obj",
"(",
"lambda",
"k",
",",
"v",
":",
"pick_deep",
... | Implementation of pick that recurses. This tests the same keys at every level of dict and in lists
:param pick_dct: Deep dict matching some portion of dct.
:param dct: Dct to filter. Any key matching pick_dct pass through. It doesn't matter what the pick_dct value
is as long as the key exists. Arrays also p... | [
"Implementation",
"of",
"pick",
"that",
"recurses",
".",
"This",
"tests",
"the",
"same",
"keys",
"at",
"every",
"level",
"of",
"dict",
"and",
"in",
"lists",
":",
"param",
"pick_dct",
":",
"Deep",
"dict",
"matching",
"some",
"portion",
"of",
"dct",
".",
"... | train | https://github.com/calocan/rescape-python-helpers/blob/91a1724f062ee40a25aa60fc96b2d7acadd99618/rescape_python_helpers/functional/ramda.py#L280-L302 |
calocan/rescape-python-helpers | rescape_python_helpers/functional/ramda.py | map_with_obj_deep | def map_with_obj_deep(f, dct):
"""
Implementation of map that recurses. This tests the same keys at every level of dict and in lists
:param f: 2-ary function expecting a key and value and returns a modified value
:param dct: Dict for deep processing
:return: Modified dct with matching props mapped
... | python | def map_with_obj_deep(f, dct):
"""
Implementation of map that recurses. This tests the same keys at every level of dict and in lists
:param f: 2-ary function expecting a key and value and returns a modified value
:param dct: Dict for deep processing
:return: Modified dct with matching props mapped
... | [
"def",
"map_with_obj_deep",
"(",
"f",
",",
"dct",
")",
":",
"return",
"_map_deep",
"(",
"lambda",
"k",
",",
"v",
":",
"[",
"k",
",",
"f",
"(",
"k",
",",
"v",
")",
"]",
",",
"dct",
")"
] | Implementation of map that recurses. This tests the same keys at every level of dict and in lists
:param f: 2-ary function expecting a key and value and returns a modified value
:param dct: Dict for deep processing
:return: Modified dct with matching props mapped | [
"Implementation",
"of",
"map",
"that",
"recurses",
".",
"This",
"tests",
"the",
"same",
"keys",
"at",
"every",
"level",
"of",
"dict",
"and",
"in",
"lists",
":",
"param",
"f",
":",
"2",
"-",
"ary",
"function",
"expecting",
"a",
"key",
"and",
"value",
"a... | train | https://github.com/calocan/rescape-python-helpers/blob/91a1724f062ee40a25aa60fc96b2d7acadd99618/rescape_python_helpers/functional/ramda.py#L306-L313 |
calocan/rescape-python-helpers | rescape_python_helpers/functional/ramda.py | map_keys_deep | def map_keys_deep(f, dct):
"""
Implementation of map that recurses. This tests the same keys at every level of dict and in lists
:param f: 2-ary function expecting a key and value and returns a modified key
:param dct: Dict for deep processing
:return: Modified dct with matching props mapped
"""... | python | def map_keys_deep(f, dct):
"""
Implementation of map that recurses. This tests the same keys at every level of dict and in lists
:param f: 2-ary function expecting a key and value and returns a modified key
:param dct: Dict for deep processing
:return: Modified dct with matching props mapped
"""... | [
"def",
"map_keys_deep",
"(",
"f",
",",
"dct",
")",
":",
"return",
"_map_deep",
"(",
"lambda",
"k",
",",
"v",
":",
"[",
"f",
"(",
"k",
",",
"v",
")",
",",
"v",
"]",
",",
"dct",
")"
] | Implementation of map that recurses. This tests the same keys at every level of dict and in lists
:param f: 2-ary function expecting a key and value and returns a modified key
:param dct: Dict for deep processing
:return: Modified dct with matching props mapped | [
"Implementation",
"of",
"map",
"that",
"recurses",
".",
"This",
"tests",
"the",
"same",
"keys",
"at",
"every",
"level",
"of",
"dict",
"and",
"in",
"lists",
":",
"param",
"f",
":",
"2",
"-",
"ary",
"function",
"expecting",
"a",
"key",
"and",
"value",
"a... | train | https://github.com/calocan/rescape-python-helpers/blob/91a1724f062ee40a25aa60fc96b2d7acadd99618/rescape_python_helpers/functional/ramda.py#L317-L324 |
calocan/rescape-python-helpers | rescape_python_helpers/functional/ramda.py | _map_deep | def _map_deep(f, dct):
"""
Used by map_deep and map_keys_deep
:param map_props:
:param f: Expects a key and value and returns a pair
:param dct:
:return:
"""
if isinstance(dict, dct):
return map_key_values(lambda k, v: f(k, _map_deep(f, v)), dct)
elif isinstance((list, tuple... | python | def _map_deep(f, dct):
"""
Used by map_deep and map_keys_deep
:param map_props:
:param f: Expects a key and value and returns a pair
:param dct:
:return:
"""
if isinstance(dict, dct):
return map_key_values(lambda k, v: f(k, _map_deep(f, v)), dct)
elif isinstance((list, tuple... | [
"def",
"_map_deep",
"(",
"f",
",",
"dct",
")",
":",
"if",
"isinstance",
"(",
"dict",
",",
"dct",
")",
":",
"return",
"map_key_values",
"(",
"lambda",
"k",
",",
"v",
":",
"f",
"(",
"k",
",",
"_map_deep",
"(",
"f",
",",
"v",
")",
")",
",",
"dct",... | Used by map_deep and map_keys_deep
:param map_props:
:param f: Expects a key and value and returns a pair
:param dct:
:return: | [
"Used",
"by",
"map_deep",
"and",
"map_keys_deep",
":",
"param",
"map_props",
":",
":",
"param",
"f",
":",
"Expects",
"a",
"key",
"and",
"value",
"and",
"returns",
"a",
"pair",
":",
"param",
"dct",
":",
":",
"return",
":"
] | train | https://github.com/calocan/rescape-python-helpers/blob/91a1724f062ee40a25aa60fc96b2d7acadd99618/rescape_python_helpers/functional/ramda.py#L327-L343 |
calocan/rescape-python-helpers | rescape_python_helpers/functional/ramda.py | dict_matches_params_deep | def dict_matches_params_deep(params_dct, dct):
"""
Filters deeply by comparing dct to filter_dct's value at each depth. Whenever a mismatch occurs the whole
thing returns false
:param params_dct: dict matching any portion of dct. E.g. filter_dct = {foo: {bar: 1}} would allow
{foo: {bar: 1, car: 2}} ... | python | def dict_matches_params_deep(params_dct, dct):
"""
Filters deeply by comparing dct to filter_dct's value at each depth. Whenever a mismatch occurs the whole
thing returns false
:param params_dct: dict matching any portion of dct. E.g. filter_dct = {foo: {bar: 1}} would allow
{foo: {bar: 1, car: 2}} ... | [
"def",
"dict_matches_params_deep",
"(",
"params_dct",
",",
"dct",
")",
":",
"def",
"recurse_if_param_exists",
"(",
"params",
",",
"key",
",",
"value",
")",
":",
"\"\"\"\n If a param[key] exists, recurse. Otherwise return True since there is no param to contest value\n ... | Filters deeply by comparing dct to filter_dct's value at each depth. Whenever a mismatch occurs the whole
thing returns false
:param params_dct: dict matching any portion of dct. E.g. filter_dct = {foo: {bar: 1}} would allow
{foo: {bar: 1, car: 2}} to pass, {foo: {bar: 2}} would fail, {goo: ...} would fail
... | [
"Filters",
"deeply",
"by",
"comparing",
"dct",
"to",
"filter_dct",
"s",
"value",
"at",
"each",
"depth",
".",
"Whenever",
"a",
"mismatch",
"occurs",
"the",
"whole",
"thing",
"returns",
"false",
":",
"param",
"params_dct",
":",
"dict",
"matching",
"any",
"port... | train | https://github.com/calocan/rescape-python-helpers/blob/91a1724f062ee40a25aa60fc96b2d7acadd99618/rescape_python_helpers/functional/ramda.py#L347-L402 |
calocan/rescape-python-helpers | rescape_python_helpers/functional/ramda.py | join | def join(strin, items):
"""
Ramda implementation of join
:param strin:
:param items:
:return:
"""
return strin.join(map(lambda item: str(item), items)) | python | def join(strin, items):
"""
Ramda implementation of join
:param strin:
:param items:
:return:
"""
return strin.join(map(lambda item: str(item), items)) | [
"def",
"join",
"(",
"strin",
",",
"items",
")",
":",
"return",
"strin",
".",
"join",
"(",
"map",
"(",
"lambda",
"item",
":",
"str",
"(",
"item",
")",
",",
"items",
")",
")"
] | Ramda implementation of join
:param strin:
:param items:
:return: | [
"Ramda",
"implementation",
"of",
"join",
":",
"param",
"strin",
":",
":",
"param",
"items",
":",
":",
"return",
":"
] | train | https://github.com/calocan/rescape-python-helpers/blob/91a1724f062ee40a25aa60fc96b2d7acadd99618/rescape_python_helpers/functional/ramda.py#L406-L413 |
calocan/rescape-python-helpers | rescape_python_helpers/functional/ramda.py | map_with_obj | def map_with_obj(f, dct):
"""
Implementation of Ramda's mapObjIndexed without the final argument.
This returns the original key with the mapped value. Use map_key_values to modify the keys too
:param f: Called with a key and value
:param dct:
:return {dict}: Keyed by the original key, va... | python | def map_with_obj(f, dct):
"""
Implementation of Ramda's mapObjIndexed without the final argument.
This returns the original key with the mapped value. Use map_key_values to modify the keys too
:param f: Called with a key and value
:param dct:
:return {dict}: Keyed by the original key, va... | [
"def",
"map_with_obj",
"(",
"f",
",",
"dct",
")",
":",
"f_dict",
"=",
"{",
"}",
"for",
"k",
",",
"v",
"in",
"dct",
".",
"items",
"(",
")",
":",
"f_dict",
"[",
"k",
"]",
"=",
"f",
"(",
"k",
",",
"v",
")",
"return",
"f_dict"
] | Implementation of Ramda's mapObjIndexed without the final argument.
This returns the original key with the mapped value. Use map_key_values to modify the keys too
:param f: Called with a key and value
:param dct:
:return {dict}: Keyed by the original key, valued by the mapped value | [
"Implementation",
"of",
"Ramda",
"s",
"mapObjIndexed",
"without",
"the",
"final",
"argument",
".",
"This",
"returns",
"the",
"original",
"key",
"with",
"the",
"mapped",
"value",
".",
"Use",
"map_key_values",
"to",
"modify",
"the",
"keys",
"too",
":",
"param",
... | train | https://github.com/calocan/rescape-python-helpers/blob/91a1724f062ee40a25aa60fc96b2d7acadd99618/rescape_python_helpers/functional/ramda.py#L462-L473 |
calocan/rescape-python-helpers | rescape_python_helpers/functional/ramda.py | map_keys | def map_keys(f, dct):
"""
Calls f with each key of dct, possibly returning a modified key. Values are unchanged
:param f: Called with each key and returns the same key or a modified key
:param dct:
:return: A dct with keys possibly modifed but values unchanged
"""
f_dict = {}
for k, ... | python | def map_keys(f, dct):
"""
Calls f with each key of dct, possibly returning a modified key. Values are unchanged
:param f: Called with each key and returns the same key or a modified key
:param dct:
:return: A dct with keys possibly modifed but values unchanged
"""
f_dict = {}
for k, ... | [
"def",
"map_keys",
"(",
"f",
",",
"dct",
")",
":",
"f_dict",
"=",
"{",
"}",
"for",
"k",
",",
"v",
"in",
"dct",
".",
"items",
"(",
")",
":",
"f_dict",
"[",
"f",
"(",
"k",
")",
"]",
"=",
"v",
"return",
"f_dict"
] | Calls f with each key of dct, possibly returning a modified key. Values are unchanged
:param f: Called with each key and returns the same key or a modified key
:param dct:
:return: A dct with keys possibly modifed but values unchanged | [
"Calls",
"f",
"with",
"each",
"key",
"of",
"dct",
"possibly",
"returning",
"a",
"modified",
"key",
".",
"Values",
"are",
"unchanged",
":",
"param",
"f",
":",
"Called",
"with",
"each",
"key",
"and",
"returns",
"the",
"same",
"key",
"or",
"a",
"modified",
... | train | https://github.com/calocan/rescape-python-helpers/blob/91a1724f062ee40a25aa60fc96b2d7acadd99618/rescape_python_helpers/functional/ramda.py#L499-L509 |
calocan/rescape-python-helpers | rescape_python_helpers/functional/ramda.py | map_keys_with_obj | def map_keys_with_obj(f, dct):
"""
Calls f with each key and value of dct, possibly returning a modified key. Values are unchanged
:param f: Called with each key and value and returns the same key or a modified key
:param dct:
:return: A dct with keys possibly modifed but values unchanged
""... | python | def map_keys_with_obj(f, dct):
"""
Calls f with each key and value of dct, possibly returning a modified key. Values are unchanged
:param f: Called with each key and value and returns the same key or a modified key
:param dct:
:return: A dct with keys possibly modifed but values unchanged
""... | [
"def",
"map_keys_with_obj",
"(",
"f",
",",
"dct",
")",
":",
"f_dict",
"=",
"{",
"}",
"for",
"k",
",",
"v",
"in",
"dct",
".",
"items",
"(",
")",
":",
"f_dict",
"[",
"f",
"(",
"k",
",",
"v",
")",
"]",
"=",
"v",
"return",
"f_dict"
] | Calls f with each key and value of dct, possibly returning a modified key. Values are unchanged
:param f: Called with each key and value and returns the same key or a modified key
:param dct:
:return: A dct with keys possibly modifed but values unchanged | [
"Calls",
"f",
"with",
"each",
"key",
"and",
"value",
"of",
"dct",
"possibly",
"returning",
"a",
"modified",
"key",
".",
"Values",
"are",
"unchanged",
":",
"param",
"f",
":",
"Called",
"with",
"each",
"key",
"and",
"value",
"and",
"returns",
"the",
"same"... | train | https://github.com/calocan/rescape-python-helpers/blob/91a1724f062ee40a25aa60fc96b2d7acadd99618/rescape_python_helpers/functional/ramda.py#L513-L523 |
calocan/rescape-python-helpers | rescape_python_helpers/functional/ramda.py | merge_deep | def merge_deep(dct1, dct2, merger=None):
"""
Deep merge by this spec below
:param dct1:
:param dct2:
:param merger Optional merger
:return:
"""
my_merger = merger or Merger(
# pass in a list of tuples,with the
# strategies you are looking to apply
# to each ty... | python | def merge_deep(dct1, dct2, merger=None):
"""
Deep merge by this spec below
:param dct1:
:param dct2:
:param merger Optional merger
:return:
"""
my_merger = merger or Merger(
# pass in a list of tuples,with the
# strategies you are looking to apply
# to each ty... | [
"def",
"merge_deep",
"(",
"dct1",
",",
"dct2",
",",
"merger",
"=",
"None",
")",
":",
"my_merger",
"=",
"merger",
"or",
"Merger",
"(",
"# pass in a list of tuples,with the",
"# strategies you are looking to apply",
"# to each type.",
"[",
"(",
"list",
",",
"[",
"\"... | Deep merge by this spec below
:param dct1:
:param dct2:
:param merger Optional merger
:return: | [
"Deep",
"merge",
"by",
"this",
"spec",
"below",
":",
"param",
"dct1",
":",
":",
"param",
"dct2",
":",
":",
"param",
"merger",
"Optional",
"merger",
":",
"return",
":"
] | train | https://github.com/calocan/rescape-python-helpers/blob/91a1724f062ee40a25aa60fc96b2d7acadd99618/rescape_python_helpers/functional/ramda.py#L538-L561 |
calocan/rescape-python-helpers | rescape_python_helpers/functional/ramda.py | merge_all | def merge_all(dcts):
"""
Shallow merge all the dcts
:param dcts:
:return:
"""
return reduce(
lambda accum, dct: merge(accum, dct),
dict(),
dcts
) | python | def merge_all(dcts):
"""
Shallow merge all the dcts
:param dcts:
:return:
"""
return reduce(
lambda accum, dct: merge(accum, dct),
dict(),
dcts
) | [
"def",
"merge_all",
"(",
"dcts",
")",
":",
"return",
"reduce",
"(",
"lambda",
"accum",
",",
"dct",
":",
"merge",
"(",
"accum",
",",
"dct",
")",
",",
"dict",
"(",
")",
",",
"dcts",
")"
] | Shallow merge all the dcts
:param dcts:
:return: | [
"Shallow",
"merge",
"all",
"the",
"dcts",
":",
"param",
"dcts",
":",
":",
"return",
":"
] | train | https://github.com/calocan/rescape-python-helpers/blob/91a1724f062ee40a25aa60fc96b2d7acadd99618/rescape_python_helpers/functional/ramda.py#L564-L574 |
calocan/rescape-python-helpers | rescape_python_helpers/functional/ramda.py | from_pairs_to_array_values | def from_pairs_to_array_values(pairs):
"""
Like from pairs but combines duplicate key values into arrays
:param pairs:
:return:
"""
result = {}
for pair in pairs:
result[pair[0]] = concat(prop_or([], pair[0], result), [pair[1]])
return result | python | def from_pairs_to_array_values(pairs):
"""
Like from pairs but combines duplicate key values into arrays
:param pairs:
:return:
"""
result = {}
for pair in pairs:
result[pair[0]] = concat(prop_or([], pair[0], result), [pair[1]])
return result | [
"def",
"from_pairs_to_array_values",
"(",
"pairs",
")",
":",
"result",
"=",
"{",
"}",
"for",
"pair",
"in",
"pairs",
":",
"result",
"[",
"pair",
"[",
"0",
"]",
"]",
"=",
"concat",
"(",
"prop_or",
"(",
"[",
"]",
",",
"pair",
"[",
"0",
"]",
",",
"re... | Like from pairs but combines duplicate key values into arrays
:param pairs:
:return: | [
"Like",
"from",
"pairs",
"but",
"combines",
"duplicate",
"key",
"values",
"into",
"arrays",
":",
"param",
"pairs",
":",
":",
"return",
":"
] | train | https://github.com/calocan/rescape-python-helpers/blob/91a1724f062ee40a25aa60fc96b2d7acadd99618/rescape_python_helpers/functional/ramda.py#L658-L667 |
calocan/rescape-python-helpers | rescape_python_helpers/functional/ramda.py | map_prop_value_as_index | def map_prop_value_as_index(prp, lst):
"""
Returns the given prop of each item in the list
:param prp:
:param lst:
:return:
"""
return from_pairs(map(lambda item: (prop(prp, item), item), lst)) | python | def map_prop_value_as_index(prp, lst):
"""
Returns the given prop of each item in the list
:param prp:
:param lst:
:return:
"""
return from_pairs(map(lambda item: (prop(prp, item), item), lst)) | [
"def",
"map_prop_value_as_index",
"(",
"prp",
",",
"lst",
")",
":",
"return",
"from_pairs",
"(",
"map",
"(",
"lambda",
"item",
":",
"(",
"prop",
"(",
"prp",
",",
"item",
")",
",",
"item",
")",
",",
"lst",
")",
")"
] | Returns the given prop of each item in the list
:param prp:
:param lst:
:return: | [
"Returns",
"the",
"given",
"prop",
"of",
"each",
"item",
"in",
"the",
"list",
":",
"param",
"prp",
":",
":",
"param",
"lst",
":",
":",
"return",
":"
] | train | https://github.com/calocan/rescape-python-helpers/blob/91a1724f062ee40a25aa60fc96b2d7acadd99618/rescape_python_helpers/functional/ramda.py#L698-L705 |
calocan/rescape-python-helpers | rescape_python_helpers/functional/ramda.py | key_string_to_lens_path | def key_string_to_lens_path(key_string):
"""
Converts a key string like 'foo.bar.0.wopper' to ['foo', 'bar', 0, 'wopper']
:param {String} keyString The dot-separated key string
:return {[String]} The lens array containing string or integers
"""
return map(
if_else(
isinstance(int)... | python | def key_string_to_lens_path(key_string):
"""
Converts a key string like 'foo.bar.0.wopper' to ['foo', 'bar', 0, 'wopper']
:param {String} keyString The dot-separated key string
:return {[String]} The lens array containing string or integers
"""
return map(
if_else(
isinstance(int)... | [
"def",
"key_string_to_lens_path",
"(",
"key_string",
")",
":",
"return",
"map",
"(",
"if_else",
"(",
"isinstance",
"(",
"int",
")",
",",
"# convert to int",
"lambda",
"s",
":",
"int",
"(",
"s",
")",
",",
"# Leave the string alone",
"identity",
")",
",",
"key... | Converts a key string like 'foo.bar.0.wopper' to ['foo', 'bar', 0, 'wopper']
:param {String} keyString The dot-separated key string
:return {[String]} The lens array containing string or integers | [
"Converts",
"a",
"key",
"string",
"like",
"foo",
".",
"bar",
".",
"0",
".",
"wopper",
"to",
"[",
"foo",
"bar",
"0",
"wopper",
"]",
":",
"param",
"{",
"String",
"}",
"keyString",
"The",
"dot",
"-",
"separated",
"key",
"string",
":",
"return",
"{",
"... | train | https://github.com/calocan/rescape-python-helpers/blob/91a1724f062ee40a25aa60fc96b2d7acadd99618/rescape_python_helpers/functional/ramda.py#L791-L806 |
calocan/rescape-python-helpers | rescape_python_helpers/functional/ramda.py | fake_lens_path_view | def fake_lens_path_view(lens_path, obj):
"""
Simulates R.view with a lens_path since we don't have lens functions
:param lens_path: Array of string paths
:param obj: Object containing the given path
:return: The value at the path or None
"""
segment = head(lens_path)
return if_else(
... | python | def fake_lens_path_view(lens_path, obj):
"""
Simulates R.view with a lens_path since we don't have lens functions
:param lens_path: Array of string paths
:param obj: Object containing the given path
:return: The value at the path or None
"""
segment = head(lens_path)
return if_else(
... | [
"def",
"fake_lens_path_view",
"(",
"lens_path",
",",
"obj",
")",
":",
"segment",
"=",
"head",
"(",
"lens_path",
")",
"return",
"if_else",
"(",
"both",
"(",
"lambda",
"_",
":",
"identity",
"(",
"segment",
")",
",",
"has",
"(",
"segment",
")",
")",
",",
... | Simulates R.view with a lens_path since we don't have lens functions
:param lens_path: Array of string paths
:param obj: Object containing the given path
:return: The value at the path or None | [
"Simulates",
"R",
".",
"view",
"with",
"a",
"lens_path",
"since",
"we",
"don",
"t",
"have",
"lens",
"functions",
":",
"param",
"lens_path",
":",
"Array",
"of",
"string",
"paths",
":",
"param",
"obj",
":",
"Object",
"containing",
"the",
"given",
"path",
"... | train | https://github.com/calocan/rescape-python-helpers/blob/91a1724f062ee40a25aa60fc96b2d7acadd99618/rescape_python_helpers/functional/ramda.py#L810-L824 |
calocan/rescape-python-helpers | rescape_python_helpers/functional/ramda.py | fake_lens_path_set | def fake_lens_path_set(lens_path, value, obj):
"""
Simulates R.set with a lens_path since we don't have lens functions
:param lens_path: Array of string paths
:param value: The value to set at the lens path
:param obj: Object containing the given path
:return: The value at the path or None
"... | python | def fake_lens_path_set(lens_path, value, obj):
"""
Simulates R.set with a lens_path since we don't have lens functions
:param lens_path: Array of string paths
:param value: The value to set at the lens path
:param obj: Object containing the given path
:return: The value at the path or None
"... | [
"def",
"fake_lens_path_set",
"(",
"lens_path",
",",
"value",
",",
"obj",
")",
":",
"segment",
"=",
"head",
"(",
"lens_path",
")",
"obj_copy",
"=",
"copy",
".",
"copy",
"(",
"obj",
")",
"def",
"set_array_index",
"(",
"i",
",",
"v",
",",
"l",
")",
":",... | Simulates R.set with a lens_path since we don't have lens functions
:param lens_path: Array of string paths
:param value: The value to set at the lens path
:param obj: Object containing the given path
:return: The value at the path or None | [
"Simulates",
"R",
".",
"set",
"with",
"a",
"lens_path",
"since",
"we",
"don",
"t",
"have",
"lens",
"functions",
":",
"param",
"lens_path",
":",
"Array",
"of",
"string",
"paths",
":",
"param",
"value",
":",
"The",
"value",
"to",
"set",
"at",
"the",
"len... | train | https://github.com/calocan/rescape-python-helpers/blob/91a1724f062ee40a25aa60fc96b2d7acadd99618/rescape_python_helpers/functional/ramda.py#L828-L870 |
calocan/rescape-python-helpers | rescape_python_helpers/functional/ramda.py | unflatten_dct | def unflatten_dct(obj):
"""
Undoes the work of flatten_dict
@param {Object} obj 1-D object in the form returned by flattenObj
@returns {Object} The original
:param obj:
:return:
"""
def reduce_func(accum, key_string_and_value):
key_string = key_string_and_value[0]
val... | python | def unflatten_dct(obj):
"""
Undoes the work of flatten_dict
@param {Object} obj 1-D object in the form returned by flattenObj
@returns {Object} The original
:param obj:
:return:
"""
def reduce_func(accum, key_string_and_value):
key_string = key_string_and_value[0]
val... | [
"def",
"unflatten_dct",
"(",
"obj",
")",
":",
"def",
"reduce_func",
"(",
"accum",
",",
"key_string_and_value",
")",
":",
"key_string",
"=",
"key_string_and_value",
"[",
"0",
"]",
"value",
"=",
"key_string_and_value",
"[",
"1",
"]",
"item_key_path",
"=",
"key_s... | Undoes the work of flatten_dict
@param {Object} obj 1-D object in the form returned by flattenObj
@returns {Object} The original
:param obj:
:return: | [
"Undoes",
"the",
"work",
"of",
"flatten_dict"
] | train | https://github.com/calocan/rescape-python-helpers/blob/91a1724f062ee40a25aa60fc96b2d7acadd99618/rescape_python_helpers/functional/ramda.py#L873-L915 |
jay-johnson/antinex-client | antinex_client/utils.py | ppj | def ppj(json_data):
"""ppj
:param json_data: dictionary to print
"""
return str(json.dumps(
json_data,
sort_keys=True,
indent=4,
separators=(',', ': '))) | python | def ppj(json_data):
"""ppj
:param json_data: dictionary to print
"""
return str(json.dumps(
json_data,
sort_keys=True,
indent=4,
separators=(',', ': '))) | [
"def",
"ppj",
"(",
"json_data",
")",
":",
"return",
"str",
"(",
"json",
".",
"dumps",
"(",
"json_data",
",",
"sort_keys",
"=",
"True",
",",
"indent",
"=",
"4",
",",
"separators",
"=",
"(",
"','",
",",
"': '",
")",
")",
")"
] | ppj
:param json_data: dictionary to print | [
"ppj"
] | train | https://github.com/jay-johnson/antinex-client/blob/850ba2a2fe21c836e071def618dcecc9caf5d59c/antinex_client/utils.py#L41-L50 |
praekeltfoundation/molo.commenting | molo/commenting/admin.py | AdminModeratorMixin.change_view | def change_view(self, request, object_id, form_url='', extra_context=None):
"""
Override change view to add extra context enabling moderate tool.
"""
context = {
'has_moderate_tool': True
}
if extra_context:
context.update(extra_context)
re... | python | def change_view(self, request, object_id, form_url='', extra_context=None):
"""
Override change view to add extra context enabling moderate tool.
"""
context = {
'has_moderate_tool': True
}
if extra_context:
context.update(extra_context)
re... | [
"def",
"change_view",
"(",
"self",
",",
"request",
",",
"object_id",
",",
"form_url",
"=",
"''",
",",
"extra_context",
"=",
"None",
")",
":",
"context",
"=",
"{",
"'has_moderate_tool'",
":",
"True",
"}",
"if",
"extra_context",
":",
"context",
".",
"update"... | Override change view to add extra context enabling moderate tool. | [
"Override",
"change",
"view",
"to",
"add",
"extra",
"context",
"enabling",
"moderate",
"tool",
"."
] | train | https://github.com/praekeltfoundation/molo.commenting/blob/94549bd75e4a5c5b3db43149e32d636330b3969c/molo/commenting/admin.py#L156-L170 |
praekeltfoundation/molo.commenting | molo/commenting/admin.py | AdminModeratorMixin.get_urls | def get_urls(self):
"""
Add aditional moderate url.
"""
from django.conf.urls import url
urls = super(AdminModeratorMixin, self).get_urls()
info = self.model._meta.app_label, self.model._meta.model_name
return [
url(r'^(.+)/moderate/$',
... | python | def get_urls(self):
"""
Add aditional moderate url.
"""
from django.conf.urls import url
urls = super(AdminModeratorMixin, self).get_urls()
info = self.model._meta.app_label, self.model._meta.model_name
return [
url(r'^(.+)/moderate/$',
... | [
"def",
"get_urls",
"(",
"self",
")",
":",
"from",
"django",
".",
"conf",
".",
"urls",
"import",
"url",
"urls",
"=",
"super",
"(",
"AdminModeratorMixin",
",",
"self",
")",
".",
"get_urls",
"(",
")",
"info",
"=",
"self",
".",
"model",
".",
"_meta",
"."... | Add aditional moderate url. | [
"Add",
"aditional",
"moderate",
"url",
"."
] | train | https://github.com/praekeltfoundation/molo.commenting/blob/94549bd75e4a5c5b3db43149e32d636330b3969c/molo/commenting/admin.py#L172-L183 |
feliphebueno/Rinzler | rinzler/core/response.py | Response.render | def render(self, indent=0):
"""
Renders a HttpResponse for the ongoing request
:param indent int
:rtype: HttpResponse
"""
self.__indent = indent
return HttpResponse(
str(self), content_type=self.__content_type, charset=self.__charset, **self.__kwargs
... | python | def render(self, indent=0):
"""
Renders a HttpResponse for the ongoing request
:param indent int
:rtype: HttpResponse
"""
self.__indent = indent
return HttpResponse(
str(self), content_type=self.__content_type, charset=self.__charset, **self.__kwargs
... | [
"def",
"render",
"(",
"self",
",",
"indent",
"=",
"0",
")",
":",
"self",
".",
"__indent",
"=",
"indent",
"return",
"HttpResponse",
"(",
"str",
"(",
"self",
")",
",",
"content_type",
"=",
"self",
".",
"__content_type",
",",
"charset",
"=",
"self",
".",
... | Renders a HttpResponse for the ongoing request
:param indent int
:rtype: HttpResponse | [
"Renders",
"a",
"HttpResponse",
"for",
"the",
"ongoing",
"request",
":",
"param",
"indent",
"int",
":",
"rtype",
":",
"HttpResponse"
] | train | https://github.com/feliphebueno/Rinzler/blob/7f6d5445b5662cba2e8938bb82c7f3ef94e5ded8/rinzler/core/response.py#L34-L43 |
feliphebueno/Rinzler | rinzler/logger/log.py | setup_logging | def setup_logging(default_path='logging.yaml', env_key='LOG_CFG'):
"""
Setup logging configuration
"""
path = default_path
value = os.getenv(env_key, None)
if value:
path = value
if os.path.exists(path):
with open(path, 'rt') as f:
configs = yaml.safe_load(f.read(... | python | def setup_logging(default_path='logging.yaml', env_key='LOG_CFG'):
"""
Setup logging configuration
"""
path = default_path
value = os.getenv(env_key, None)
if value:
path = value
if os.path.exists(path):
with open(path, 'rt') as f:
configs = yaml.safe_load(f.read(... | [
"def",
"setup_logging",
"(",
"default_path",
"=",
"'logging.yaml'",
",",
"env_key",
"=",
"'LOG_CFG'",
")",
":",
"path",
"=",
"default_path",
"value",
"=",
"os",
".",
"getenv",
"(",
"env_key",
",",
"None",
")",
"if",
"value",
":",
"path",
"=",
"value",
"i... | Setup logging configuration | [
"Setup",
"logging",
"configuration"
] | train | https://github.com/feliphebueno/Rinzler/blob/7f6d5445b5662cba2e8938bb82c7f3ef94e5ded8/rinzler/logger/log.py#L9-L22 |
feliphebueno/Rinzler | rinzler/core/route_mapping.py | RouteMapping.get | def get(self, route: str(), callback: object()):
"""
Binds a GET route with the given callback
:rtype: object
"""
self.__set_route('get', {route: callback})
return RouteMapping | python | def get(self, route: str(), callback: object()):
"""
Binds a GET route with the given callback
:rtype: object
"""
self.__set_route('get', {route: callback})
return RouteMapping | [
"def",
"get",
"(",
"self",
",",
"route",
":",
"str",
"(",
")",
",",
"callback",
":",
"object",
"(",
")",
")",
":",
"self",
".",
"__set_route",
"(",
"'get'",
",",
"{",
"route",
":",
"callback",
"}",
")",
"return",
"RouteMapping"
] | Binds a GET route with the given callback
:rtype: object | [
"Binds",
"a",
"GET",
"route",
"with",
"the",
"given",
"callback",
":",
"rtype",
":",
"object"
] | train | https://github.com/feliphebueno/Rinzler/blob/7f6d5445b5662cba2e8938bb82c7f3ef94e5ded8/rinzler/core/route_mapping.py#L16-L22 |
feliphebueno/Rinzler | rinzler/core/route_mapping.py | RouteMapping.post | def post(self, route: str(), callback: object()):
"""
Binds a POST route with the given callback
:rtype: object
"""
self.__set_route('post', {route: callback})
return RouteMapping | python | def post(self, route: str(), callback: object()):
"""
Binds a POST route with the given callback
:rtype: object
"""
self.__set_route('post', {route: callback})
return RouteMapping | [
"def",
"post",
"(",
"self",
",",
"route",
":",
"str",
"(",
")",
",",
"callback",
":",
"object",
"(",
")",
")",
":",
"self",
".",
"__set_route",
"(",
"'post'",
",",
"{",
"route",
":",
"callback",
"}",
")",
"return",
"RouteMapping"
] | Binds a POST route with the given callback
:rtype: object | [
"Binds",
"a",
"POST",
"route",
"with",
"the",
"given",
"callback",
":",
"rtype",
":",
"object"
] | train | https://github.com/feliphebueno/Rinzler/blob/7f6d5445b5662cba2e8938bb82c7f3ef94e5ded8/rinzler/core/route_mapping.py#L24-L30 |
feliphebueno/Rinzler | rinzler/core/route_mapping.py | RouteMapping.put | def put(self, route: str(), callback: object()):
"""
Binds a PUT route with the given callback
:rtype: object
"""
self.__set_route('put', {route: callback})
return RouteMapping | python | def put(self, route: str(), callback: object()):
"""
Binds a PUT route with the given callback
:rtype: object
"""
self.__set_route('put', {route: callback})
return RouteMapping | [
"def",
"put",
"(",
"self",
",",
"route",
":",
"str",
"(",
")",
",",
"callback",
":",
"object",
"(",
")",
")",
":",
"self",
".",
"__set_route",
"(",
"'put'",
",",
"{",
"route",
":",
"callback",
"}",
")",
"return",
"RouteMapping"
] | Binds a PUT route with the given callback
:rtype: object | [
"Binds",
"a",
"PUT",
"route",
"with",
"the",
"given",
"callback",
":",
"rtype",
":",
"object"
] | train | https://github.com/feliphebueno/Rinzler/blob/7f6d5445b5662cba2e8938bb82c7f3ef94e5ded8/rinzler/core/route_mapping.py#L32-L38 |
feliphebueno/Rinzler | rinzler/core/route_mapping.py | RouteMapping.patch | def patch(self, route: str(), callback: object()):
"""
Binds a PATCH route with the given callback
:rtype: object
"""
self.__set_route('patch', {route: callback})
return RouteMapping | python | def patch(self, route: str(), callback: object()):
"""
Binds a PATCH route with the given callback
:rtype: object
"""
self.__set_route('patch', {route: callback})
return RouteMapping | [
"def",
"patch",
"(",
"self",
",",
"route",
":",
"str",
"(",
")",
",",
"callback",
":",
"object",
"(",
")",
")",
":",
"self",
".",
"__set_route",
"(",
"'patch'",
",",
"{",
"route",
":",
"callback",
"}",
")",
"return",
"RouteMapping"
] | Binds a PATCH route with the given callback
:rtype: object | [
"Binds",
"a",
"PATCH",
"route",
"with",
"the",
"given",
"callback",
":",
"rtype",
":",
"object"
] | train | https://github.com/feliphebueno/Rinzler/blob/7f6d5445b5662cba2e8938bb82c7f3ef94e5ded8/rinzler/core/route_mapping.py#L40-L46 |
feliphebueno/Rinzler | rinzler/core/route_mapping.py | RouteMapping.delete | def delete(self, route: str(), callback: object()):
"""
Binds a PUT route with the given callback
:rtype: object
"""
self.__set_route('delete', {route: callback})
return RouteMapping | python | def delete(self, route: str(), callback: object()):
"""
Binds a PUT route with the given callback
:rtype: object
"""
self.__set_route('delete', {route: callback})
return RouteMapping | [
"def",
"delete",
"(",
"self",
",",
"route",
":",
"str",
"(",
")",
",",
"callback",
":",
"object",
"(",
")",
")",
":",
"self",
".",
"__set_route",
"(",
"'delete'",
",",
"{",
"route",
":",
"callback",
"}",
")",
"return",
"RouteMapping"
] | Binds a PUT route with the given callback
:rtype: object | [
"Binds",
"a",
"PUT",
"route",
"with",
"the",
"given",
"callback",
":",
"rtype",
":",
"object"
] | train | https://github.com/feliphebueno/Rinzler/blob/7f6d5445b5662cba2e8938bb82c7f3ef94e5ded8/rinzler/core/route_mapping.py#L48-L54 |
feliphebueno/Rinzler | rinzler/core/route_mapping.py | RouteMapping.head | def head(self, route: str(), callback: object()):
"""
Binds a HEAD route with the given callback
:rtype: object
"""
self.__set_route('head', {route: callback})
return RouteMapping | python | def head(self, route: str(), callback: object()):
"""
Binds a HEAD route with the given callback
:rtype: object
"""
self.__set_route('head', {route: callback})
return RouteMapping | [
"def",
"head",
"(",
"self",
",",
"route",
":",
"str",
"(",
")",
",",
"callback",
":",
"object",
"(",
")",
")",
":",
"self",
".",
"__set_route",
"(",
"'head'",
",",
"{",
"route",
":",
"callback",
"}",
")",
"return",
"RouteMapping"
] | Binds a HEAD route with the given callback
:rtype: object | [
"Binds",
"a",
"HEAD",
"route",
"with",
"the",
"given",
"callback",
":",
"rtype",
":",
"object"
] | train | https://github.com/feliphebueno/Rinzler/blob/7f6d5445b5662cba2e8938bb82c7f3ef94e5ded8/rinzler/core/route_mapping.py#L56-L62 |
feliphebueno/Rinzler | rinzler/core/route_mapping.py | RouteMapping.options | def options(self, route: str(), callback: object()):
"""
Binds a OPTIONS route with the given callback
:rtype: object
"""
self.__set_route('options', {route: callback})
return RouteMapping | python | def options(self, route: str(), callback: object()):
"""
Binds a OPTIONS route with the given callback
:rtype: object
"""
self.__set_route('options', {route: callback})
return RouteMapping | [
"def",
"options",
"(",
"self",
",",
"route",
":",
"str",
"(",
")",
",",
"callback",
":",
"object",
"(",
")",
")",
":",
"self",
".",
"__set_route",
"(",
"'options'",
",",
"{",
"route",
":",
"callback",
"}",
")",
"return",
"RouteMapping"
] | Binds a OPTIONS route with the given callback
:rtype: object | [
"Binds",
"a",
"OPTIONS",
"route",
"with",
"the",
"given",
"callback",
":",
"rtype",
":",
"object"
] | train | https://github.com/feliphebueno/Rinzler/blob/7f6d5445b5662cba2e8938bb82c7f3ef94e5ded8/rinzler/core/route_mapping.py#L64-L70 |
feliphebueno/Rinzler | rinzler/core/route_mapping.py | RouteMapping.__set_route | def __set_route(self, type_route, route):
"""
Sets the given type_route and route to the route mapping
:rtype: object
"""
if type_route in self.__routes:
if not self.verify_route_already_bound(type_route, route):
self.__routes[type_route].append(route)... | python | def __set_route(self, type_route, route):
"""
Sets the given type_route and route to the route mapping
:rtype: object
"""
if type_route in self.__routes:
if not self.verify_route_already_bound(type_route, route):
self.__routes[type_route].append(route)... | [
"def",
"__set_route",
"(",
"self",
",",
"type_route",
",",
"route",
")",
":",
"if",
"type_route",
"in",
"self",
".",
"__routes",
":",
"if",
"not",
"self",
".",
"verify_route_already_bound",
"(",
"type_route",
",",
"route",
")",
":",
"self",
".",
"__routes"... | Sets the given type_route and route to the route mapping
:rtype: object | [
"Sets",
"the",
"given",
"type_route",
"and",
"route",
"to",
"the",
"route",
"mapping",
":",
"rtype",
":",
"object"
] | train | https://github.com/feliphebueno/Rinzler/blob/7f6d5445b5662cba2e8938bb82c7f3ef94e5ded8/rinzler/core/route_mapping.py#L72-L82 |
gmr/helper | helper/unix.py | operating_system | def operating_system():
"""Return a string identifying the operating system the application
is running on.
:rtype: str
"""
if platform.system() == 'Darwin':
return 'OS X Version %s' % platform.mac_ver()[0]
distribution = ' '.join(platform.linux_distribution()).strip()
os_platform =... | python | def operating_system():
"""Return a string identifying the operating system the application
is running on.
:rtype: str
"""
if platform.system() == 'Darwin':
return 'OS X Version %s' % platform.mac_ver()[0]
distribution = ' '.join(platform.linux_distribution()).strip()
os_platform =... | [
"def",
"operating_system",
"(",
")",
":",
"if",
"platform",
".",
"system",
"(",
")",
"==",
"'Darwin'",
":",
"return",
"'OS X Version %s'",
"%",
"platform",
".",
"mac_ver",
"(",
")",
"[",
"0",
"]",
"distribution",
"=",
"' '",
".",
"join",
"(",
"platform",... | Return a string identifying the operating system the application
is running on.
:rtype: str | [
"Return",
"a",
"string",
"identifying",
"the",
"operating",
"system",
"the",
"application",
"is",
"running",
"on",
"."
] | train | https://github.com/gmr/helper/blob/fe8e45fc8eabf619429b2940c682c252ee33c082/helper/unix.py#L27-L40 |
gmr/helper | helper/unix.py | Daemon.start | def start(self):
"""Daemonize if the process is not already running."""
if self._is_already_running():
LOGGER.error('Is already running')
sys.exit(1)
try:
self._daemonize()
self.controller.start()
except Exception as error:
sys.... | python | def start(self):
"""Daemonize if the process is not already running."""
if self._is_already_running():
LOGGER.error('Is already running')
sys.exit(1)
try:
self._daemonize()
self.controller.start()
except Exception as error:
sys.... | [
"def",
"start",
"(",
"self",
")",
":",
"if",
"self",
".",
"_is_already_running",
"(",
")",
":",
"LOGGER",
".",
"error",
"(",
"'Is already running'",
")",
"sys",
".",
"exit",
"(",
"1",
")",
"try",
":",
"self",
".",
"_daemonize",
"(",
")",
"self",
".",... | Daemonize if the process is not already running. | [
"Daemonize",
"if",
"the",
"process",
"is",
"not",
"already",
"running",
"."
] | train | https://github.com/gmr/helper/blob/fe8e45fc8eabf619429b2940c682c252ee33c082/helper/unix.py#L85-L114 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.