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 |
|---|---|---|---|---|---|---|---|---|---|---|
UpCloudLtd/upcloud-python-api | upcloud_api/cloud_manager/server_mixin.py | ServerManager.create_server | def create_server(self, server):
"""
Create a server and its storages based on a (locally created) Server object.
Populates the given Server instance with the API response.
0.3.0: also supports giving the entire POST body as a dict that is directly
serialised into JSON. Refer t... | python | def create_server(self, server):
"""
Create a server and its storages based on a (locally created) Server object.
Populates the given Server instance with the API response.
0.3.0: also supports giving the entire POST body as a dict that is directly
serialised into JSON. Refer t... | [
"def",
"create_server",
"(",
"self",
",",
"server",
")",
":",
"if",
"isinstance",
"(",
"server",
",",
"Server",
")",
":",
"body",
"=",
"server",
".",
"prepare_post_body",
"(",
")",
"else",
":",
"server",
"=",
"Server",
".",
"_create_server_obj",
"(",
"se... | Create a server and its storages based on a (locally created) Server object.
Populates the given Server instance with the API response.
0.3.0: also supports giving the entire POST body as a dict that is directly
serialised into JSON. Refer to the REST API documentation for correct format.
... | [
"Create",
"a",
"server",
"and",
"its",
"storages",
"based",
"on",
"a",
"(",
"locally",
"created",
")",
"Server",
"object",
"."
] | train | https://github.com/UpCloudLtd/upcloud-python-api/blob/954b0ad7c4b932b2be31a95d88975f6b0eeac8ed/upcloud_api/cloud_manager/server_mixin.py#L80-L127 |
UpCloudLtd/upcloud-python-api | upcloud_api/cloud_manager/server_mixin.py | ServerManager.modify_server | def modify_server(self, UUID, **kwargs):
"""
modify_server allows updating the server's updateable_fields.
Note: Server's IP-addresses and Storages are managed by their own add/remove methods.
"""
body = dict()
body['server'] = {}
for arg in kwargs:
i... | python | def modify_server(self, UUID, **kwargs):
"""
modify_server allows updating the server's updateable_fields.
Note: Server's IP-addresses and Storages are managed by their own add/remove methods.
"""
body = dict()
body['server'] = {}
for arg in kwargs:
i... | [
"def",
"modify_server",
"(",
"self",
",",
"UUID",
",",
"*",
"*",
"kwargs",
")",
":",
"body",
"=",
"dict",
"(",
")",
"body",
"[",
"'server'",
"]",
"=",
"{",
"}",
"for",
"arg",
"in",
"kwargs",
":",
"if",
"arg",
"not",
"in",
"Server",
".",
"updateab... | modify_server allows updating the server's updateable_fields.
Note: Server's IP-addresses and Storages are managed by their own add/remove methods. | [
"modify_server",
"allows",
"updating",
"the",
"server",
"s",
"updateable_fields",
"."
] | train | https://github.com/UpCloudLtd/upcloud-python-api/blob/954b0ad7c4b932b2be31a95d88975f6b0eeac8ed/upcloud_api/cloud_manager/server_mixin.py#L129-L158 |
UpCloudLtd/upcloud-python-api | upcloud_api/cloud_manager/server_mixin.py | ServerManager.get_server_data | def get_server_data(self, UUID):
"""
Return '/server/uuid' data in Python dict.
Creates object representations of any IP-address and Storage.
"""
data = self.get_request('/server/{0}'.format(UUID))
server = data['server']
# Populate subobjects
IPAddresse... | python | def get_server_data(self, UUID):
"""
Return '/server/uuid' data in Python dict.
Creates object representations of any IP-address and Storage.
"""
data = self.get_request('/server/{0}'.format(UUID))
server = data['server']
# Populate subobjects
IPAddresse... | [
"def",
"get_server_data",
"(",
"self",
",",
"UUID",
")",
":",
"data",
"=",
"self",
".",
"get_request",
"(",
"'/server/{0}'",
".",
"format",
"(",
"UUID",
")",
")",
"server",
"=",
"data",
"[",
"'server'",
"]",
"# Populate subobjects",
"IPAddresses",
"=",
"IP... | Return '/server/uuid' data in Python dict.
Creates object representations of any IP-address and Storage. | [
"Return",
"/",
"server",
"/",
"uuid",
"data",
"in",
"Python",
"dict",
"."
] | train | https://github.com/UpCloudLtd/upcloud-python-api/blob/954b0ad7c4b932b2be31a95d88975f6b0eeac8ed/upcloud_api/cloud_manager/server_mixin.py#L170-L186 |
csirtgadgets/csirtgsdk-py | csirtgsdk/__init__.py | feed | def feed(f, limit=25):
"""
Pull a feed
:param f: feed name (eg: csirtgadgetes/correlated)
:param limit: return value limit (default 25)
:return: Feed dict
"""
if '/' not in f:
raise ValueError('feed name must be formatted like: '
'csirtgadgets/scanners')
... | python | def feed(f, limit=25):
"""
Pull a feed
:param f: feed name (eg: csirtgadgetes/correlated)
:param limit: return value limit (default 25)
:return: Feed dict
"""
if '/' not in f:
raise ValueError('feed name must be formatted like: '
'csirtgadgets/scanners')
... | [
"def",
"feed",
"(",
"f",
",",
"limit",
"=",
"25",
")",
":",
"if",
"'/'",
"not",
"in",
"f",
":",
"raise",
"ValueError",
"(",
"'feed name must be formatted like: '",
"'csirtgadgets/scanners'",
")",
"user",
",",
"f",
"=",
"f",
".",
"split",
"(",
"'/'",
")",... | Pull a feed
:param f: feed name (eg: csirtgadgetes/correlated)
:param limit: return value limit (default 25)
:return: Feed dict | [
"Pull",
"a",
"feed",
":",
"param",
"f",
":",
"feed",
"name",
"(",
"eg",
":",
"csirtgadgetes",
"/",
"correlated",
")",
":",
"param",
"limit",
":",
"return",
"value",
"limit",
"(",
"default",
"25",
")",
":",
"return",
":",
"Feed",
"dict"
] | train | https://github.com/csirtgadgets/csirtgsdk-py/blob/5a7ed9c5e6fa27170366ecbdef710dc80d537dc2/csirtgsdk/__init__.py#L11-L24 |
csirtgadgets/csirtgsdk-py | csirtgsdk/__init__.py | indicator_create | def indicator_create(f, i):
"""
Create an indicator in a feed
:param f: feed name (eg: wes/test)
:param i: indicator dict (eg: {'indicator': 'example.com', 'tags': ['ssh'],
'description': 'this is a test'})
:return: dict of indicator
"""
if '/' not in f:
raise ValueError('feed na... | python | def indicator_create(f, i):
"""
Create an indicator in a feed
:param f: feed name (eg: wes/test)
:param i: indicator dict (eg: {'indicator': 'example.com', 'tags': ['ssh'],
'description': 'this is a test'})
:return: dict of indicator
"""
if '/' not in f:
raise ValueError('feed na... | [
"def",
"indicator_create",
"(",
"f",
",",
"i",
")",
":",
"if",
"'/'",
"not",
"in",
"f",
":",
"raise",
"ValueError",
"(",
"'feed name must be formatted like: '",
"'csirtgadgets/scanners'",
")",
"if",
"not",
"i",
":",
"raise",
"ValueError",
"(",
"'missing indicato... | Create an indicator in a feed
:param f: feed name (eg: wes/test)
:param i: indicator dict (eg: {'indicator': 'example.com', 'tags': ['ssh'],
'description': 'this is a test'})
:return: dict of indicator | [
"Create",
"an",
"indicator",
"in",
"a",
"feed",
":",
"param",
"f",
":",
"feed",
"name",
"(",
"eg",
":",
"wes",
"/",
"test",
")",
":",
"param",
"i",
":",
"indicator",
"dict",
"(",
"eg",
":",
"{",
"indicator",
":",
"example",
".",
"com",
"tags",
":... | train | https://github.com/csirtgadgets/csirtgsdk-py/blob/5a7ed9c5e6fa27170366ecbdef710dc80d537dc2/csirtgsdk/__init__.py#L39-L61 |
ivanyu/idx2numpy | idx2numpy/converters.py | convert_from_file | def convert_from_file(file):
"""
Reads the content of file in IDX format, converts it into numpy.ndarray and
returns it.
file is a file-like object (with read() method) or a file name.
"""
if isinstance(file, six_string_types):
with open(file, 'rb') as f:
return _internal_con... | python | def convert_from_file(file):
"""
Reads the content of file in IDX format, converts it into numpy.ndarray and
returns it.
file is a file-like object (with read() method) or a file name.
"""
if isinstance(file, six_string_types):
with open(file, 'rb') as f:
return _internal_con... | [
"def",
"convert_from_file",
"(",
"file",
")",
":",
"if",
"isinstance",
"(",
"file",
",",
"six_string_types",
")",
":",
"with",
"open",
"(",
"file",
",",
"'rb'",
")",
"as",
"f",
":",
"return",
"_internal_convert",
"(",
"f",
")",
"else",
":",
"return",
"... | Reads the content of file in IDX format, converts it into numpy.ndarray and
returns it.
file is a file-like object (with read() method) or a file name. | [
"Reads",
"the",
"content",
"of",
"file",
"in",
"IDX",
"format",
"converts",
"it",
"into",
"numpy",
".",
"ndarray",
"and",
"returns",
"it",
".",
"file",
"is",
"a",
"file",
"-",
"like",
"object",
"(",
"with",
"read",
"()",
"method",
")",
"or",
"a",
"fi... | train | https://github.com/ivanyu/idx2numpy/blob/9b88698314973226212181d1747dfad6c6974e51/idx2numpy/converters.py#L49-L59 |
ivanyu/idx2numpy | idx2numpy/converters.py | _internal_convert | def _internal_convert(inp):
"""
Converts file in IDX format provided by file-like input into numpy.ndarray
and returns it.
"""
'''
Converts file in IDX format provided by file-like input into numpy.ndarray
and returns it.
'''
# Read the "magic number" - 4 bytes.
try:
mn ... | python | def _internal_convert(inp):
"""
Converts file in IDX format provided by file-like input into numpy.ndarray
and returns it.
"""
'''
Converts file in IDX format provided by file-like input into numpy.ndarray
and returns it.
'''
# Read the "magic number" - 4 bytes.
try:
mn ... | [
"def",
"_internal_convert",
"(",
"inp",
")",
":",
"'''\n Converts file in IDX format provided by file-like input into numpy.ndarray\n and returns it.\n '''",
"# Read the \"magic number\" - 4 bytes.",
"try",
":",
"mn",
"=",
"struct",
".",
"unpack",
"(",
"'>BBBB'",
",",
"i... | Converts file in IDX format provided by file-like input into numpy.ndarray
and returns it. | [
"Converts",
"file",
"in",
"IDX",
"format",
"provided",
"by",
"file",
"-",
"like",
"input",
"into",
"numpy",
".",
"ndarray",
"and",
"returns",
"it",
"."
] | train | https://github.com/ivanyu/idx2numpy/blob/9b88698314973226212181d1747dfad6c6974e51/idx2numpy/converters.py#L71-L127 |
ivanyu/idx2numpy | idx2numpy/converters.py | convert_to_file | def convert_to_file(file, ndarr):
"""
Writes the contents of the numpy.ndarray ndarr to file in IDX format.
file is a file-like object (with write() method) or a file name.
"""
if isinstance(file, six_string_types):
with open(file, 'wb') as fp:
_internal_write(fp, ndarr)
else... | python | def convert_to_file(file, ndarr):
"""
Writes the contents of the numpy.ndarray ndarr to file in IDX format.
file is a file-like object (with write() method) or a file name.
"""
if isinstance(file, six_string_types):
with open(file, 'wb') as fp:
_internal_write(fp, ndarr)
else... | [
"def",
"convert_to_file",
"(",
"file",
",",
"ndarr",
")",
":",
"if",
"isinstance",
"(",
"file",
",",
"six_string_types",
")",
":",
"with",
"open",
"(",
"file",
",",
"'wb'",
")",
"as",
"fp",
":",
"_internal_write",
"(",
"fp",
",",
"ndarr",
")",
"else",
... | Writes the contents of the numpy.ndarray ndarr to file in IDX format.
file is a file-like object (with write() method) or a file name. | [
"Writes",
"the",
"contents",
"of",
"the",
"numpy",
".",
"ndarray",
"ndarr",
"to",
"file",
"in",
"IDX",
"format",
".",
"file",
"is",
"a",
"file",
"-",
"like",
"object",
"(",
"with",
"write",
"()",
"method",
")",
"or",
"a",
"file",
"name",
"."
] | train | https://github.com/ivanyu/idx2numpy/blob/9b88698314973226212181d1747dfad6c6974e51/idx2numpy/converters.py#L130-L139 |
ivanyu/idx2numpy | idx2numpy/converters.py | convert_to_string | def convert_to_string(ndarr):
"""
Writes the contents of the numpy.ndarray ndarr to bytes in IDX format and
returns it.
"""
with contextlib.closing(BytesIO()) as bytesio:
_internal_write(bytesio, ndarr)
return bytesio.getvalue() | python | def convert_to_string(ndarr):
"""
Writes the contents of the numpy.ndarray ndarr to bytes in IDX format and
returns it.
"""
with contextlib.closing(BytesIO()) as bytesio:
_internal_write(bytesio, ndarr)
return bytesio.getvalue() | [
"def",
"convert_to_string",
"(",
"ndarr",
")",
":",
"with",
"contextlib",
".",
"closing",
"(",
"BytesIO",
"(",
")",
")",
"as",
"bytesio",
":",
"_internal_write",
"(",
"bytesio",
",",
"ndarr",
")",
"return",
"bytesio",
".",
"getvalue",
"(",
")"
] | Writes the contents of the numpy.ndarray ndarr to bytes in IDX format and
returns it. | [
"Writes",
"the",
"contents",
"of",
"the",
"numpy",
".",
"ndarray",
"ndarr",
"to",
"bytes",
"in",
"IDX",
"format",
"and",
"returns",
"it",
"."
] | train | https://github.com/ivanyu/idx2numpy/blob/9b88698314973226212181d1747dfad6c6974e51/idx2numpy/converters.py#L142-L149 |
ivanyu/idx2numpy | idx2numpy/converters.py | _internal_write | def _internal_write(out_stream, arr):
"""
Writes numpy.ndarray arr to a file-like object (with write() method) in
IDX format.
"""
if arr.size == 0:
raise FormatError('Cannot encode empty array.')
try:
type_byte, struct_lib_type = _DATA_TYPES_NUMPY[str(arr.dtype)]
except Key... | python | def _internal_write(out_stream, arr):
"""
Writes numpy.ndarray arr to a file-like object (with write() method) in
IDX format.
"""
if arr.size == 0:
raise FormatError('Cannot encode empty array.')
try:
type_byte, struct_lib_type = _DATA_TYPES_NUMPY[str(arr.dtype)]
except Key... | [
"def",
"_internal_write",
"(",
"out_stream",
",",
"arr",
")",
":",
"if",
"arr",
".",
"size",
"==",
"0",
":",
"raise",
"FormatError",
"(",
"'Cannot encode empty array.'",
")",
"try",
":",
"type_byte",
",",
"struct_lib_type",
"=",
"_DATA_TYPES_NUMPY",
"[",
"str"... | Writes numpy.ndarray arr to a file-like object (with write() method) in
IDX format. | [
"Writes",
"numpy",
".",
"ndarray",
"arr",
"to",
"a",
"file",
"-",
"like",
"object",
"(",
"with",
"write",
"()",
"method",
")",
"in",
"IDX",
"format",
"."
] | train | https://github.com/ivanyu/idx2numpy/blob/9b88698314973226212181d1747dfad6c6974e51/idx2numpy/converters.py#L152-L190 |
KKBOX/OpenAPI-Python | kkbox_developer_sdk/auth_flow.py | KKBOXOAuth.fetch_access_token_by_client_credentials | def fetch_access_token_by_client_credentials(self):
'''
There are three ways to let you start using KKBOX's Open/Partner
API. The first way among them is to generate a client
credential to fetch an access token to let KKBOX identify
you. It allows you to access public data from K... | python | def fetch_access_token_by_client_credentials(self):
'''
There are three ways to let you start using KKBOX's Open/Partner
API. The first way among them is to generate a client
credential to fetch an access token to let KKBOX identify
you. It allows you to access public data from K... | [
"def",
"fetch_access_token_by_client_credentials",
"(",
"self",
")",
":",
"client_credential_base",
"=",
"'%s:%s'",
"%",
"(",
"self",
".",
"client_id",
",",
"self",
".",
"client_secret",
")",
"try",
":",
"client_credentials",
"=",
"base64",
".",
"b64encode",
"(",
... | There are three ways to let you start using KKBOX's Open/Partner
API. The first way among them is to generate a client
credential to fetch an access token to let KKBOX identify
you. It allows you to access public data from KKBOX such as
public albums, playlists and so on.
Howeve... | [
"There",
"are",
"three",
"ways",
"to",
"let",
"you",
"start",
"using",
"KKBOX",
"s",
"Open",
"/",
"Partner",
"API",
".",
"The",
"first",
"way",
"among",
"them",
"is",
"to",
"generate",
"a",
"client",
"credential",
"to",
"fetch",
"an",
"access",
"token",
... | train | https://github.com/KKBOX/OpenAPI-Python/blob/77aa22fd300ed987d5507a5b66b149edcd28047d/kkbox_developer_sdk/auth_flow.py#L27-L60 |
UpCloudLtd/upcloud-python-api | upcloud_api/constants.py | OperatingSystems.get_OS_UUID | def get_OS_UUID(cls, os):
"""
Validate Storage OS and its UUID.
If the OS is a custom OS UUID, don't validate against templates.
"""
if os in cls.templates:
return cls.templates[os]
uuid_regexp = '^[0-9a-z]{8}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{12}... | python | def get_OS_UUID(cls, os):
"""
Validate Storage OS and its UUID.
If the OS is a custom OS UUID, don't validate against templates.
"""
if os in cls.templates:
return cls.templates[os]
uuid_regexp = '^[0-9a-z]{8}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{12}... | [
"def",
"get_OS_UUID",
"(",
"cls",
",",
"os",
")",
":",
"if",
"os",
"in",
"cls",
".",
"templates",
":",
"return",
"cls",
".",
"templates",
"[",
"os",
"]",
"uuid_regexp",
"=",
"'^[0-9a-z]{8}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{12}$'",
"if",
"re",
".",
"... | Validate Storage OS and its UUID.
If the OS is a custom OS UUID, don't validate against templates. | [
"Validate",
"Storage",
"OS",
"and",
"its",
"UUID",
"."
] | train | https://github.com/UpCloudLtd/upcloud-python-api/blob/954b0ad7c4b932b2be31a95d88975f6b0eeac8ed/upcloud_api/constants.py#L43-L60 |
tanwanirahul/django-batch-requests | batch_requests/concurrent/executor.py | Executor.execute | def execute(self, requests, resp_generator, *args, **kwargs):
'''
Calls the resp_generator for all the requests in parallel in an asynchronous way.
'''
result_futures = [self.executor_pool.submit(resp_generator, req, *args, **kwargs) for req in requests]
resp = [res_future.re... | python | def execute(self, requests, resp_generator, *args, **kwargs):
'''
Calls the resp_generator for all the requests in parallel in an asynchronous way.
'''
result_futures = [self.executor_pool.submit(resp_generator, req, *args, **kwargs) for req in requests]
resp = [res_future.re... | [
"def",
"execute",
"(",
"self",
",",
"requests",
",",
"resp_generator",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"result_futures",
"=",
"[",
"self",
".",
"executor_pool",
".",
"submit",
"(",
"resp_generator",
",",
"req",
",",
"*",
"args",
",... | Calls the resp_generator for all the requests in parallel in an asynchronous way. | [
"Calls",
"the",
"resp_generator",
"for",
"all",
"the",
"requests",
"in",
"parallel",
"in",
"an",
"asynchronous",
"way",
"."
] | train | https://github.com/tanwanirahul/django-batch-requests/blob/9c5afc42f7542f466247f4ffed9c44e1c49fa20d/batch_requests/concurrent/executor.py#L17-L23 |
tanwanirahul/django-batch-requests | batch_requests/concurrent/executor.py | SequentialExecutor.execute | def execute(self, requests, resp_generator, *args, **kwargs):
'''
Calls the resp_generator for all the requests in sequential order.
'''
return [resp_generator(request) for request in requests] | python | def execute(self, requests, resp_generator, *args, **kwargs):
'''
Calls the resp_generator for all the requests in sequential order.
'''
return [resp_generator(request) for request in requests] | [
"def",
"execute",
"(",
"self",
",",
"requests",
",",
"resp_generator",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"return",
"[",
"resp_generator",
"(",
"request",
")",
"for",
"request",
"in",
"requests",
"]"
] | Calls the resp_generator for all the requests in sequential order. | [
"Calls",
"the",
"resp_generator",
"for",
"all",
"the",
"requests",
"in",
"sequential",
"order",
"."
] | train | https://github.com/tanwanirahul/django-batch-requests/blob/9c5afc42f7542f466247f4ffed9c44e1c49fa20d/batch_requests/concurrent/executor.py#L31-L35 |
csirtgadgets/csirtgsdk-py | csirtgsdk/client/cli.py | setup_logging | def setup_logging(args):
"""
Sets up basic logging
:param args: ArgParse arguments
:return: nothing. sets logger up globally
"""
loglevel = logging.WARNING
if args.verbose:
loglevel = logging.INFO
if args.debug:
loglevel = logging.DEBUG
console = logging.StreamHandl... | python | def setup_logging(args):
"""
Sets up basic logging
:param args: ArgParse arguments
:return: nothing. sets logger up globally
"""
loglevel = logging.WARNING
if args.verbose:
loglevel = logging.INFO
if args.debug:
loglevel = logging.DEBUG
console = logging.StreamHandl... | [
"def",
"setup_logging",
"(",
"args",
")",
":",
"loglevel",
"=",
"logging",
".",
"WARNING",
"if",
"args",
".",
"verbose",
":",
"loglevel",
"=",
"logging",
".",
"INFO",
"if",
"args",
".",
"debug",
":",
"loglevel",
"=",
"logging",
".",
"DEBUG",
"console",
... | Sets up basic logging
:param args: ArgParse arguments
:return: nothing. sets logger up globally | [
"Sets",
"up",
"basic",
"logging"
] | train | https://github.com/csirtgadgets/csirtgsdk-py/blob/5a7ed9c5e6fa27170366ecbdef710dc80d537dc2/csirtgsdk/client/cli.py#L18-L34 |
UpCloudLtd/upcloud-python-api | upcloud_api/cloud_manager/ip_address_mixin.py | IPManager.get_ip | def get_ip(self, address):
"""
Get an IPAddress object with the IP address (string) from the API.
e.g manager.get_ip('80.69.175.210')
"""
res = self.get_request('/ip_address/' + address)
return IPAddress(cloud_manager=self, **res['ip_address']) | python | def get_ip(self, address):
"""
Get an IPAddress object with the IP address (string) from the API.
e.g manager.get_ip('80.69.175.210')
"""
res = self.get_request('/ip_address/' + address)
return IPAddress(cloud_manager=self, **res['ip_address']) | [
"def",
"get_ip",
"(",
"self",
",",
"address",
")",
":",
"res",
"=",
"self",
".",
"get_request",
"(",
"'/ip_address/'",
"+",
"address",
")",
"return",
"IPAddress",
"(",
"cloud_manager",
"=",
"self",
",",
"*",
"*",
"res",
"[",
"'ip_address'",
"]",
")"
] | Get an IPAddress object with the IP address (string) from the API.
e.g manager.get_ip('80.69.175.210') | [
"Get",
"an",
"IPAddress",
"object",
"with",
"the",
"IP",
"address",
"(",
"string",
")",
"from",
"the",
"API",
"."
] | train | https://github.com/UpCloudLtd/upcloud-python-api/blob/954b0ad7c4b932b2be31a95d88975f6b0eeac8ed/upcloud_api/cloud_manager/ip_address_mixin.py#L16-L23 |
UpCloudLtd/upcloud-python-api | upcloud_api/cloud_manager/ip_address_mixin.py | IPManager.get_ips | def get_ips(self):
"""
Get all IPAddress objects from the API.
"""
res = self.get_request('/ip_address')
IPs = IPAddress._create_ip_address_objs(res['ip_addresses'], cloud_manager=self)
return IPs | python | def get_ips(self):
"""
Get all IPAddress objects from the API.
"""
res = self.get_request('/ip_address')
IPs = IPAddress._create_ip_address_objs(res['ip_addresses'], cloud_manager=self)
return IPs | [
"def",
"get_ips",
"(",
"self",
")",
":",
"res",
"=",
"self",
".",
"get_request",
"(",
"'/ip_address'",
")",
"IPs",
"=",
"IPAddress",
".",
"_create_ip_address_objs",
"(",
"res",
"[",
"'ip_addresses'",
"]",
",",
"cloud_manager",
"=",
"self",
")",
"return",
"... | Get all IPAddress objects from the API. | [
"Get",
"all",
"IPAddress",
"objects",
"from",
"the",
"API",
"."
] | train | https://github.com/UpCloudLtd/upcloud-python-api/blob/954b0ad7c4b932b2be31a95d88975f6b0eeac8ed/upcloud_api/cloud_manager/ip_address_mixin.py#L25-L31 |
UpCloudLtd/upcloud-python-api | upcloud_api/cloud_manager/ip_address_mixin.py | IPManager.attach_ip | def attach_ip(self, server, family='IPv4'):
"""
Attach a new (random) IPAddress to the given server (object or UUID).
"""
body = {
'ip_address': {
'server': str(server),
'family': family
}
}
res = self.request('POST... | python | def attach_ip(self, server, family='IPv4'):
"""
Attach a new (random) IPAddress to the given server (object or UUID).
"""
body = {
'ip_address': {
'server': str(server),
'family': family
}
}
res = self.request('POST... | [
"def",
"attach_ip",
"(",
"self",
",",
"server",
",",
"family",
"=",
"'IPv4'",
")",
":",
"body",
"=",
"{",
"'ip_address'",
":",
"{",
"'server'",
":",
"str",
"(",
"server",
")",
",",
"'family'",
":",
"family",
"}",
"}",
"res",
"=",
"self",
".",
"requ... | Attach a new (random) IPAddress to the given server (object or UUID). | [
"Attach",
"a",
"new",
"(",
"random",
")",
"IPAddress",
"to",
"the",
"given",
"server",
"(",
"object",
"or",
"UUID",
")",
"."
] | train | https://github.com/UpCloudLtd/upcloud-python-api/blob/954b0ad7c4b932b2be31a95d88975f6b0eeac8ed/upcloud_api/cloud_manager/ip_address_mixin.py#L33-L45 |
UpCloudLtd/upcloud-python-api | upcloud_api/cloud_manager/ip_address_mixin.py | IPManager.modify_ip | def modify_ip(self, ip_addr, ptr_record):
"""
Modify an IP address' ptr-record (Reverse DNS).
Accepts an IPAddress instance (object) or its address (string).
"""
body = {
'ip_address': {
'ptr_record': ptr_record
}
}
res = ... | python | def modify_ip(self, ip_addr, ptr_record):
"""
Modify an IP address' ptr-record (Reverse DNS).
Accepts an IPAddress instance (object) or its address (string).
"""
body = {
'ip_address': {
'ptr_record': ptr_record
}
}
res = ... | [
"def",
"modify_ip",
"(",
"self",
",",
"ip_addr",
",",
"ptr_record",
")",
":",
"body",
"=",
"{",
"'ip_address'",
":",
"{",
"'ptr_record'",
":",
"ptr_record",
"}",
"}",
"res",
"=",
"self",
".",
"request",
"(",
"'PUT'",
",",
"'/ip_address/'",
"+",
"str",
... | Modify an IP address' ptr-record (Reverse DNS).
Accepts an IPAddress instance (object) or its address (string). | [
"Modify",
"an",
"IP",
"address",
"ptr",
"-",
"record",
"(",
"Reverse",
"DNS",
")",
"."
] | train | https://github.com/UpCloudLtd/upcloud-python-api/blob/954b0ad7c4b932b2be31a95d88975f6b0eeac8ed/upcloud_api/cloud_manager/ip_address_mixin.py#L47-L60 |
csirtgadgets/csirtgsdk-py | csirtgsdk/feed.py | Feed.new | def new(self, user, name, description=None):
"""
Creates a new Feed object
:param user: feed username
:param name: feed name
:param description: feed description
:return: dict
"""
uri = self.client.remote + '/users/{0}/feeds'.format(user)
data = ... | python | def new(self, user, name, description=None):
"""
Creates a new Feed object
:param user: feed username
:param name: feed name
:param description: feed description
:return: dict
"""
uri = self.client.remote + '/users/{0}/feeds'.format(user)
data = ... | [
"def",
"new",
"(",
"self",
",",
"user",
",",
"name",
",",
"description",
"=",
"None",
")",
":",
"uri",
"=",
"self",
".",
"client",
".",
"remote",
"+",
"'/users/{0}/feeds'",
".",
"format",
"(",
"user",
")",
"data",
"=",
"{",
"'feed'",
":",
"{",
"'na... | Creates a new Feed object
:param user: feed username
:param name: feed name
:param description: feed description
:return: dict | [
"Creates",
"a",
"new",
"Feed",
"object"
] | train | https://github.com/csirtgadgets/csirtgsdk-py/blob/5a7ed9c5e6fa27170366ecbdef710dc80d537dc2/csirtgsdk/feed.py#L32-L51 |
csirtgadgets/csirtgsdk-py | csirtgsdk/feed.py | Feed.delete | def delete(self, user, name):
"""
Removes a feed
:param user: feed username
:param name: feed name
:return: true/false
"""
uri = self.client.remote + '/users/{}/feeds/{}'.format(user, name)
resp = self.client.session.delete(uri)
return resp.stat... | python | def delete(self, user, name):
"""
Removes a feed
:param user: feed username
:param name: feed name
:return: true/false
"""
uri = self.client.remote + '/users/{}/feeds/{}'.format(user, name)
resp = self.client.session.delete(uri)
return resp.stat... | [
"def",
"delete",
"(",
"self",
",",
"user",
",",
"name",
")",
":",
"uri",
"=",
"self",
".",
"client",
".",
"remote",
"+",
"'/users/{}/feeds/{}'",
".",
"format",
"(",
"user",
",",
"name",
")",
"resp",
"=",
"self",
".",
"client",
".",
"session",
".",
... | Removes a feed
:param user: feed username
:param name: feed name
:return: true/false | [
"Removes",
"a",
"feed"
] | train | https://github.com/csirtgadgets/csirtgsdk-py/blob/5a7ed9c5e6fa27170366ecbdef710dc80d537dc2/csirtgsdk/feed.py#L53-L65 |
csirtgadgets/csirtgsdk-py | csirtgsdk/feed.py | Feed.index | def index(self, user):
"""
Returns a list of Feeds from the API
:param user: feed username
:return: list
Example:
ret = feed.index('csirtgadgets')
"""
uri = self.client.remote + '/users/{0}/feeds'.format(user)
return self.client.get(uri) | python | def index(self, user):
"""
Returns a list of Feeds from the API
:param user: feed username
:return: list
Example:
ret = feed.index('csirtgadgets')
"""
uri = self.client.remote + '/users/{0}/feeds'.format(user)
return self.client.get(uri) | [
"def",
"index",
"(",
"self",
",",
"user",
")",
":",
"uri",
"=",
"self",
".",
"client",
".",
"remote",
"+",
"'/users/{0}/feeds'",
".",
"format",
"(",
"user",
")",
"return",
"self",
".",
"client",
".",
"get",
"(",
"uri",
")"
] | Returns a list of Feeds from the API
:param user: feed username
:return: list
Example:
ret = feed.index('csirtgadgets') | [
"Returns",
"a",
"list",
"of",
"Feeds",
"from",
"the",
"API"
] | train | https://github.com/csirtgadgets/csirtgsdk-py/blob/5a7ed9c5e6fa27170366ecbdef710dc80d537dc2/csirtgsdk/feed.py#L69-L80 |
csirtgadgets/csirtgsdk-py | csirtgsdk/feed.py | Feed.show | def show(self, user, name, limit=None, lasttime=None):
"""
Returns a specific Feed from the API
:param user: feed username
:param name: feed name
:param limit: limit the results
:param lasttime: only show >= lasttime
:return: dict
Example:
re... | python | def show(self, user, name, limit=None, lasttime=None):
"""
Returns a specific Feed from the API
:param user: feed username
:param name: feed name
:param limit: limit the results
:param lasttime: only show >= lasttime
:return: dict
Example:
re... | [
"def",
"show",
"(",
"self",
",",
"user",
",",
"name",
",",
"limit",
"=",
"None",
",",
"lasttime",
"=",
"None",
")",
":",
"uri",
"=",
"self",
".",
"client",
".",
"remote",
"+",
"'/users/{0}/feeds/{1}'",
".",
"format",
"(",
"user",
",",
"name",
")",
... | Returns a specific Feed from the API
:param user: feed username
:param name: feed name
:param limit: limit the results
:param lasttime: only show >= lasttime
:return: dict
Example:
ret = feed.show('csirtgadgets', 'port-scanners', limit=5) | [
"Returns",
"a",
"specific",
"Feed",
"from",
"the",
"API"
] | train | https://github.com/csirtgadgets/csirtgsdk-py/blob/5a7ed9c5e6fa27170366ecbdef710dc80d537dc2/csirtgsdk/feed.py#L82-L96 |
codenerix/django-codenerix | codenerix/context.py | codenerix | def codenerix(request):
'''
Codenerix CONTEXT
'''
# Get values
DEBUG = getattr(settings, 'DEBUG', False)
VERSION = getattr(settings, 'VERSION', _('WARNING: No version set to this code, add VERSION contant to your configuration'))
# Set environment
return {
'DEBUG': DEBUG,
... | python | def codenerix(request):
'''
Codenerix CONTEXT
'''
# Get values
DEBUG = getattr(settings, 'DEBUG', False)
VERSION = getattr(settings, 'VERSION', _('WARNING: No version set to this code, add VERSION contant to your configuration'))
# Set environment
return {
'DEBUG': DEBUG,
... | [
"def",
"codenerix",
"(",
"request",
")",
":",
"# Get values",
"DEBUG",
"=",
"getattr",
"(",
"settings",
",",
"'DEBUG'",
",",
"False",
")",
"VERSION",
"=",
"getattr",
"(",
"settings",
",",
"'VERSION'",
",",
"_",
"(",
"'WARNING: No version set to this code, add VE... | Codenerix CONTEXT | [
"Codenerix",
"CONTEXT"
] | train | https://github.com/codenerix/django-codenerix/blob/1f5527b352141caaee902b37b2648791a06bd57d/codenerix/context.py#L28-L41 |
CTPUG/wafer | wafer/users/views.py | ProfileView.build_object | def build_object(self, obj):
"""Override django-bakery to skip profiles that raise 404"""
try:
build_path = self.get_build_path(obj)
self.request = self.create_request(build_path)
self.request.user = AnonymousUser()
self.set_kwargs(obj)
self.bu... | python | def build_object(self, obj):
"""Override django-bakery to skip profiles that raise 404"""
try:
build_path = self.get_build_path(obj)
self.request = self.create_request(build_path)
self.request.user = AnonymousUser()
self.set_kwargs(obj)
self.bu... | [
"def",
"build_object",
"(",
"self",
",",
"obj",
")",
":",
"try",
":",
"build_path",
"=",
"self",
".",
"get_build_path",
"(",
"obj",
")",
"self",
".",
"request",
"=",
"self",
".",
"create_request",
"(",
"build_path",
")",
"self",
".",
"request",
".",
"u... | Override django-bakery to skip profiles that raise 404 | [
"Override",
"django",
"-",
"bakery",
"to",
"skip",
"profiles",
"that",
"raise",
"404"
] | train | https://github.com/CTPUG/wafer/blob/a20af3c399267f76373dc342f4d542a9bc457c35/wafer/users/views.py#L49-L59 |
CTPUG/wafer | wafer/schedule/views.py | make_schedule_row | def make_schedule_row(schedule_day, slot, seen_items):
"""Create a row for the schedule table."""
row = ScheduleRow(schedule_day, slot)
skip = {}
expanding = {}
all_items = list(slot.scheduleitem_set
.select_related('talk', 'page', 'venue')
.all())
for ... | python | def make_schedule_row(schedule_day, slot, seen_items):
"""Create a row for the schedule table."""
row = ScheduleRow(schedule_day, slot)
skip = {}
expanding = {}
all_items = list(slot.scheduleitem_set
.select_related('talk', 'page', 'venue')
.all())
for ... | [
"def",
"make_schedule_row",
"(",
"schedule_day",
",",
"slot",
",",
"seen_items",
")",
":",
"row",
"=",
"ScheduleRow",
"(",
"schedule_day",
",",
"slot",
")",
"skip",
"=",
"{",
"}",
"expanding",
"=",
"{",
"}",
"all_items",
"=",
"list",
"(",
"slot",
".",
... | Create a row for the schedule table. | [
"Create",
"a",
"row",
"for",
"the",
"schedule",
"table",
"."
] | train | https://github.com/CTPUG/wafer/blob/a20af3c399267f76373dc342f4d542a9bc457c35/wafer/schedule/views.py#L57-L108 |
CTPUG/wafer | wafer/schedule/views.py | generate_schedule | def generate_schedule(today=None):
"""Helper function which creates an ordered list of schedule days"""
# We create a list of slots and schedule items
schedule_days = {}
seen_items = {}
for slot in Slot.objects.all().order_by('end_time', 'start_time', 'day'):
day = slot.get_day()
if ... | python | def generate_schedule(today=None):
"""Helper function which creates an ordered list of schedule days"""
# We create a list of slots and schedule items
schedule_days = {}
seen_items = {}
for slot in Slot.objects.all().order_by('end_time', 'start_time', 'day'):
day = slot.get_day()
if ... | [
"def",
"generate_schedule",
"(",
"today",
"=",
"None",
")",
":",
"# We create a list of slots and schedule items",
"schedule_days",
"=",
"{",
"}",
"seen_items",
"=",
"{",
"}",
"for",
"slot",
"in",
"Slot",
".",
"objects",
".",
"all",
"(",
")",
".",
"order_by",
... | Helper function which creates an ordered list of schedule days | [
"Helper",
"function",
"which",
"creates",
"an",
"ordered",
"list",
"of",
"schedule",
"days"
] | train | https://github.com/CTPUG/wafer/blob/a20af3c399267f76373dc342f4d542a9bc457c35/wafer/schedule/views.py#L111-L126 |
CTPUG/wafer | wafer/schedule/views.py | ScheduleXmlView.get_context_data | def get_context_data(self, **kwargs):
"""Allow adding a 'render_description' parameter"""
context = super(ScheduleXmlView, self).get_context_data(**kwargs)
if self.request.GET.get('render_description', None) == '1':
context['render_description'] = True
else:
conte... | python | def get_context_data(self, **kwargs):
"""Allow adding a 'render_description' parameter"""
context = super(ScheduleXmlView, self).get_context_data(**kwargs)
if self.request.GET.get('render_description', None) == '1':
context['render_description'] = True
else:
conte... | [
"def",
"get_context_data",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"context",
"=",
"super",
"(",
"ScheduleXmlView",
",",
"self",
")",
".",
"get_context_data",
"(",
"*",
"*",
"kwargs",
")",
"if",
"self",
".",
"request",
".",
"GET",
".",
"get",
... | Allow adding a 'render_description' parameter | [
"Allow",
"adding",
"a",
"render_description",
"parameter"
] | train | https://github.com/CTPUG/wafer/blob/a20af3c399267f76373dc342f4d542a9bc457c35/wafer/schedule/views.py#L164-L171 |
CTPUG/wafer | wafer/schedule/views.py | ICalView.get | def get(self, request):
"""Create a iCal file from the schedule"""
# Heavily inspired by https://djangosnippets.org/snippets/2223/ and
# the icalendar documentation
calendar = Calendar()
site = get_current_site(request)
calendar.add('prodid', '-//%s Schedule//%s//' % (sit... | python | def get(self, request):
"""Create a iCal file from the schedule"""
# Heavily inspired by https://djangosnippets.org/snippets/2223/ and
# the icalendar documentation
calendar = Calendar()
site = get_current_site(request)
calendar.add('prodid', '-//%s Schedule//%s//' % (sit... | [
"def",
"get",
"(",
"self",
",",
"request",
")",
":",
"# Heavily inspired by https://djangosnippets.org/snippets/2223/ and",
"# the icalendar documentation",
"calendar",
"=",
"Calendar",
"(",
")",
"site",
"=",
"get_current_site",
"(",
"request",
")",
"calendar",
".",
"ad... | Create a iCal file from the schedule | [
"Create",
"a",
"iCal",
"file",
"from",
"the",
"schedule"
] | train | https://github.com/CTPUG/wafer/blob/a20af3c399267f76373dc342f4d542a9bc457c35/wafer/schedule/views.py#L344-L367 |
CTPUG/wafer | wafer/pages/views.py | slug | def slug(request, url):
"""Look up a page by url (which is a tree of slugs)"""
page = None
if url:
for slug in url.split('/'):
if not slug:
continue
try:
page = Page.objects.get(slug=slug, parent=page)
except Page.DoesNotExist:
... | python | def slug(request, url):
"""Look up a page by url (which is a tree of slugs)"""
page = None
if url:
for slug in url.split('/'):
if not slug:
continue
try:
page = Page.objects.get(slug=slug, parent=page)
except Page.DoesNotExist:
... | [
"def",
"slug",
"(",
"request",
",",
"url",
")",
":",
"page",
"=",
"None",
"if",
"url",
":",
"for",
"slug",
"in",
"url",
".",
"split",
"(",
"'/'",
")",
":",
"if",
"not",
"slug",
":",
"continue",
"try",
":",
"page",
"=",
"Page",
".",
"objects",
"... | Look up a page by url (which is a tree of slugs) | [
"Look",
"up",
"a",
"page",
"by",
"url",
"(",
"which",
"is",
"a",
"tree",
"of",
"slugs",
")"
] | train | https://github.com/CTPUG/wafer/blob/a20af3c399267f76373dc342f4d542a9bc457c35/wafer/pages/views.py#L88-L117 |
CTPUG/wafer | wafer/pages/views.py | ShowPage.build_object | def build_object(self, obj):
"""Override django-bakery to skip pages marked exclude_from_static"""
if not obj.exclude_from_static:
super(ShowPage, self).build_object(obj) | python | def build_object(self, obj):
"""Override django-bakery to skip pages marked exclude_from_static"""
if not obj.exclude_from_static:
super(ShowPage, self).build_object(obj) | [
"def",
"build_object",
"(",
"self",
",",
"obj",
")",
":",
"if",
"not",
"obj",
".",
"exclude_from_static",
":",
"super",
"(",
"ShowPage",
",",
"self",
")",
".",
"build_object",
"(",
"obj",
")"
] | Override django-bakery to skip pages marked exclude_from_static | [
"Override",
"django",
"-",
"bakery",
"to",
"skip",
"pages",
"marked",
"exclude_from_static"
] | train | https://github.com/CTPUG/wafer/blob/a20af3c399267f76373dc342f4d542a9bc457c35/wafer/pages/views.py#L23-L26 |
CTPUG/wafer | wafer/talks/views.py | TalkView.build_object | def build_object(self, obj):
"""Override django-bakery to skip talks that raise 403"""
try:
super(TalkView, self).build_object(obj)
except PermissionDenied:
# We cleanup the directory created
self.unbuild_object(obj) | python | def build_object(self, obj):
"""Override django-bakery to skip talks that raise 403"""
try:
super(TalkView, self).build_object(obj)
except PermissionDenied:
# We cleanup the directory created
self.unbuild_object(obj) | [
"def",
"build_object",
"(",
"self",
",",
"obj",
")",
":",
"try",
":",
"super",
"(",
"TalkView",
",",
"self",
")",
".",
"build_object",
"(",
"obj",
")",
"except",
"PermissionDenied",
":",
"# We cleanup the directory created",
"self",
".",
"unbuild_object",
"(",... | Override django-bakery to skip talks that raise 403 | [
"Override",
"django",
"-",
"bakery",
"to",
"skip",
"talks",
"that",
"raise",
"403"
] | train | https://github.com/CTPUG/wafer/blob/a20af3c399267f76373dc342f4d542a9bc457c35/wafer/talks/views.py#L61-L67 |
CTPUG/wafer | wafer/talks/views.py | TalkView.get_object | def get_object(self, *args, **kwargs):
'''Only talk owners can see talks, unless they've been accepted'''
object_ = super(TalkView, self).get_object(*args, **kwargs)
if not object_.can_view(self.request.user):
raise PermissionDenied
return object_ | python | def get_object(self, *args, **kwargs):
'''Only talk owners can see talks, unless they've been accepted'''
object_ = super(TalkView, self).get_object(*args, **kwargs)
if not object_.can_view(self.request.user):
raise PermissionDenied
return object_ | [
"def",
"get_object",
"(",
"self",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"object_",
"=",
"super",
"(",
"TalkView",
",",
"self",
")",
".",
"get_object",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
"if",
"not",
"object_",
".",
"ca... | Only talk owners can see talks, unless they've been accepted | [
"Only",
"talk",
"owners",
"can",
"see",
"talks",
"unless",
"they",
"ve",
"been",
"accepted"
] | train | https://github.com/CTPUG/wafer/blob/a20af3c399267f76373dc342f4d542a9bc457c35/wafer/talks/views.py#L74-L79 |
CTPUG/wafer | wafer/talks/views.py | TalkView.render_to_response | def render_to_response(self, *args, **kwargs):
'''Canonicalize the URL if the slug changed'''
if self.request.path != self.object.get_absolute_url():
return HttpResponseRedirect(self.object.get_absolute_url())
return super(TalkView, self).render_to_response(*args, **kwargs) | python | def render_to_response(self, *args, **kwargs):
'''Canonicalize the URL if the slug changed'''
if self.request.path != self.object.get_absolute_url():
return HttpResponseRedirect(self.object.get_absolute_url())
return super(TalkView, self).render_to_response(*args, **kwargs) | [
"def",
"render_to_response",
"(",
"self",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"self",
".",
"request",
".",
"path",
"!=",
"self",
".",
"object",
".",
"get_absolute_url",
"(",
")",
":",
"return",
"HttpResponseRedirect",
"(",
"self",
... | Canonicalize the URL if the slug changed | [
"Canonicalize",
"the",
"URL",
"if",
"the",
"slug",
"changed"
] | train | https://github.com/CTPUG/wafer/blob/a20af3c399267f76373dc342f4d542a9bc457c35/wafer/talks/views.py#L81-L85 |
CTPUG/wafer | wafer/talks/views.py | TalkWithdraw.delete | def delete(self, request, *args, **kwargs):
"""Override delete to only withdraw"""
talk = self.get_object()
talk.status = WITHDRAWN
talk.save()
revisions.set_user(self.request.user)
revisions.set_comment("Talk Withdrawn")
return HttpResponseRedirect(self.success_u... | python | def delete(self, request, *args, **kwargs):
"""Override delete to only withdraw"""
talk = self.get_object()
talk.status = WITHDRAWN
talk.save()
revisions.set_user(self.request.user)
revisions.set_comment("Talk Withdrawn")
return HttpResponseRedirect(self.success_u... | [
"def",
"delete",
"(",
"self",
",",
"request",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"talk",
"=",
"self",
".",
"get_object",
"(",
")",
"talk",
".",
"status",
"=",
"WITHDRAWN",
"talk",
".",
"save",
"(",
")",
"revisions",
".",
"set_user... | Override delete to only withdraw | [
"Override",
"delete",
"to",
"only",
"withdraw"
] | train | https://github.com/CTPUG/wafer/blob/a20af3c399267f76373dc342f4d542a9bc457c35/wafer/talks/views.py#L173-L180 |
CTPUG/wafer | wafer/utils.py | order_results_by | def order_results_by(*fields):
"""A decorator that applies an ordering to the QuerySet returned by a
function.
"""
def decorator(f):
@functools.wraps(f)
def wrapper(*args, **kw):
result = f(*args, **kw)
return result.order_by(*fields)
return wrapper
... | python | def order_results_by(*fields):
"""A decorator that applies an ordering to the QuerySet returned by a
function.
"""
def decorator(f):
@functools.wraps(f)
def wrapper(*args, **kw):
result = f(*args, **kw)
return result.order_by(*fields)
return wrapper
... | [
"def",
"order_results_by",
"(",
"*",
"fields",
")",
":",
"def",
"decorator",
"(",
"f",
")",
":",
"@",
"functools",
".",
"wraps",
"(",
"f",
")",
"def",
"wrapper",
"(",
"*",
"args",
",",
"*",
"*",
"kw",
")",
":",
"result",
"=",
"f",
"(",
"*",
"ar... | A decorator that applies an ordering to the QuerySet returned by a
function. | [
"A",
"decorator",
"that",
"applies",
"an",
"ordering",
"to",
"the",
"QuerySet",
"returned",
"by",
"a",
"function",
"."
] | train | https://github.com/CTPUG/wafer/blob/a20af3c399267f76373dc342f4d542a9bc457c35/wafer/utils.py#L21-L31 |
CTPUG/wafer | wafer/utils.py | cache_result | def cache_result(cache_key, timeout):
"""A decorator for caching the result of a function."""
def decorator(f):
cache_name = settings.WAFER_CACHE
@functools.wraps(f)
def wrapper(*args, **kw):
cache = caches[cache_name]
result = cache.get(cache_key)
if... | python | def cache_result(cache_key, timeout):
"""A decorator for caching the result of a function."""
def decorator(f):
cache_name = settings.WAFER_CACHE
@functools.wraps(f)
def wrapper(*args, **kw):
cache = caches[cache_name]
result = cache.get(cache_key)
if... | [
"def",
"cache_result",
"(",
"cache_key",
",",
"timeout",
")",
":",
"def",
"decorator",
"(",
"f",
")",
":",
"cache_name",
"=",
"settings",
".",
"WAFER_CACHE",
"@",
"functools",
".",
"wraps",
"(",
"f",
")",
"def",
"wrapper",
"(",
"*",
"args",
",",
"*",
... | A decorator for caching the result of a function. | [
"A",
"decorator",
"for",
"caching",
"the",
"result",
"of",
"a",
"function",
"."
] | train | https://github.com/CTPUG/wafer/blob/a20af3c399267f76373dc342f4d542a9bc457c35/wafer/utils.py#L34-L54 |
CTPUG/wafer | wafer/utils.py | PaginatedBuildableListView.build_queryset | def build_queryset(self):
"""Override django-bakery's build logic to fake pagination."""
paths = [(os.path.join(self.build_prefix, 'index.html'), {})]
self.request = None
queryset = self.get_queryset()
paginator = self.get_paginator(queryset, self.get_paginate_by(queryset))
... | python | def build_queryset(self):
"""Override django-bakery's build logic to fake pagination."""
paths = [(os.path.join(self.build_prefix, 'index.html'), {})]
self.request = None
queryset = self.get_queryset()
paginator = self.get_paginator(queryset, self.get_paginate_by(queryset))
... | [
"def",
"build_queryset",
"(",
"self",
")",
":",
"paths",
"=",
"[",
"(",
"os",
".",
"path",
".",
"join",
"(",
"self",
".",
"build_prefix",
",",
"'index.html'",
")",
",",
"{",
"}",
")",
"]",
"self",
".",
"request",
"=",
"None",
"queryset",
"=",
"self... | Override django-bakery's build logic to fake pagination. | [
"Override",
"django",
"-",
"bakery",
"s",
"build",
"logic",
"to",
"fake",
"pagination",
"."
] | train | https://github.com/CTPUG/wafer/blob/a20af3c399267f76373dc342f4d542a9bc457c35/wafer/utils.py#L83-L101 |
codenerix/django-codenerix | codenerix/forms.py | BaseForm.get_groups | def get_groups(self, gs=None, processed=[], initial=True):
'''
<--------------------------------------- 12 columns ------------------------------------>
<--- 6 columns ---> <--- 6 columns --->
------------------------------------------ -----------... | python | def get_groups(self, gs=None, processed=[], initial=True):
'''
<--------------------------------------- 12 columns ------------------------------------>
<--- 6 columns ---> <--- 6 columns --->
------------------------------------------ -----------... | [
"def",
"get_groups",
"(",
"self",
",",
"gs",
"=",
"None",
",",
"processed",
"=",
"[",
"]",
",",
"initial",
"=",
"True",
")",
":",
"# Check if language is set",
"if",
"not",
"self",
".",
"__language",
":",
"raise",
"IOError",
"(",
"\"ERROR: No language suplie... | <--------------------------------------- 12 columns ------------------------------------>
<--- 6 columns ---> <--- 6 columns --->
------------------------------------------ ------------------------------------------
| Info ... | [
"<",
"---------------------------------------",
"12",
"columns",
"------------------------------------",
">",
"<",
"---",
"6",
"columns",
"---",
">",
"<",
"---",
"6",
"columns",
"---",
">",
"------------------------------------------",
"-----------------------------------------... | train | https://github.com/codenerix/django-codenerix/blob/1f5527b352141caaee902b37b2648791a06bd57d/codenerix/forms.py#L95-L502 |
CTPUG/wafer | wafer/context_processors.py | site_info | def site_info(request):
'''Expose the site's info to templates'''
site = get_current_site(request)
context = {
'WAFER_CONFERENCE_NAME': site.name,
'WAFER_CONFERENCE_DOMAIN': site.domain,
}
return context | python | def site_info(request):
'''Expose the site's info to templates'''
site = get_current_site(request)
context = {
'WAFER_CONFERENCE_NAME': site.name,
'WAFER_CONFERENCE_DOMAIN': site.domain,
}
return context | [
"def",
"site_info",
"(",
"request",
")",
":",
"site",
"=",
"get_current_site",
"(",
"request",
")",
"context",
"=",
"{",
"'WAFER_CONFERENCE_NAME'",
":",
"site",
".",
"name",
",",
"'WAFER_CONFERENCE_DOMAIN'",
":",
"site",
".",
"domain",
",",
"}",
"return",
"c... | Expose the site's info to templates | [
"Expose",
"the",
"site",
"s",
"info",
"to",
"templates"
] | train | https://github.com/CTPUG/wafer/blob/a20af3c399267f76373dc342f4d542a9bc457c35/wafer/context_processors.py#L6-L13 |
CTPUG/wafer | wafer/context_processors.py | navigation_info | def navigation_info(request):
'''Expose whether to display the navigation header and footer'''
if request.GET.get('wafer_hide_navigation') == "1":
nav_class = "wafer-invisible"
else:
nav_class = "wafer-visible"
context = {
'WAFER_NAVIGATION_VISIBILITY': nav_class,
}
retur... | python | def navigation_info(request):
'''Expose whether to display the navigation header and footer'''
if request.GET.get('wafer_hide_navigation') == "1":
nav_class = "wafer-invisible"
else:
nav_class = "wafer-visible"
context = {
'WAFER_NAVIGATION_VISIBILITY': nav_class,
}
retur... | [
"def",
"navigation_info",
"(",
"request",
")",
":",
"if",
"request",
".",
"GET",
".",
"get",
"(",
"'wafer_hide_navigation'",
")",
"==",
"\"1\"",
":",
"nav_class",
"=",
"\"wafer-invisible\"",
"else",
":",
"nav_class",
"=",
"\"wafer-visible\"",
"context",
"=",
"... | Expose whether to display the navigation header and footer | [
"Expose",
"whether",
"to",
"display",
"the",
"navigation",
"header",
"and",
"footer"
] | train | https://github.com/CTPUG/wafer/blob/a20af3c399267f76373dc342f4d542a9bc457c35/wafer/context_processors.py#L16-L25 |
CTPUG/wafer | wafer/context_processors.py | registration_settings | def registration_settings(request):
'''Expose selected settings to templates'''
context = {}
for setting in (
'WAFER_SSO',
'WAFER_HIDE_LOGIN',
'WAFER_REGISTRATION_OPEN',
'WAFER_REGISTRATION_MODE',
'WAFER_TALKS_OPEN',
'WAFER_VIDEO_LICENS... | python | def registration_settings(request):
'''Expose selected settings to templates'''
context = {}
for setting in (
'WAFER_SSO',
'WAFER_HIDE_LOGIN',
'WAFER_REGISTRATION_OPEN',
'WAFER_REGISTRATION_MODE',
'WAFER_TALKS_OPEN',
'WAFER_VIDEO_LICENS... | [
"def",
"registration_settings",
"(",
"request",
")",
":",
"context",
"=",
"{",
"}",
"for",
"setting",
"in",
"(",
"'WAFER_SSO'",
",",
"'WAFER_HIDE_LOGIN'",
",",
"'WAFER_REGISTRATION_OPEN'",
",",
"'WAFER_REGISTRATION_MODE'",
",",
"'WAFER_TALKS_OPEN'",
",",
"'WAFER_VIDEO... | Expose selected settings to templates | [
"Expose",
"selected",
"settings",
"to",
"templates"
] | train | https://github.com/CTPUG/wafer/blob/a20af3c399267f76373dc342f4d542a9bc457c35/wafer/context_processors.py#L37-L49 |
codenerix/django-codenerix | codenerix/models_people.py | GenPerson.profiles | def profiles(self):
'''
return the rolls this people is related with
'''
limit = []
if self.is_admin():
limit.append(_("Administrator"))
limit.sort()
return limit | python | def profiles(self):
'''
return the rolls this people is related with
'''
limit = []
if self.is_admin():
limit.append(_("Administrator"))
limit.sort()
return limit | [
"def",
"profiles",
"(",
"self",
")",
":",
"limit",
"=",
"[",
"]",
"if",
"self",
".",
"is_admin",
"(",
")",
":",
"limit",
".",
"append",
"(",
"_",
"(",
"\"Administrator\"",
")",
")",
"limit",
".",
"sort",
"(",
")",
"return",
"limit"
] | return the rolls this people is related with | [
"return",
"the",
"rolls",
"this",
"people",
"is",
"related",
"with"
] | train | https://github.com/codenerix/django-codenerix/blob/1f5527b352141caaee902b37b2648791a06bd57d/codenerix/models_people.py#L114-L124 |
markchil/gptools | gptools/kernel/matern.py | matern_function | def matern_function(Xi, Xj, *args):
r"""Matern covariance function of arbitrary dimension, for use with :py:class:`ArbitraryKernel`.
The Matern kernel has the following hyperparameters, always referenced in
the order listed:
= ===== ====================================
0 sigma prefactor
... | python | def matern_function(Xi, Xj, *args):
r"""Matern covariance function of arbitrary dimension, for use with :py:class:`ArbitraryKernel`.
The Matern kernel has the following hyperparameters, always referenced in
the order listed:
= ===== ====================================
0 sigma prefactor
... | [
"def",
"matern_function",
"(",
"Xi",
",",
"Xj",
",",
"*",
"args",
")",
":",
"num_dim",
"=",
"len",
"(",
"args",
")",
"-",
"2",
"nu",
"=",
"args",
"[",
"1",
"]",
"if",
"isinstance",
"(",
"Xi",
",",
"scipy",
".",
"ndarray",
")",
":",
"if",
"isins... | r"""Matern covariance function of arbitrary dimension, for use with :py:class:`ArbitraryKernel`.
The Matern kernel has the following hyperparameters, always referenced in
the order listed:
= ===== ====================================
0 sigma prefactor
1 nu order of kernel
2 l1 le... | [
"r",
"Matern",
"covariance",
"function",
"of",
"arbitrary",
"dimension",
"for",
"use",
"with",
":",
"py",
":",
"class",
":",
"ArbitraryKernel",
".",
"The",
"Matern",
"kernel",
"has",
"the",
"following",
"hyperparameters",
"always",
"referenced",
"in",
"the",
"... | train | https://github.com/markchil/gptools/blob/225db52bfe6baef1516529ad22177aa2cf7b71e4/gptools/kernel/matern.py#L44-L100 |
markchil/gptools | gptools/kernel/matern.py | MaternKernel._compute_k | def _compute_k(self, tau):
r"""Evaluate the kernel directly at the given values of `tau`.
Parameters
----------
tau : :py:class:`Matrix`, (`M`, `D`)
`M` inputs with dimension `D`.
Returns
-------
k : :py:class:`Array`, (`M`,)
... | python | def _compute_k(self, tau):
r"""Evaluate the kernel directly at the given values of `tau`.
Parameters
----------
tau : :py:class:`Matrix`, (`M`, `D`)
`M` inputs with dimension `D`.
Returns
-------
k : :py:class:`Array`, (`M`,)
... | [
"def",
"_compute_k",
"(",
"self",
",",
"tau",
")",
":",
"y",
",",
"r2l2",
"=",
"self",
".",
"_compute_y",
"(",
"tau",
",",
"return_r2l2",
"=",
"True",
")",
"k",
"=",
"2.0",
"**",
"(",
"1.0",
"-",
"self",
".",
"nu",
")",
"/",
"scipy",
".",
"spec... | r"""Evaluate the kernel directly at the given values of `tau`.
Parameters
----------
tau : :py:class:`Matrix`, (`M`, `D`)
`M` inputs with dimension `D`.
Returns
-------
k : :py:class:`Array`, (`M`,)
:math:`k(\tau)` (less the :math... | [
"r",
"Evaluate",
"the",
"kernel",
"directly",
"at",
"the",
"given",
"values",
"of",
"tau",
".",
"Parameters",
"----------",
"tau",
":",
":",
"py",
":",
"class",
":",
"Matrix",
"(",
"M",
"D",
")",
"M",
"inputs",
"with",
"dimension",
"D",
".",
"Returns",... | train | https://github.com/markchil/gptools/blob/225db52bfe6baef1516529ad22177aa2cf7b71e4/gptools/kernel/matern.py#L296-L312 |
markchil/gptools | gptools/kernel/matern.py | MaternKernel._compute_y | def _compute_y(self, tau, return_r2l2=False):
r"""Covert tau to :math:`y=2\nu\sum_i(\tau_i^2/l_i^2)`.
Parameters
----------
tau : :py:class:`Matrix`, (`M`, `D`)
`M` inputs with dimension `D`.
return_r2l2 : bool, optional
Set to True to return a tu... | python | def _compute_y(self, tau, return_r2l2=False):
r"""Covert tau to :math:`y=2\nu\sum_i(\tau_i^2/l_i^2)`.
Parameters
----------
tau : :py:class:`Matrix`, (`M`, `D`)
`M` inputs with dimension `D`.
return_r2l2 : bool, optional
Set to True to return a tu... | [
"def",
"_compute_y",
"(",
"self",
",",
"tau",
",",
"return_r2l2",
"=",
"False",
")",
":",
"r2l2",
"=",
"self",
".",
"_compute_r2l2",
"(",
"tau",
")",
"y",
"=",
"2.0",
"*",
"self",
".",
"nu",
"*",
"r2l2",
"if",
"return_r2l2",
":",
"return",
"(",
"y"... | r"""Covert tau to :math:`y=2\nu\sum_i(\tau_i^2/l_i^2)`.
Parameters
----------
tau : :py:class:`Matrix`, (`M`, `D`)
`M` inputs with dimension `D`.
return_r2l2 : bool, optional
Set to True to return a tuple of (`y`, `r2l2`). Default is False
(on... | [
"r",
"Covert",
"tau",
"to",
":",
"math",
":",
"y",
"=",
"2",
"\\",
"nu",
"\\",
"sum_i",
"(",
"\\",
"tau_i^2",
"/",
"l_i^2",
")",
".",
"Parameters",
"----------",
"tau",
":",
":",
"py",
":",
"class",
":",
"Matrix",
"(",
"M",
"D",
")",
"M",
"inpu... | train | https://github.com/markchil/gptools/blob/225db52bfe6baef1516529ad22177aa2cf7b71e4/gptools/kernel/matern.py#L314-L337 |
markchil/gptools | gptools/kernel/matern.py | MaternKernel._compute_y_wrapper | def _compute_y_wrapper(self, *args):
r"""Convert tau to :math:`y=\sqrt{2\nu\sum_i(\tau_i^2/l_i^2)}`.
Takes `tau` as an argument list for compatibility with :py:func:`mpmath.diff`.
Parameters
----------
tau[0] : scalar float
First element of `tau`.
... | python | def _compute_y_wrapper(self, *args):
r"""Convert tau to :math:`y=\sqrt{2\nu\sum_i(\tau_i^2/l_i^2)}`.
Takes `tau` as an argument list for compatibility with :py:func:`mpmath.diff`.
Parameters
----------
tau[0] : scalar float
First element of `tau`.
... | [
"def",
"_compute_y_wrapper",
"(",
"self",
",",
"*",
"args",
")",
":",
"return",
"self",
".",
"_compute_y",
"(",
"scipy",
".",
"atleast_2d",
"(",
"scipy",
".",
"asarray",
"(",
"args",
",",
"dtype",
"=",
"float",
")",
")",
")"
] | r"""Convert tau to :math:`y=\sqrt{2\nu\sum_i(\tau_i^2/l_i^2)}`.
Takes `tau` as an argument list for compatibility with :py:func:`mpmath.diff`.
Parameters
----------
tau[0] : scalar float
First element of `tau`.
tau[1] : And so on...
... | [
"r",
"Convert",
"tau",
"to",
":",
"math",
":",
"y",
"=",
"\\",
"sqrt",
"{",
"2",
"\\",
"nu",
"\\",
"sum_i",
"(",
"\\",
"tau_i^2",
"/",
"l_i^2",
")",
"}",
".",
"Takes",
"tau",
"as",
"an",
"argument",
"list",
"for",
"compatibility",
"with",
":",
"p... | train | https://github.com/markchil/gptools/blob/225db52bfe6baef1516529ad22177aa2cf7b71e4/gptools/kernel/matern.py#L339-L355 |
markchil/gptools | gptools/kernel/matern.py | MaternKernel._compute_dk_dy | def _compute_dk_dy(self, y, n):
r"""Evaluate the derivative of the outer form of the Matern kernel.
Uses the general Leibniz rule to compute the n-th derivative of:
.. math::
f(y) = \frac{2^{1-\nu}}{\Gamma(\nu)} y^{\nu/2} K_\nu(y^{1/2})
Par... | python | def _compute_dk_dy(self, y, n):
r"""Evaluate the derivative of the outer form of the Matern kernel.
Uses the general Leibniz rule to compute the n-th derivative of:
.. math::
f(y) = \frac{2^{1-\nu}}{\Gamma(\nu)} y^{\nu/2} K_\nu(y^{1/2})
Par... | [
"def",
"_compute_dk_dy",
"(",
"self",
",",
"y",
",",
"n",
")",
":",
"return",
"2.0",
"**",
"(",
"1",
"-",
"self",
".",
"nu",
")",
"/",
"(",
"scipy",
".",
"special",
".",
"gamma",
"(",
"self",
".",
"nu",
")",
")",
"*",
"yn2Kn2Der",
"(",
"self",
... | r"""Evaluate the derivative of the outer form of the Matern kernel.
Uses the general Leibniz rule to compute the n-th derivative of:
.. math::
f(y) = \frac{2^{1-\nu}}{\Gamma(\nu)} y^{\nu/2} K_\nu(y^{1/2})
Parameters
----------
y : :... | [
"r",
"Evaluate",
"the",
"derivative",
"of",
"the",
"outer",
"form",
"of",
"the",
"Matern",
"kernel",
".",
"Uses",
"the",
"general",
"Leibniz",
"rule",
"to",
"compute",
"the",
"n",
"-",
"th",
"derivative",
"of",
":",
"..",
"math",
"::",
"f",
"(",
"y",
... | train | https://github.com/markchil/gptools/blob/225db52bfe6baef1516529ad22177aa2cf7b71e4/gptools/kernel/matern.py#L357-L378 |
markchil/gptools | gptools/kernel/matern.py | MaternKernel._compute_dy_dtau | def _compute_dy_dtau(self, tau, b, r2l2):
r"""Evaluate the derivative of the inner argument of the Matern kernel.
Take the derivative of
.. math::
y = 2 \nu \sum_i(\tau_i^2 / l_i^2)
Parameters
----------
tau : :py:class:`Mat... | python | def _compute_dy_dtau(self, tau, b, r2l2):
r"""Evaluate the derivative of the inner argument of the Matern kernel.
Take the derivative of
.. math::
y = 2 \nu \sum_i(\tau_i^2 / l_i^2)
Parameters
----------
tau : :py:class:`Mat... | [
"def",
"_compute_dy_dtau",
"(",
"self",
",",
"tau",
",",
"b",
",",
"r2l2",
")",
":",
"if",
"len",
"(",
"b",
")",
"==",
"0",
":",
"return",
"self",
".",
"_compute_y",
"(",
"tau",
")",
"elif",
"len",
"(",
"b",
")",
"==",
"1",
":",
"return",
"4.0"... | r"""Evaluate the derivative of the inner argument of the Matern kernel.
Take the derivative of
.. math::
y = 2 \nu \sum_i(\tau_i^2 / l_i^2)
Parameters
----------
tau : :py:class:`Matrix`, (`M`, `D`)
`M` inputs with dimen... | [
"r",
"Evaluate",
"the",
"derivative",
"of",
"the",
"inner",
"argument",
"of",
"the",
"Matern",
"kernel",
".",
"Take",
"the",
"derivative",
"of",
"..",
"math",
"::",
"y",
"=",
"2",
"\\",
"nu",
"\\",
"sum_i",
"(",
"\\",
"tau_i^2",
"/",
"l_i^2",
")",
"P... | train | https://github.com/markchil/gptools/blob/225db52bfe6baef1516529ad22177aa2cf7b71e4/gptools/kernel/matern.py#L380-L410 |
markchil/gptools | gptools/kernel/matern.py | MaternKernel._compute_dk_dtau_on_partition | def _compute_dk_dtau_on_partition(self, tau, p):
"""Evaluate the term inside the sum of Faa di Bruno's formula for the given partition.
Overrides the version from :py:class:`gptools.kernel.core.ChainRuleKernel`
in order to get the correct behavior at the origin.
Paramet... | python | def _compute_dk_dtau_on_partition(self, tau, p):
"""Evaluate the term inside the sum of Faa di Bruno's formula for the given partition.
Overrides the version from :py:class:`gptools.kernel.core.ChainRuleKernel`
in order to get the correct behavior at the origin.
Paramet... | [
"def",
"_compute_dk_dtau_on_partition",
"(",
"self",
",",
"tau",
",",
"p",
")",
":",
"# Find the derivative order:",
"n",
"=",
"len",
"(",
"p",
")",
"y",
",",
"r2l2",
"=",
"self",
".",
"_compute_y",
"(",
"tau",
",",
"return_r2l2",
"=",
"True",
")",
"# Ke... | Evaluate the term inside the sum of Faa di Bruno's formula for the given partition.
Overrides the version from :py:class:`gptools.kernel.core.ChainRuleKernel`
in order to get the correct behavior at the origin.
Parameters
----------
tau : :py:class:`Matrix`, (`M... | [
"Evaluate",
"the",
"term",
"inside",
"the",
"sum",
"of",
"Faa",
"di",
"Bruno",
"s",
"formula",
"for",
"the",
"given",
"partition",
".",
"Overrides",
"the",
"version",
"from",
":",
"py",
":",
"class",
":",
"gptools",
".",
"kernel",
".",
"core",
".",
"Ch... | train | https://github.com/markchil/gptools/blob/225db52bfe6baef1516529ad22177aa2cf7b71e4/gptools/kernel/matern.py#L412-L459 |
coursera/courseraoauth2client | courseraoauth2client/utils.py | add_logging_parser | def add_logging_parser(main_parser):
"Build an argparse argument parser to parse the command line."
main_parser.set_defaults(setup_logging=set_logging_level)
verbosity_group = main_parser.add_mutually_exclusive_group(required=False)
verbosity_group.add_argument(
'--verbose',
'-v',
... | python | def add_logging_parser(main_parser):
"Build an argparse argument parser to parse the command line."
main_parser.set_defaults(setup_logging=set_logging_level)
verbosity_group = main_parser.add_mutually_exclusive_group(required=False)
verbosity_group.add_argument(
'--verbose',
'-v',
... | [
"def",
"add_logging_parser",
"(",
"main_parser",
")",
":",
"main_parser",
".",
"set_defaults",
"(",
"setup_logging",
"=",
"set_logging_level",
")",
"verbosity_group",
"=",
"main_parser",
".",
"add_mutually_exclusive_group",
"(",
"required",
"=",
"False",
")",
"verbosi... | Build an argparse argument parser to parse the command line. | [
"Build",
"an",
"argparse",
"argument",
"parser",
"to",
"parse",
"the",
"command",
"line",
"."
] | train | https://github.com/coursera/courseraoauth2client/blob/4edd991defe26bfc768ab28a30368cace40baf44/courseraoauth2client/utils.py#L28-L52 |
coursera/courseraoauth2client | courseraoauth2client/utils.py | set_logging_level | def set_logging_level(args):
"Computes and sets the logging level from the parsed arguments."
root_logger = logging.getLogger()
level = logging.INFO
logging.getLogger('requests.packages.urllib3').setLevel(logging.WARNING)
if "verbose" in args and args.verbose is not None:
logging.getLogger('... | python | def set_logging_level(args):
"Computes and sets the logging level from the parsed arguments."
root_logger = logging.getLogger()
level = logging.INFO
logging.getLogger('requests.packages.urllib3').setLevel(logging.WARNING)
if "verbose" in args and args.verbose is not None:
logging.getLogger('... | [
"def",
"set_logging_level",
"(",
"args",
")",
":",
"root_logger",
"=",
"logging",
".",
"getLogger",
"(",
")",
"level",
"=",
"logging",
".",
"INFO",
"logging",
".",
"getLogger",
"(",
"'requests.packages.urllib3'",
")",
".",
"setLevel",
"(",
"logging",
".",
"W... | Computes and sets the logging level from the parsed arguments. | [
"Computes",
"and",
"sets",
"the",
"logging",
"level",
"from",
"the",
"parsed",
"arguments",
"."
] | train | https://github.com/coursera/courseraoauth2client/blob/4edd991defe26bfc768ab28a30368cace40baf44/courseraoauth2client/utils.py#L55-L83 |
codenerix/django-codenerix | codenerix/authbackend.py | check_auth | def check_auth(user):
'''
Check if the user should or shouldn't be inside the system:
- If the user is staff or superuser: LOGIN GRANTED
- If the user has a Person and it is not "disabled": LOGIN GRANTED
- Elsewhere: LOGIN DENIED
'''
# Initialize authentication
auth = None
person = ... | python | def check_auth(user):
'''
Check if the user should or shouldn't be inside the system:
- If the user is staff or superuser: LOGIN GRANTED
- If the user has a Person and it is not "disabled": LOGIN GRANTED
- Elsewhere: LOGIN DENIED
'''
# Initialize authentication
auth = None
person = ... | [
"def",
"check_auth",
"(",
"user",
")",
":",
"# Initialize authentication",
"auth",
"=",
"None",
"person",
"=",
"None",
"# Check if there is an user",
"if",
"user",
":",
"# It means that Django accepted the user and it is active",
"if",
"user",
".",
"is_staff",
"or",
"us... | Check if the user should or shouldn't be inside the system:
- If the user is staff or superuser: LOGIN GRANTED
- If the user has a Person and it is not "disabled": LOGIN GRANTED
- Elsewhere: LOGIN DENIED | [
"Check",
"if",
"the",
"user",
"should",
"or",
"shouldn",
"t",
"be",
"inside",
"the",
"system",
":",
"-",
"If",
"the",
"user",
"is",
"staff",
"or",
"superuser",
":",
"LOGIN",
"GRANTED",
"-",
"If",
"the",
"user",
"has",
"a",
"Person",
"and",
"it",
"is"... | train | https://github.com/codenerix/django-codenerix/blob/1f5527b352141caaee902b37b2648791a06bd57d/codenerix/authbackend.py#L42-L77 |
codenerix/django-codenerix | codenerix/authbackend.py | ActiveDirectoryGroupMembershipSSLBackend.debug | def debug(self, msg):
'''
Handle the debugging to a file
'''
# If debug is not disabled
if self.__debug is not False:
# If never was set, try to set it up
if self.__debug is None:
# Check what do we have inside settings
de... | python | def debug(self, msg):
'''
Handle the debugging to a file
'''
# If debug is not disabled
if self.__debug is not False:
# If never was set, try to set it up
if self.__debug is None:
# Check what do we have inside settings
de... | [
"def",
"debug",
"(",
"self",
",",
"msg",
")",
":",
"# If debug is not disabled",
"if",
"self",
".",
"__debug",
"is",
"not",
"False",
":",
"# If never was set, try to set it up",
"if",
"self",
".",
"__debug",
"is",
"None",
":",
"# Check what do we have inside setting... | Handle the debugging to a file | [
"Handle",
"the",
"debugging",
"to",
"a",
"file"
] | train | https://github.com/codenerix/django-codenerix/blob/1f5527b352141caaee902b37b2648791a06bd57d/codenerix/authbackend.py#L407-L429 |
codenerix/django-codenerix | codenerix/authbackend.py | ActiveDirectoryGroupMembershipSSLBackend.authenticate | def authenticate(self, *args, **kwargs):
'''
Authenticate the user agains LDAP
'''
# Get config
username = kwargs.get("username", None)
password = kwargs.get("password", None)
# Check user in Active Directory (authorization == None if can not connect to Active D... | python | def authenticate(self, *args, **kwargs):
'''
Authenticate the user agains LDAP
'''
# Get config
username = kwargs.get("username", None)
password = kwargs.get("password", None)
# Check user in Active Directory (authorization == None if can not connect to Active D... | [
"def",
"authenticate",
"(",
"self",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"# Get config",
"username",
"=",
"kwargs",
".",
"get",
"(",
"\"username\"",
",",
"None",
")",
"password",
"=",
"kwargs",
".",
"get",
"(",
"\"password\"",
",",
"Non... | Authenticate the user agains LDAP | [
"Authenticate",
"the",
"user",
"agains",
"LDAP"
] | train | https://github.com/codenerix/django-codenerix/blob/1f5527b352141caaee902b37b2648791a06bd57d/codenerix/authbackend.py#L493-L527 |
codenerix/django-codenerix | codenerix/authbackend.py | ActiveDirectoryGroupMembershipSSLBackend.get_or_create_user | def get_or_create_user(self, username, password):
'''
Get or create the given user
'''
# Get the groups for this user
info = self.get_ad_info(username, password)
self.debug("INFO found: {}".format(info))
# Find the user
try:
user = User.objec... | python | def get_or_create_user(self, username, password):
'''
Get or create the given user
'''
# Get the groups for this user
info = self.get_ad_info(username, password)
self.debug("INFO found: {}".format(info))
# Find the user
try:
user = User.objec... | [
"def",
"get_or_create_user",
"(",
"self",
",",
"username",
",",
"password",
")",
":",
"# Get the groups for this user",
"info",
"=",
"self",
".",
"get_ad_info",
"(",
"username",
",",
"password",
")",
"self",
".",
"debug",
"(",
"\"INFO found: {}\"",
".",
"format"... | Get or create the given user | [
"Get",
"or",
"create",
"the",
"given",
"user"
] | train | https://github.com/codenerix/django-codenerix/blob/1f5527b352141caaee902b37b2648791a06bd57d/codenerix/authbackend.py#L633-L681 |
codenerix/django-codenerix | codenerix/authbackend.py | ActiveDirectoryGroupMembershipSSLBackend.synchronize | def synchronize(self, user, info):
'''
It tries to do a group synchronization if possible
This methods should be redeclared by the developer
'''
self.debug("Synchronize!")
# Remove all groups from this user
user.groups.clear()
# For all domains found fo... | python | def synchronize(self, user, info):
'''
It tries to do a group synchronization if possible
This methods should be redeclared by the developer
'''
self.debug("Synchronize!")
# Remove all groups from this user
user.groups.clear()
# For all domains found fo... | [
"def",
"synchronize",
"(",
"self",
",",
"user",
",",
"info",
")",
":",
"self",
".",
"debug",
"(",
"\"Synchronize!\"",
")",
"# Remove all groups from this user",
"user",
".",
"groups",
".",
"clear",
"(",
")",
"# For all domains found for this user",
"for",
"domain"... | It tries to do a group synchronization if possible
This methods should be redeclared by the developer | [
"It",
"tries",
"to",
"do",
"a",
"group",
"synchronization",
"if",
"possible",
"This",
"methods",
"should",
"be",
"redeclared",
"by",
"the",
"developer"
] | train | https://github.com/codenerix/django-codenerix/blob/1f5527b352141caaee902b37b2648791a06bd57d/codenerix/authbackend.py#L698-L717 |
markchil/gptools | gptools/kernel/core.py | Kernel.set_hyperparams | def set_hyperparams(self, new_params):
"""Sets the free hyperparameters to the new parameter values in new_params.
Parameters
----------
new_params : :py:class:`Array` or other Array-like, (len(:py:attr:`self.free_params`),)
New parameter values, ordered as dictated ... | python | def set_hyperparams(self, new_params):
"""Sets the free hyperparameters to the new parameter values in new_params.
Parameters
----------
new_params : :py:class:`Array` or other Array-like, (len(:py:attr:`self.free_params`),)
New parameter values, ordered as dictated ... | [
"def",
"set_hyperparams",
"(",
"self",
",",
"new_params",
")",
":",
"new_params",
"=",
"scipy",
".",
"asarray",
"(",
"new_params",
",",
"dtype",
"=",
"float",
")",
"if",
"len",
"(",
"new_params",
")",
"==",
"len",
"(",
"self",
".",
"free_params",
")",
... | Sets the free hyperparameters to the new parameter values in new_params.
Parameters
----------
new_params : :py:class:`Array` or other Array-like, (len(:py:attr:`self.free_params`),)
New parameter values, ordered as dictated by the docstring for the
class. | [
"Sets",
"the",
"free",
"hyperparameters",
"to",
"the",
"new",
"parameter",
"values",
"in",
"new_params",
".",
"Parameters",
"----------",
"new_params",
":",
":",
"py",
":",
"class",
":",
"Array",
"or",
"other",
"Array",
"-",
"like",
"(",
"len",
"(",
":",
... | train | https://github.com/markchil/gptools/blob/225db52bfe6baef1516529ad22177aa2cf7b71e4/gptools/kernel/core.py#L236-L256 |
markchil/gptools | gptools/kernel/core.py | Kernel._compute_r2l2 | def _compute_r2l2(self, tau, return_l=False):
r"""Compute the anisotropic :math:`r^2/l^2` term for the given `tau`.
Here, :math:`\tau=X_i-X_j` is the difference vector. Computes
.. math::
\frac{r^2}{l^2} = \sum_i\frac{\tau_i^2}{l_{i}^{2}}
Assume... | python | def _compute_r2l2(self, tau, return_l=False):
r"""Compute the anisotropic :math:`r^2/l^2` term for the given `tau`.
Here, :math:`\tau=X_i-X_j` is the difference vector. Computes
.. math::
\frac{r^2}{l^2} = \sum_i\frac{\tau_i^2}{l_{i}^{2}}
Assume... | [
"def",
"_compute_r2l2",
"(",
"self",
",",
"tau",
",",
"return_l",
"=",
"False",
")",
":",
"l_mat",
"=",
"scipy",
".",
"tile",
"(",
"self",
".",
"params",
"[",
"-",
"self",
".",
"num_dim",
":",
"]",
",",
"(",
"tau",
".",
"shape",
"[",
"0",
"]",
... | r"""Compute the anisotropic :math:`r^2/l^2` term for the given `tau`.
Here, :math:`\tau=X_i-X_j` is the difference vector. Computes
.. math::
\frac{r^2}{l^2} = \sum_i\frac{\tau_i^2}{l_{i}^{2}}
Assumes that the length parameters are the last `num_dim` el... | [
"r",
"Compute",
"the",
"anisotropic",
":",
"math",
":",
"r^2",
"/",
"l^2",
"term",
"for",
"the",
"given",
"tau",
".",
"Here",
":",
"math",
":",
"\\",
"tau",
"=",
"X_i",
"-",
"X_j",
"is",
"the",
"difference",
"vector",
".",
"Computes",
"..",
"math",
... | train | https://github.com/markchil/gptools/blob/225db52bfe6baef1516529ad22177aa2cf7b71e4/gptools/kernel/core.py#L349-L386 |
markchil/gptools | gptools/kernel/core.py | BinaryKernel.enforce_bounds | def enforce_bounds(self, v):
"""Set `enforce_bounds` for both of the kernels to a new value.
"""
self._enforce_bounds = v
self.k1.enforce_bounds = v
self.k2.enforce_bounds = v | python | def enforce_bounds(self, v):
"""Set `enforce_bounds` for both of the kernels to a new value.
"""
self._enforce_bounds = v
self.k1.enforce_bounds = v
self.k2.enforce_bounds = v | [
"def",
"enforce_bounds",
"(",
"self",
",",
"v",
")",
":",
"self",
".",
"_enforce_bounds",
"=",
"v",
"self",
".",
"k1",
".",
"enforce_bounds",
"=",
"v",
"self",
".",
"k2",
".",
"enforce_bounds",
"=",
"v"
] | Set `enforce_bounds` for both of the kernels to a new value. | [
"Set",
"enforce_bounds",
"for",
"both",
"of",
"the",
"kernels",
"to",
"a",
"new",
"value",
"."
] | train | https://github.com/markchil/gptools/blob/225db52bfe6baef1516529ad22177aa2cf7b71e4/gptools/kernel/core.py#L426-L431 |
markchil/gptools | gptools/kernel/core.py | BinaryKernel.free_param_bounds | def free_param_bounds(self):
"""Returns the bounds of the free hyperparameters.
Returns
-------
free_param_bounds : :py:class:`Array`
Array of the bounds of the free parameters, in order.
"""
return scipy.concatenate((self.k1.free_param_bounds, self.k... | python | def free_param_bounds(self):
"""Returns the bounds of the free hyperparameters.
Returns
-------
free_param_bounds : :py:class:`Array`
Array of the bounds of the free parameters, in order.
"""
return scipy.concatenate((self.k1.free_param_bounds, self.k... | [
"def",
"free_param_bounds",
"(",
"self",
")",
":",
"return",
"scipy",
".",
"concatenate",
"(",
"(",
"self",
".",
"k1",
".",
"free_param_bounds",
",",
"self",
".",
"k2",
".",
"free_param_bounds",
")",
")"
] | Returns the bounds of the free hyperparameters.
Returns
-------
free_param_bounds : :py:class:`Array`
Array of the bounds of the free parameters, in order. | [
"Returns",
"the",
"bounds",
"of",
"the",
"free",
"hyperparameters",
".",
"Returns",
"-------",
"free_param_bounds",
":",
":",
"py",
":",
"class",
":",
"Array",
"Array",
"of",
"the",
"bounds",
"of",
"the",
"free",
"parameters",
"in",
"order",
"."
] | train | https://github.com/markchil/gptools/blob/225db52bfe6baef1516529ad22177aa2cf7b71e4/gptools/kernel/core.py#L443-L451 |
markchil/gptools | gptools/kernel/core.py | BinaryKernel.free_param_names | def free_param_names(self):
"""Returns the names of the free hyperparameters.
Returns
-------
free_param_names : :py:class:`Array`
Array of the names of the free parameters, in order.
"""
return scipy.concatenate((self.k1.free_param_names, self.k2.fre... | python | def free_param_names(self):
"""Returns the names of the free hyperparameters.
Returns
-------
free_param_names : :py:class:`Array`
Array of the names of the free parameters, in order.
"""
return scipy.concatenate((self.k1.free_param_names, self.k2.fre... | [
"def",
"free_param_names",
"(",
"self",
")",
":",
"return",
"scipy",
".",
"concatenate",
"(",
"(",
"self",
".",
"k1",
".",
"free_param_names",
",",
"self",
".",
"k2",
".",
"free_param_names",
")",
")"
] | Returns the names of the free hyperparameters.
Returns
-------
free_param_names : :py:class:`Array`
Array of the names of the free parameters, in order. | [
"Returns",
"the",
"names",
"of",
"the",
"free",
"hyperparameters",
".",
"Returns",
"-------",
"free_param_names",
":",
":",
"py",
":",
"class",
":",
"Array",
"Array",
"of",
"the",
"names",
"of",
"the",
"free",
"parameters",
"in",
"order",
"."
] | train | https://github.com/markchil/gptools/blob/225db52bfe6baef1516529ad22177aa2cf7b71e4/gptools/kernel/core.py#L454-L462 |
markchil/gptools | gptools/kernel/core.py | BinaryKernel.set_hyperparams | def set_hyperparams(self, new_params):
"""Set the (free) hyperparameters.
Parameters
----------
new_params : :py:class:`Array` or other Array-like
New values of the free parameters.
Raises
------
ValueError
If the length o... | python | def set_hyperparams(self, new_params):
"""Set the (free) hyperparameters.
Parameters
----------
new_params : :py:class:`Array` or other Array-like
New values of the free parameters.
Raises
------
ValueError
If the length o... | [
"def",
"set_hyperparams",
"(",
"self",
",",
"new_params",
")",
":",
"new_params",
"=",
"scipy",
".",
"asarray",
"(",
"new_params",
",",
"dtype",
"=",
"float",
")",
"if",
"len",
"(",
"new_params",
")",
"==",
"len",
"(",
"self",
".",
"free_params",
")",
... | Set the (free) hyperparameters.
Parameters
----------
new_params : :py:class:`Array` or other Array-like
New values of the free parameters.
Raises
------
ValueError
If the length of `new_params` is not consistent with :py:attr:`se... | [
"Set",
"the",
"(",
"free",
")",
"hyperparameters",
".",
"Parameters",
"----------",
"new_params",
":",
":",
"py",
":",
"class",
":",
"Array",
"or",
"other",
"Array",
"-",
"like",
"New",
"values",
"of",
"the",
"free",
"parameters",
".",
"Raises",
"------",
... | train | https://github.com/markchil/gptools/blob/225db52bfe6baef1516529ad22177aa2cf7b71e4/gptools/kernel/core.py#L473-L493 |
markchil/gptools | gptools/kernel/core.py | ChainRuleKernel._compute_dk_dtau | def _compute_dk_dtau(self, tau, n):
r"""Evaluate :math:`dk/d\tau` at the specified locations with the specified derivatives.
Parameters
----------
tau : :py:class:`Matrix`, (`M`, `D`)
`M` inputs with dimension `D`.
n : :py:class:`Array`, (`D`,)
De... | python | def _compute_dk_dtau(self, tau, n):
r"""Evaluate :math:`dk/d\tau` at the specified locations with the specified derivatives.
Parameters
----------
tau : :py:class:`Matrix`, (`M`, `D`)
`M` inputs with dimension `D`.
n : :py:class:`Array`, (`D`,)
De... | [
"def",
"_compute_dk_dtau",
"(",
"self",
",",
"tau",
",",
"n",
")",
":",
"# Construct the derivative pattern:",
"# For each dimension, this will contain the index of the dimension",
"# repeated a number of times equal to the order of derivative with",
"# respect to that dimension.",
"# Ex... | r"""Evaluate :math:`dk/d\tau` at the specified locations with the specified derivatives.
Parameters
----------
tau : :py:class:`Matrix`, (`M`, `D`)
`M` inputs with dimension `D`.
n : :py:class:`Array`, (`D`,)
Degree of derivative with respect to each dime... | [
"r",
"Evaluate",
":",
"math",
":",
"dk",
"/",
"d",
"\\",
"tau",
"at",
"the",
"specified",
"locations",
"with",
"the",
"specified",
"derivatives",
".",
"Parameters",
"----------",
"tau",
":",
":",
"py",
":",
"class",
":",
"Matrix",
"(",
"M",
"D",
")",
... | train | https://github.com/markchil/gptools/blob/225db52bfe6baef1516529ad22177aa2cf7b71e4/gptools/kernel/core.py#L671-L707 |
markchil/gptools | gptools/kernel/core.py | ChainRuleKernel._compute_dk_dtau_on_partition | def _compute_dk_dtau_on_partition(self, tau, p):
"""Evaluate the term inside the sum of Faa di Bruno's formula for the given partition.
Parameters
----------
tau : :py:class:`Matrix`, (`M`, `D`)
`M` inputs with dimension `D`.
p : list of :py:class:`Array`
... | python | def _compute_dk_dtau_on_partition(self, tau, p):
"""Evaluate the term inside the sum of Faa di Bruno's formula for the given partition.
Parameters
----------
tau : :py:class:`Matrix`, (`M`, `D`)
`M` inputs with dimension `D`.
p : list of :py:class:`Array`
... | [
"def",
"_compute_dk_dtau_on_partition",
"(",
"self",
",",
"tau",
",",
"p",
")",
":",
"y",
",",
"r2l2",
"=",
"self",
".",
"_compute_y",
"(",
"tau",
",",
"return_r2l2",
"=",
"True",
")",
"# Compute the d^(|pi|)f/dy term:",
"dk_dtau",
"=",
"self",
".",
"_comput... | Evaluate the term inside the sum of Faa di Bruno's formula for the given partition.
Parameters
----------
tau : :py:class:`Matrix`, (`M`, `D`)
`M` inputs with dimension `D`.
p : list of :py:class:`Array`
Each element is a block of the partition representi... | [
"Evaluate",
"the",
"term",
"inside",
"the",
"sum",
"of",
"Faa",
"di",
"Bruno",
"s",
"formula",
"for",
"the",
"given",
"partition",
".",
"Parameters",
"----------",
"tau",
":",
":",
"py",
":",
"class",
":",
"Matrix",
"(",
"M",
"D",
")",
"M",
"inputs",
... | train | https://github.com/markchil/gptools/blob/225db52bfe6baef1516529ad22177aa2cf7b71e4/gptools/kernel/core.py#L709-L732 |
markchil/gptools | gptools/kernel/core.py | ArbitraryKernel._mask_cov_func | def _mask_cov_func(self, *args):
"""Masks the covariance function into a form usable by :py:func:`mpmath.diff`.
Parameters
----------
*args : `num_dim` * 2 floats
The individual elements of Xi and Xj to be passed to :py:attr:`cov_func`.
"""
# Have to ... | python | def _mask_cov_func(self, *args):
"""Masks the covariance function into a form usable by :py:func:`mpmath.diff`.
Parameters
----------
*args : `num_dim` * 2 floats
The individual elements of Xi and Xj to be passed to :py:attr:`cov_func`.
"""
# Have to ... | [
"def",
"_mask_cov_func",
"(",
"self",
",",
"*",
"args",
")",
":",
"# Have to do it in two cases to get the 1d unwrapped properly:",
"if",
"self",
".",
"num_dim",
"==",
"1",
":",
"return",
"self",
".",
"cov_func",
"(",
"args",
"[",
"0",
"]",
",",
"args",
"[",
... | Masks the covariance function into a form usable by :py:func:`mpmath.diff`.
Parameters
----------
*args : `num_dim` * 2 floats
The individual elements of Xi and Xj to be passed to :py:attr:`cov_func`. | [
"Masks",
"the",
"covariance",
"function",
"into",
"a",
"form",
"usable",
"by",
":",
"py",
":",
"func",
":",
"mpmath",
".",
"diff",
".",
"Parameters",
"----------",
"*",
"args",
":",
"num_dim",
"*",
"2",
"floats",
"The",
"individual",
"elements",
"of",
"X... | train | https://github.com/markchil/gptools/blob/225db52bfe6baef1516529ad22177aa2cf7b71e4/gptools/kernel/core.py#L858-L870 |
markchil/gptools | gptools/mean.py | constant | def constant(X, n, mu, hyper_deriv=None):
"""Function implementing a constant mean suitable for use with :py:class:`MeanFunction`.
"""
if (n == 0).all():
if hyper_deriv is not None:
return scipy.ones(X.shape[0])
else:
return mu * scipy.ones(X.shape[0])
else:
... | python | def constant(X, n, mu, hyper_deriv=None):
"""Function implementing a constant mean suitable for use with :py:class:`MeanFunction`.
"""
if (n == 0).all():
if hyper_deriv is not None:
return scipy.ones(X.shape[0])
else:
return mu * scipy.ones(X.shape[0])
else:
... | [
"def",
"constant",
"(",
"X",
",",
"n",
",",
"mu",
",",
"hyper_deriv",
"=",
"None",
")",
":",
"if",
"(",
"n",
"==",
"0",
")",
".",
"all",
"(",
")",
":",
"if",
"hyper_deriv",
"is",
"not",
"None",
":",
"return",
"scipy",
".",
"ones",
"(",
"X",
"... | Function implementing a constant mean suitable for use with :py:class:`MeanFunction`. | [
"Function",
"implementing",
"a",
"constant",
"mean",
"suitable",
"for",
"use",
"with",
":",
"py",
":",
"class",
":",
"MeanFunction",
"."
] | train | https://github.com/markchil/gptools/blob/225db52bfe6baef1516529ad22177aa2cf7b71e4/gptools/mean.py#L293-L302 |
markchil/gptools | gptools/mean.py | mtanh | def mtanh(alpha, z):
"""Modified hyperbolic tangent function mtanh(z; alpha).
Parameters
----------
alpha : float
The core slope of the mtanh.
z : float or array
The coordinate of the mtanh.
"""
z = scipy.asarray(z)
ez = scipy.exp(z)
enz = 1.0 / ez
return ((1... | python | def mtanh(alpha, z):
"""Modified hyperbolic tangent function mtanh(z; alpha).
Parameters
----------
alpha : float
The core slope of the mtanh.
z : float or array
The coordinate of the mtanh.
"""
z = scipy.asarray(z)
ez = scipy.exp(z)
enz = 1.0 / ez
return ((1... | [
"def",
"mtanh",
"(",
"alpha",
",",
"z",
")",
":",
"z",
"=",
"scipy",
".",
"asarray",
"(",
"z",
")",
"ez",
"=",
"scipy",
".",
"exp",
"(",
"z",
")",
"enz",
"=",
"1.0",
"/",
"ez",
"return",
"(",
"(",
"1",
"+",
"alpha",
"*",
"z",
")",
"*",
"e... | Modified hyperbolic tangent function mtanh(z; alpha).
Parameters
----------
alpha : float
The core slope of the mtanh.
z : float or array
The coordinate of the mtanh. | [
"Modified",
"hyperbolic",
"tangent",
"function",
"mtanh",
"(",
"z",
";",
"alpha",
")",
".",
"Parameters",
"----------",
"alpha",
":",
"float",
"The",
"core",
"slope",
"of",
"the",
"mtanh",
".",
"z",
":",
"float",
"or",
"array",
"The",
"coordinate",
"of",
... | train | https://github.com/markchil/gptools/blob/225db52bfe6baef1516529ad22177aa2cf7b71e4/gptools/mean.py#L321-L334 |
markchil/gptools | gptools/mean.py | mtanh_profile | def mtanh_profile(X, n, x0, delta, alpha, h, b, hyper_deriv=None):
"""Profile used with the mtanh function to fit profiles, suitable for use with :py:class:`MeanFunction`.
Only supports univariate data!
Parameters
----------
X : array, (`M`, 1)
The points to evaluate at.
n : ar... | python | def mtanh_profile(X, n, x0, delta, alpha, h, b, hyper_deriv=None):
"""Profile used with the mtanh function to fit profiles, suitable for use with :py:class:`MeanFunction`.
Only supports univariate data!
Parameters
----------
X : array, (`M`, 1)
The points to evaluate at.
n : ar... | [
"def",
"mtanh_profile",
"(",
"X",
",",
"n",
",",
"x0",
",",
"delta",
",",
"alpha",
",",
"h",
",",
"b",
",",
"hyper_deriv",
"=",
"None",
")",
":",
"X",
"=",
"X",
"[",
":",
",",
"0",
"]",
"z",
"=",
"(",
"x0",
"-",
"X",
")",
"/",
"delta",
"i... | Profile used with the mtanh function to fit profiles, suitable for use with :py:class:`MeanFunction`.
Only supports univariate data!
Parameters
----------
X : array, (`M`, 1)
The points to evaluate at.
n : array, (1,)
The order of derivative to compute. Only up to first der... | [
"Profile",
"used",
"with",
"the",
"mtanh",
"function",
"to",
"fit",
"profiles",
"suitable",
"for",
"use",
"with",
":",
"py",
":",
"class",
":",
"MeanFunction",
".",
"Only",
"supports",
"univariate",
"data!",
"Parameters",
"----------",
"X",
":",
"array",
"("... | train | https://github.com/markchil/gptools/blob/225db52bfe6baef1516529ad22177aa2cf7b71e4/gptools/mean.py#L336-L419 |
markchil/gptools | gptools/mean.py | linear | def linear(X, n, *args, **kwargs):
"""Linear mean function of arbitrary dimension, suitable for use with :py:class:`MeanFunction`.
The form is :math:`m_0 * X[:, 0] + m_1 * X[:, 1] + \dots + b`.
Parameters
----------
X : array, (`M`, `D`)
The points to evaluate the model at.
n :... | python | def linear(X, n, *args, **kwargs):
"""Linear mean function of arbitrary dimension, suitable for use with :py:class:`MeanFunction`.
The form is :math:`m_0 * X[:, 0] + m_1 * X[:, 1] + \dots + b`.
Parameters
----------
X : array, (`M`, `D`)
The points to evaluate the model at.
n :... | [
"def",
"linear",
"(",
"X",
",",
"n",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"hyper_deriv",
"=",
"kwargs",
".",
"pop",
"(",
"'hyper_deriv'",
",",
"None",
")",
"m",
"=",
"scipy",
".",
"asarray",
"(",
"args",
"[",
":",
"-",
"1",
"]",... | Linear mean function of arbitrary dimension, suitable for use with :py:class:`MeanFunction`.
The form is :math:`m_0 * X[:, 0] + m_1 * X[:, 1] + \dots + b`.
Parameters
----------
X : array, (`M`, `D`)
The points to evaluate the model at.
n : array of non-negative int, (`D`)
... | [
"Linear",
"mean",
"function",
"of",
"arbitrary",
"dimension",
"suitable",
"for",
"use",
"with",
":",
"py",
":",
"class",
":",
"MeanFunction",
".",
"The",
"form",
"is",
":",
"math",
":",
"m_0",
"*",
"X",
"[",
":",
"0",
"]",
"+",
"m_1",
"*",
"X",
"["... | train | https://github.com/markchil/gptools/blob/225db52bfe6baef1516529ad22177aa2cf7b71e4/gptools/mean.py#L446-L484 |
CTPUG/wafer | wafer/schedule/models.py | update_schedule_items | def update_schedule_items(*args, **kw):
"""We save all the schedule items associated with this slot, so
the last_update time is updated to reflect any changes to the
timing of the slots"""
slot = kw.pop('instance', None)
if not slot:
return
for item in slot.scheduleitem_set.all():
... | python | def update_schedule_items(*args, **kw):
"""We save all the schedule items associated with this slot, so
the last_update time is updated to reflect any changes to the
timing of the slots"""
slot = kw.pop('instance', None)
if not slot:
return
for item in slot.scheduleitem_set.all():
... | [
"def",
"update_schedule_items",
"(",
"*",
"args",
",",
"*",
"*",
"kw",
")",
":",
"slot",
"=",
"kw",
".",
"pop",
"(",
"'instance'",
",",
"None",
")",
"if",
"not",
"slot",
":",
"return",
"for",
"item",
"in",
"slot",
".",
"scheduleitem_set",
".",
"all",... | We save all the schedule items associated with this slot, so
the last_update time is updated to reflect any changes to the
timing of the slots | [
"We",
"save",
"all",
"the",
"schedule",
"items",
"associated",
"with",
"this",
"slot",
"so",
"the",
"last_update",
"time",
"is",
"updated",
"to",
"reflect",
"any",
"changes",
"to",
"the",
"timing",
"of",
"the",
"slots"
] | train | https://github.com/CTPUG/wafer/blob/a20af3c399267f76373dc342f4d542a9bc457c35/wafer/schedule/models.py#L287-L303 |
CTPUG/wafer | wafer/compare/admin.py | make_diff | def make_diff(current, revision):
"""Create the difference between the current revision and a previous version"""
the_diff = []
dmp = diff_match_patch()
for field in (set(current.field_dict.keys()) | set(revision.field_dict.keys())):
# These exclusions really should be configurable
if f... | python | def make_diff(current, revision):
"""Create the difference between the current revision and a previous version"""
the_diff = []
dmp = diff_match_patch()
for field in (set(current.field_dict.keys()) | set(revision.field_dict.keys())):
# These exclusions really should be configurable
if f... | [
"def",
"make_diff",
"(",
"current",
",",
"revision",
")",
":",
"the_diff",
"=",
"[",
"]",
"dmp",
"=",
"diff_match_patch",
"(",
")",
"for",
"field",
"in",
"(",
"set",
"(",
"current",
".",
"field_dict",
".",
"keys",
"(",
")",
")",
"|",
"set",
"(",
"r... | Create the difference between the current revision and a previous version | [
"Create",
"the",
"difference",
"between",
"the",
"current",
"revision",
"and",
"a",
"previous",
"version"
] | train | https://github.com/CTPUG/wafer/blob/a20af3c399267f76373dc342f4d542a9bc457c35/wafer/compare/admin.py#L61-L107 |
CTPUG/wafer | wafer/compare/admin.py | CompareVersionAdmin.compare_view | def compare_view(self, request, object_id, version_id, extra_context=None):
"""Actually compare two versions."""
opts = self.model._meta
object_id = unquote(object_id)
# get_for_object's ordering means this is always the latest revision.
# The reversion we want to compare to
... | python | def compare_view(self, request, object_id, version_id, extra_context=None):
"""Actually compare two versions."""
opts = self.model._meta
object_id = unquote(object_id)
# get_for_object's ordering means this is always the latest revision.
# The reversion we want to compare to
... | [
"def",
"compare_view",
"(",
"self",
",",
"request",
",",
"object_id",
",",
"version_id",
",",
"extra_context",
"=",
"None",
")",
":",
"opts",
"=",
"self",
".",
"model",
".",
"_meta",
"object_id",
"=",
"unquote",
"(",
"object_id",
")",
"# get_for_object's ord... | Actually compare two versions. | [
"Actually",
"compare",
"two",
"versions",
"."
] | train | https://github.com/CTPUG/wafer/blob/a20af3c399267f76373dc342f4d542a9bc457c35/wafer/compare/admin.py#L129-L154 |
CTPUG/wafer | wafer/compare/admin.py | CompareVersionAdmin.comparelist_view | def comparelist_view(self, request, object_id, extra_context=None):
"""Allow selecting versions to compare."""
opts = self.model._meta
object_id = unquote(object_id)
current = get_object_or_404(self.model, pk=object_id)
# As done by reversion's history_view
action_list = ... | python | def comparelist_view(self, request, object_id, extra_context=None):
"""Allow selecting versions to compare."""
opts = self.model._meta
object_id = unquote(object_id)
current = get_object_or_404(self.model, pk=object_id)
# As done by reversion's history_view
action_list = ... | [
"def",
"comparelist_view",
"(",
"self",
",",
"request",
",",
"object_id",
",",
"extra_context",
"=",
"None",
")",
":",
"opts",
"=",
"self",
".",
"model",
".",
"_meta",
"object_id",
"=",
"unquote",
"(",
"object_id",
")",
"current",
"=",
"get_object_or_404",
... | Allow selecting versions to compare. | [
"Allow",
"selecting",
"versions",
"to",
"compare",
"."
] | train | https://github.com/CTPUG/wafer/blob/a20af3c399267f76373dc342f4d542a9bc457c35/wafer/compare/admin.py#L156-L177 |
codenerix/django-codenerix | codenerix/views.py | grv | def grv(struct, position):
'''
This function helps to convert date information for showing proper filtering
'''
if position == 'year':
size = 4
else:
size = 2
if (struct[position][2]):
rightnow = str(struct[position][0]).zfill(size)
else:
if position == 'year... | python | def grv(struct, position):
'''
This function helps to convert date information for showing proper filtering
'''
if position == 'year':
size = 4
else:
size = 2
if (struct[position][2]):
rightnow = str(struct[position][0]).zfill(size)
else:
if position == 'year... | [
"def",
"grv",
"(",
"struct",
",",
"position",
")",
":",
"if",
"position",
"==",
"'year'",
":",
"size",
"=",
"4",
"else",
":",
"size",
"=",
"2",
"if",
"(",
"struct",
"[",
"position",
"]",
"[",
"2",
"]",
")",
":",
"rightnow",
"=",
"str",
"(",
"st... | This function helps to convert date information for showing proper filtering | [
"This",
"function",
"helps",
"to",
"convert",
"date",
"information",
"for",
"showing",
"proper",
"filtering"
] | train | https://github.com/codenerix/django-codenerix/blob/1f5527b352141caaee902b37b2648791a06bd57d/codenerix/views.py#L96-L112 |
codenerix/django-codenerix | codenerix/views.py | GenBase._setup | def _setup(self, request):
'''
Entry point for this class, here we decide basic stuff
'''
# Get details from self
info = model_inspect(self)
self._appname = getattr(self, 'appname', info['appname'])
self._modelname = getattr(self, 'modelname', info['modelname'])
... | python | def _setup(self, request):
'''
Entry point for this class, here we decide basic stuff
'''
# Get details from self
info = model_inspect(self)
self._appname = getattr(self, 'appname', info['appname'])
self._modelname = getattr(self, 'modelname', info['modelname'])
... | [
"def",
"_setup",
"(",
"self",
",",
"request",
")",
":",
"# Get details from self",
"info",
"=",
"model_inspect",
"(",
"self",
")",
"self",
".",
"_appname",
"=",
"getattr",
"(",
"self",
",",
"'appname'",
",",
"info",
"[",
"'appname'",
"]",
")",
"self",
".... | Entry point for this class, here we decide basic stuff | [
"Entry",
"point",
"for",
"this",
"class",
"here",
"we",
"decide",
"basic",
"stuff"
] | train | https://github.com/codenerix/django-codenerix/blob/1f5527b352141caaee902b37b2648791a06bd57d/codenerix/views.py#L610-L631 |
codenerix/django-codenerix | codenerix/views.py | GenBase.get_template_names | def get_template_names(self):
'''
Build the list of templates related to this user
'''
# Get user template
template_model = getattr(self, 'template_model', "{0}/{1}_{2}".format(self._appname.lower(), self._modelname.lower(), self.get_template_names_key))
template_model_e... | python | def get_template_names(self):
'''
Build the list of templates related to this user
'''
# Get user template
template_model = getattr(self, 'template_model', "{0}/{1}_{2}".format(self._appname.lower(), self._modelname.lower(), self.get_template_names_key))
template_model_e... | [
"def",
"get_template_names",
"(",
"self",
")",
":",
"# Get user template",
"template_model",
"=",
"getattr",
"(",
"self",
",",
"'template_model'",
",",
"\"{0}/{1}_{2}\"",
".",
"format",
"(",
"self",
".",
"_appname",
".",
"lower",
"(",
")",
",",
"self",
".",
... | Build the list of templates related to this user | [
"Build",
"the",
"list",
"of",
"templates",
"related",
"to",
"this",
"user"
] | train | https://github.com/codenerix/django-codenerix/blob/1f5527b352141caaee902b37b2648791a06bd57d/codenerix/views.py#L633-L646 |
codenerix/django-codenerix | codenerix/views.py | GenBase.get_context_data | def get_context_data(self, **kwargs):
'''
Set a base context
'''
# Call the base implementation first to get a context
context = super(GenBase, self).get_context_data(**kwargs)
# Update general context with the stuff we already calculated
if hasattr(self, 'html_... | python | def get_context_data(self, **kwargs):
'''
Set a base context
'''
# Call the base implementation first to get a context
context = super(GenBase, self).get_context_data(**kwargs)
# Update general context with the stuff we already calculated
if hasattr(self, 'html_... | [
"def",
"get_context_data",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"# Call the base implementation first to get a context",
"context",
"=",
"super",
"(",
"GenBase",
",",
"self",
")",
".",
"get_context_data",
"(",
"*",
"*",
"kwargs",
")",
"# Update general ... | Set a base context | [
"Set",
"a",
"base",
"context"
] | train | https://github.com/codenerix/django-codenerix/blob/1f5527b352141caaee902b37b2648791a06bd57d/codenerix/views.py#L648-L668 |
codenerix/django-codenerix | codenerix/views.py | GenList.dispatch | def dispatch(self, *args, **kwargs):
'''
Entry point for this class, here we decide basic stuff
'''
# Get if this class is working as only a base render and List funcionality shouldn't be enabled
onlybase = getattr(self, "onlybase", False)
# REST not available when only... | python | def dispatch(self, *args, **kwargs):
'''
Entry point for this class, here we decide basic stuff
'''
# Get if this class is working as only a base render and List funcionality shouldn't be enabled
onlybase = getattr(self, "onlybase", False)
# REST not available when only... | [
"def",
"dispatch",
"(",
"self",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"# Get if this class is working as only a base render and List funcionality shouldn't be enabled",
"onlybase",
"=",
"getattr",
"(",
"self",
",",
"\"onlybase\"",
",",
"False",
")",
"# ... | Entry point for this class, here we decide basic stuff | [
"Entry",
"point",
"for",
"this",
"class",
"here",
"we",
"decide",
"basic",
"stuff"
] | train | https://github.com/codenerix/django-codenerix/blob/1f5527b352141caaee902b37b2648791a06bd57d/codenerix/views.py#L1180-L1287 |
codenerix/django-codenerix | codenerix/views.py | GenList.get_queryset | def get_queryset(self, raw_query=False):
# Call the base implementation
if not self.haystack:
queryset = super(GenList, self).get_queryset()
else:
queryset = SearchQuerySet().models(self.model)
# Optional tweak methods
Mfields = None
MlimitQ = Non... | python | def get_queryset(self, raw_query=False):
# Call the base implementation
if not self.haystack:
queryset = super(GenList, self).get_queryset()
else:
queryset = SearchQuerySet().models(self.model)
# Optional tweak methods
Mfields = None
MlimitQ = Non... | [
"def",
"get_queryset",
"(",
"self",
",",
"raw_query",
"=",
"False",
")",
":",
"# Call the base implementation",
"if",
"not",
"self",
".",
"haystack",
":",
"queryset",
"=",
"super",
"(",
"GenList",
",",
"self",
")",
".",
"get_queryset",
"(",
")",
"else",
":... | raise Exception("FOUND: {} -- __foreignkeys: {} -- __columns: {} -- autorules_keys: {} -- \
query_select_related: {} -- query_renamed: {} -- query_optimizer: {} | use_extra: {}| -- \
query: {} -- meta.fields: {} -- fields_related_model: {} -- query_verifier: {}\
-- ??? {} == {}".form... | [
"raise",
"Exception",
"(",
"FOUND",
":",
"{}",
"--",
"__foreignkeys",
":",
"{}",
"--",
"__columns",
":",
"{}",
"--",
"autorules_keys",
":",
"{}",
"--",
"\\",
"query_select_related",
":",
"{}",
"--",
"query_renamed",
":",
"{}",
"--",
"query_optimizer",
":",
... | train | https://github.com/codenerix/django-codenerix/blob/1f5527b352141caaee902b37b2648791a06bd57d/codenerix/views.py#L1353-L2336 |
codenerix/django-codenerix | codenerix/views.py | GenList.get_context_data | def get_context_data(self, **kwargs):
'''
Generic list view with validation included and object transfering support
'''
# Call the base implementation first to get a context
context = super(GenList, self).get_context_data(**kwargs)
# Update general context with the stuff... | python | def get_context_data(self, **kwargs):
'''
Generic list view with validation included and object transfering support
'''
# Call the base implementation first to get a context
context = super(GenList, self).get_context_data(**kwargs)
# Update general context with the stuff... | [
"def",
"get_context_data",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"# Call the base implementation first to get a context",
"context",
"=",
"super",
"(",
"GenList",
",",
"self",
")",
".",
"get_context_data",
"(",
"*",
"*",
"kwargs",
")",
"# Update general ... | Generic list view with validation included and object transfering support | [
"Generic",
"list",
"view",
"with",
"validation",
"included",
"and",
"object",
"transfering",
"support"
] | train | https://github.com/codenerix/django-codenerix/blob/1f5527b352141caaee902b37b2648791a06bd57d/codenerix/views.py#L2338-L2417 |
codenerix/django-codenerix | codenerix/views.py | GenList.get_context_json | def get_context_json(self, context):
'''
Return a base answer for a json answer
'''
# Initialize answer
answer = {}
# Metadata builder
answer['meta'] = self.__jcontext_metadata(context)
# Filter builder
answer['filter'] = self.__jcontext_filter(c... | python | def get_context_json(self, context):
'''
Return a base answer for a json answer
'''
# Initialize answer
answer = {}
# Metadata builder
answer['meta'] = self.__jcontext_metadata(context)
# Filter builder
answer['filter'] = self.__jcontext_filter(c... | [
"def",
"get_context_json",
"(",
"self",
",",
"context",
")",
":",
"# Initialize answer",
"answer",
"=",
"{",
"}",
"# Metadata builder",
"answer",
"[",
"'meta'",
"]",
"=",
"self",
".",
"__jcontext_metadata",
"(",
"context",
")",
"# Filter builder",
"answer",
"[",... | Return a base answer for a json answer | [
"Return",
"a",
"base",
"answer",
"for",
"a",
"json",
"answer"
] | train | https://github.com/codenerix/django-codenerix/blob/1f5527b352141caaee902b37b2648791a06bd57d/codenerix/views.py#L2609-L2630 |
codenerix/django-codenerix | codenerix/views.py | GenList.set_context_json | def set_context_json(self, jsonquery):
'''
Get a json parameter and rebuild the context back to a dictionary (probably kwargs)
'''
# Make sure we are getting dicts
if type(jsonquery) != dict:
raise IOError("set_json_context() method can be called only with dictionari... | python | def set_context_json(self, jsonquery):
'''
Get a json parameter and rebuild the context back to a dictionary (probably kwargs)
'''
# Make sure we are getting dicts
if type(jsonquery) != dict:
raise IOError("set_json_context() method can be called only with dictionari... | [
"def",
"set_context_json",
"(",
"self",
",",
"jsonquery",
")",
":",
"# Make sure we are getting dicts",
"if",
"type",
"(",
"jsonquery",
")",
"!=",
"dict",
":",
"raise",
"IOError",
"(",
"\"set_json_context() method can be called only with dictionaries, you gave me a '{}'\"",
... | Get a json parameter and rebuild the context back to a dictionary (probably kwargs) | [
"Get",
"a",
"json",
"parameter",
"and",
"rebuild",
"the",
"context",
"back",
"to",
"a",
"dictionary",
"(",
"probably",
"kwargs",
")"
] | train | https://github.com/codenerix/django-codenerix/blob/1f5527b352141caaee902b37b2648791a06bd57d/codenerix/views.py#L2632-L2682 |
codenerix/django-codenerix | codenerix/views.py | GenModify.dispatch | def dispatch(self, request, **kwargs):
'''
Entry point for this class, here we decide basic stuff
'''
# Check if this is a webservice request
self.json_worker = (bool(getattr(self.request, "authtoken", False))) or (self.json is True)
self.__authtoken = (bool(getattr(self... | python | def dispatch(self, request, **kwargs):
'''
Entry point for this class, here we decide basic stuff
'''
# Check if this is a webservice request
self.json_worker = (bool(getattr(self.request, "authtoken", False))) or (self.json is True)
self.__authtoken = (bool(getattr(self... | [
"def",
"dispatch",
"(",
"self",
",",
"request",
",",
"*",
"*",
"kwargs",
")",
":",
"# Check if this is a webservice request",
"self",
".",
"json_worker",
"=",
"(",
"bool",
"(",
"getattr",
"(",
"self",
".",
"request",
",",
"\"authtoken\"",
",",
"False",
")",
... | Entry point for this class, here we decide basic stuff | [
"Entry",
"point",
"for",
"this",
"class",
"here",
"we",
"decide",
"basic",
"stuff"
] | train | https://github.com/codenerix/django-codenerix/blob/1f5527b352141caaee902b37b2648791a06bd57d/codenerix/views.py#L3004-L3030 |
codenerix/django-codenerix | codenerix/views.py | GenModify.get_form | def get_form(self, form_class=None):
'''
Set form groups to the groups specified in the view if defined
'''
formobj = super(GenModify, self).get_form(form_class)
# Set requested group to this form
selfgroups = getattr(self, "form_groups", None)
if selfgroups:
... | python | def get_form(self, form_class=None):
'''
Set form groups to the groups specified in the view if defined
'''
formobj = super(GenModify, self).get_form(form_class)
# Set requested group to this form
selfgroups = getattr(self, "form_groups", None)
if selfgroups:
... | [
"def",
"get_form",
"(",
"self",
",",
"form_class",
"=",
"None",
")",
":",
"formobj",
"=",
"super",
"(",
"GenModify",
",",
"self",
")",
".",
"get_form",
"(",
"form_class",
")",
"# Set requested group to this form",
"selfgroups",
"=",
"getattr",
"(",
"self",
"... | Set form groups to the groups specified in the view if defined | [
"Set",
"form",
"groups",
"to",
"the",
"groups",
"specified",
"in",
"the",
"view",
"if",
"defined"
] | train | https://github.com/codenerix/django-codenerix/blob/1f5527b352141caaee902b37b2648791a06bd57d/codenerix/views.py#L3316-L3335 |
codenerix/django-codenerix | codenerix/views.py | GenDelete.dispatch | def dispatch(self, request, **kwargs):
'''
Entry point for this class, here we decide basic stuff
'''
# Delete method must happen with POST not with GET
if request.method == 'POST':
# Check if this is a webservice request
self.__authtoken = (bool(getattr(... | python | def dispatch(self, request, **kwargs):
'''
Entry point for this class, here we decide basic stuff
'''
# Delete method must happen with POST not with GET
if request.method == 'POST':
# Check if this is a webservice request
self.__authtoken = (bool(getattr(... | [
"def",
"dispatch",
"(",
"self",
",",
"request",
",",
"*",
"*",
"kwargs",
")",
":",
"# Delete method must happen with POST not with GET",
"if",
"request",
".",
"method",
"==",
"'POST'",
":",
"# Check if this is a webservice request",
"self",
".",
"__authtoken",
"=",
... | Entry point for this class, here we decide basic stuff | [
"Entry",
"point",
"for",
"this",
"class",
"here",
"we",
"decide",
"basic",
"stuff"
] | train | https://github.com/codenerix/django-codenerix/blob/1f5527b352141caaee902b37b2648791a06bd57d/codenerix/views.py#L3415-L3432 |
codenerix/django-codenerix | codenerix/views.py | GenDetail.dispatch | def dispatch(self, request, **kwargs):
'''
Entry point for this class, here we decide basic stuff
'''
# Check if this is a REST query to pusth the answer to responde in JSON
if bool(self.request.META.get('HTTP_X_REST', False)):
self.json = True
# Check if th... | python | def dispatch(self, request, **kwargs):
'''
Entry point for this class, here we decide basic stuff
'''
# Check if this is a REST query to pusth the answer to responde in JSON
if bool(self.request.META.get('HTTP_X_REST', False)):
self.json = True
# Check if th... | [
"def",
"dispatch",
"(",
"self",
",",
"request",
",",
"*",
"*",
"kwargs",
")",
":",
"# Check if this is a REST query to pusth the answer to responde in JSON",
"if",
"bool",
"(",
"self",
".",
"request",
".",
"META",
".",
"get",
"(",
"'HTTP_X_REST'",
",",
"False",
... | Entry point for this class, here we decide basic stuff | [
"Entry",
"point",
"for",
"this",
"class",
"here",
"we",
"decide",
"basic",
"stuff"
] | train | https://github.com/codenerix/django-codenerix/blob/1f5527b352141caaee902b37b2648791a06bd57d/codenerix/views.py#L3490-L3530 |
codenerix/django-codenerix | codenerix/views.py | GenDetail.get_filled_structure | def get_filled_structure(self, subgroup=None):
'''
method in charged of filling an structure containing the object fields
values taking into account the 'group' attribute from the corresponding
form object, which is necesary to fill the details form as it is configured
in the 'gr... | python | def get_filled_structure(self, subgroup=None):
'''
method in charged of filling an structure containing the object fields
values taking into account the 'group' attribute from the corresponding
form object, which is necesary to fill the details form as it is configured
in the 'gr... | [
"def",
"get_filled_structure",
"(",
"self",
",",
"subgroup",
"=",
"None",
")",
":",
"# initilize the result structure",
"result",
"=",
"[",
"]",
"# the object corresponding model content is taken into a dictionary",
"object_content",
"=",
"model_to_dict",
"(",
"self",
".",
... | method in charged of filling an structure containing the object fields
values taking into account the 'group' attribute from the corresponding
form object, which is necesary to fill the details form as it is configured
in the 'group' attribute | [
"method",
"in",
"charged",
"of",
"filling",
"an",
"structure",
"containing",
"the",
"object",
"fields",
"values",
"taking",
"into",
"account",
"the",
"group",
"attribute",
"from",
"the",
"corresponding",
"form",
"object",
"which",
"is",
"necesary",
"to",
"fill",... | train | https://github.com/codenerix/django-codenerix/blob/1f5527b352141caaee902b37b2648791a06bd57d/codenerix/views.py#L3532-L3668 |
codenerix/django-codenerix | codenerix/djng/widgets.py | flatatt | def flatatt(attrs):
"""
Pilfered from `django.forms.utils`:
Convert a dictionary of attributes to a single string.
The returned string will contain a leading space followed by key="value",
XML-style pairs. In the case of a boolean value, the key will appear
without a value. Otherwise, the value ... | python | def flatatt(attrs):
"""
Pilfered from `django.forms.utils`:
Convert a dictionary of attributes to a single string.
The returned string will contain a leading space followed by key="value",
XML-style pairs. In the case of a boolean value, the key will appear
without a value. Otherwise, the value ... | [
"def",
"flatatt",
"(",
"attrs",
")",
":",
"key_value_attrs",
"=",
"[",
"]",
"boolean_attrs",
"=",
"[",
"]",
"for",
"attr",
",",
"value",
"in",
"attrs",
".",
"items",
"(",
")",
":",
"if",
"isinstance",
"(",
"value",
",",
"bool",
")",
":",
"if",
"val... | Pilfered from `django.forms.utils`:
Convert a dictionary of attributes to a single string.
The returned string will contain a leading space followed by key="value",
XML-style pairs. In the case of a boolean value, the key will appear
without a value. Otherwise, the value is formatted through its own dic... | [
"Pilfered",
"from",
"django",
".",
"forms",
".",
"utils",
":",
"Convert",
"a",
"dictionary",
"of",
"attributes",
"to",
"a",
"single",
"string",
".",
"The",
"returned",
"string",
"will",
"contain",
"a",
"leading",
"space",
"followed",
"by",
"key",
"=",
"val... | train | https://github.com/codenerix/django-codenerix/blob/1f5527b352141caaee902b37b2648791a06bd57d/codenerix/djng/widgets.py#L11-L41 |
markchil/gptools | gptools/kernel/rational_quadratic.py | RationalQuadraticKernel._compute_k | def _compute_k(self, tau):
r"""Evaluate the kernel directly at the given values of `tau`.
Parameters
----------
tau : :py:class:`Matrix`, (`M`, `D`)
`M` inputs with dimension `D`.
Returns
-------
k : :py:class:`Array`, (`M`,)
... | python | def _compute_k(self, tau):
r"""Evaluate the kernel directly at the given values of `tau`.
Parameters
----------
tau : :py:class:`Matrix`, (`M`, `D`)
`M` inputs with dimension `D`.
Returns
-------
k : :py:class:`Array`, (`M`,)
... | [
"def",
"_compute_k",
"(",
"self",
",",
"tau",
")",
":",
"y",
"=",
"self",
".",
"_compute_y",
"(",
"tau",
")",
"return",
"y",
"**",
"(",
"-",
"self",
".",
"params",
"[",
"1",
"]",
")"
] | r"""Evaluate the kernel directly at the given values of `tau`.
Parameters
----------
tau : :py:class:`Matrix`, (`M`, `D`)
`M` inputs with dimension `D`.
Returns
-------
k : :py:class:`Array`, (`M`,)
:math:`k(\tau)` (less t... | [
"r",
"Evaluate",
"the",
"kernel",
"directly",
"at",
"the",
"given",
"values",
"of",
"tau",
".",
"Parameters",
"----------",
"tau",
":",
":",
"py",
":",
"class",
":",
"Matrix",
"(",
"M",
"D",
")",
"M",
"inputs",
"with",
"dimension",
"D",
".",
"Returns",... | train | https://github.com/markchil/gptools/blob/225db52bfe6baef1516529ad22177aa2cf7b71e4/gptools/kernel/rational_quadratic.py#L74-L88 |
markchil/gptools | gptools/kernel/rational_quadratic.py | RationalQuadraticKernel._compute_dk_dy | def _compute_dk_dy(self, y, n):
"""Evaluate the derivative of the outer form of the RQ kernel.
Parameters
----------
y : :py:class:`Array`, (`M`,)
`M` inputs to evaluate at.
n : non-negative scalar int
Order of derivative to compute.
... | python | def _compute_dk_dy(self, y, n):
"""Evaluate the derivative of the outer form of the RQ kernel.
Parameters
----------
y : :py:class:`Array`, (`M`,)
`M` inputs to evaluate at.
n : non-negative scalar int
Order of derivative to compute.
... | [
"def",
"_compute_dk_dy",
"(",
"self",
",",
"y",
",",
"n",
")",
":",
"p",
"=",
"fixed_poch",
"(",
"1.0",
"-",
"self",
".",
"params",
"[",
"1",
"]",
"-",
"n",
",",
"n",
")",
"return",
"p",
"*",
"y",
"**",
"(",
"-",
"self",
".",
"params",
"[",
... | Evaluate the derivative of the outer form of the RQ kernel.
Parameters
----------
y : :py:class:`Array`, (`M`,)
`M` inputs to evaluate at.
n : non-negative scalar int
Order of derivative to compute.
Returns
-------
dk_dy :... | [
"Evaluate",
"the",
"derivative",
"of",
"the",
"outer",
"form",
"of",
"the",
"RQ",
"kernel",
".",
"Parameters",
"----------",
"y",
":",
":",
"py",
":",
"class",
":",
"Array",
"(",
"M",
")",
"M",
"inputs",
"to",
"evaluate",
"at",
".",
"n",
":",
"non",
... | train | https://github.com/markchil/gptools/blob/225db52bfe6baef1516529ad22177aa2cf7b71e4/gptools/kernel/rational_quadratic.py#L116-L132 |
CTPUG/wafer | wafer/pages/management/commands/load_pages.py | Command.get_parent | def get_parent(self, directory):
"""
Given a directory name, return the Page representing it in the menu
heirarchy.
"""
assert settings.PAGE_DIR.startswith('/')
assert settings.PAGE_DIR.endswith('/')
parents = directory[len(settings.PAGE_DIR):]
page = No... | python | def get_parent(self, directory):
"""
Given a directory name, return the Page representing it in the menu
heirarchy.
"""
assert settings.PAGE_DIR.startswith('/')
assert settings.PAGE_DIR.endswith('/')
parents = directory[len(settings.PAGE_DIR):]
page = No... | [
"def",
"get_parent",
"(",
"self",
",",
"directory",
")",
":",
"assert",
"settings",
".",
"PAGE_DIR",
".",
"startswith",
"(",
"'/'",
")",
"assert",
"settings",
".",
"PAGE_DIR",
".",
"endswith",
"(",
"'/'",
")",
"parents",
"=",
"directory",
"[",
"len",
"("... | Given a directory name, return the Page representing it in the menu
heirarchy. | [
"Given",
"a",
"directory",
"name",
"return",
"the",
"Page",
"representing",
"it",
"in",
"the",
"menu",
"heirarchy",
"."
] | train | https://github.com/CTPUG/wafer/blob/a20af3c399267f76373dc342f4d542a9bc457c35/wafer/pages/management/commands/load_pages.py#L24-L38 |
CTPUG/wafer | wafer/registration/templatetags/wafer_sso.py | wafer_sso_url | def wafer_sso_url(context, sso_method):
'''
Return the correct URL to SSO with the given method.
'''
request = context.request
url = reverse(getattr(views, '%s_login' % sso_method))
if 'next' in request.GET:
url += '?' + urlencode({'next': request.GET['next']})
return url | python | def wafer_sso_url(context, sso_method):
'''
Return the correct URL to SSO with the given method.
'''
request = context.request
url = reverse(getattr(views, '%s_login' % sso_method))
if 'next' in request.GET:
url += '?' + urlencode({'next': request.GET['next']})
return url | [
"def",
"wafer_sso_url",
"(",
"context",
",",
"sso_method",
")",
":",
"request",
"=",
"context",
".",
"request",
"url",
"=",
"reverse",
"(",
"getattr",
"(",
"views",
",",
"'%s_login'",
"%",
"sso_method",
")",
")",
"if",
"'next'",
"in",
"request",
".",
"GE... | Return the correct URL to SSO with the given method. | [
"Return",
"the",
"correct",
"URL",
"to",
"SSO",
"with",
"the",
"given",
"method",
"."
] | train | https://github.com/CTPUG/wafer/blob/a20af3c399267f76373dc342f4d542a9bc457c35/wafer/registration/templatetags/wafer_sso.py#L11-L19 |
coursera/courseraoauth2client | courseraoauth2client/commands/config.py | authorize | def authorize(args):
"""
Authorizes Coursera's OAuth2 client for using coursera.org API servers for
a specific application
"""
oauth2_instance = oauth2.build_oauth2(args.app, args)
oauth2_instance.build_authorizer()
logging.info('Application "%s" authorized!', args.app) | python | def authorize(args):
"""
Authorizes Coursera's OAuth2 client for using coursera.org API servers for
a specific application
"""
oauth2_instance = oauth2.build_oauth2(args.app, args)
oauth2_instance.build_authorizer()
logging.info('Application "%s" authorized!', args.app) | [
"def",
"authorize",
"(",
"args",
")",
":",
"oauth2_instance",
"=",
"oauth2",
".",
"build_oauth2",
"(",
"args",
".",
"app",
",",
"args",
")",
"oauth2_instance",
".",
"build_authorizer",
"(",
")",
"logging",
".",
"info",
"(",
"'Application \"%s\" authorized!'",
... | Authorizes Coursera's OAuth2 client for using coursera.org API servers for
a specific application | [
"Authorizes",
"Coursera",
"s",
"OAuth2",
"client",
"for",
"using",
"coursera",
".",
"org",
"API",
"servers",
"for",
"a",
"specific",
"application"
] | train | https://github.com/coursera/courseraoauth2client/blob/4edd991defe26bfc768ab28a30368cace40baf44/courseraoauth2client/commands/config.py#L31-L38 |
coursera/courseraoauth2client | courseraoauth2client/commands/config.py | check_auth | def check_auth(args):
"""
Checks courseraoauth2client's connectivity to the coursera.org API servers
for a specific application
"""
oauth2_instance = oauth2.build_oauth2(args.app, args)
auth = oauth2_instance.build_authorizer()
my_profile_url = (
'https://api.coursera.org/api/externa... | python | def check_auth(args):
"""
Checks courseraoauth2client's connectivity to the coursera.org API servers
for a specific application
"""
oauth2_instance = oauth2.build_oauth2(args.app, args)
auth = oauth2_instance.build_authorizer()
my_profile_url = (
'https://api.coursera.org/api/externa... | [
"def",
"check_auth",
"(",
"args",
")",
":",
"oauth2_instance",
"=",
"oauth2",
".",
"build_oauth2",
"(",
"args",
".",
"app",
",",
"args",
")",
"auth",
"=",
"oauth2_instance",
".",
"build_authorizer",
"(",
")",
"my_profile_url",
"=",
"(",
"'https://api.coursera.... | Checks courseraoauth2client's connectivity to the coursera.org API servers
for a specific application | [
"Checks",
"courseraoauth2client",
"s",
"connectivity",
"to",
"the",
"coursera",
".",
"org",
"API",
"servers",
"for",
"a",
"specific",
"application"
] | train | https://github.com/coursera/courseraoauth2client/blob/4edd991defe26bfc768ab28a30368cace40baf44/courseraoauth2client/commands/config.py#L41-L79 |
coursera/courseraoauth2client | courseraoauth2client/commands/config.py | display_auth_cache | def display_auth_cache(args):
'''
Writes to the screen the state of the authentication cache. (For debugging
authentication issues.) BEWARE: DO NOT email the output of this command!!!
You must keep the tokens secure. Treat them as passwords.
'''
oauth2_instance = oauth2.build_oauth2(args.app, ar... | python | def display_auth_cache(args):
'''
Writes to the screen the state of the authentication cache. (For debugging
authentication issues.) BEWARE: DO NOT email the output of this command!!!
You must keep the tokens secure. Treat them as passwords.
'''
oauth2_instance = oauth2.build_oauth2(args.app, ar... | [
"def",
"display_auth_cache",
"(",
"args",
")",
":",
"oauth2_instance",
"=",
"oauth2",
".",
"build_oauth2",
"(",
"args",
".",
"app",
",",
"args",
")",
"if",
"not",
"args",
".",
"quiet",
">",
"0",
":",
"token",
"=",
"oauth2_instance",
".",
"token_cache",
"... | Writes to the screen the state of the authentication cache. (For debugging
authentication issues.) BEWARE: DO NOT email the output of this command!!!
You must keep the tokens secure. Treat them as passwords. | [
"Writes",
"to",
"the",
"screen",
"the",
"state",
"of",
"the",
"authentication",
"cache",
".",
"(",
"For",
"debugging",
"authentication",
"issues",
".",
")",
"BEWARE",
":",
"DO",
"NOT",
"email",
"the",
"output",
"of",
"this",
"command!!!",
"You",
"must",
"k... | train | https://github.com/coursera/courseraoauth2client/blob/4edd991defe26bfc768ab28a30368cace40baf44/courseraoauth2client/commands/config.py#L82-L105 |
markchil/gptools | gptools/kernel/gibbs.py | tanh_warp_arb | def tanh_warp_arb(X, l1, l2, lw, x0):
r"""Warps the `X` coordinate with the tanh model
.. math::
l = \frac{l_1 + l_2}{2} - \frac{l_1 - l_2}{2}\tanh\frac{x-x_0}{l_w}
Parameters
----------
X : :py:class:`Array`, (`M`,) or scalar float
`M` locations to evaluate length sca... | python | def tanh_warp_arb(X, l1, l2, lw, x0):
r"""Warps the `X` coordinate with the tanh model
.. math::
l = \frac{l_1 + l_2}{2} - \frac{l_1 - l_2}{2}\tanh\frac{x-x_0}{l_w}
Parameters
----------
X : :py:class:`Array`, (`M`,) or scalar float
`M` locations to evaluate length sca... | [
"def",
"tanh_warp_arb",
"(",
"X",
",",
"l1",
",",
"l2",
",",
"lw",
",",
"x0",
")",
":",
"if",
"isinstance",
"(",
"X",
",",
"scipy",
".",
"ndarray",
")",
":",
"if",
"isinstance",
"(",
"X",
",",
"scipy",
".",
"matrix",
")",
":",
"X",
"=",
"scipy"... | r"""Warps the `X` coordinate with the tanh model
.. math::
l = \frac{l_1 + l_2}{2} - \frac{l_1 - l_2}{2}\tanh\frac{x-x_0}{l_w}
Parameters
----------
X : :py:class:`Array`, (`M`,) or scalar float
`M` locations to evaluate length scale at.
l1 : positive float
Sma... | [
"r",
"Warps",
"the",
"X",
"coordinate",
"with",
"the",
"tanh",
"model",
"..",
"math",
"::",
"l",
"=",
"\\",
"frac",
"{",
"l_1",
"+",
"l_2",
"}",
"{",
"2",
"}",
"-",
"\\",
"frac",
"{",
"l_1",
"-",
"l_2",
"}",
"{",
"2",
"}",
"\\",
"tanh",
"\\",... | train | https://github.com/markchil/gptools/blob/225db52bfe6baef1516529ad22177aa2cf7b71e4/gptools/kernel/gibbs.py#L37-L67 |
markchil/gptools | gptools/kernel/gibbs.py | gauss_warp_arb | def gauss_warp_arb(X, l1, l2, lw, x0):
r"""Warps the `X` coordinate with a Gaussian-shaped divot.
.. math::
l = l_1 - (l_1 - l_2) \exp\left ( -4\ln 2\frac{(X-x_0)^2}{l_{w}^{2}} \right )
Parameters
----------
X : :py:class:`Array`, (`M`,) or scalar float
`M` locatio... | python | def gauss_warp_arb(X, l1, l2, lw, x0):
r"""Warps the `X` coordinate with a Gaussian-shaped divot.
.. math::
l = l_1 - (l_1 - l_2) \exp\left ( -4\ln 2\frac{(X-x_0)^2}{l_{w}^{2}} \right )
Parameters
----------
X : :py:class:`Array`, (`M`,) or scalar float
`M` locatio... | [
"def",
"gauss_warp_arb",
"(",
"X",
",",
"l1",
",",
"l2",
",",
"lw",
",",
"x0",
")",
":",
"if",
"isinstance",
"(",
"X",
",",
"scipy",
".",
"ndarray",
")",
":",
"if",
"isinstance",
"(",
"X",
",",
"scipy",
".",
"matrix",
")",
":",
"X",
"=",
"scipy... | r"""Warps the `X` coordinate with a Gaussian-shaped divot.
.. math::
l = l_1 - (l_1 - l_2) \exp\left ( -4\ln 2\frac{(X-x_0)^2}{l_{w}^{2}} \right )
Parameters
----------
X : :py:class:`Array`, (`M`,) or scalar float
`M` locations to evaluate length scale at.
l1 : po... | [
"r",
"Warps",
"the",
"X",
"coordinate",
"with",
"a",
"Gaussian",
"-",
"shaped",
"divot",
".",
"..",
"math",
"::",
"l",
"=",
"l_1",
"-",
"(",
"l_1",
"-",
"l_2",
")",
"\\",
"exp",
"\\",
"left",
"(",
"-",
"4",
"\\",
"ln",
"2",
"\\",
"frac",
"{",
... | train | https://github.com/markchil/gptools/blob/225db52bfe6baef1516529ad22177aa2cf7b71e4/gptools/kernel/gibbs.py#L69-L99 |
markchil/gptools | gptools/kernel/gibbs.py | tanh_warp | def tanh_warp(x, n, l1, l2, lw, x0):
r"""Implements a tanh warping function and its derivative.
.. math::
l = \frac{l_1 + l_2}{2} - \frac{l_1 - l_2}{2}\tanh\frac{x-x_0}{l_w}
Parameters
----------
x : float or array of float
Locations to evaluate the function at.
n ... | python | def tanh_warp(x, n, l1, l2, lw, x0):
r"""Implements a tanh warping function and its derivative.
.. math::
l = \frac{l_1 + l_2}{2} - \frac{l_1 - l_2}{2}\tanh\frac{x-x_0}{l_w}
Parameters
----------
x : float or array of float
Locations to evaluate the function at.
n ... | [
"def",
"tanh_warp",
"(",
"x",
",",
"n",
",",
"l1",
",",
"l2",
",",
"lw",
",",
"x0",
")",
":",
"if",
"n",
"==",
"0",
":",
"return",
"(",
"l1",
"+",
"l2",
")",
"/",
"2.0",
"-",
"(",
"l1",
"-",
"l2",
")",
"/",
"2.0",
"*",
"scipy",
".",
"ta... | r"""Implements a tanh warping function and its derivative.
.. math::
l = \frac{l_1 + l_2}{2} - \frac{l_1 - l_2}{2}\tanh\frac{x-x_0}{l_w}
Parameters
----------
x : float or array of float
Locations to evaluate the function at.
n : int
Derivative order to take. U... | [
"r",
"Implements",
"a",
"tanh",
"warping",
"function",
"and",
"its",
"derivative",
".",
"..",
"math",
"::",
"l",
"=",
"\\",
"frac",
"{",
"l_1",
"+",
"l_2",
"}",
"{",
"2",
"}",
"-",
"\\",
"frac",
"{",
"l_1",
"-",
"l_2",
"}",
"{",
"2",
"}",
"\\",... | train | https://github.com/markchil/gptools/blob/225db52bfe6baef1516529ad22177aa2cf7b71e4/gptools/kernel/gibbs.py#L401-L438 |
markchil/gptools | gptools/kernel/gibbs.py | double_tanh_warp | def double_tanh_warp(x, n, lcore, lmid, ledge, la, lb, xa, xb):
r"""Implements a sum-of-tanh warping function and its derivative.
.. math::
l = a\tanh\frac{x-x_a}{l_a} + b\tanh\frac{x-x_b}{l_b}
Parameters
----------
x : float or array of float
Locations to evaluate the... | python | def double_tanh_warp(x, n, lcore, lmid, ledge, la, lb, xa, xb):
r"""Implements a sum-of-tanh warping function and its derivative.
.. math::
l = a\tanh\frac{x-x_a}{l_a} + b\tanh\frac{x-x_b}{l_b}
Parameters
----------
x : float or array of float
Locations to evaluate the... | [
"def",
"double_tanh_warp",
"(",
"x",
",",
"n",
",",
"lcore",
",",
"lmid",
",",
"ledge",
",",
"la",
",",
"lb",
",",
"xa",
",",
"xb",
")",
":",
"a",
",",
"b",
",",
"c",
"=",
"scipy",
".",
"dot",
"(",
"[",
"[",
"-",
"0.5",
",",
"0",
",",
"0.... | r"""Implements a sum-of-tanh warping function and its derivative.
.. math::
l = a\tanh\frac{x-x_a}{l_a} + b\tanh\frac{x-x_b}{l_b}
Parameters
----------
x : float or array of float
Locations to evaluate the function at.
n : int
Derivative order to take. Used for... | [
"r",
"Implements",
"a",
"sum",
"-",
"of",
"-",
"tanh",
"warping",
"function",
"and",
"its",
"derivative",
".",
"..",
"math",
"::",
"l",
"=",
"a",
"\\",
"tanh",
"\\",
"frac",
"{",
"x",
"-",
"x_a",
"}",
"{",
"l_a",
"}",
"+",
"b",
"\\",
"tanh",
"\... | train | https://github.com/markchil/gptools/blob/225db52bfe6baef1516529ad22177aa2cf7b71e4/gptools/kernel/gibbs.py#L479-L528 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.