repo stringlengths 7 55 | path stringlengths 4 127 | func_name stringlengths 1 88 | original_string stringlengths 75 19.8k | language stringclasses 1
value | code stringlengths 75 19.8k | code_tokens list | docstring stringlengths 3 17.3k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 87 242 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
sighingnow/parsec.py | src/parsec/__init__.py | Value.aggregate | def aggregate(self, other=None):
'''collect the furthest failure from self and other.'''
if not self.status:
return self
if not other:
return self
if not other.status:
return other
return Value(True, other.index, self.value + other.value, None) | python | def aggregate(self, other=None):
'''collect the furthest failure from self and other.'''
if not self.status:
return self
if not other:
return self
if not other.status:
return other
return Value(True, other.index, self.value + other.value, None) | [
"def",
"aggregate",
"(",
"self",
",",
"other",
"=",
"None",
")",
":",
"if",
"not",
"self",
".",
"status",
":",
"return",
"self",
"if",
"not",
"other",
":",
"return",
"self",
"if",
"not",
"other",
".",
"status",
":",
"return",
"other",
"return",
"Valu... | collect the furthest failure from self and other. | [
"collect",
"the",
"furthest",
"failure",
"from",
"self",
"and",
"other",
"."
] | ed50e1e259142757470b925f8d20dfe5ad223af0 | https://github.com/sighingnow/parsec.py/blob/ed50e1e259142757470b925f8d20dfe5ad223af0/src/parsec/__init__.py#L64-L72 | train |
sighingnow/parsec.py | src/parsec/__init__.py | Value.combinate | def combinate(values):
'''aggregate multiple values into tuple'''
prev_v = None
for v in values:
if prev_v:
if not v:
return prev_v
if not v.status:
return v
out_values = tuple([v.value for v in values])
... | python | def combinate(values):
'''aggregate multiple values into tuple'''
prev_v = None
for v in values:
if prev_v:
if not v:
return prev_v
if not v.status:
return v
out_values = tuple([v.value for v in values])
... | [
"def",
"combinate",
"(",
"values",
")",
":",
"prev_v",
"=",
"None",
"for",
"v",
"in",
"values",
":",
"if",
"prev_v",
":",
"if",
"not",
"v",
":",
"return",
"prev_v",
"if",
"not",
"v",
".",
"status",
":",
"return",
"v",
"out_values",
"=",
"tuple",
"(... | aggregate multiple values into tuple | [
"aggregate",
"multiple",
"values",
"into",
"tuple"
] | ed50e1e259142757470b925f8d20dfe5ad223af0 | https://github.com/sighingnow/parsec.py/blob/ed50e1e259142757470b925f8d20dfe5ad223af0/src/parsec/__init__.py#L75-L85 | train |
sighingnow/parsec.py | src/parsec/__init__.py | Parser.parse_partial | def parse_partial(self, text):
'''Parse the longest possible prefix of a given string.
Return a tuple of the result value and the rest of the string.
If failed, raise a ParseError. '''
if not isinstance(text, str):
raise TypeError(
'Can only parsing string but... | python | def parse_partial(self, text):
'''Parse the longest possible prefix of a given string.
Return a tuple of the result value and the rest of the string.
If failed, raise a ParseError. '''
if not isinstance(text, str):
raise TypeError(
'Can only parsing string but... | [
"def",
"parse_partial",
"(",
"self",
",",
"text",
")",
":",
"if",
"not",
"isinstance",
"(",
"text",
",",
"str",
")",
":",
"raise",
"TypeError",
"(",
"'Can only parsing string but got {!r}'",
".",
"format",
"(",
"text",
")",
")",
"res",
"=",
"self",
"(",
... | Parse the longest possible prefix of a given string.
Return a tuple of the result value and the rest of the string.
If failed, raise a ParseError. | [
"Parse",
"the",
"longest",
"possible",
"prefix",
"of",
"a",
"given",
"string",
".",
"Return",
"a",
"tuple",
"of",
"the",
"result",
"value",
"and",
"the",
"rest",
"of",
"the",
"string",
".",
"If",
"failed",
"raise",
"a",
"ParseError",
"."
] | ed50e1e259142757470b925f8d20dfe5ad223af0 | https://github.com/sighingnow/parsec.py/blob/ed50e1e259142757470b925f8d20dfe5ad223af0/src/parsec/__init__.py#L117-L128 | train |
sighingnow/parsec.py | src/parsec/__init__.py | Parser.bind | def bind(self, fn):
'''This is the monadic binding operation. Returns a parser which, if
parser is successful, passes the result to fn, and continues with the
parser returned from fn.
'''
@Parser
def bind_parser(text, index):
res = self(text, index)
... | python | def bind(self, fn):
'''This is the monadic binding operation. Returns a parser which, if
parser is successful, passes the result to fn, and continues with the
parser returned from fn.
'''
@Parser
def bind_parser(text, index):
res = self(text, index)
... | [
"def",
"bind",
"(",
"self",
",",
"fn",
")",
":",
"@",
"Parser",
"def",
"bind_parser",
"(",
"text",
",",
"index",
")",
":",
"res",
"=",
"self",
"(",
"text",
",",
"index",
")",
"return",
"res",
"if",
"not",
"res",
".",
"status",
"else",
"fn",
"(",
... | This is the monadic binding operation. Returns a parser which, if
parser is successful, passes the result to fn, and continues with the
parser returned from fn. | [
"This",
"is",
"the",
"monadic",
"binding",
"operation",
".",
"Returns",
"a",
"parser",
"which",
"if",
"parser",
"is",
"successful",
"passes",
"the",
"result",
"to",
"fn",
"and",
"continues",
"with",
"the",
"parser",
"returned",
"from",
"fn",
"."
] | ed50e1e259142757470b925f8d20dfe5ad223af0 | https://github.com/sighingnow/parsec.py/blob/ed50e1e259142757470b925f8d20dfe5ad223af0/src/parsec/__init__.py#L140-L149 | train |
sighingnow/parsec.py | src/parsec/__init__.py | Parser.parsecmap | def parsecmap(self, fn):
'''Returns a parser that transforms the produced value of parser with `fn`.'''
return self.bind(lambda res: Parser(lambda _, index: Value.success(index, fn(res)))) | python | def parsecmap(self, fn):
'''Returns a parser that transforms the produced value of parser with `fn`.'''
return self.bind(lambda res: Parser(lambda _, index: Value.success(index, fn(res)))) | [
"def",
"parsecmap",
"(",
"self",
",",
"fn",
")",
":",
"return",
"self",
".",
"bind",
"(",
"lambda",
"res",
":",
"Parser",
"(",
"lambda",
"_",
",",
"index",
":",
"Value",
".",
"success",
"(",
"index",
",",
"fn",
"(",
"res",
")",
")",
")",
")"
] | Returns a parser that transforms the produced value of parser with `fn`. | [
"Returns",
"a",
"parser",
"that",
"transforms",
"the",
"produced",
"value",
"of",
"parser",
"with",
"fn",
"."
] | ed50e1e259142757470b925f8d20dfe5ad223af0 | https://github.com/sighingnow/parsec.py/blob/ed50e1e259142757470b925f8d20dfe5ad223af0/src/parsec/__init__.py#L218-L220 | train |
sighingnow/parsec.py | src/parsec/__init__.py | Parser.parsecapp | def parsecapp(self, other):
'''Returns a parser that applies the produced value of this parser to the produced value of `other`.'''
# pylint: disable=unnecessary-lambda
return self.bind(lambda res: other.parsecmap(lambda x: res(x))) | python | def parsecapp(self, other):
'''Returns a parser that applies the produced value of this parser to the produced value of `other`.'''
# pylint: disable=unnecessary-lambda
return self.bind(lambda res: other.parsecmap(lambda x: res(x))) | [
"def",
"parsecapp",
"(",
"self",
",",
"other",
")",
":",
"return",
"self",
".",
"bind",
"(",
"lambda",
"res",
":",
"other",
".",
"parsecmap",
"(",
"lambda",
"x",
":",
"res",
"(",
"x",
")",
")",
")"
] | Returns a parser that applies the produced value of this parser to the produced value of `other`. | [
"Returns",
"a",
"parser",
"that",
"applies",
"the",
"produced",
"value",
"of",
"this",
"parser",
"to",
"the",
"produced",
"value",
"of",
"other",
"."
] | ed50e1e259142757470b925f8d20dfe5ad223af0 | https://github.com/sighingnow/parsec.py/blob/ed50e1e259142757470b925f8d20dfe5ad223af0/src/parsec/__init__.py#L222-L225 | train |
sighingnow/parsec.py | src/parsec/__init__.py | Parser.result | def result(self, res):
'''Return a value according to the parameter `res` when parse successfully.'''
return self >> Parser(lambda _, index: Value.success(index, res)) | python | def result(self, res):
'''Return a value according to the parameter `res` when parse successfully.'''
return self >> Parser(lambda _, index: Value.success(index, res)) | [
"def",
"result",
"(",
"self",
",",
"res",
")",
":",
"return",
"self",
">>",
"Parser",
"(",
"lambda",
"_",
",",
"index",
":",
"Value",
".",
"success",
"(",
"index",
",",
"res",
")",
")"
] | Return a value according to the parameter `res` when parse successfully. | [
"Return",
"a",
"value",
"according",
"to",
"the",
"parameter",
"res",
"when",
"parse",
"successfully",
"."
] | ed50e1e259142757470b925f8d20dfe5ad223af0 | https://github.com/sighingnow/parsec.py/blob/ed50e1e259142757470b925f8d20dfe5ad223af0/src/parsec/__init__.py#L227-L229 | train |
sighingnow/parsec.py | src/parsec/__init__.py | Parser.mark | def mark(self):
'''Mark the line and column information of the result of this parser.'''
def pos(text, index):
return ParseError.loc_info(text, index)
@Parser
def mark_parser(text, index):
res = self(text, index)
if res.status:
return ... | python | def mark(self):
'''Mark the line and column information of the result of this parser.'''
def pos(text, index):
return ParseError.loc_info(text, index)
@Parser
def mark_parser(text, index):
res = self(text, index)
if res.status:
return ... | [
"def",
"mark",
"(",
"self",
")",
":",
"def",
"pos",
"(",
"text",
",",
"index",
")",
":",
"return",
"ParseError",
".",
"loc_info",
"(",
"text",
",",
"index",
")",
"@",
"Parser",
"def",
"mark_parser",
"(",
"text",
",",
"index",
")",
":",
"res",
"=",
... | Mark the line and column information of the result of this parser. | [
"Mark",
"the",
"line",
"and",
"column",
"information",
"of",
"the",
"result",
"of",
"this",
"parser",
"."
] | ed50e1e259142757470b925f8d20dfe5ad223af0 | https://github.com/sighingnow/parsec.py/blob/ed50e1e259142757470b925f8d20dfe5ad223af0/src/parsec/__init__.py#L231-L243 | train |
sighingnow/parsec.py | src/parsec/__init__.py | Parser.desc | def desc(self, description):
'''Describe a parser, when it failed, print out the description text.'''
return self | Parser(lambda _, index: Value.failure(index, description)) | python | def desc(self, description):
'''Describe a parser, when it failed, print out the description text.'''
return self | Parser(lambda _, index: Value.failure(index, description)) | [
"def",
"desc",
"(",
"self",
",",
"description",
")",
":",
"return",
"self",
"|",
"Parser",
"(",
"lambda",
"_",
",",
"index",
":",
"Value",
".",
"failure",
"(",
"index",
",",
"description",
")",
")"
] | Describe a parser, when it failed, print out the description text. | [
"Describe",
"a",
"parser",
"when",
"it",
"failed",
"print",
"out",
"the",
"description",
"text",
"."
] | ed50e1e259142757470b925f8d20dfe5ad223af0 | https://github.com/sighingnow/parsec.py/blob/ed50e1e259142757470b925f8d20dfe5ad223af0/src/parsec/__init__.py#L245-L247 | train |
pecan/pecan | pecan/routing.py | route | def route(*args):
"""
This function is used to define an explicit route for a path segment.
You generally only want to use this in situations where your desired path
segment is not a valid Python variable/function name.
For example, if you wanted to be able to route to:
/path/with-dashes/
... | python | def route(*args):
"""
This function is used to define an explicit route for a path segment.
You generally only want to use this in situations where your desired path
segment is not a valid Python variable/function name.
For example, if you wanted to be able to route to:
/path/with-dashes/
... | [
"def",
"route",
"(",
"*",
"args",
")",
":",
"def",
"_validate_route",
"(",
"route",
")",
":",
"if",
"not",
"isinstance",
"(",
"route",
",",
"six",
".",
"string_types",
")",
":",
"raise",
"TypeError",
"(",
"'%s must be a string'",
"%",
"route",
")",
"if",... | This function is used to define an explicit route for a path segment.
You generally only want to use this in situations where your desired path
segment is not a valid Python variable/function name.
For example, if you wanted to be able to route to:
/path/with-dashes/
...the following is invalid ... | [
"This",
"function",
"is",
"used",
"to",
"define",
"an",
"explicit",
"route",
"for",
"a",
"path",
"segment",
"."
] | 833d0653fa0e6bbfb52545b091c30182105f4a82 | https://github.com/pecan/pecan/blob/833d0653fa0e6bbfb52545b091c30182105f4a82/pecan/routing.py#L19-L101 | train |
pecan/pecan | pecan/routing.py | lookup_controller | def lookup_controller(obj, remainder, request=None):
'''
Traverses the requested url path and returns the appropriate controller
object, including default routes.
Handles common errors gracefully.
'''
if request is None:
warnings.warn(
(
"The function signatu... | python | def lookup_controller(obj, remainder, request=None):
'''
Traverses the requested url path and returns the appropriate controller
object, including default routes.
Handles common errors gracefully.
'''
if request is None:
warnings.warn(
(
"The function signatu... | [
"def",
"lookup_controller",
"(",
"obj",
",",
"remainder",
",",
"request",
"=",
"None",
")",
":",
"if",
"request",
"is",
"None",
":",
"warnings",
".",
"warn",
"(",
"(",
"\"The function signature for %s.lookup_controller is changing \"",
"\"in the next version of pecan.\\... | Traverses the requested url path and returns the appropriate controller
object, including default routes.
Handles common errors gracefully. | [
"Traverses",
"the",
"requested",
"url",
"path",
"and",
"returns",
"the",
"appropriate",
"controller",
"object",
"including",
"default",
"routes",
"."
] | 833d0653fa0e6bbfb52545b091c30182105f4a82 | https://github.com/pecan/pecan/blob/833d0653fa0e6bbfb52545b091c30182105f4a82/pecan/routing.py#L119-L170 | train |
pecan/pecan | pecan/routing.py | find_object | def find_object(obj, remainder, notfound_handlers, request):
'''
'Walks' the url path in search of an action for which a controller is
implemented and returns that controller object along with what's left
of the remainder.
'''
prev_obj = None
while True:
if obj is None:
r... | python | def find_object(obj, remainder, notfound_handlers, request):
'''
'Walks' the url path in search of an action for which a controller is
implemented and returns that controller object along with what's left
of the remainder.
'''
prev_obj = None
while True:
if obj is None:
r... | [
"def",
"find_object",
"(",
"obj",
",",
"remainder",
",",
"notfound_handlers",
",",
"request",
")",
":",
"prev_obj",
"=",
"None",
"while",
"True",
":",
"if",
"obj",
"is",
"None",
":",
"raise",
"PecanNotFound",
"if",
"iscontroller",
"(",
"obj",
")",
":",
"... | 'Walks' the url path in search of an action for which a controller is
implemented and returns that controller object along with what's left
of the remainder. | [
"Walks",
"the",
"url",
"path",
"in",
"search",
"of",
"an",
"action",
"for",
"which",
"a",
"controller",
"is",
"implemented",
"and",
"returns",
"that",
"controller",
"object",
"along",
"with",
"what",
"s",
"left",
"of",
"the",
"remainder",
"."
] | 833d0653fa0e6bbfb52545b091c30182105f4a82 | https://github.com/pecan/pecan/blob/833d0653fa0e6bbfb52545b091c30182105f4a82/pecan/routing.py#L188-L269 | train |
pecan/pecan | pecan/secure.py | unlocked | def unlocked(func_or_obj):
"""
This method unlocks method or class attribute on a SecureController. Can
be used to decorate or wrap an attribute
"""
if ismethod(func_or_obj) or isfunction(func_or_obj):
return _unlocked_method(func_or_obj)
else:
return _UnlockedAttribute(func_or_... | python | def unlocked(func_or_obj):
"""
This method unlocks method or class attribute on a SecureController. Can
be used to decorate or wrap an attribute
"""
if ismethod(func_or_obj) or isfunction(func_or_obj):
return _unlocked_method(func_or_obj)
else:
return _UnlockedAttribute(func_or_... | [
"def",
"unlocked",
"(",
"func_or_obj",
")",
":",
"if",
"ismethod",
"(",
"func_or_obj",
")",
"or",
"isfunction",
"(",
"func_or_obj",
")",
":",
"return",
"_unlocked_method",
"(",
"func_or_obj",
")",
"else",
":",
"return",
"_UnlockedAttribute",
"(",
"func_or_obj",
... | This method unlocks method or class attribute on a SecureController. Can
be used to decorate or wrap an attribute | [
"This",
"method",
"unlocks",
"method",
"or",
"class",
"attribute",
"on",
"a",
"SecureController",
".",
"Can",
"be",
"used",
"to",
"decorate",
"or",
"wrap",
"an",
"attribute"
] | 833d0653fa0e6bbfb52545b091c30182105f4a82 | https://github.com/pecan/pecan/blob/833d0653fa0e6bbfb52545b091c30182105f4a82/pecan/secure.py#L101-L109 | train |
pecan/pecan | pecan/secure.py | secure | def secure(func_or_obj, check_permissions_for_obj=None):
"""
This method secures a method or class depending on invocation.
To decorate a method use one argument:
@secure(<check_permissions_method>)
To secure a class, invoke with two arguments:
secure(<obj instance>, <check_permissions... | python | def secure(func_or_obj, check_permissions_for_obj=None):
"""
This method secures a method or class depending on invocation.
To decorate a method use one argument:
@secure(<check_permissions_method>)
To secure a class, invoke with two arguments:
secure(<obj instance>, <check_permissions... | [
"def",
"secure",
"(",
"func_or_obj",
",",
"check_permissions_for_obj",
"=",
"None",
")",
":",
"if",
"_allowed_check_permissions_types",
"(",
"func_or_obj",
")",
":",
"return",
"_secure_method",
"(",
"func_or_obj",
")",
"else",
":",
"if",
"not",
"_allowed_check_permi... | This method secures a method or class depending on invocation.
To decorate a method use one argument:
@secure(<check_permissions_method>)
To secure a class, invoke with two arguments:
secure(<obj instance>, <check_permissions_method>) | [
"This",
"method",
"secures",
"a",
"method",
"or",
"class",
"depending",
"on",
"invocation",
"."
] | 833d0653fa0e6bbfb52545b091c30182105f4a82 | https://github.com/pecan/pecan/blob/833d0653fa0e6bbfb52545b091c30182105f4a82/pecan/secure.py#L112-L129 | train |
pecan/pecan | pecan/secure.py | _make_wrapper | def _make_wrapper(f):
"""return a wrapped function with a copy of the _pecan context"""
@wraps(f)
def wrapper(*args, **kwargs):
return f(*args, **kwargs)
wrapper._pecan = f._pecan.copy()
return wrapper | python | def _make_wrapper(f):
"""return a wrapped function with a copy of the _pecan context"""
@wraps(f)
def wrapper(*args, **kwargs):
return f(*args, **kwargs)
wrapper._pecan = f._pecan.copy()
return wrapper | [
"def",
"_make_wrapper",
"(",
"f",
")",
":",
"@",
"wraps",
"(",
"f",
")",
"def",
"wrapper",
"(",
"*",
"args",
",",
"**",
"kwargs",
")",
":",
"return",
"f",
"(",
"*",
"args",
",",
"**",
"kwargs",
")",
"wrapper",
".",
"_pecan",
"=",
"f",
".",
"_pe... | return a wrapped function with a copy of the _pecan context | [
"return",
"a",
"wrapped",
"function",
"with",
"a",
"copy",
"of",
"the",
"_pecan",
"context"
] | 833d0653fa0e6bbfb52545b091c30182105f4a82 | https://github.com/pecan/pecan/blob/833d0653fa0e6bbfb52545b091c30182105f4a82/pecan/secure.py#L195-L201 | train |
pecan/pecan | pecan/secure.py | handle_security | def handle_security(controller, im_self=None):
""" Checks the security of a controller. """
if controller._pecan.get('secured', False):
check_permissions = controller._pecan['check_permissions']
if isinstance(check_permissions, six.string_types):
check_permissions = getattr(
... | python | def handle_security(controller, im_self=None):
""" Checks the security of a controller. """
if controller._pecan.get('secured', False):
check_permissions = controller._pecan['check_permissions']
if isinstance(check_permissions, six.string_types):
check_permissions = getattr(
... | [
"def",
"handle_security",
"(",
"controller",
",",
"im_self",
"=",
"None",
")",
":",
"if",
"controller",
".",
"_pecan",
".",
"get",
"(",
"'secured'",
",",
"False",
")",
":",
"check_permissions",
"=",
"controller",
".",
"_pecan",
"[",
"'check_permissions'",
"]... | Checks the security of a controller. | [
"Checks",
"the",
"security",
"of",
"a",
"controller",
"."
] | 833d0653fa0e6bbfb52545b091c30182105f4a82 | https://github.com/pecan/pecan/blob/833d0653fa0e6bbfb52545b091c30182105f4a82/pecan/secure.py#L205-L217 | train |
pecan/pecan | pecan/secure.py | cross_boundary | def cross_boundary(prev_obj, obj):
""" Check permissions as we move between object instances. """
if prev_obj is None:
return
if isinstance(obj, _SecuredAttribute):
# a secure attribute can live in unsecure class so we have to set
# while we walk the route
obj.parent = prev_... | python | def cross_boundary(prev_obj, obj):
""" Check permissions as we move between object instances. """
if prev_obj is None:
return
if isinstance(obj, _SecuredAttribute):
# a secure attribute can live in unsecure class so we have to set
# while we walk the route
obj.parent = prev_... | [
"def",
"cross_boundary",
"(",
"prev_obj",
",",
"obj",
")",
":",
"if",
"prev_obj",
"is",
"None",
":",
"return",
"if",
"isinstance",
"(",
"obj",
",",
"_SecuredAttribute",
")",
":",
"obj",
".",
"parent",
"=",
"prev_obj",
"if",
"hasattr",
"(",
"prev_obj",
",... | Check permissions as we move between object instances. | [
"Check",
"permissions",
"as",
"we",
"move",
"between",
"object",
"instances",
"."
] | 833d0653fa0e6bbfb52545b091c30182105f4a82 | https://github.com/pecan/pecan/blob/833d0653fa0e6bbfb52545b091c30182105f4a82/pecan/secure.py#L220-L232 | train |
pecan/pecan | pecan/scaffolds/__init__.py | makedirs | def makedirs(directory):
""" Resursively create a named directory. """
parent = os.path.dirname(os.path.abspath(directory))
if not os.path.exists(parent):
makedirs(parent)
os.mkdir(directory) | python | def makedirs(directory):
""" Resursively create a named directory. """
parent = os.path.dirname(os.path.abspath(directory))
if not os.path.exists(parent):
makedirs(parent)
os.mkdir(directory) | [
"def",
"makedirs",
"(",
"directory",
")",
":",
"parent",
"=",
"os",
".",
"path",
".",
"dirname",
"(",
"os",
".",
"path",
".",
"abspath",
"(",
"directory",
")",
")",
"if",
"not",
"os",
".",
"path",
".",
"exists",
"(",
"parent",
")",
":",
"makedirs",... | Resursively create a named directory. | [
"Resursively",
"create",
"a",
"named",
"directory",
"."
] | 833d0653fa0e6bbfb52545b091c30182105f4a82 | https://github.com/pecan/pecan/blob/833d0653fa0e6bbfb52545b091c30182105f4a82/pecan/scaffolds/__init__.py#L105-L110 | train |
pecan/pecan | pecan/scaffolds/__init__.py | substitute_filename | def substitute_filename(fn, variables):
""" Substitute +variables+ in file directory names. """
for var, value in variables.items():
fn = fn.replace('+%s+' % var, str(value))
return fn | python | def substitute_filename(fn, variables):
""" Substitute +variables+ in file directory names. """
for var, value in variables.items():
fn = fn.replace('+%s+' % var, str(value))
return fn | [
"def",
"substitute_filename",
"(",
"fn",
",",
"variables",
")",
":",
"for",
"var",
",",
"value",
"in",
"variables",
".",
"items",
"(",
")",
":",
"fn",
"=",
"fn",
".",
"replace",
"(",
"'+%s+'",
"%",
"var",
",",
"str",
"(",
"value",
")",
")",
"return... | Substitute +variables+ in file directory names. | [
"Substitute",
"+",
"variables",
"+",
"in",
"file",
"directory",
"names",
"."
] | 833d0653fa0e6bbfb52545b091c30182105f4a82 | https://github.com/pecan/pecan/blob/833d0653fa0e6bbfb52545b091c30182105f4a82/pecan/scaffolds/__init__.py#L113-L117 | train |
pecan/pecan | pecan/__init__.py | make_app | def make_app(root, **kw):
'''
Utility for creating the Pecan application object. This function should
generally be called from the ``setup_app`` function in your project's
``app.py`` file.
:param root: A string representing a root controller object (e.g.,
"myapp.controller.root.Ro... | python | def make_app(root, **kw):
'''
Utility for creating the Pecan application object. This function should
generally be called from the ``setup_app`` function in your project's
``app.py`` file.
:param root: A string representing a root controller object (e.g.,
"myapp.controller.root.Ro... | [
"def",
"make_app",
"(",
"root",
",",
"**",
"kw",
")",
":",
"logging",
"=",
"kw",
".",
"get",
"(",
"'logging'",
",",
"{",
"}",
")",
"debug",
"=",
"kw",
".",
"get",
"(",
"'debug'",
",",
"False",
")",
"if",
"logging",
":",
"if",
"debug",
":",
"try... | Utility for creating the Pecan application object. This function should
generally be called from the ``setup_app`` function in your project's
``app.py`` file.
:param root: A string representing a root controller object (e.g.,
"myapp.controller.root.RootController")
:param static_root:... | [
"Utility",
"for",
"creating",
"the",
"Pecan",
"application",
"object",
".",
"This",
"function",
"should",
"generally",
"be",
"called",
"from",
"the",
"setup_app",
"function",
"in",
"your",
"project",
"s",
"app",
".",
"py",
"file",
"."
] | 833d0653fa0e6bbfb52545b091c30182105f4a82 | https://github.com/pecan/pecan/blob/833d0653fa0e6bbfb52545b091c30182105f4a82/pecan/__init__.py#L33-L134 | train |
pecan/pecan | pecan/configuration.py | conf_from_file | def conf_from_file(filepath):
'''
Creates a configuration dictionary from a file.
:param filepath: The path to the file.
'''
abspath = os.path.abspath(os.path.expanduser(filepath))
conf_dict = {}
if not os.path.isfile(abspath):
raise RuntimeError('`%s` is not a file.' % abspath)
... | python | def conf_from_file(filepath):
'''
Creates a configuration dictionary from a file.
:param filepath: The path to the file.
'''
abspath = os.path.abspath(os.path.expanduser(filepath))
conf_dict = {}
if not os.path.isfile(abspath):
raise RuntimeError('`%s` is not a file.' % abspath)
... | [
"def",
"conf_from_file",
"(",
"filepath",
")",
":",
"abspath",
"=",
"os",
".",
"path",
".",
"abspath",
"(",
"os",
".",
"path",
".",
"expanduser",
"(",
"filepath",
")",
")",
"conf_dict",
"=",
"{",
"}",
"if",
"not",
"os",
".",
"path",
".",
"isfile",
... | Creates a configuration dictionary from a file.
:param filepath: The path to the file. | [
"Creates",
"a",
"configuration",
"dictionary",
"from",
"a",
"file",
"."
] | 833d0653fa0e6bbfb52545b091c30182105f4a82 | https://github.com/pecan/pecan/blob/833d0653fa0e6bbfb52545b091c30182105f4a82/pecan/configuration.py#L154-L186 | train |
pecan/pecan | pecan/configuration.py | get_conf_path_from_env | def get_conf_path_from_env():
'''
If the ``PECAN_CONFIG`` environment variable exists and it points to
a valid path it will return that, otherwise it will raise
a ``RuntimeError``.
'''
config_path = os.environ.get('PECAN_CONFIG')
if not config_path:
error = "PECAN_CONFIG is not set a... | python | def get_conf_path_from_env():
'''
If the ``PECAN_CONFIG`` environment variable exists and it points to
a valid path it will return that, otherwise it will raise
a ``RuntimeError``.
'''
config_path = os.environ.get('PECAN_CONFIG')
if not config_path:
error = "PECAN_CONFIG is not set a... | [
"def",
"get_conf_path_from_env",
"(",
")",
":",
"config_path",
"=",
"os",
".",
"environ",
".",
"get",
"(",
"'PECAN_CONFIG'",
")",
"if",
"not",
"config_path",
":",
"error",
"=",
"\"PECAN_CONFIG is not set and \"",
"\"no config file was passed as an argument.\"",
"elif",
... | If the ``PECAN_CONFIG`` environment variable exists and it points to
a valid path it will return that, otherwise it will raise
a ``RuntimeError``. | [
"If",
"the",
"PECAN_CONFIG",
"environment",
"variable",
"exists",
"and",
"it",
"points",
"to",
"a",
"valid",
"path",
"it",
"will",
"return",
"that",
"otherwise",
"it",
"will",
"raise",
"a",
"RuntimeError",
"."
] | 833d0653fa0e6bbfb52545b091c30182105f4a82 | https://github.com/pecan/pecan/blob/833d0653fa0e6bbfb52545b091c30182105f4a82/pecan/configuration.py#L189-L204 | train |
pecan/pecan | pecan/configuration.py | conf_from_dict | def conf_from_dict(conf_dict):
'''
Creates a configuration dictionary from a dictionary.
:param conf_dict: The configuration dictionary.
'''
conf = Config(filename=conf_dict.get('__file__', ''))
for k, v in six.iteritems(conf_dict):
if k.startswith('__'):
continue
e... | python | def conf_from_dict(conf_dict):
'''
Creates a configuration dictionary from a dictionary.
:param conf_dict: The configuration dictionary.
'''
conf = Config(filename=conf_dict.get('__file__', ''))
for k, v in six.iteritems(conf_dict):
if k.startswith('__'):
continue
e... | [
"def",
"conf_from_dict",
"(",
"conf_dict",
")",
":",
"conf",
"=",
"Config",
"(",
"filename",
"=",
"conf_dict",
".",
"get",
"(",
"'__file__'",
",",
"''",
")",
")",
"for",
"k",
",",
"v",
"in",
"six",
".",
"iteritems",
"(",
"conf_dict",
")",
":",
"if",
... | Creates a configuration dictionary from a dictionary.
:param conf_dict: The configuration dictionary. | [
"Creates",
"a",
"configuration",
"dictionary",
"from",
"a",
"dictionary",
"."
] | 833d0653fa0e6bbfb52545b091c30182105f4a82 | https://github.com/pecan/pecan/blob/833d0653fa0e6bbfb52545b091c30182105f4a82/pecan/configuration.py#L207-L222 | train |
pecan/pecan | pecan/configuration.py | set_config | def set_config(config, overwrite=False):
'''
Updates the global configuration.
:param config: Can be a dictionary containing configuration, or a string
which represents a (relative) configuration filename.
'''
if config is None:
config = get_conf_path_from_env()
# m... | python | def set_config(config, overwrite=False):
'''
Updates the global configuration.
:param config: Can be a dictionary containing configuration, or a string
which represents a (relative) configuration filename.
'''
if config is None:
config = get_conf_path_from_env()
# m... | [
"def",
"set_config",
"(",
"config",
",",
"overwrite",
"=",
"False",
")",
":",
"if",
"config",
"is",
"None",
":",
"config",
"=",
"get_conf_path_from_env",
"(",
")",
"if",
"overwrite",
"is",
"True",
":",
"_runtime_conf",
".",
"empty",
"(",
")",
"if",
"isin... | Updates the global configuration.
:param config: Can be a dictionary containing configuration, or a string
which represents a (relative) configuration filename. | [
"Updates",
"the",
"global",
"configuration",
"."
] | 833d0653fa0e6bbfb52545b091c30182105f4a82 | https://github.com/pecan/pecan/blob/833d0653fa0e6bbfb52545b091c30182105f4a82/pecan/configuration.py#L233-L256 | train |
pecan/pecan | pecan/configuration.py | Config.update | def update(self, conf_dict):
'''
Updates this configuration with a dictionary.
:param conf_dict: A python dictionary to update this configuration
with.
'''
if isinstance(conf_dict, dict):
iterator = six.iteritems(conf_dict)
else:
... | python | def update(self, conf_dict):
'''
Updates this configuration with a dictionary.
:param conf_dict: A python dictionary to update this configuration
with.
'''
if isinstance(conf_dict, dict):
iterator = six.iteritems(conf_dict)
else:
... | [
"def",
"update",
"(",
"self",
",",
"conf_dict",
")",
":",
"if",
"isinstance",
"(",
"conf_dict",
",",
"dict",
")",
":",
"iterator",
"=",
"six",
".",
"iteritems",
"(",
"conf_dict",
")",
"else",
":",
"iterator",
"=",
"iter",
"(",
"conf_dict",
")",
"for",
... | Updates this configuration with a dictionary.
:param conf_dict: A python dictionary to update this configuration
with. | [
"Updates",
"this",
"configuration",
"with",
"a",
"dictionary",
"."
] | 833d0653fa0e6bbfb52545b091c30182105f4a82 | https://github.com/pecan/pecan/blob/833d0653fa0e6bbfb52545b091c30182105f4a82/pecan/configuration.py#L57-L79 | train |
pecan/pecan | pecan/configuration.py | Config.to_dict | def to_dict(self, prefix=None):
'''
Converts recursively the Config object into a valid dictionary.
:param prefix: A string to optionally prefix all key elements in the
returned dictonary.
'''
conf_obj = dict(self)
return self.__dictify__(conf_obj... | python | def to_dict(self, prefix=None):
'''
Converts recursively the Config object into a valid dictionary.
:param prefix: A string to optionally prefix all key elements in the
returned dictonary.
'''
conf_obj = dict(self)
return self.__dictify__(conf_obj... | [
"def",
"to_dict",
"(",
"self",
",",
"prefix",
"=",
"None",
")",
":",
"conf_obj",
"=",
"dict",
"(",
"self",
")",
"return",
"self",
".",
"__dictify__",
"(",
"conf_obj",
",",
"prefix",
")"
] | Converts recursively the Config object into a valid dictionary.
:param prefix: A string to optionally prefix all key elements in the
returned dictonary. | [
"Converts",
"recursively",
"the",
"Config",
"object",
"into",
"a",
"valid",
"dictionary",
"."
] | 833d0653fa0e6bbfb52545b091c30182105f4a82 | https://github.com/pecan/pecan/blob/833d0653fa0e6bbfb52545b091c30182105f4a82/pecan/configuration.py#L100-L109 | train |
pecan/pecan | pecan/core.py | override_template | def override_template(template, content_type=None):
'''
Call within a controller to override the template that is used in
your response.
:param template: a valid path to a template file, just as you would specify
in an ``@expose``.
:param content_type: a valid MIME type to use ... | python | def override_template(template, content_type=None):
'''
Call within a controller to override the template that is used in
your response.
:param template: a valid path to a template file, just as you would specify
in an ``@expose``.
:param content_type: a valid MIME type to use ... | [
"def",
"override_template",
"(",
"template",
",",
"content_type",
"=",
"None",
")",
":",
"request",
".",
"pecan",
"[",
"'override_template'",
"]",
"=",
"template",
"if",
"content_type",
":",
"request",
".",
"pecan",
"[",
"'override_content_type'",
"]",
"=",
"c... | Call within a controller to override the template that is used in
your response.
:param template: a valid path to a template file, just as you would specify
in an ``@expose``.
:param content_type: a valid MIME type to use for the response.func_closure | [
"Call",
"within",
"a",
"controller",
"to",
"override",
"the",
"template",
"that",
"is",
"used",
"in",
"your",
"response",
"."
] | 833d0653fa0e6bbfb52545b091c30182105f4a82 | https://github.com/pecan/pecan/blob/833d0653fa0e6bbfb52545b091c30182105f4a82/pecan/core.py#L98-L110 | train |
pecan/pecan | pecan/core.py | abort | def abort(status_code, detail='', headers=None, comment=None, **kw):
'''
Raise an HTTP status code, as specified. Useful for returning status
codes like 401 Unauthorized or 403 Forbidden.
:param status_code: The HTTP status code as an integer.
:param detail: The message to send along, as a string.
... | python | def abort(status_code, detail='', headers=None, comment=None, **kw):
'''
Raise an HTTP status code, as specified. Useful for returning status
codes like 401 Unauthorized or 403 Forbidden.
:param status_code: The HTTP status code as an integer.
:param detail: The message to send along, as a string.
... | [
"def",
"abort",
"(",
"status_code",
",",
"detail",
"=",
"''",
",",
"headers",
"=",
"None",
",",
"comment",
"=",
"None",
",",
"**",
"kw",
")",
":",
"try",
":",
"_",
",",
"_",
",",
"traceback",
"=",
"sys",
".",
"exc_info",
"(",
")",
"webob_exception"... | Raise an HTTP status code, as specified. Useful for returning status
codes like 401 Unauthorized or 403 Forbidden.
:param status_code: The HTTP status code as an integer.
:param detail: The message to send along, as a string.
:param headers: A dictionary of headers to send along with the response.
... | [
"Raise",
"an",
"HTTP",
"status",
"code",
"as",
"specified",
".",
"Useful",
"for",
"returning",
"status",
"codes",
"like",
"401",
"Unauthorized",
"or",
"403",
"Forbidden",
"."
] | 833d0653fa0e6bbfb52545b091c30182105f4a82 | https://github.com/pecan/pecan/blob/833d0653fa0e6bbfb52545b091c30182105f4a82/pecan/core.py#L113-L141 | train |
pecan/pecan | pecan/core.py | redirect | def redirect(location=None, internal=False, code=None, headers={},
add_slash=False, request=None):
'''
Perform a redirect, either internal or external. An internal redirect
performs the redirect server-side, while the external redirect utilizes
an HTTP 302 status code.
:param location:... | python | def redirect(location=None, internal=False, code=None, headers={},
add_slash=False, request=None):
'''
Perform a redirect, either internal or external. An internal redirect
performs the redirect server-side, while the external redirect utilizes
an HTTP 302 status code.
:param location:... | [
"def",
"redirect",
"(",
"location",
"=",
"None",
",",
"internal",
"=",
"False",
",",
"code",
"=",
"None",
",",
"headers",
"=",
"{",
"}",
",",
"add_slash",
"=",
"False",
",",
"request",
"=",
"None",
")",
":",
"request",
"=",
"request",
"or",
"state",
... | Perform a redirect, either internal or external. An internal redirect
performs the redirect server-side, while the external redirect utilizes
an HTTP 302 status code.
:param location: The HTTP location to redirect to.
:param internal: A boolean indicating whether the redirect should be
... | [
"Perform",
"a",
"redirect",
"either",
"internal",
"or",
"external",
".",
"An",
"internal",
"redirect",
"performs",
"the",
"redirect",
"server",
"-",
"side",
"while",
"the",
"external",
"redirect",
"utilizes",
"an",
"HTTP",
"302",
"status",
"code",
"."
] | 833d0653fa0e6bbfb52545b091c30182105f4a82 | https://github.com/pecan/pecan/blob/833d0653fa0e6bbfb52545b091c30182105f4a82/pecan/core.py#L144-L183 | train |
pecan/pecan | pecan/core.py | load_app | def load_app(config, **kwargs):
'''
Used to load a ``Pecan`` application and its environment based on passed
configuration.
:param config: Can be a dictionary containing configuration, a string which
represents a (relative) configuration filename
returns a pecan.Pecan object
... | python | def load_app(config, **kwargs):
'''
Used to load a ``Pecan`` application and its environment based on passed
configuration.
:param config: Can be a dictionary containing configuration, a string which
represents a (relative) configuration filename
returns a pecan.Pecan object
... | [
"def",
"load_app",
"(",
"config",
",",
"**",
"kwargs",
")",
":",
"from",
".",
"configuration",
"import",
"_runtime_conf",
",",
"set_config",
"set_config",
"(",
"config",
",",
"overwrite",
"=",
"True",
")",
"for",
"package_name",
"in",
"getattr",
"(",
"_runti... | Used to load a ``Pecan`` application and its environment based on passed
configuration.
:param config: Can be a dictionary containing configuration, a string which
represents a (relative) configuration filename
returns a pecan.Pecan object | [
"Used",
"to",
"load",
"a",
"Pecan",
"application",
"and",
"its",
"environment",
"based",
"on",
"passed",
"configuration",
"."
] | 833d0653fa0e6bbfb52545b091c30182105f4a82 | https://github.com/pecan/pecan/blob/833d0653fa0e6bbfb52545b091c30182105f4a82/pecan/core.py#L202-L223 | train |
pecan/pecan | pecan/core.py | PecanBase.route | def route(self, req, node, path):
'''
Looks up a controller from a node based upon the specified path.
:param node: The node, such as a root controller object.
:param path: The path to look up on this node.
'''
path = path.split('/')[1:]
try:
node, re... | python | def route(self, req, node, path):
'''
Looks up a controller from a node based upon the specified path.
:param node: The node, such as a root controller object.
:param path: The path to look up on this node.
'''
path = path.split('/')[1:]
try:
node, re... | [
"def",
"route",
"(",
"self",
",",
"req",
",",
"node",
",",
"path",
")",
":",
"path",
"=",
"path",
".",
"split",
"(",
"'/'",
")",
"[",
"1",
":",
"]",
"try",
":",
"node",
",",
"remainder",
"=",
"lookup_controller",
"(",
"node",
",",
"path",
",",
... | Looks up a controller from a node based upon the specified path.
:param node: The node, such as a root controller object.
:param path: The path to look up on this node. | [
"Looks",
"up",
"a",
"controller",
"from",
"a",
"node",
"based",
"upon",
"the",
"specified",
"path",
"."
] | 833d0653fa0e6bbfb52545b091c30182105f4a82 | https://github.com/pecan/pecan/blob/833d0653fa0e6bbfb52545b091c30182105f4a82/pecan/core.py#L284-L308 | train |
pecan/pecan | pecan/core.py | PecanBase.determine_hooks | def determine_hooks(self, controller=None):
'''
Determines the hooks to be run, in which order.
:param controller: If specified, includes hooks for a specific
controller.
'''
controller_hooks = []
if controller:
controller_hooks = ... | python | def determine_hooks(self, controller=None):
'''
Determines the hooks to be run, in which order.
:param controller: If specified, includes hooks for a specific
controller.
'''
controller_hooks = []
if controller:
controller_hooks = ... | [
"def",
"determine_hooks",
"(",
"self",
",",
"controller",
"=",
"None",
")",
":",
"controller_hooks",
"=",
"[",
"]",
"if",
"controller",
":",
"controller_hooks",
"=",
"_cfg",
"(",
"controller",
")",
".",
"get",
"(",
"'hooks'",
",",
"[",
"]",
")",
"if",
... | Determines the hooks to be run, in which order.
:param controller: If specified, includes hooks for a specific
controller. | [
"Determines",
"the",
"hooks",
"to",
"be",
"run",
"in",
"which",
"order",
"."
] | 833d0653fa0e6bbfb52545b091c30182105f4a82 | https://github.com/pecan/pecan/blob/833d0653fa0e6bbfb52545b091c30182105f4a82/pecan/core.py#L310-L328 | train |
pecan/pecan | pecan/core.py | PecanBase.handle_hooks | def handle_hooks(self, hooks, hook_type, *args):
'''
Processes hooks of the specified type.
:param hook_type: The type of hook, including ``before``, ``after``,
``on_error``, and ``on_route``.
:param \*args: Arguments to pass to the hooks.
'''
i... | python | def handle_hooks(self, hooks, hook_type, *args):
'''
Processes hooks of the specified type.
:param hook_type: The type of hook, including ``before``, ``after``,
``on_error``, and ``on_route``.
:param \*args: Arguments to pass to the hooks.
'''
i... | [
"def",
"handle_hooks",
"(",
"self",
",",
"hooks",
",",
"hook_type",
",",
"*",
"args",
")",
":",
"if",
"hook_type",
"not",
"in",
"[",
"'before'",
",",
"'on_route'",
"]",
":",
"hooks",
"=",
"reversed",
"(",
"hooks",
")",
"for",
"hook",
"in",
"hooks",
"... | Processes hooks of the specified type.
:param hook_type: The type of hook, including ``before``, ``after``,
``on_error``, and ``on_route``.
:param \*args: Arguments to pass to the hooks. | [
"Processes",
"hooks",
"of",
"the",
"specified",
"type",
"."
] | 833d0653fa0e6bbfb52545b091c30182105f4a82 | https://github.com/pecan/pecan/blob/833d0653fa0e6bbfb52545b091c30182105f4a82/pecan/core.py#L330-L346 | train |
pecan/pecan | pecan/core.py | PecanBase.get_args | def get_args(self, state, all_params, remainder, argspec, im_self):
'''
Determines the arguments for a controller based upon parameters
passed the argument specification for the controller.
'''
args = []
varargs = []
kwargs = dict()
valid_args = argspec.ar... | python | def get_args(self, state, all_params, remainder, argspec, im_self):
'''
Determines the arguments for a controller based upon parameters
passed the argument specification for the controller.
'''
args = []
varargs = []
kwargs = dict()
valid_args = argspec.ar... | [
"def",
"get_args",
"(",
"self",
",",
"state",
",",
"all_params",
",",
"remainder",
",",
"argspec",
",",
"im_self",
")",
":",
"args",
"=",
"[",
"]",
"varargs",
"=",
"[",
"]",
"kwargs",
"=",
"dict",
"(",
")",
"valid_args",
"=",
"argspec",
".",
"args",
... | Determines the arguments for a controller based upon parameters
passed the argument specification for the controller. | [
"Determines",
"the",
"arguments",
"for",
"a",
"controller",
"based",
"upon",
"parameters",
"passed",
"the",
"argument",
"specification",
"for",
"the",
"controller",
"."
] | 833d0653fa0e6bbfb52545b091c30182105f4a82 | https://github.com/pecan/pecan/blob/833d0653fa0e6bbfb52545b091c30182105f4a82/pecan/core.py#L348-L404 | train |
pecan/pecan | pecan/commands/shell.py | ShellCommand.run | def run(self, args):
"""
Load the pecan app, prepare the locals, sets the
banner, and invokes the python shell.
"""
super(ShellCommand, self).run(args)
# load the application
app = self.load_app()
# prepare the locals
locs = dict(__name__='pecan-... | python | def run(self, args):
"""
Load the pecan app, prepare the locals, sets the
banner, and invokes the python shell.
"""
super(ShellCommand, self).run(args)
# load the application
app = self.load_app()
# prepare the locals
locs = dict(__name__='pecan-... | [
"def",
"run",
"(",
"self",
",",
"args",
")",
":",
"super",
"(",
"ShellCommand",
",",
"self",
")",
".",
"run",
"(",
"args",
")",
"app",
"=",
"self",
".",
"load_app",
"(",
")",
"locs",
"=",
"dict",
"(",
"__name__",
"=",
"'pecan-admin'",
")",
"locs",
... | Load the pecan app, prepare the locals, sets the
banner, and invokes the python shell. | [
"Load",
"the",
"pecan",
"app",
"prepare",
"the",
"locals",
"sets",
"the",
"banner",
"and",
"invokes",
"the",
"python",
"shell",
"."
] | 833d0653fa0e6bbfb52545b091c30182105f4a82 | https://github.com/pecan/pecan/blob/833d0653fa0e6bbfb52545b091c30182105f4a82/pecan/commands/shell.py#L108-L148 | train |
pecan/pecan | pecan/commands/shell.py | ShellCommand.load_model | def load_model(self, config):
"""
Load the model extension module
"""
for package_name in getattr(config.app, 'modules', []):
module = __import__(package_name, fromlist=['model'])
if hasattr(module, 'model'):
return module.model
return None | python | def load_model(self, config):
"""
Load the model extension module
"""
for package_name in getattr(config.app, 'modules', []):
module = __import__(package_name, fromlist=['model'])
if hasattr(module, 'model'):
return module.model
return None | [
"def",
"load_model",
"(",
"self",
",",
"config",
")",
":",
"for",
"package_name",
"in",
"getattr",
"(",
"config",
".",
"app",
",",
"'modules'",
",",
"[",
"]",
")",
":",
"module",
"=",
"__import__",
"(",
"package_name",
",",
"fromlist",
"=",
"[",
"'mode... | Load the model extension module | [
"Load",
"the",
"model",
"extension",
"module"
] | 833d0653fa0e6bbfb52545b091c30182105f4a82 | https://github.com/pecan/pecan/blob/833d0653fa0e6bbfb52545b091c30182105f4a82/pecan/commands/shell.py#L169-L177 | train |
pecan/pecan | pecan/rest.py | RestController._handle_bad_rest_arguments | def _handle_bad_rest_arguments(self, controller, remainder, request):
"""
Ensure that the argspec for a discovered controller actually matched
the positional arguments in the request path. If not, raise
a webob.exc.HTTPBadRequest.
"""
argspec = self._get_args_for_control... | python | def _handle_bad_rest_arguments(self, controller, remainder, request):
"""
Ensure that the argspec for a discovered controller actually matched
the positional arguments in the request path. If not, raise
a webob.exc.HTTPBadRequest.
"""
argspec = self._get_args_for_control... | [
"def",
"_handle_bad_rest_arguments",
"(",
"self",
",",
"controller",
",",
"remainder",
",",
"request",
")",
":",
"argspec",
"=",
"self",
".",
"_get_args_for_controller",
"(",
"controller",
")",
"fixed_args",
"=",
"len",
"(",
"argspec",
")",
"-",
"len",
"(",
... | Ensure that the argspec for a discovered controller actually matched
the positional arguments in the request path. If not, raise
a webob.exc.HTTPBadRequest. | [
"Ensure",
"that",
"the",
"argspec",
"for",
"a",
"discovered",
"controller",
"actually",
"matched",
"the",
"positional",
"arguments",
"in",
"the",
"request",
"path",
".",
"If",
"not",
"raise",
"a",
"webob",
".",
"exc",
".",
"HTTPBadRequest",
"."
] | 833d0653fa0e6bbfb52545b091c30182105f4a82 | https://github.com/pecan/pecan/blob/833d0653fa0e6bbfb52545b091c30182105f4a82/pecan/rest.py#L75-L89 | train |
pecan/pecan | pecan/rest.py | RestController._route | def _route(self, args, request=None):
'''
Routes a request to the appropriate controller and returns its result.
Performs a bit of validation - refuses to route delete and put actions
via a GET request).
'''
if request is None:
from pecan import request
... | python | def _route(self, args, request=None):
'''
Routes a request to the appropriate controller and returns its result.
Performs a bit of validation - refuses to route delete and put actions
via a GET request).
'''
if request is None:
from pecan import request
... | [
"def",
"_route",
"(",
"self",
",",
"args",
",",
"request",
"=",
"None",
")",
":",
"if",
"request",
"is",
"None",
":",
"from",
"pecan",
"import",
"request",
"method",
"=",
"request",
".",
"params",
".",
"get",
"(",
"'_method'",
",",
"request",
".",
"m... | Routes a request to the appropriate controller and returns its result.
Performs a bit of validation - refuses to route delete and put actions
via a GET request). | [
"Routes",
"a",
"request",
"to",
"the",
"appropriate",
"controller",
"and",
"returns",
"its",
"result",
"."
] | 833d0653fa0e6bbfb52545b091c30182105f4a82 | https://github.com/pecan/pecan/blob/833d0653fa0e6bbfb52545b091c30182105f4a82/pecan/rest.py#L103-L178 | train |
pecan/pecan | pecan/rest.py | RestController._find_controller | def _find_controller(self, *args):
'''
Returns the appropriate controller for routing a custom action.
'''
for name in args:
obj = self._lookup_child(name)
if obj and iscontroller(obj):
return obj
return None | python | def _find_controller(self, *args):
'''
Returns the appropriate controller for routing a custom action.
'''
for name in args:
obj = self._lookup_child(name)
if obj and iscontroller(obj):
return obj
return None | [
"def",
"_find_controller",
"(",
"self",
",",
"*",
"args",
")",
":",
"for",
"name",
"in",
"args",
":",
"obj",
"=",
"self",
".",
"_lookup_child",
"(",
"name",
")",
"if",
"obj",
"and",
"iscontroller",
"(",
"obj",
")",
":",
"return",
"obj",
"return",
"No... | Returns the appropriate controller for routing a custom action. | [
"Returns",
"the",
"appropriate",
"controller",
"for",
"routing",
"a",
"custom",
"action",
"."
] | 833d0653fa0e6bbfb52545b091c30182105f4a82 | https://github.com/pecan/pecan/blob/833d0653fa0e6bbfb52545b091c30182105f4a82/pecan/rest.py#L195-L203 | train |
pecan/pecan | pecan/rest.py | RestController._find_sub_controllers | def _find_sub_controllers(self, remainder, request):
'''
Identifies the correct controller to route to by analyzing the
request URI.
'''
# need either a get_one or get to parse args
method = None
for name in ('get_one', 'get'):
if hasattr(self, name):
... | python | def _find_sub_controllers(self, remainder, request):
'''
Identifies the correct controller to route to by analyzing the
request URI.
'''
# need either a get_one or get to parse args
method = None
for name in ('get_one', 'get'):
if hasattr(self, name):
... | [
"def",
"_find_sub_controllers",
"(",
"self",
",",
"remainder",
",",
"request",
")",
":",
"method",
"=",
"None",
"for",
"name",
"in",
"(",
"'get_one'",
",",
"'get'",
")",
":",
"if",
"hasattr",
"(",
"self",
",",
"name",
")",
":",
"method",
"=",
"name",
... | Identifies the correct controller to route to by analyzing the
request URI. | [
"Identifies",
"the",
"correct",
"controller",
"to",
"route",
"to",
"by",
"analyzing",
"the",
"request",
"URI",
"."
] | 833d0653fa0e6bbfb52545b091c30182105f4a82 | https://github.com/pecan/pecan/blob/833d0653fa0e6bbfb52545b091c30182105f4a82/pecan/rest.py#L205-L244 | train |
pecan/pecan | pecan/rest.py | RestController._handle_get | def _handle_get(self, method, remainder, request=None):
'''
Routes ``GET`` actions to the appropriate controller.
'''
if request is None:
self._raise_method_deprecation_warning(self._handle_get)
# route to a get_all or get if no additional parts are available
... | python | def _handle_get(self, method, remainder, request=None):
'''
Routes ``GET`` actions to the appropriate controller.
'''
if request is None:
self._raise_method_deprecation_warning(self._handle_get)
# route to a get_all or get if no additional parts are available
... | [
"def",
"_handle_get",
"(",
"self",
",",
"method",
",",
"remainder",
",",
"request",
"=",
"None",
")",
":",
"if",
"request",
"is",
"None",
":",
"self",
".",
"_raise_method_deprecation_warning",
"(",
"self",
".",
"_handle_get",
")",
"if",
"not",
"remainder",
... | Routes ``GET`` actions to the appropriate controller. | [
"Routes",
"GET",
"actions",
"to",
"the",
"appropriate",
"controller",
"."
] | 833d0653fa0e6bbfb52545b091c30182105f4a82 | https://github.com/pecan/pecan/blob/833d0653fa0e6bbfb52545b091c30182105f4a82/pecan/rest.py#L270-L309 | train |
pecan/pecan | pecan/rest.py | RestController._handle_delete | def _handle_delete(self, method, remainder, request=None):
'''
Routes ``DELETE`` actions to the appropriate controller.
'''
if request is None:
self._raise_method_deprecation_warning(self._handle_delete)
if remainder:
match = self._handle_custom_action(me... | python | def _handle_delete(self, method, remainder, request=None):
'''
Routes ``DELETE`` actions to the appropriate controller.
'''
if request is None:
self._raise_method_deprecation_warning(self._handle_delete)
if remainder:
match = self._handle_custom_action(me... | [
"def",
"_handle_delete",
"(",
"self",
",",
"method",
",",
"remainder",
",",
"request",
"=",
"None",
")",
":",
"if",
"request",
"is",
"None",
":",
"self",
".",
"_raise_method_deprecation_warning",
"(",
"self",
".",
"_handle_delete",
")",
"if",
"remainder",
":... | Routes ``DELETE`` actions to the appropriate controller. | [
"Routes",
"DELETE",
"actions",
"to",
"the",
"appropriate",
"controller",
"."
] | 833d0653fa0e6bbfb52545b091c30182105f4a82 | https://github.com/pecan/pecan/blob/833d0653fa0e6bbfb52545b091c30182105f4a82/pecan/rest.py#L311-L342 | train |
pecan/pecan | pecan/rest.py | RestController._handle_post | def _handle_post(self, method, remainder, request=None):
'''
Routes ``POST`` requests.
'''
if request is None:
self._raise_method_deprecation_warning(self._handle_post)
# check for custom POST/PUT requests
if remainder:
match = self._handle_custom... | python | def _handle_post(self, method, remainder, request=None):
'''
Routes ``POST`` requests.
'''
if request is None:
self._raise_method_deprecation_warning(self._handle_post)
# check for custom POST/PUT requests
if remainder:
match = self._handle_custom... | [
"def",
"_handle_post",
"(",
"self",
",",
"method",
",",
"remainder",
",",
"request",
"=",
"None",
")",
":",
"if",
"request",
"is",
"None",
":",
"self",
".",
"_raise_method_deprecation_warning",
"(",
"self",
".",
"_handle_post",
")",
"if",
"remainder",
":",
... | Routes ``POST`` requests. | [
"Routes",
"POST",
"requests",
"."
] | 833d0653fa0e6bbfb52545b091c30182105f4a82 | https://github.com/pecan/pecan/blob/833d0653fa0e6bbfb52545b091c30182105f4a82/pecan/rest.py#L344-L366 | train |
pecan/pecan | pecan/templating.py | format_line_context | def format_line_context(filename, lineno, context=10):
'''
Formats the the line context for error rendering.
:param filename: the location of the file, within which the error occurred
:param lineno: the offending line number
:param context: number of lines of code to display before and after the
... | python | def format_line_context(filename, lineno, context=10):
'''
Formats the the line context for error rendering.
:param filename: the location of the file, within which the error occurred
:param lineno: the offending line number
:param context: number of lines of code to display before and after the
... | [
"def",
"format_line_context",
"(",
"filename",
",",
"lineno",
",",
"context",
"=",
"10",
")",
":",
"with",
"open",
"(",
"filename",
")",
"as",
"f",
":",
"lines",
"=",
"f",
".",
"readlines",
"(",
")",
"lineno",
"=",
"lineno",
"-",
"1",
"if",
"lineno",... | Formats the the line context for error rendering.
:param filename: the location of the file, within which the error occurred
:param lineno: the offending line number
:param context: number of lines of code to display before and after the
offending line. | [
"Formats",
"the",
"the",
"line",
"context",
"for",
"error",
"rendering",
"."
] | 833d0653fa0e6bbfb52545b091c30182105f4a82 | https://github.com/pecan/pecan/blob/833d0653fa0e6bbfb52545b091c30182105f4a82/pecan/templating.py#L183-L207 | train |
pecan/pecan | pecan/templating.py | ExtraNamespace.make_ns | def make_ns(self, ns):
'''
Returns the `lazily` created template namespace.
'''
if self.namespace:
val = {}
val.update(self.namespace)
val.update(ns)
return val
else:
return ns | python | def make_ns(self, ns):
'''
Returns the `lazily` created template namespace.
'''
if self.namespace:
val = {}
val.update(self.namespace)
val.update(ns)
return val
else:
return ns | [
"def",
"make_ns",
"(",
"self",
",",
"ns",
")",
":",
"if",
"self",
".",
"namespace",
":",
"val",
"=",
"{",
"}",
"val",
".",
"update",
"(",
"self",
".",
"namespace",
")",
"val",
".",
"update",
"(",
"ns",
")",
"return",
"val",
"else",
":",
"return",... | Returns the `lazily` created template namespace. | [
"Returns",
"the",
"lazily",
"created",
"template",
"namespace",
"."
] | 833d0653fa0e6bbfb52545b091c30182105f4a82 | https://github.com/pecan/pecan/blob/833d0653fa0e6bbfb52545b091c30182105f4a82/pecan/templating.py#L229-L239 | train |
pecan/pecan | pecan/templating.py | RendererFactory.get | def get(self, name, template_path):
'''
Returns the renderer object.
:param name: name of the requested renderer
:param template_path: path to the template
'''
if name not in self._renderers:
cls = self._renderer_classes.get(name)
if cls is None:
... | python | def get(self, name, template_path):
'''
Returns the renderer object.
:param name: name of the requested renderer
:param template_path: path to the template
'''
if name not in self._renderers:
cls = self._renderer_classes.get(name)
if cls is None:
... | [
"def",
"get",
"(",
"self",
",",
"name",
",",
"template_path",
")",
":",
"if",
"name",
"not",
"in",
"self",
".",
"_renderers",
":",
"cls",
"=",
"self",
".",
"_renderer_classes",
".",
"get",
"(",
"name",
")",
"if",
"cls",
"is",
"None",
":",
"return",
... | Returns the renderer object.
:param name: name of the requested renderer
:param template_path: path to the template | [
"Returns",
"the",
"renderer",
"object",
"."
] | 833d0653fa0e6bbfb52545b091c30182105f4a82 | https://github.com/pecan/pecan/blob/833d0653fa0e6bbfb52545b091c30182105f4a82/pecan/templating.py#L274-L287 | train |
pecan/pecan | pecan/jsonify.py | GenericJSON.default | def default(self, obj):
'''
Converts an object and returns a ``JSON``-friendly structure.
:param obj: object or structure to be converted into a
``JSON``-ifiable structure
Considers the following special cases in order:
* object has a callable __json__() at... | python | def default(self, obj):
'''
Converts an object and returns a ``JSON``-friendly structure.
:param obj: object or structure to be converted into a
``JSON``-ifiable structure
Considers the following special cases in order:
* object has a callable __json__() at... | [
"def",
"default",
"(",
"self",
",",
"obj",
")",
":",
"if",
"hasattr",
"(",
"obj",
",",
"'__json__'",
")",
"and",
"six",
".",
"callable",
"(",
"obj",
".",
"__json__",
")",
":",
"return",
"obj",
".",
"__json__",
"(",
")",
"elif",
"isinstance",
"(",
"... | Converts an object and returns a ``JSON``-friendly structure.
:param obj: object or structure to be converted into a
``JSON``-ifiable structure
Considers the following special cases in order:
* object has a callable __json__() attribute defined
returns the resu... | [
"Converts",
"an",
"object",
"and",
"returns",
"a",
"JSON",
"-",
"friendly",
"structure",
"."
] | 833d0653fa0e6bbfb52545b091c30182105f4a82 | https://github.com/pecan/pecan/blob/833d0653fa0e6bbfb52545b091c30182105f4a82/pecan/jsonify.py#L49-L108 | train |
pecan/pecan | pecan/util.py | getargspec | def getargspec(method):
"""
Drill through layers of decorators attempting to locate the actual argspec
for a method.
"""
argspec = _getargspec(method)
args = argspec[0]
if args and args[0] == 'self':
return argspec
if hasattr(method, '__func__'):
method = method.__func__... | python | def getargspec(method):
"""
Drill through layers of decorators attempting to locate the actual argspec
for a method.
"""
argspec = _getargspec(method)
args = argspec[0]
if args and args[0] == 'self':
return argspec
if hasattr(method, '__func__'):
method = method.__func__... | [
"def",
"getargspec",
"(",
"method",
")",
":",
"argspec",
"=",
"_getargspec",
"(",
"method",
")",
"args",
"=",
"argspec",
"[",
"0",
"]",
"if",
"args",
"and",
"args",
"[",
"0",
"]",
"==",
"'self'",
":",
"return",
"argspec",
"if",
"hasattr",
"(",
"metho... | Drill through layers of decorators attempting to locate the actual argspec
for a method. | [
"Drill",
"through",
"layers",
"of",
"decorators",
"attempting",
"to",
"locate",
"the",
"actual",
"argspec",
"for",
"a",
"method",
"."
] | 833d0653fa0e6bbfb52545b091c30182105f4a82 | https://github.com/pecan/pecan/blob/833d0653fa0e6bbfb52545b091c30182105f4a82/pecan/util.py#L12-L54 | train |
pecan/pecan | pecan/commands/serve.py | gunicorn_run | def gunicorn_run():
"""
The ``gunicorn_pecan`` command for launching ``pecan`` applications
"""
try:
from gunicorn.app.wsgiapp import WSGIApplication
except ImportError as exc:
args = exc.args
arg0 = args[0] if args else ''
arg0 += ' (are you sure `gunicorn` is instal... | python | def gunicorn_run():
"""
The ``gunicorn_pecan`` command for launching ``pecan`` applications
"""
try:
from gunicorn.app.wsgiapp import WSGIApplication
except ImportError as exc:
args = exc.args
arg0 = args[0] if args else ''
arg0 += ' (are you sure `gunicorn` is instal... | [
"def",
"gunicorn_run",
"(",
")",
":",
"try",
":",
"from",
"gunicorn",
".",
"app",
".",
"wsgiapp",
"import",
"WSGIApplication",
"except",
"ImportError",
"as",
"exc",
":",
"args",
"=",
"exc",
".",
"args",
"arg0",
"=",
"args",
"[",
"0",
"]",
"if",
"args",... | The ``gunicorn_pecan`` command for launching ``pecan`` applications | [
"The",
"gunicorn_pecan",
"command",
"for",
"launching",
"pecan",
"applications"
] | 833d0653fa0e6bbfb52545b091c30182105f4a82 | https://github.com/pecan/pecan/blob/833d0653fa0e6bbfb52545b091c30182105f4a82/pecan/commands/serve.py#L155-L198 | train |
pecan/pecan | pecan/commands/serve.py | ServeCommand.serve | def serve(self, app, conf):
"""
A very simple approach for a WSGI server.
"""
if self.args.reload:
try:
self.watch_and_spawn(conf)
except ImportError:
print('The `--reload` option requires `watchdog` to be '
'... | python | def serve(self, app, conf):
"""
A very simple approach for a WSGI server.
"""
if self.args.reload:
try:
self.watch_and_spawn(conf)
except ImportError:
print('The `--reload` option requires `watchdog` to be '
'... | [
"def",
"serve",
"(",
"self",
",",
"app",
",",
"conf",
")",
":",
"if",
"self",
".",
"args",
".",
"reload",
":",
"try",
":",
"self",
".",
"watch_and_spawn",
"(",
"conf",
")",
"except",
"ImportError",
":",
"print",
"(",
"'The `--reload` option requires `watch... | A very simple approach for a WSGI server. | [
"A",
"very",
"simple",
"approach",
"for",
"a",
"WSGI",
"server",
"."
] | 833d0653fa0e6bbfb52545b091c30182105f4a82 | https://github.com/pecan/pecan/blob/833d0653fa0e6bbfb52545b091c30182105f4a82/pecan/commands/serve.py#L139-L152 | train |
pecan/pecan | pecan/commands/serve.py | PecanWSGIRequestHandler.log_message | def log_message(self, format, *args):
"""
overrides the ``log_message`` method from the wsgiref server so that
normal logging works with whatever configuration the application has
been set to.
Levels are inferred from the HTTP status code, 4XX codes are treated as
warnin... | python | def log_message(self, format, *args):
"""
overrides the ``log_message`` method from the wsgiref server so that
normal logging works with whatever configuration the application has
been set to.
Levels are inferred from the HTTP status code, 4XX codes are treated as
warnin... | [
"def",
"log_message",
"(",
"self",
",",
"format",
",",
"*",
"args",
")",
":",
"code",
"=",
"args",
"[",
"1",
"]",
"[",
"0",
"]",
"levels",
"=",
"{",
"'4'",
":",
"'warning'",
",",
"'5'",
":",
"'error'",
"}",
"log_handler",
"=",
"getattr",
"(",
"lo... | overrides the ``log_message`` method from the wsgiref server so that
normal logging works with whatever configuration the application has
been set to.
Levels are inferred from the HTTP status code, 4XX codes are treated as
warnings, 5XX as errors and everything else as INFO level. | [
"overrides",
"the",
"log_message",
"method",
"from",
"the",
"wsgiref",
"server",
"so",
"that",
"normal",
"logging",
"works",
"with",
"whatever",
"configuration",
"the",
"application",
"has",
"been",
"set",
"to",
"."
] | 833d0653fa0e6bbfb52545b091c30182105f4a82 | https://github.com/pecan/pecan/blob/833d0653fa0e6bbfb52545b091c30182105f4a82/pecan/commands/serve.py#L213-L229 | train |
pecan/pecan | pecan/decorators.py | expose | def expose(template=None,
generic=False,
route=None,
**kw):
'''
Decorator used to flag controller methods as being "exposed" for
access via HTTP, and to configure that access.
:param template: The path to a template, relative to the base template
d... | python | def expose(template=None,
generic=False,
route=None,
**kw):
'''
Decorator used to flag controller methods as being "exposed" for
access via HTTP, and to configure that access.
:param template: The path to a template, relative to the base template
d... | [
"def",
"expose",
"(",
"template",
"=",
"None",
",",
"generic",
"=",
"False",
",",
"route",
"=",
"None",
",",
"**",
"kw",
")",
":",
"content_type",
"=",
"kw",
".",
"get",
"(",
"'content_type'",
",",
"'text/html'",
")",
"if",
"template",
"==",
"'json'",
... | Decorator used to flag controller methods as being "exposed" for
access via HTTP, and to configure that access.
:param template: The path to a template, relative to the base template
directory. Can also be passed a string representing
a special or custom renderer, suc... | [
"Decorator",
"used",
"to",
"flag",
"controller",
"methods",
"as",
"being",
"exposed",
"for",
"access",
"via",
"HTTP",
"and",
"to",
"configure",
"that",
"access",
"."
] | 833d0653fa0e6bbfb52545b091c30182105f4a82 | https://github.com/pecan/pecan/blob/833d0653fa0e6bbfb52545b091c30182105f4a82/pecan/decorators.py#L25-L95 | train |
craft-ai/craft-ai-client-python | craftai/time.py | Time.to_dict | def to_dict(self):
"""Returns the Time instance as a usable dictionary for craftai"""
return {
"timestamp": int(self.timestamp),
"timezone": self.timezone,
"time_of_day": self.time_of_day,
"day_of_week": self.day_of_week,
"day_of_month": self.day_of_month,
"month_of_year": se... | python | def to_dict(self):
"""Returns the Time instance as a usable dictionary for craftai"""
return {
"timestamp": int(self.timestamp),
"timezone": self.timezone,
"time_of_day": self.time_of_day,
"day_of_week": self.day_of_week,
"day_of_month": self.day_of_month,
"month_of_year": se... | [
"def",
"to_dict",
"(",
"self",
")",
":",
"return",
"{",
"\"timestamp\"",
":",
"int",
"(",
"self",
".",
"timestamp",
")",
",",
"\"timezone\"",
":",
"self",
".",
"timezone",
",",
"\"time_of_day\"",
":",
"self",
".",
"time_of_day",
",",
"\"day_of_week\"",
":"... | Returns the Time instance as a usable dictionary for craftai | [
"Returns",
"the",
"Time",
"instance",
"as",
"a",
"usable",
"dictionary",
"for",
"craftai"
] | 8bc1a9038511540930371aacfdde0f4040e08f24 | https://github.com/craft-ai/craft-ai-client-python/blob/8bc1a9038511540930371aacfdde0f4040e08f24/craftai/time.py#L138-L148 | train |
craft-ai/craft-ai-client-python | craftai/time.py | Time.timestamp_from_datetime | def timestamp_from_datetime(date_time):
"""Returns POSIX timestamp as float"""
if date_time.tzinfo is None:
return time.mktime((date_time.year, date_time.month, date_time.day, date_time.hour,
date_time.minute, date_time.second,
-1, -1, -1)) + date_time.m... | python | def timestamp_from_datetime(date_time):
"""Returns POSIX timestamp as float"""
if date_time.tzinfo is None:
return time.mktime((date_time.year, date_time.month, date_time.day, date_time.hour,
date_time.minute, date_time.second,
-1, -1, -1)) + date_time.m... | [
"def",
"timestamp_from_datetime",
"(",
"date_time",
")",
":",
"if",
"date_time",
".",
"tzinfo",
"is",
"None",
":",
"return",
"time",
".",
"mktime",
"(",
"(",
"date_time",
".",
"year",
",",
"date_time",
".",
"month",
",",
"date_time",
".",
"day",
",",
"da... | Returns POSIX timestamp as float | [
"Returns",
"POSIX",
"timestamp",
"as",
"float"
] | 8bc1a9038511540930371aacfdde0f4040e08f24 | https://github.com/craft-ai/craft-ai-client-python/blob/8bc1a9038511540930371aacfdde0f4040e08f24/craftai/time.py#L151-L157 | train |
craft-ai/craft-ai-client-python | craftai/client.py | CraftAIClient.create_agent | def create_agent(self, configuration, agent_id=""):
"""Create an agent.
:param dict configuration: Form given by the craftai documentation.
:param str agent_id: Optional. The id of the agent to create. It
must be an str containing only characters in "a-zA-Z0-9_-" and
must be between 1 and 36 charac... | python | def create_agent(self, configuration, agent_id=""):
"""Create an agent.
:param dict configuration: Form given by the craftai documentation.
:param str agent_id: Optional. The id of the agent to create. It
must be an str containing only characters in "a-zA-Z0-9_-" and
must be between 1 and 36 charac... | [
"def",
"create_agent",
"(",
"self",
",",
"configuration",
",",
"agent_id",
"=",
"\"\"",
")",
":",
"ct_header",
"=",
"{",
"\"Content-Type\"",
":",
"\"application/json; charset=utf-8\"",
"}",
"payload",
"=",
"{",
"\"configuration\"",
":",
"configuration",
"}",
"if",... | Create an agent.
:param dict configuration: Form given by the craftai documentation.
:param str agent_id: Optional. The id of the agent to create. It
must be an str containing only characters in "a-zA-Z0-9_-" and
must be between 1 and 36 characters.
:default agent_id: "", the agent_id is generated.... | [
"Create",
"an",
"agent",
"."
] | 8bc1a9038511540930371aacfdde0f4040e08f24 | https://github.com/craft-ai/craft-ai-client-python/blob/8bc1a9038511540930371aacfdde0f4040e08f24/craftai/client.py#L112-L151 | train |
craft-ai/craft-ai-client-python | craftai/client.py | CraftAIClient.delete_agent | def delete_agent(self, agent_id):
"""Delete an agent.
:param str agent_id: The id of the agent to delete. It must
be an str containing only characters in "a-zA-Z0-9_-" and
must be between 1 and 36 characters.
:return: agent deleted.
:rtype: dict.
"""
# Raises an error when agent_id is ... | python | def delete_agent(self, agent_id):
"""Delete an agent.
:param str agent_id: The id of the agent to delete. It must
be an str containing only characters in "a-zA-Z0-9_-" and
must be between 1 and 36 characters.
:return: agent deleted.
:rtype: dict.
"""
# Raises an error when agent_id is ... | [
"def",
"delete_agent",
"(",
"self",
",",
"agent_id",
")",
":",
"self",
".",
"_check_agent_id",
"(",
"agent_id",
")",
"req_url",
"=",
"\"{}/agents/{}\"",
".",
"format",
"(",
"self",
".",
"_base_url",
",",
"agent_id",
")",
"resp",
"=",
"self",
".",
"_request... | Delete an agent.
:param str agent_id: The id of the agent to delete. It must
be an str containing only characters in "a-zA-Z0-9_-" and
must be between 1 and 36 characters.
:return: agent deleted.
:rtype: dict. | [
"Delete",
"an",
"agent",
"."
] | 8bc1a9038511540930371aacfdde0f4040e08f24 | https://github.com/craft-ai/craft-ai-client-python/blob/8bc1a9038511540930371aacfdde0f4040e08f24/craftai/client.py#L205-L223 | train |
craft-ai/craft-ai-client-python | craftai/client.py | CraftAIClient.delete_agents_bulk | def delete_agents_bulk(self, payload):
"""Delete a group of agents
:param list payload: Contains the informations to delete the agents.
It's in the form [{"id": agent_id}].
With id an str containing only characters in "a-zA-Z0-9_-" and must
be between 1 and 36 characters.
:return: the list of ... | python | def delete_agents_bulk(self, payload):
"""Delete a group of agents
:param list payload: Contains the informations to delete the agents.
It's in the form [{"id": agent_id}].
With id an str containing only characters in "a-zA-Z0-9_-" and must
be between 1 and 36 characters.
:return: the list of ... | [
"def",
"delete_agents_bulk",
"(",
"self",
",",
"payload",
")",
":",
"valid_indices",
",",
"invalid_indices",
",",
"invalid_agents",
"=",
"self",
".",
"_check_agent_id_bulk",
"(",
"payload",
")",
"valid_agents",
"=",
"self",
".",
"_create_and_send_json_bulk",
"(",
... | Delete a group of agents
:param list payload: Contains the informations to delete the agents.
It's in the form [{"id": agent_id}].
With id an str containing only characters in "a-zA-Z0-9_-" and must
be between 1 and 36 characters.
:return: the list of agents deleted which are represented with
... | [
"Delete",
"a",
"group",
"of",
"agents"
] | 8bc1a9038511540930371aacfdde0f4040e08f24 | https://github.com/craft-ai/craft-ai-client-python/blob/8bc1a9038511540930371aacfdde0f4040e08f24/craftai/client.py#L225-L254 | train |
craft-ai/craft-ai-client-python | craftai/client.py | CraftAIClient.add_operations | def add_operations(self, agent_id, operations):
"""Add operations to an agent.
:param str agent_id: The id of the agent to delete. It must be
an str containing only characters in "a-zA-Z0-9_-" and must be
between 1 and 36 characters. It must referenced an existing agent.
:param list operations: Con... | python | def add_operations(self, agent_id, operations):
"""Add operations to an agent.
:param str agent_id: The id of the agent to delete. It must be
an str containing only characters in "a-zA-Z0-9_-" and must be
between 1 and 36 characters. It must referenced an existing agent.
:param list operations: Con... | [
"def",
"add_operations",
"(",
"self",
",",
"agent_id",
",",
"operations",
")",
":",
"self",
".",
"_check_agent_id",
"(",
"agent_id",
")",
"ct_header",
"=",
"{",
"\"Content-Type\"",
":",
"\"application/json; charset=utf-8\"",
"}",
"offset",
"=",
"0",
"is_looping",
... | Add operations to an agent.
:param str agent_id: The id of the agent to delete. It must be
an str containing only characters in "a-zA-Z0-9_-" and must be
between 1 and 36 characters. It must referenced an existing agent.
:param list operations: Contains dictionnaries that has the
form given in the ... | [
"Add",
"operations",
"to",
"an",
"agent",
"."
] | 8bc1a9038511540930371aacfdde0f4040e08f24 | https://github.com/craft-ai/craft-ai-client-python/blob/8bc1a9038511540930371aacfdde0f4040e08f24/craftai/client.py#L285-L331 | train |
craft-ai/craft-ai-client-python | craftai/client.py | CraftAIClient._add_operations_bulk | def _add_operations_bulk(self, chunked_data):
"""Tool for the function add_operations_bulk. It send the requests to
add the operations to the agents.
:param list chunked_data: list of list of the agents and their operations
to add. Each chunk can be requested at the same time.
:return: list of age... | python | def _add_operations_bulk(self, chunked_data):
"""Tool for the function add_operations_bulk. It send the requests to
add the operations to the agents.
:param list chunked_data: list of list of the agents and their operations
to add. Each chunk can be requested at the same time.
:return: list of age... | [
"def",
"_add_operations_bulk",
"(",
"self",
",",
"chunked_data",
")",
":",
"url",
"=",
"\"{}/bulk/context\"",
".",
"format",
"(",
"self",
".",
"_base_url",
")",
"ct_header",
"=",
"{",
"\"Content-Type\"",
":",
"\"application/json; charset=utf-8\"",
"}",
"responses",
... | Tool for the function add_operations_bulk. It send the requests to
add the operations to the agents.
:param list chunked_data: list of list of the agents and their operations
to add. Each chunk can be requested at the same time.
:return: list of agents containing a message about the added
operatio... | [
"Tool",
"for",
"the",
"function",
"add_operations_bulk",
".",
"It",
"send",
"the",
"requests",
"to",
"add",
"the",
"operations",
"to",
"the",
"agents",
"."
] | 8bc1a9038511540930371aacfdde0f4040e08f24 | https://github.com/craft-ai/craft-ai-client-python/blob/8bc1a9038511540930371aacfdde0f4040e08f24/craftai/client.py#L333-L368 | train |
craft-ai/craft-ai-client-python | craftai/client.py | CraftAIClient.add_operations_bulk | def add_operations_bulk(self, payload):
"""Add operations to a group of agents.
:param list payload: contains the informations necessary for the action.
It's in the form [{"id": agent_id, "operations": operations}]
With id that is an str containing only characters in "a-zA-Z0-9_-"
and must be betwe... | python | def add_operations_bulk(self, payload):
"""Add operations to a group of agents.
:param list payload: contains the informations necessary for the action.
It's in the form [{"id": agent_id, "operations": operations}]
With id that is an str containing only characters in "a-zA-Z0-9_-"
and must be betwe... | [
"def",
"add_operations_bulk",
"(",
"self",
",",
"payload",
")",
":",
"valid_indices",
",",
"_",
",",
"_",
"=",
"self",
".",
"_check_agent_id_bulk",
"(",
"payload",
")",
"valid_payload",
"=",
"[",
"payload",
"[",
"i",
"]",
"for",
"i",
"in",
"valid_indices",... | Add operations to a group of agents.
:param list payload: contains the informations necessary for the action.
It's in the form [{"id": agent_id, "operations": operations}]
With id that is an str containing only characters in "a-zA-Z0-9_-"
and must be between 1 and 36 characters. It must referenced an
... | [
"Add",
"operations",
"to",
"a",
"group",
"of",
"agents",
"."
] | 8bc1a9038511540930371aacfdde0f4040e08f24 | https://github.com/craft-ai/craft-ai-client-python/blob/8bc1a9038511540930371aacfdde0f4040e08f24/craftai/client.py#L370-L412 | train |
craft-ai/craft-ai-client-python | craftai/client.py | CraftAIClient._get_decision_tree | def _get_decision_tree(self, agent_id, timestamp, version):
"""Tool for the function get_decision_tree.
:param str agent_id: the id of the agent to get the tree. It
must be an str containing only characters in "a-zA-Z0-9_-" and
must be between 1 and 36 characters.
:param int timestamp: Optional. Th... | python | def _get_decision_tree(self, agent_id, timestamp, version):
"""Tool for the function get_decision_tree.
:param str agent_id: the id of the agent to get the tree. It
must be an str containing only characters in "a-zA-Z0-9_-" and
must be between 1 and 36 characters.
:param int timestamp: Optional. Th... | [
"def",
"_get_decision_tree",
"(",
"self",
",",
"agent_id",
",",
"timestamp",
",",
"version",
")",
":",
"headers",
"=",
"self",
".",
"_headers",
".",
"copy",
"(",
")",
"headers",
"[",
"\"x-craft-ai-tree-version\"",
"]",
"=",
"version",
"if",
"timestamp",
"is"... | Tool for the function get_decision_tree.
:param str agent_id: the id of the agent to get the tree. It
must be an str containing only characters in "a-zA-Z0-9_-" and
must be between 1 and 36 characters.
:param int timestamp: Optional. The decision tree is comptuted
at this timestamp.
:default ti... | [
"Tool",
"for",
"the",
"function",
"get_decision_tree",
"."
] | 8bc1a9038511540930371aacfdde0f4040e08f24 | https://github.com/craft-ai/craft-ai-client-python/blob/8bc1a9038511540930371aacfdde0f4040e08f24/craftai/client.py#L485-L514 | train |
craft-ai/craft-ai-client-python | craftai/client.py | CraftAIClient.get_decision_tree | def get_decision_tree(self, agent_id, timestamp=None, version=DEFAULT_DECISION_TREE_VERSION):
"""Get decision tree.
:param str agent_id: the id of the agent to get the tree. It
must be an str containing only characters in "a-zA-Z0-9_-" and
must be between 1 and 36 characters.
:param int timestamp: ... | python | def get_decision_tree(self, agent_id, timestamp=None, version=DEFAULT_DECISION_TREE_VERSION):
"""Get decision tree.
:param str agent_id: the id of the agent to get the tree. It
must be an str containing only characters in "a-zA-Z0-9_-" and
must be between 1 and 36 characters.
:param int timestamp: ... | [
"def",
"get_decision_tree",
"(",
"self",
",",
"agent_id",
",",
"timestamp",
"=",
"None",
",",
"version",
"=",
"DEFAULT_DECISION_TREE_VERSION",
")",
":",
"self",
".",
"_check_agent_id",
"(",
"agent_id",
")",
"if",
"self",
".",
"_config",
"[",
"\"decisionTreeRetri... | Get decision tree.
:param str agent_id: the id of the agent to get the tree. It
must be an str containing only characters in "a-zA-Z0-9_-" and
must be between 1 and 36 characters.
:param int timestamp: Optional. The decision tree is comptuted
at this timestamp.
:default timestamp: None, means t... | [
"Get",
"decision",
"tree",
"."
] | 8bc1a9038511540930371aacfdde0f4040e08f24 | https://github.com/craft-ai/craft-ai-client-python/blob/8bc1a9038511540930371aacfdde0f4040e08f24/craftai/client.py#L516-L552 | train |
craft-ai/craft-ai-client-python | craftai/client.py | CraftAIClient._get_decision_trees_bulk | def _get_decision_trees_bulk(self, payload, valid_indices, invalid_indices, invalid_dts):
"""Tool for the function get_decision_trees_bulk.
:param list payload: contains the informations necessary for getting
the trees. Its form is the same than for the function.
get_decision_trees_bulk.
:param lis... | python | def _get_decision_trees_bulk(self, payload, valid_indices, invalid_indices, invalid_dts):
"""Tool for the function get_decision_trees_bulk.
:param list payload: contains the informations necessary for getting
the trees. Its form is the same than for the function.
get_decision_trees_bulk.
:param lis... | [
"def",
"_get_decision_trees_bulk",
"(",
"self",
",",
"payload",
",",
"valid_indices",
",",
"invalid_indices",
",",
"invalid_dts",
")",
":",
"valid_dts",
"=",
"self",
".",
"_create_and_send_json_bulk",
"(",
"[",
"payload",
"[",
"i",
"]",
"for",
"i",
"in",
"vali... | Tool for the function get_decision_trees_bulk.
:param list payload: contains the informations necessary for getting
the trees. Its form is the same than for the function.
get_decision_trees_bulk.
:param list valid_indices: list of the indices of the valid agent id.
:param list invalid_indices: list... | [
"Tool",
"for",
"the",
"function",
"get_decision_trees_bulk",
"."
] | 8bc1a9038511540930371aacfdde0f4040e08f24 | https://github.com/craft-ai/craft-ai-client-python/blob/8bc1a9038511540930371aacfdde0f4040e08f24/craftai/client.py#L554-L575 | train |
craft-ai/craft-ai-client-python | craftai/client.py | CraftAIClient.get_decision_trees_bulk | def get_decision_trees_bulk(self, payload, version=DEFAULT_DECISION_TREE_VERSION):
"""Get a group of decision trees.
:param list payload: contains the informations necessary for getting
the trees. It's in the form [{"id": agent_id, "timestamp": timestamp}]
With id a str containing only characters in "a... | python | def get_decision_trees_bulk(self, payload, version=DEFAULT_DECISION_TREE_VERSION):
"""Get a group of decision trees.
:param list payload: contains the informations necessary for getting
the trees. It's in the form [{"id": agent_id, "timestamp": timestamp}]
With id a str containing only characters in "a... | [
"def",
"get_decision_trees_bulk",
"(",
"self",
",",
"payload",
",",
"version",
"=",
"DEFAULT_DECISION_TREE_VERSION",
")",
":",
"headers",
"=",
"self",
".",
"_headers",
".",
"copy",
"(",
")",
"headers",
"[",
"\"x-craft-ai-tree-version\"",
"]",
"=",
"version",
"va... | Get a group of decision trees.
:param list payload: contains the informations necessary for getting
the trees. It's in the form [{"id": agent_id, "timestamp": timestamp}]
With id a str containing only characters in "a-zA-Z0-9_-" and must be
between 1 and 36 characters. It must referenced an existing ag... | [
"Get",
"a",
"group",
"of",
"decision",
"trees",
"."
] | 8bc1a9038511540930371aacfdde0f4040e08f24 | https://github.com/craft-ai/craft-ai-client-python/blob/8bc1a9038511540930371aacfdde0f4040e08f24/craftai/client.py#L577-L623 | train |
craft-ai/craft-ai-client-python | craftai/client.py | CraftAIClient._decode_response | def _decode_response(response):
"""Decode the response of a request.
:param response: response of a request.
:return: decoded response.
:raise Error: Raise the error given by the request.
"""
status_code = response.status_code
message = "Status code " + str(status_code)
try:
me... | python | def _decode_response(response):
"""Decode the response of a request.
:param response: response of a request.
:return: decoded response.
:raise Error: Raise the error given by the request.
"""
status_code = response.status_code
message = "Status code " + str(status_code)
try:
me... | [
"def",
"_decode_response",
"(",
"response",
")",
":",
"status_code",
"=",
"response",
".",
"status_code",
"message",
"=",
"\"Status code \"",
"+",
"str",
"(",
"status_code",
")",
"try",
":",
"message",
"=",
"CraftAIClient",
".",
"_parse_body",
"(",
"response",
... | Decode the response of a request.
:param response: response of a request.
:return: decoded response.
:raise Error: Raise the error given by the request. | [
"Decode",
"the",
"response",
"of",
"a",
"request",
"."
] | 8bc1a9038511540930371aacfdde0f4040e08f24 | https://github.com/craft-ai/craft-ai-client-python/blob/8bc1a9038511540930371aacfdde0f4040e08f24/craftai/client.py#L639-L660 | train |
craft-ai/craft-ai-client-python | craftai/client.py | CraftAIClient._decode_response_bulk | def _decode_response_bulk(response_bulk):
"""Decode the response of each agent given by a bulk function.
:param list response_bulk: list of dictionnary which represents
the response for an agent.
:return: decoded response.
:rtype: list of dict.
"""
resp = []
for response in response_bu... | python | def _decode_response_bulk(response_bulk):
"""Decode the response of each agent given by a bulk function.
:param list response_bulk: list of dictionnary which represents
the response for an agent.
:return: decoded response.
:rtype: list of dict.
"""
resp = []
for response in response_bu... | [
"def",
"_decode_response_bulk",
"(",
"response_bulk",
")",
":",
"resp",
"=",
"[",
"]",
"for",
"response",
"in",
"response_bulk",
":",
"if",
"(",
"\"status\"",
"in",
"response",
")",
"and",
"(",
"response",
".",
"get",
"(",
"\"status\"",
")",
"==",
"201",
... | Decode the response of each agent given by a bulk function.
:param list response_bulk: list of dictionnary which represents
the response for an agent.
:return: decoded response.
:rtype: list of dict. | [
"Decode",
"the",
"response",
"of",
"each",
"agent",
"given",
"by",
"a",
"bulk",
"function",
"."
] | 8bc1a9038511540930371aacfdde0f4040e08f24 | https://github.com/craft-ai/craft-ai-client-python/blob/8bc1a9038511540930371aacfdde0f4040e08f24/craftai/client.py#L663-L691 | train |
craft-ai/craft-ai-client-python | craftai/client.py | CraftAIClient._get_error_from_status | def _get_error_from_status(status_code, message):
"""Give the error corresponding to the status code.
:param int status_code: status code of the response to
a request.
:param str message: error message given by the response.
:return: error corresponding to the status code.
:rtype: Error.
"... | python | def _get_error_from_status(status_code, message):
"""Give the error corresponding to the status code.
:param int status_code: status code of the response to
a request.
:param str message: error message given by the response.
:return: error corresponding to the status code.
:rtype: Error.
"... | [
"def",
"_get_error_from_status",
"(",
"status_code",
",",
"message",
")",
":",
"if",
"status_code",
"==",
"202",
":",
"err",
"=",
"CraftAiLongRequestTimeOutError",
"(",
"message",
")",
"elif",
"status_code",
"==",
"401",
"or",
"status_code",
"==",
"403",
":",
... | Give the error corresponding to the status code.
:param int status_code: status code of the response to
a request.
:param str message: error message given by the response.
:return: error corresponding to the status code.
:rtype: Error. | [
"Give",
"the",
"error",
"corresponding",
"to",
"the",
"status",
"code",
"."
] | 8bc1a9038511540930371aacfdde0f4040e08f24 | https://github.com/craft-ai/craft-ai-client-python/blob/8bc1a9038511540930371aacfdde0f4040e08f24/craftai/client.py#L694-L725 | train |
craft-ai/craft-ai-client-python | craftai/client.py | CraftAIClient._check_agent_id | def _check_agent_id(agent_id):
"""Checks that the given agent_id is a valid non-empty string.
:param str agent_id: agent id to check.
:raise CraftAiBadRequestError: If the given agent_id is not of
type string or if it is an empty string.
"""
if (not isinstance(agent_id, six.string_types) or
... | python | def _check_agent_id(agent_id):
"""Checks that the given agent_id is a valid non-empty string.
:param str agent_id: agent id to check.
:raise CraftAiBadRequestError: If the given agent_id is not of
type string or if it is an empty string.
"""
if (not isinstance(agent_id, six.string_types) or
... | [
"def",
"_check_agent_id",
"(",
"agent_id",
")",
":",
"if",
"(",
"not",
"isinstance",
"(",
"agent_id",
",",
"six",
".",
"string_types",
")",
"or",
"AGENT_ID_PATTERN",
".",
"match",
"(",
"agent_id",
")",
"is",
"None",
")",
":",
"raise",
"CraftAiBadRequestError... | Checks that the given agent_id is a valid non-empty string.
:param str agent_id: agent id to check.
:raise CraftAiBadRequestError: If the given agent_id is not of
type string or if it is an empty string. | [
"Checks",
"that",
"the",
"given",
"agent_id",
"is",
"a",
"valid",
"non",
"-",
"empty",
"string",
"."
] | 8bc1a9038511540930371aacfdde0f4040e08f24 | https://github.com/craft-ai/craft-ai-client-python/blob/8bc1a9038511540930371aacfdde0f4040e08f24/craftai/client.py#L728-L738 | train |
craft-ai/craft-ai-client-python | craftai/client.py | CraftAIClient._check_agent_id_bulk | def _check_agent_id_bulk(self, payload):
"""Checks that all the given agent ids are valid non-empty strings
and if the agents are serializable.
:param list payload: list of dictionnary which represents an agent.
:return: list of the agents with valid ids, list of the agents with
invalid ids, list ... | python | def _check_agent_id_bulk(self, payload):
"""Checks that all the given agent ids are valid non-empty strings
and if the agents are serializable.
:param list payload: list of dictionnary which represents an agent.
:return: list of the agents with valid ids, list of the agents with
invalid ids, list ... | [
"def",
"_check_agent_id_bulk",
"(",
"self",
",",
"payload",
")",
":",
"invalid_agent_indices",
"=",
"[",
"]",
"valid_agent_indices",
"=",
"[",
"]",
"invalid_payload",
"=",
"[",
"]",
"for",
"index",
",",
"agent",
"in",
"enumerate",
"(",
"payload",
")",
":",
... | Checks that all the given agent ids are valid non-empty strings
and if the agents are serializable.
:param list payload: list of dictionnary which represents an agent.
:return: list of the agents with valid ids, list of the agents with
invalid ids, list of the dictionnaries with valid ids.
:rtype:... | [
"Checks",
"that",
"all",
"the",
"given",
"agent",
"ids",
"are",
"valid",
"non",
"-",
"empty",
"strings",
"and",
"if",
"the",
"agents",
"are",
"serializable",
"."
] | 8bc1a9038511540930371aacfdde0f4040e08f24 | https://github.com/craft-ai/craft-ai-client-python/blob/8bc1a9038511540930371aacfdde0f4040e08f24/craftai/client.py#L740-L778 | train |
craft-ai/craft-ai-client-python | craftai/client.py | CraftAIClient._recreate_list_with_indices | def _recreate_list_with_indices(indices1, values1, indices2, values2):
"""Create a list in the right order.
:param list indices1: contains the list of indices corresponding to
the values in values1.
:param list values1: contains the first list of values.
:param list indices2: contains the list of i... | python | def _recreate_list_with_indices(indices1, values1, indices2, values2):
"""Create a list in the right order.
:param list indices1: contains the list of indices corresponding to
the values in values1.
:param list values1: contains the first list of values.
:param list indices2: contains the list of i... | [
"def",
"_recreate_list_with_indices",
"(",
"indices1",
",",
"values1",
",",
"indices2",
",",
"values2",
")",
":",
"list_indices",
"=",
"sorted",
"(",
"indices1",
"+",
"indices2",
")",
"for",
"i",
",",
"index",
"in",
"enumerate",
"(",
"list_indices",
")",
":"... | Create a list in the right order.
:param list indices1: contains the list of indices corresponding to
the values in values1.
:param list values1: contains the first list of values.
:param list indices2: contains the list of indices corresponding to
the values in values2.
:param list values2: co... | [
"Create",
"a",
"list",
"in",
"the",
"right",
"order",
"."
] | 8bc1a9038511540930371aacfdde0f4040e08f24 | https://github.com/craft-ai/craft-ai-client-python/blob/8bc1a9038511540930371aacfdde0f4040e08f24/craftai/client.py#L781-L805 | train |
craft-ai/craft-ai-client-python | craftai/client.py | CraftAIClient._create_and_send_json_bulk | def _create_and_send_json_bulk(self, payload, req_url, request_type="POST"):
"""Create a json, do a request to the URL and process the response.
:param list payload: contains the informations necessary for the action.
It's a list of dictionnary.
:param str req_url: URL to request with the payload.
... | python | def _create_and_send_json_bulk(self, payload, req_url, request_type="POST"):
"""Create a json, do a request to the URL and process the response.
:param list payload: contains the informations necessary for the action.
It's a list of dictionnary.
:param str req_url: URL to request with the payload.
... | [
"def",
"_create_and_send_json_bulk",
"(",
"self",
",",
"payload",
",",
"req_url",
",",
"request_type",
"=",
"\"POST\"",
")",
":",
"ct_header",
"=",
"{",
"\"Content-Type\"",
":",
"\"application/json; charset=utf-8\"",
"}",
"try",
":",
"json_pl",
"=",
"json",
".",
... | Create a json, do a request to the URL and process the response.
:param list payload: contains the informations necessary for the action.
It's a list of dictionnary.
:param str req_url: URL to request with the payload.
:param str request_type: type of request, either "POST" or "DELETE".
:default re... | [
"Create",
"a",
"json",
"do",
"a",
"request",
"to",
"the",
"URL",
"and",
"process",
"the",
"response",
"."
] | 8bc1a9038511540930371aacfdde0f4040e08f24 | https://github.com/craft-ai/craft-ai-client-python/blob/8bc1a9038511540930371aacfdde0f4040e08f24/craftai/client.py#L807-L844 | train |
Shizmob/pydle | pydle/features/ctcp.py | construct_ctcp | def construct_ctcp(*parts):
""" Construct CTCP message. """
message = ' '.join(parts)
message = message.replace('\0', CTCP_ESCAPE_CHAR + '0')
message = message.replace('\n', CTCP_ESCAPE_CHAR + 'n')
message = message.replace('\r', CTCP_ESCAPE_CHAR + 'r')
message = message.replace(CTCP_ESCAPE_CHAR... | python | def construct_ctcp(*parts):
""" Construct CTCP message. """
message = ' '.join(parts)
message = message.replace('\0', CTCP_ESCAPE_CHAR + '0')
message = message.replace('\n', CTCP_ESCAPE_CHAR + 'n')
message = message.replace('\r', CTCP_ESCAPE_CHAR + 'r')
message = message.replace(CTCP_ESCAPE_CHAR... | [
"def",
"construct_ctcp",
"(",
"*",
"parts",
")",
":",
"message",
"=",
"' '",
".",
"join",
"(",
"parts",
")",
"message",
"=",
"message",
".",
"replace",
"(",
"'\\0'",
",",
"CTCP_ESCAPE_CHAR",
"+",
"'0'",
")",
"message",
"=",
"message",
".",
"replace",
"... | Construct CTCP message. | [
"Construct",
"CTCP",
"message",
"."
] | 7ec7d65d097318ed0bcdc5d8401470287d8c7cf7 | https://github.com/Shizmob/pydle/blob/7ec7d65d097318ed0bcdc5d8401470287d8c7cf7/pydle/features/ctcp.py#L105-L112 | train |
Shizmob/pydle | pydle/features/ctcp.py | parse_ctcp | def parse_ctcp(query):
""" Strip and de-quote CTCP messages. """
query = query.strip(CTCP_DELIMITER)
query = query.replace(CTCP_ESCAPE_CHAR + '0', '\0')
query = query.replace(CTCP_ESCAPE_CHAR + 'n', '\n')
query = query.replace(CTCP_ESCAPE_CHAR + 'r', '\r')
query = query.replace(CTCP_ESCAPE_CHAR ... | python | def parse_ctcp(query):
""" Strip and de-quote CTCP messages. """
query = query.strip(CTCP_DELIMITER)
query = query.replace(CTCP_ESCAPE_CHAR + '0', '\0')
query = query.replace(CTCP_ESCAPE_CHAR + 'n', '\n')
query = query.replace(CTCP_ESCAPE_CHAR + 'r', '\r')
query = query.replace(CTCP_ESCAPE_CHAR ... | [
"def",
"parse_ctcp",
"(",
"query",
")",
":",
"query",
"=",
"query",
".",
"strip",
"(",
"CTCP_DELIMITER",
")",
"query",
"=",
"query",
".",
"replace",
"(",
"CTCP_ESCAPE_CHAR",
"+",
"'0'",
",",
"'\\0'",
")",
"query",
"=",
"query",
".",
"replace",
"(",
"CT... | Strip and de-quote CTCP messages. | [
"Strip",
"and",
"de",
"-",
"quote",
"CTCP",
"messages",
"."
] | 7ec7d65d097318ed0bcdc5d8401470287d8c7cf7 | https://github.com/Shizmob/pydle/blob/7ec7d65d097318ed0bcdc5d8401470287d8c7cf7/pydle/features/ctcp.py#L114-L123 | train |
Shizmob/pydle | pydle/features/ctcp.py | CTCPSupport.on_ctcp_version | async def on_ctcp_version(self, by, target, contents):
""" Built-in CTCP version as some networks seem to require it. """
import pydle
version = '{name} v{ver}'.format(name=pydle.__name__, ver=pydle.__version__)
self.ctcp_reply(by, 'VERSION', version) | python | async def on_ctcp_version(self, by, target, contents):
""" Built-in CTCP version as some networks seem to require it. """
import pydle
version = '{name} v{ver}'.format(name=pydle.__name__, ver=pydle.__version__)
self.ctcp_reply(by, 'VERSION', version) | [
"async",
"def",
"on_ctcp_version",
"(",
"self",
",",
"by",
",",
"target",
",",
"contents",
")",
":",
"import",
"pydle",
"version",
"=",
"'{name} v{ver}'",
".",
"format",
"(",
"name",
"=",
"pydle",
".",
"__name__",
",",
"ver",
"=",
"pydle",
".",
"__versio... | Built-in CTCP version as some networks seem to require it. | [
"Built",
"-",
"in",
"CTCP",
"version",
"as",
"some",
"networks",
"seem",
"to",
"require",
"it",
"."
] | 7ec7d65d097318ed0bcdc5d8401470287d8c7cf7 | https://github.com/Shizmob/pydle/blob/7ec7d65d097318ed0bcdc5d8401470287d8c7cf7/pydle/features/ctcp.py#L34-L39 | train |
Shizmob/pydle | pydle/features/ctcp.py | CTCPSupport.ctcp | async def ctcp(self, target, query, contents=None):
""" Send a CTCP request to a target. """
if self.is_channel(target) and not self.in_channel(target):
raise client.NotInChannel(target)
await self.message(target, construct_ctcp(query, contents)) | python | async def ctcp(self, target, query, contents=None):
""" Send a CTCP request to a target. """
if self.is_channel(target) and not self.in_channel(target):
raise client.NotInChannel(target)
await self.message(target, construct_ctcp(query, contents)) | [
"async",
"def",
"ctcp",
"(",
"self",
",",
"target",
",",
"query",
",",
"contents",
"=",
"None",
")",
":",
"if",
"self",
".",
"is_channel",
"(",
"target",
")",
"and",
"not",
"self",
".",
"in_channel",
"(",
"target",
")",
":",
"raise",
"client",
".",
... | Send a CTCP request to a target. | [
"Send",
"a",
"CTCP",
"request",
"to",
"a",
"target",
"."
] | 7ec7d65d097318ed0bcdc5d8401470287d8c7cf7 | https://github.com/Shizmob/pydle/blob/7ec7d65d097318ed0bcdc5d8401470287d8c7cf7/pydle/features/ctcp.py#L44-L49 | train |
Shizmob/pydle | pydle/features/ctcp.py | CTCPSupport.ctcp_reply | async def ctcp_reply(self, target, query, response):
""" Send a CTCP reply to a target. """
if self.is_channel(target) and not self.in_channel(target):
raise client.NotInChannel(target)
await self.notice(target, construct_ctcp(query, response)) | python | async def ctcp_reply(self, target, query, response):
""" Send a CTCP reply to a target. """
if self.is_channel(target) and not self.in_channel(target):
raise client.NotInChannel(target)
await self.notice(target, construct_ctcp(query, response)) | [
"async",
"def",
"ctcp_reply",
"(",
"self",
",",
"target",
",",
"query",
",",
"response",
")",
":",
"if",
"self",
".",
"is_channel",
"(",
"target",
")",
"and",
"not",
"self",
".",
"in_channel",
"(",
"target",
")",
":",
"raise",
"client",
".",
"NotInChan... | Send a CTCP reply to a target. | [
"Send",
"a",
"CTCP",
"reply",
"to",
"a",
"target",
"."
] | 7ec7d65d097318ed0bcdc5d8401470287d8c7cf7 | https://github.com/Shizmob/pydle/blob/7ec7d65d097318ed0bcdc5d8401470287d8c7cf7/pydle/features/ctcp.py#L51-L56 | train |
Shizmob/pydle | pydle/features/ctcp.py | CTCPSupport.on_raw_privmsg | async def on_raw_privmsg(self, message):
""" Modify PRIVMSG to redirect CTCP messages. """
nick, metadata = self._parse_user(message.source)
target, msg = message.params
if is_ctcp(msg):
self._sync_user(nick, metadata)
type, contents = parse_ctcp(msg)
... | python | async def on_raw_privmsg(self, message):
""" Modify PRIVMSG to redirect CTCP messages. """
nick, metadata = self._parse_user(message.source)
target, msg = message.params
if is_ctcp(msg):
self._sync_user(nick, metadata)
type, contents = parse_ctcp(msg)
... | [
"async",
"def",
"on_raw_privmsg",
"(",
"self",
",",
"message",
")",
":",
"nick",
",",
"metadata",
"=",
"self",
".",
"_parse_user",
"(",
"message",
".",
"source",
")",
"target",
",",
"msg",
"=",
"message",
".",
"params",
"if",
"is_ctcp",
"(",
"msg",
")"... | Modify PRIVMSG to redirect CTCP messages. | [
"Modify",
"PRIVMSG",
"to",
"redirect",
"CTCP",
"messages",
"."
] | 7ec7d65d097318ed0bcdc5d8401470287d8c7cf7 | https://github.com/Shizmob/pydle/blob/7ec7d65d097318ed0bcdc5d8401470287d8c7cf7/pydle/features/ctcp.py#L61-L77 | train |
Shizmob/pydle | pydle/features/ctcp.py | CTCPSupport.on_raw_notice | async def on_raw_notice(self, message):
""" Modify NOTICE to redirect CTCP messages. """
nick, metadata = self._parse_user(message.source)
target, msg = message.params
if is_ctcp(msg):
self._sync_user(nick, metadata)
type, response = parse_ctcp(msg)
... | python | async def on_raw_notice(self, message):
""" Modify NOTICE to redirect CTCP messages. """
nick, metadata = self._parse_user(message.source)
target, msg = message.params
if is_ctcp(msg):
self._sync_user(nick, metadata)
type, response = parse_ctcp(msg)
... | [
"async",
"def",
"on_raw_notice",
"(",
"self",
",",
"message",
")",
":",
"nick",
",",
"metadata",
"=",
"self",
".",
"_parse_user",
"(",
"message",
".",
"source",
")",
"target",
",",
"msg",
"=",
"message",
".",
"params",
"if",
"is_ctcp",
"(",
"msg",
")",... | Modify NOTICE to redirect CTCP messages. | [
"Modify",
"NOTICE",
"to",
"redirect",
"CTCP",
"messages",
"."
] | 7ec7d65d097318ed0bcdc5d8401470287d8c7cf7 | https://github.com/Shizmob/pydle/blob/7ec7d65d097318ed0bcdc5d8401470287d8c7cf7/pydle/features/ctcp.py#L80-L96 | train |
Shizmob/pydle | pydle/features/ircv3/cap.py | CapabilityNegotiationSupport._register | async def _register(self):
""" Hijack registration to send a CAP LS first. """
if self.registered:
self.logger.debug("skipping cap registration, already registered!")
return
# Ask server to list capabilities.
await self.rawmsg('CAP', 'LS', '302')
# Regis... | python | async def _register(self):
""" Hijack registration to send a CAP LS first. """
if self.registered:
self.logger.debug("skipping cap registration, already registered!")
return
# Ask server to list capabilities.
await self.rawmsg('CAP', 'LS', '302')
# Regis... | [
"async",
"def",
"_register",
"(",
"self",
")",
":",
"if",
"self",
".",
"registered",
":",
"self",
".",
"logger",
".",
"debug",
"(",
"\"skipping cap registration, already registered!\"",
")",
"return",
"await",
"self",
".",
"rawmsg",
"(",
"'CAP'",
",",
"'LS'",
... | Hijack registration to send a CAP LS first. | [
"Hijack",
"registration",
"to",
"send",
"a",
"CAP",
"LS",
"first",
"."
] | 7ec7d65d097318ed0bcdc5d8401470287d8c7cf7 | https://github.com/Shizmob/pydle/blob/7ec7d65d097318ed0bcdc5d8401470287d8c7cf7/pydle/features/ircv3/cap.py#L31-L41 | train |
Shizmob/pydle | pydle/features/ircv3/cap.py | CapabilityNegotiationSupport._capability_negotiated | async def _capability_negotiated(self, capab):
""" Mark capability as negotiated, and end negotiation if we're done. """
self._capabilities_negotiating.discard(capab)
if not self._capabilities_requested and not self._capabilities_negotiating:
await self.rawmsg('CAP', 'END') | python | async def _capability_negotiated(self, capab):
""" Mark capability as negotiated, and end negotiation if we're done. """
self._capabilities_negotiating.discard(capab)
if not self._capabilities_requested and not self._capabilities_negotiating:
await self.rawmsg('CAP', 'END') | [
"async",
"def",
"_capability_negotiated",
"(",
"self",
",",
"capab",
")",
":",
"self",
".",
"_capabilities_negotiating",
".",
"discard",
"(",
"capab",
")",
"if",
"not",
"self",
".",
"_capabilities_requested",
"and",
"not",
"self",
".",
"_capabilities_negotiating",... | Mark capability as negotiated, and end negotiation if we're done. | [
"Mark",
"capability",
"as",
"negotiated",
"and",
"end",
"negotiation",
"if",
"we",
"re",
"done",
"."
] | 7ec7d65d097318ed0bcdc5d8401470287d8c7cf7 | https://github.com/Shizmob/pydle/blob/7ec7d65d097318ed0bcdc5d8401470287d8c7cf7/pydle/features/ircv3/cap.py#L55-L60 | train |
Shizmob/pydle | pydle/features/ircv3/cap.py | CapabilityNegotiationSupport.on_raw_cap | async def on_raw_cap(self, message):
""" Handle CAP message. """
target, subcommand = message.params[:2]
params = message.params[2:]
# Call handler.
attr = 'on_raw_cap_' + pydle.protocol.identifierify(subcommand)
if hasattr(self, attr):
await getattr(self, at... | python | async def on_raw_cap(self, message):
""" Handle CAP message. """
target, subcommand = message.params[:2]
params = message.params[2:]
# Call handler.
attr = 'on_raw_cap_' + pydle.protocol.identifierify(subcommand)
if hasattr(self, attr):
await getattr(self, at... | [
"async",
"def",
"on_raw_cap",
"(",
"self",
",",
"message",
")",
":",
"target",
",",
"subcommand",
"=",
"message",
".",
"params",
"[",
":",
"2",
"]",
"params",
"=",
"message",
".",
"params",
"[",
"2",
":",
"]",
"attr",
"=",
"'on_raw_cap_'",
"+",
"pydl... | Handle CAP message. | [
"Handle",
"CAP",
"message",
"."
] | 7ec7d65d097318ed0bcdc5d8401470287d8c7cf7 | https://github.com/Shizmob/pydle/blob/7ec7d65d097318ed0bcdc5d8401470287d8c7cf7/pydle/features/ircv3/cap.py#L65-L75 | train |
Shizmob/pydle | pydle/features/ircv3/cap.py | CapabilityNegotiationSupport.on_raw_cap_ls | async def on_raw_cap_ls(self, params):
""" Update capability mapping. Request capabilities. """
to_request = set()
for capab in params[0].split():
capab, value = self._capability_normalize(capab)
# Only process new capabilities.
if capab in self._capabilitie... | python | async def on_raw_cap_ls(self, params):
""" Update capability mapping. Request capabilities. """
to_request = set()
for capab in params[0].split():
capab, value = self._capability_normalize(capab)
# Only process new capabilities.
if capab in self._capabilitie... | [
"async",
"def",
"on_raw_cap_ls",
"(",
"self",
",",
"params",
")",
":",
"to_request",
"=",
"set",
"(",
")",
"for",
"capab",
"in",
"params",
"[",
"0",
"]",
".",
"split",
"(",
")",
":",
"capab",
",",
"value",
"=",
"self",
".",
"_capability_normalize",
"... | Update capability mapping. Request capabilities. | [
"Update",
"capability",
"mapping",
".",
"Request",
"capabilities",
"."
] | 7ec7d65d097318ed0bcdc5d8401470287d8c7cf7 | https://github.com/Shizmob/pydle/blob/7ec7d65d097318ed0bcdc5d8401470287d8c7cf7/pydle/features/ircv3/cap.py#L77-L106 | train |
Shizmob/pydle | pydle/features/ircv3/cap.py | CapabilityNegotiationSupport.on_raw_cap_list | async def on_raw_cap_list(self, params):
""" Update active capabilities. """
self._capabilities = { capab: False for capab in self._capabilities }
for capab in params[0].split():
capab, value = self._capability_normalize(capab)
self._capabilities[capab] = value if value ... | python | async def on_raw_cap_list(self, params):
""" Update active capabilities. """
self._capabilities = { capab: False for capab in self._capabilities }
for capab in params[0].split():
capab, value = self._capability_normalize(capab)
self._capabilities[capab] = value if value ... | [
"async",
"def",
"on_raw_cap_list",
"(",
"self",
",",
"params",
")",
":",
"self",
".",
"_capabilities",
"=",
"{",
"capab",
":",
"False",
"for",
"capab",
"in",
"self",
".",
"_capabilities",
"}",
"for",
"capab",
"in",
"params",
"[",
"0",
"]",
".",
"split"... | Update active capabilities. | [
"Update",
"active",
"capabilities",
"."
] | 7ec7d65d097318ed0bcdc5d8401470287d8c7cf7 | https://github.com/Shizmob/pydle/blob/7ec7d65d097318ed0bcdc5d8401470287d8c7cf7/pydle/features/ircv3/cap.py#L108-L114 | train |
Shizmob/pydle | pydle/features/ircv3/cap.py | CapabilityNegotiationSupport.on_raw_410 | async def on_raw_410(self, message):
""" Unknown CAP subcommand or CAP error. Force-end negotiations. """
self.logger.error('Server sent "Unknown CAP subcommand: %s". Aborting capability negotiation.', message.params[0])
self._capabilities_requested = set()
self._capabilities_negotiatin... | python | async def on_raw_410(self, message):
""" Unknown CAP subcommand or CAP error. Force-end negotiations. """
self.logger.error('Server sent "Unknown CAP subcommand: %s". Aborting capability negotiation.', message.params[0])
self._capabilities_requested = set()
self._capabilities_negotiatin... | [
"async",
"def",
"on_raw_410",
"(",
"self",
",",
"message",
")",
":",
"self",
".",
"logger",
".",
"error",
"(",
"'Server sent \"Unknown CAP subcommand: %s\". Aborting capability negotiation.'",
",",
"message",
".",
"params",
"[",
"0",
"]",
")",
"self",
".",
"_capab... | Unknown CAP subcommand or CAP error. Force-end negotiations. | [
"Unknown",
"CAP",
"subcommand",
"or",
"CAP",
"error",
".",
"Force",
"-",
"end",
"negotiations",
"."
] | 7ec7d65d097318ed0bcdc5d8401470287d8c7cf7 | https://github.com/Shizmob/pydle/blob/7ec7d65d097318ed0bcdc5d8401470287d8c7cf7/pydle/features/ircv3/cap.py#L179-L185 | train |
Shizmob/pydle | pydle/features/ircv3/sasl.py | SASLSupport._sasl_start | async def _sasl_start(self, mechanism):
""" Initiate SASL authentication. """
# The rest will be handled in on_raw_authenticate()/_sasl_respond().
await self.rawmsg('AUTHENTICATE', mechanism)
# create a partial, required for our callback to get the kwarg
_sasl_partial = partial(s... | python | async def _sasl_start(self, mechanism):
""" Initiate SASL authentication. """
# The rest will be handled in on_raw_authenticate()/_sasl_respond().
await self.rawmsg('AUTHENTICATE', mechanism)
# create a partial, required for our callback to get the kwarg
_sasl_partial = partial(s... | [
"async",
"def",
"_sasl_start",
"(",
"self",
",",
"mechanism",
")",
":",
"await",
"self",
".",
"rawmsg",
"(",
"'AUTHENTICATE'",
",",
"mechanism",
")",
"_sasl_partial",
"=",
"partial",
"(",
"self",
".",
"_sasl_abort",
",",
"timeout",
"=",
"True",
")",
"self"... | Initiate SASL authentication. | [
"Initiate",
"SASL",
"authentication",
"."
] | 7ec7d65d097318ed0bcdc5d8401470287d8c7cf7 | https://github.com/Shizmob/pydle/blob/7ec7d65d097318ed0bcdc5d8401470287d8c7cf7/pydle/features/ircv3/sasl.py#L45-L51 | train |
Shizmob/pydle | pydle/features/ircv3/sasl.py | SASLSupport._sasl_abort | async def _sasl_abort(self, timeout=False):
""" Abort SASL authentication. """
if timeout:
self.logger.error('SASL authentication timed out: aborting.')
else:
self.logger.error('SASL authentication aborted.')
if self._sasl_timer:
self._sasl_timer.canc... | python | async def _sasl_abort(self, timeout=False):
""" Abort SASL authentication. """
if timeout:
self.logger.error('SASL authentication timed out: aborting.')
else:
self.logger.error('SASL authentication aborted.')
if self._sasl_timer:
self._sasl_timer.canc... | [
"async",
"def",
"_sasl_abort",
"(",
"self",
",",
"timeout",
"=",
"False",
")",
":",
"if",
"timeout",
":",
"self",
".",
"logger",
".",
"error",
"(",
"'SASL authentication timed out: aborting.'",
")",
"else",
":",
"self",
".",
"logger",
".",
"error",
"(",
"'... | Abort SASL authentication. | [
"Abort",
"SASL",
"authentication",
"."
] | 7ec7d65d097318ed0bcdc5d8401470287d8c7cf7 | https://github.com/Shizmob/pydle/blob/7ec7d65d097318ed0bcdc5d8401470287d8c7cf7/pydle/features/ircv3/sasl.py#L53-L67 | train |
Shizmob/pydle | pydle/features/ircv3/sasl.py | SASLSupport._sasl_end | async def _sasl_end(self):
""" Finalize SASL authentication. """
if self._sasl_timer:
self._sasl_timer.cancel()
self._sasl_timer = None
await self._capability_negotiated('sasl') | python | async def _sasl_end(self):
""" Finalize SASL authentication. """
if self._sasl_timer:
self._sasl_timer.cancel()
self._sasl_timer = None
await self._capability_negotiated('sasl') | [
"async",
"def",
"_sasl_end",
"(",
"self",
")",
":",
"if",
"self",
".",
"_sasl_timer",
":",
"self",
".",
"_sasl_timer",
".",
"cancel",
"(",
")",
"self",
".",
"_sasl_timer",
"=",
"None",
"await",
"self",
".",
"_capability_negotiated",
"(",
"'sasl'",
")"
] | Finalize SASL authentication. | [
"Finalize",
"SASL",
"authentication",
"."
] | 7ec7d65d097318ed0bcdc5d8401470287d8c7cf7 | https://github.com/Shizmob/pydle/blob/7ec7d65d097318ed0bcdc5d8401470287d8c7cf7/pydle/features/ircv3/sasl.py#L69-L74 | train |
Shizmob/pydle | pydle/features/ircv3/sasl.py | SASLSupport._sasl_respond | async def _sasl_respond(self):
""" Respond to SASL challenge with response. """
# Formulate a response.
if self._sasl_client:
try:
response = self._sasl_client.process(self._sasl_challenge)
except puresasl.SASLError:
response = None
... | python | async def _sasl_respond(self):
""" Respond to SASL challenge with response. """
# Formulate a response.
if self._sasl_client:
try:
response = self._sasl_client.process(self._sasl_challenge)
except puresasl.SASLError:
response = None
... | [
"async",
"def",
"_sasl_respond",
"(",
"self",
")",
":",
"if",
"self",
".",
"_sasl_client",
":",
"try",
":",
"response",
"=",
"self",
".",
"_sasl_client",
".",
"process",
"(",
"self",
".",
"_sasl_challenge",
")",
"except",
"puresasl",
".",
"SASLError",
":",... | Respond to SASL challenge with response. | [
"Respond",
"to",
"SASL",
"challenge",
"with",
"response",
"."
] | 7ec7d65d097318ed0bcdc5d8401470287d8c7cf7 | https://github.com/Shizmob/pydle/blob/7ec7d65d097318ed0bcdc5d8401470287d8c7cf7/pydle/features/ircv3/sasl.py#L76-L103 | train |
Shizmob/pydle | pydle/features/ircv3/sasl.py | SASLSupport.on_capability_sasl_available | async def on_capability_sasl_available(self, value):
""" Check whether or not SASL is available. """
if value:
self._sasl_mechanisms = value.upper().split(',')
else:
self._sasl_mechanisms = None
if self.sasl_mechanism == 'EXTERNAL' or (self.sasl_username and self... | python | async def on_capability_sasl_available(self, value):
""" Check whether or not SASL is available. """
if value:
self._sasl_mechanisms = value.upper().split(',')
else:
self._sasl_mechanisms = None
if self.sasl_mechanism == 'EXTERNAL' or (self.sasl_username and self... | [
"async",
"def",
"on_capability_sasl_available",
"(",
"self",
",",
"value",
")",
":",
"if",
"value",
":",
"self",
".",
"_sasl_mechanisms",
"=",
"value",
".",
"upper",
"(",
")",
".",
"split",
"(",
"','",
")",
"else",
":",
"self",
".",
"_sasl_mechanisms",
"... | Check whether or not SASL is available. | [
"Check",
"whether",
"or",
"not",
"SASL",
"is",
"available",
"."
] | 7ec7d65d097318ed0bcdc5d8401470287d8c7cf7 | https://github.com/Shizmob/pydle/blob/7ec7d65d097318ed0bcdc5d8401470287d8c7cf7/pydle/features/ircv3/sasl.py#L108-L119 | train |
Shizmob/pydle | pydle/features/ircv3/sasl.py | SASLSupport.on_capability_sasl_enabled | async def on_capability_sasl_enabled(self):
""" Start SASL authentication. """
if self.sasl_mechanism:
if self._sasl_mechanisms and self.sasl_mechanism not in self._sasl_mechanisms:
self.logger.warning('Requested SASL mechanism is not in server mechanism list: aborting SASL a... | python | async def on_capability_sasl_enabled(self):
""" Start SASL authentication. """
if self.sasl_mechanism:
if self._sasl_mechanisms and self.sasl_mechanism not in self._sasl_mechanisms:
self.logger.warning('Requested SASL mechanism is not in server mechanism list: aborting SASL a... | [
"async",
"def",
"on_capability_sasl_enabled",
"(",
"self",
")",
":",
"if",
"self",
".",
"sasl_mechanism",
":",
"if",
"self",
".",
"_sasl_mechanisms",
"and",
"self",
".",
"sasl_mechanism",
"not",
"in",
"self",
".",
"_sasl_mechanisms",
":",
"self",
".",
"logger"... | Start SASL authentication. | [
"Start",
"SASL",
"authentication",
"."
] | 7ec7d65d097318ed0bcdc5d8401470287d8c7cf7 | https://github.com/Shizmob/pydle/blob/7ec7d65d097318ed0bcdc5d8401470287d8c7cf7/pydle/features/ircv3/sasl.py#L121-L150 | train |
Shizmob/pydle | pydle/features/ircv3/sasl.py | SASLSupport.on_raw_authenticate | async def on_raw_authenticate(self, message):
""" Received part of the authentication challenge. """
# Cancel timeout timer.
if self._sasl_timer:
self._sasl_timer.cancel()
self._sasl_timer = None
# Add response data.
response = ' '.join(message.params)
... | python | async def on_raw_authenticate(self, message):
""" Received part of the authentication challenge. """
# Cancel timeout timer.
if self._sasl_timer:
self._sasl_timer.cancel()
self._sasl_timer = None
# Add response data.
response = ' '.join(message.params)
... | [
"async",
"def",
"on_raw_authenticate",
"(",
"self",
",",
"message",
")",
":",
"if",
"self",
".",
"_sasl_timer",
":",
"self",
".",
"_sasl_timer",
".",
"cancel",
"(",
")",
"self",
".",
"_sasl_timer",
"=",
"None",
"response",
"=",
"' '",
".",
"join",
"(",
... | Received part of the authentication challenge. | [
"Received",
"part",
"of",
"the",
"authentication",
"challenge",
"."
] | 7ec7d65d097318ed0bcdc5d8401470287d8c7cf7 | https://github.com/Shizmob/pydle/blob/7ec7d65d097318ed0bcdc5d8401470287d8c7cf7/pydle/features/ircv3/sasl.py#L155-L172 | train |
Shizmob/pydle | pydle/features/ircv3/monitor.py | MonitoringSupport.monitor | def monitor(self, target):
""" Start monitoring the online status of a user. Returns whether or not the server supports monitoring. """
if 'monitor-notify' in self._capabilities and not self.is_monitoring(target):
yield from self.rawmsg('MONITOR', '+', target)
self._monitoring.ad... | python | def monitor(self, target):
""" Start monitoring the online status of a user. Returns whether or not the server supports monitoring. """
if 'monitor-notify' in self._capabilities and not self.is_monitoring(target):
yield from self.rawmsg('MONITOR', '+', target)
self._monitoring.ad... | [
"def",
"monitor",
"(",
"self",
",",
"target",
")",
":",
"if",
"'monitor-notify'",
"in",
"self",
".",
"_capabilities",
"and",
"not",
"self",
".",
"is_monitoring",
"(",
"target",
")",
":",
"yield",
"from",
"self",
".",
"rawmsg",
"(",
"'MONITOR'",
",",
"'+'... | Start monitoring the online status of a user. Returns whether or not the server supports monitoring. | [
"Start",
"monitoring",
"the",
"online",
"status",
"of",
"a",
"user",
".",
"Returns",
"whether",
"or",
"not",
"the",
"server",
"supports",
"monitoring",
"."
] | 7ec7d65d097318ed0bcdc5d8401470287d8c7cf7 | https://github.com/Shizmob/pydle/blob/7ec7d65d097318ed0bcdc5d8401470287d8c7cf7/pydle/features/ircv3/monitor.py#L39-L46 | train |
Shizmob/pydle | pydle/features/ircv3/monitor.py | MonitoringSupport.unmonitor | def unmonitor(self, target):
""" Stop monitoring the online status of a user. Returns whether or not the server supports monitoring. """
if 'monitor-notify' in self._capabilities and self.is_monitoring(target):
yield from self.rawmsg('MONITOR', '-', target)
self._monitoring.remov... | python | def unmonitor(self, target):
""" Stop monitoring the online status of a user. Returns whether or not the server supports monitoring. """
if 'monitor-notify' in self._capabilities and self.is_monitoring(target):
yield from self.rawmsg('MONITOR', '-', target)
self._monitoring.remov... | [
"def",
"unmonitor",
"(",
"self",
",",
"target",
")",
":",
"if",
"'monitor-notify'",
"in",
"self",
".",
"_capabilities",
"and",
"self",
".",
"is_monitoring",
"(",
"target",
")",
":",
"yield",
"from",
"self",
".",
"rawmsg",
"(",
"'MONITOR'",
",",
"'-'",
",... | Stop monitoring the online status of a user. Returns whether or not the server supports monitoring. | [
"Stop",
"monitoring",
"the",
"online",
"status",
"of",
"a",
"user",
".",
"Returns",
"whether",
"or",
"not",
"the",
"server",
"supports",
"monitoring",
"."
] | 7ec7d65d097318ed0bcdc5d8401470287d8c7cf7 | https://github.com/Shizmob/pydle/blob/7ec7d65d097318ed0bcdc5d8401470287d8c7cf7/pydle/features/ircv3/monitor.py#L48-L55 | train |
Shizmob/pydle | pydle/features/ircv3/monitor.py | MonitoringSupport.on_raw_730 | async def on_raw_730(self, message):
""" Someone we are monitoring just came online. """
for nick in message.params[1].split(','):
self._create_user(nick)
await self.on_user_online(nickname) | python | async def on_raw_730(self, message):
""" Someone we are monitoring just came online. """
for nick in message.params[1].split(','):
self._create_user(nick)
await self.on_user_online(nickname) | [
"async",
"def",
"on_raw_730",
"(",
"self",
",",
"message",
")",
":",
"for",
"nick",
"in",
"message",
".",
"params",
"[",
"1",
"]",
".",
"split",
"(",
"','",
")",
":",
"self",
".",
"_create_user",
"(",
"nick",
")",
"await",
"self",
".",
"on_user_onlin... | Someone we are monitoring just came online. | [
"Someone",
"we",
"are",
"monitoring",
"just",
"came",
"online",
"."
] | 7ec7d65d097318ed0bcdc5d8401470287d8c7cf7 | https://github.com/Shizmob/pydle/blob/7ec7d65d097318ed0bcdc5d8401470287d8c7cf7/pydle/features/ircv3/monitor.py#L78-L82 | train |
Shizmob/pydle | pydle/features/ircv3/monitor.py | MonitoringSupport.on_raw_731 | async def on_raw_731(self, message):
""" Someone we are monitoring got offline. """
for nick in message.params[1].split(','):
self._destroy_user(nick, monitor_override=True)
await self.on_user_offline(nickname) | python | async def on_raw_731(self, message):
""" Someone we are monitoring got offline. """
for nick in message.params[1].split(','):
self._destroy_user(nick, monitor_override=True)
await self.on_user_offline(nickname) | [
"async",
"def",
"on_raw_731",
"(",
"self",
",",
"message",
")",
":",
"for",
"nick",
"in",
"message",
".",
"params",
"[",
"1",
"]",
".",
"split",
"(",
"','",
")",
":",
"self",
".",
"_destroy_user",
"(",
"nick",
",",
"monitor_override",
"=",
"True",
")... | Someone we are monitoring got offline. | [
"Someone",
"we",
"are",
"monitoring",
"got",
"offline",
"."
] | 7ec7d65d097318ed0bcdc5d8401470287d8c7cf7 | https://github.com/Shizmob/pydle/blob/7ec7d65d097318ed0bcdc5d8401470287d8c7cf7/pydle/features/ircv3/monitor.py#L84-L88 | train |
Shizmob/pydle | pydle/features/ircv3/ircv3_1.py | IRCv3_1Support.on_raw_account | async def on_raw_account(self, message):
""" Changes in the associated account for a nickname. """
if not self._capabilities.get('account-notify', False):
return
nick, metadata = self._parse_user(message.source)
account = message.params[0]
if nick not in self.users:... | python | async def on_raw_account(self, message):
""" Changes in the associated account for a nickname. """
if not self._capabilities.get('account-notify', False):
return
nick, metadata = self._parse_user(message.source)
account = message.params[0]
if nick not in self.users:... | [
"async",
"def",
"on_raw_account",
"(",
"self",
",",
"message",
")",
":",
"if",
"not",
"self",
".",
"_capabilities",
".",
"get",
"(",
"'account-notify'",
",",
"False",
")",
":",
"return",
"nick",
",",
"metadata",
"=",
"self",
".",
"_parse_user",
"(",
"mes... | Changes in the associated account for a nickname. | [
"Changes",
"in",
"the",
"associated",
"account",
"for",
"a",
"nickname",
"."
] | 7ec7d65d097318ed0bcdc5d8401470287d8c7cf7 | https://github.com/Shizmob/pydle/blob/7ec7d65d097318ed0bcdc5d8401470287d8c7cf7/pydle/features/ircv3/ircv3_1.py#L52-L67 | train |
Shizmob/pydle | pydle/features/ircv3/ircv3_1.py | IRCv3_1Support.on_raw_away | async def on_raw_away(self, message):
""" Process AWAY messages. """
if 'away-notify' not in self._capabilities or not self._capabilities['away-notify']:
return
nick, metadata = self._parse_user(message.source)
if nick not in self.users:
return
self._syn... | python | async def on_raw_away(self, message):
""" Process AWAY messages. """
if 'away-notify' not in self._capabilities or not self._capabilities['away-notify']:
return
nick, metadata = self._parse_user(message.source)
if nick not in self.users:
return
self._syn... | [
"async",
"def",
"on_raw_away",
"(",
"self",
",",
"message",
")",
":",
"if",
"'away-notify'",
"not",
"in",
"self",
".",
"_capabilities",
"or",
"not",
"self",
".",
"_capabilities",
"[",
"'away-notify'",
"]",
":",
"return",
"nick",
",",
"metadata",
"=",
"self... | Process AWAY messages. | [
"Process",
"AWAY",
"messages",
"."
] | 7ec7d65d097318ed0bcdc5d8401470287d8c7cf7 | https://github.com/Shizmob/pydle/blob/7ec7d65d097318ed0bcdc5d8401470287d8c7cf7/pydle/features/ircv3/ircv3_1.py#L69-L80 | train |
Shizmob/pydle | pydle/features/ircv3/ircv3_1.py | IRCv3_1Support.on_raw_join | async def on_raw_join(self, message):
""" Process extended JOIN messages. """
if 'extended-join' in self._capabilities and self._capabilities['extended-join']:
nick, metadata = self._parse_user(message.source)
channels, account, realname = message.params
self._sync_u... | python | async def on_raw_join(self, message):
""" Process extended JOIN messages. """
if 'extended-join' in self._capabilities and self._capabilities['extended-join']:
nick, metadata = self._parse_user(message.source)
channels, account, realname = message.params
self._sync_u... | [
"async",
"def",
"on_raw_join",
"(",
"self",
",",
"message",
")",
":",
"if",
"'extended-join'",
"in",
"self",
".",
"_capabilities",
"and",
"self",
".",
"_capabilities",
"[",
"'extended-join'",
"]",
":",
"nick",
",",
"metadata",
"=",
"self",
".",
"_parse_user"... | Process extended JOIN messages. | [
"Process",
"extended",
"JOIN",
"messages",
"."
] | 7ec7d65d097318ed0bcdc5d8401470287d8c7cf7 | https://github.com/Shizmob/pydle/blob/7ec7d65d097318ed0bcdc5d8401470287d8c7cf7/pydle/features/ircv3/ircv3_1.py#L82-L99 | train |
Shizmob/pydle | pydle/features/ircv3/metadata.py | MetadataSupport.on_raw_metadata | async def on_raw_metadata(self, message):
""" Metadata event. """
target, targetmeta = self._parse_user(message.params[0])
key, visibility, value = message.params[1:4]
if visibility == VISIBLITY_ALL:
visibility = None
if target in self.users:
self._sync_u... | python | async def on_raw_metadata(self, message):
""" Metadata event. """
target, targetmeta = self._parse_user(message.params[0])
key, visibility, value = message.params[1:4]
if visibility == VISIBLITY_ALL:
visibility = None
if target in self.users:
self._sync_u... | [
"async",
"def",
"on_raw_metadata",
"(",
"self",
",",
"message",
")",
":",
"target",
",",
"targetmeta",
"=",
"self",
".",
"_parse_user",
"(",
"message",
".",
"params",
"[",
"0",
"]",
")",
"key",
",",
"visibility",
",",
"value",
"=",
"message",
".",
"par... | Metadata event. | [
"Metadata",
"event",
"."
] | 7ec7d65d097318ed0bcdc5d8401470287d8c7cf7 | https://github.com/Shizmob/pydle/blob/7ec7d65d097318ed0bcdc5d8401470287d8c7cf7/pydle/features/ircv3/metadata.py#L56-L65 | train |
Shizmob/pydle | pydle/features/ircv3/metadata.py | MetadataSupport.on_raw_762 | async def on_raw_762(self, message):
""" End of metadata. """
# No way to figure out whose query this belongs to, so make a best guess
# it was the first one.
if not self._metadata_queue:
return
nickname = self._metadata_queue.pop()
future = self._pending['me... | python | async def on_raw_762(self, message):
""" End of metadata. """
# No way to figure out whose query this belongs to, so make a best guess
# it was the first one.
if not self._metadata_queue:
return
nickname = self._metadata_queue.pop()
future = self._pending['me... | [
"async",
"def",
"on_raw_762",
"(",
"self",
",",
"message",
")",
":",
"if",
"not",
"self",
".",
"_metadata_queue",
":",
"return",
"nickname",
"=",
"self",
".",
"_metadata_queue",
".",
"pop",
"(",
")",
"future",
"=",
"self",
".",
"_pending",
"[",
"'metadat... | End of metadata. | [
"End",
"of",
"metadata",
"."
] | 7ec7d65d097318ed0bcdc5d8401470287d8c7cf7 | https://github.com/Shizmob/pydle/blob/7ec7d65d097318ed0bcdc5d8401470287d8c7cf7/pydle/features/ircv3/metadata.py#L93-L102 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.