repository_name stringlengths 7 55 | func_path_in_repository stringlengths 4 223 | func_name stringlengths 1 134 | whole_func_string stringlengths 75 104k | language stringclasses 1
value | func_code_string stringlengths 75 104k | func_code_tokens listlengths 19 28.4k | func_documentation_string stringlengths 1 46.9k | func_documentation_tokens listlengths 1 1.97k | split_name stringclasses 1
value | func_code_url stringlengths 87 315 |
|---|---|---|---|---|---|---|---|---|---|---|
cstockton/py-gensend | gensend/providers/common.py | Common.types | def types(self, *args):
"""Used for debugging, returns type of each arg.
TYPES,ARG_1,...,ARG_N
%{TYPES:A,...,10} -> 'str(A) str(B) ... int(10)'
"""
return ', '.join(['{0}({1})'.format(type(arg).__name__, arg) for arg in args]) | python | def types(self, *args):
"""Used for debugging, returns type of each arg.
TYPES,ARG_1,...,ARG_N
%{TYPES:A,...,10} -> 'str(A) str(B) ... int(10)'
"""
return ', '.join(['{0}({1})'.format(type(arg).__name__, arg) for arg in args]) | [
"def",
"types",
"(",
"self",
",",
"*",
"args",
")",
":",
"return",
"', '",
".",
"join",
"(",
"[",
"'{0}({1})'",
".",
"format",
"(",
"type",
"(",
"arg",
")",
".",
"__name__",
",",
"arg",
")",
"for",
"arg",
"in",
"args",
"]",
")"
] | Used for debugging, returns type of each arg.
TYPES,ARG_1,...,ARG_N
%{TYPES:A,...,10} -> 'str(A) str(B) ... int(10)' | [
"Used",
"for",
"debugging",
"returns",
"type",
"of",
"each",
"arg",
".",
"TYPES",
"ARG_1",
"...",
"ARG_N"
] | train | https://github.com/cstockton/py-gensend/blob/8c8e911f8e8c386bea42967350beb4636fc19240/gensend/providers/common.py#L161-L167 |
cstockton/py-gensend | gensend/providers/common.py | Common.join | def join(self, *args):
"""Returns the arguments in the list joined by STR.
FIRST,JOIN_BY,ARG_1,...,ARG_N
%{JOIN: ,A,...,F} -> 'A B C ... F'
"""
call_args = list(args)
joiner = call_args.pop(0)
self.random.shuffle(call_args)
return joiner.join(call_arg... | python | def join(self, *args):
"""Returns the arguments in the list joined by STR.
FIRST,JOIN_BY,ARG_1,...,ARG_N
%{JOIN: ,A,...,F} -> 'A B C ... F'
"""
call_args = list(args)
joiner = call_args.pop(0)
self.random.shuffle(call_args)
return joiner.join(call_arg... | [
"def",
"join",
"(",
"self",
",",
"*",
"args",
")",
":",
"call_args",
"=",
"list",
"(",
"args",
")",
"joiner",
"=",
"call_args",
".",
"pop",
"(",
"0",
")",
"self",
".",
"random",
".",
"shuffle",
"(",
"call_args",
")",
"return",
"joiner",
".",
"join"... | Returns the arguments in the list joined by STR.
FIRST,JOIN_BY,ARG_1,...,ARG_N
%{JOIN: ,A,...,F} -> 'A B C ... F' | [
"Returns",
"the",
"arguments",
"in",
"the",
"list",
"joined",
"by",
"STR",
".",
"FIRST",
"JOIN_BY",
"ARG_1",
"...",
"ARG_N"
] | train | https://github.com/cstockton/py-gensend/blob/8c8e911f8e8c386bea42967350beb4636fc19240/gensend/providers/common.py#L169-L178 |
cstockton/py-gensend | gensend/providers/common.py | Common.shuffle | def shuffle(self, *args):
"""Shuffles all arguments and returns them.
ARG_1,...,ARG_N
%{SHUFFLE:A, B ,...,F} -> 'CDA B FE'
"""
call_args = list(args)
self.random.shuffle(call_args)
return ''.join(call_args) | python | def shuffle(self, *args):
"""Shuffles all arguments and returns them.
ARG_1,...,ARG_N
%{SHUFFLE:A, B ,...,F} -> 'CDA B FE'
"""
call_args = list(args)
self.random.shuffle(call_args)
return ''.join(call_args) | [
"def",
"shuffle",
"(",
"self",
",",
"*",
"args",
")",
":",
"call_args",
"=",
"list",
"(",
"args",
")",
"self",
".",
"random",
".",
"shuffle",
"(",
"call_args",
")",
"return",
"''",
".",
"join",
"(",
"call_args",
")"
] | Shuffles all arguments and returns them.
ARG_1,...,ARG_N
%{SHUFFLE:A, B ,...,F} -> 'CDA B FE' | [
"Shuffles",
"all",
"arguments",
"and",
"returns",
"them",
".",
"ARG_1",
"...",
"ARG_N"
] | train | https://github.com/cstockton/py-gensend/blob/8c8e911f8e8c386bea42967350beb4636fc19240/gensend/providers/common.py#L196-L204 |
cstockton/py-gensend | gensend/providers/common.py | Common.ipglob | def ipglob(self, *args):
"""Returns a random address from within the given ip global
https://pythonhosted.org/netaddr/api.html#ip-glob-ranges
IPGLOB:GLOB
%{IPGLOB:*.*.*.*} -> ''
"""
call_args = list(args)
return self.random.choice(IPGlob(call_args.pop(0))) | python | def ipglob(self, *args):
"""Returns a random address from within the given ip global
https://pythonhosted.org/netaddr/api.html#ip-glob-ranges
IPGLOB:GLOB
%{IPGLOB:*.*.*.*} -> ''
"""
call_args = list(args)
return self.random.choice(IPGlob(call_args.pop(0))) | [
"def",
"ipglob",
"(",
"self",
",",
"*",
"args",
")",
":",
"call_args",
"=",
"list",
"(",
"args",
")",
"return",
"self",
".",
"random",
".",
"choice",
"(",
"IPGlob",
"(",
"call_args",
".",
"pop",
"(",
"0",
")",
")",
")"
] | Returns a random address from within the given ip global
https://pythonhosted.org/netaddr/api.html#ip-glob-ranges
IPGLOB:GLOB
%{IPGLOB:*.*.*.*} -> '' | [
"Returns",
"a",
"random",
"address",
"from",
"within",
"the",
"given",
"ip",
"global",
"https",
":",
"//",
"pythonhosted",
".",
"org",
"/",
"netaddr",
"/",
"api",
".",
"html#ip",
"-",
"glob",
"-",
"ranges",
"IPGLOB",
":",
"GLOB"
] | train | https://github.com/cstockton/py-gensend/blob/8c8e911f8e8c386bea42967350beb4636fc19240/gensend/providers/common.py#L222-L230 |
cstockton/py-gensend | gensend/providers/common.py | Common.iprange | def iprange(self, *args):
"""Returns a random address from within the given range of two addresses
IPRANGE:start,end
%{IPRANGE:10.0.0.0/8,} -> ''
"""
call_args = list(args)
return self.random.choice(IPRange(call_args.pop(0), call_args.pop(0))) | python | def iprange(self, *args):
"""Returns a random address from within the given range of two addresses
IPRANGE:start,end
%{IPRANGE:10.0.0.0/8,} -> ''
"""
call_args = list(args)
return self.random.choice(IPRange(call_args.pop(0), call_args.pop(0))) | [
"def",
"iprange",
"(",
"self",
",",
"*",
"args",
")",
":",
"call_args",
"=",
"list",
"(",
"args",
")",
"return",
"self",
".",
"random",
".",
"choice",
"(",
"IPRange",
"(",
"call_args",
".",
"pop",
"(",
"0",
")",
",",
"call_args",
".",
"pop",
"(",
... | Returns a random address from within the given range of two addresses
IPRANGE:start,end
%{IPRANGE:10.0.0.0/8,} -> '' | [
"Returns",
"a",
"random",
"address",
"from",
"within",
"the",
"given",
"range",
"of",
"two",
"addresses",
"IPRANGE",
":",
"start",
"end"
] | train | https://github.com/cstockton/py-gensend/blob/8c8e911f8e8c386bea42967350beb4636fc19240/gensend/providers/common.py#L232-L239 |
cstockton/py-gensend | gensend/providers/common.py | Common.ipcidr | def ipcidr(self, *args):
"""Returns a random address from within the given cidr notation
IPCIDR:cidr
%{IPCIDR:10.0.0.0/8} -> ''
"""
call_args = list(args)
return self.random.choice(IPNetwork(call_args.pop(0))) | python | def ipcidr(self, *args):
"""Returns a random address from within the given cidr notation
IPCIDR:cidr
%{IPCIDR:10.0.0.0/8} -> ''
"""
call_args = list(args)
return self.random.choice(IPNetwork(call_args.pop(0))) | [
"def",
"ipcidr",
"(",
"self",
",",
"*",
"args",
")",
":",
"call_args",
"=",
"list",
"(",
"args",
")",
"return",
"self",
".",
"random",
".",
"choice",
"(",
"IPNetwork",
"(",
"call_args",
".",
"pop",
"(",
"0",
")",
")",
")"
] | Returns a random address from within the given cidr notation
IPCIDR:cidr
%{IPCIDR:10.0.0.0/8} -> '' | [
"Returns",
"a",
"random",
"address",
"from",
"within",
"the",
"given",
"cidr",
"notation",
"IPCIDR",
":",
"cidr"
] | train | https://github.com/cstockton/py-gensend/blob/8c8e911f8e8c386bea42967350beb4636fc19240/gensend/providers/common.py#L241-L248 |
cstockton/py-gensend | gensend/providers/common.py | Common.int | def int(self, *args):
"""Returns a random int between -sys.maxint and sys.maxint
INT
%{INT} -> '1245123'
%{INT:10} -> '10000000'
%{INT:10,20} -> '19'
"""
return self.random.randint(*self._arg_defaults(args, [-sys.maxint, sys.maxint], int)) | python | def int(self, *args):
"""Returns a random int between -sys.maxint and sys.maxint
INT
%{INT} -> '1245123'
%{INT:10} -> '10000000'
%{INT:10,20} -> '19'
"""
return self.random.randint(*self._arg_defaults(args, [-sys.maxint, sys.maxint], int)) | [
"def",
"int",
"(",
"self",
",",
"*",
"args",
")",
":",
"return",
"self",
".",
"random",
".",
"randint",
"(",
"*",
"self",
".",
"_arg_defaults",
"(",
"args",
",",
"[",
"-",
"sys",
".",
"maxint",
",",
"sys",
".",
"maxint",
"]",
",",
"int",
")",
"... | Returns a random int between -sys.maxint and sys.maxint
INT
%{INT} -> '1245123'
%{INT:10} -> '10000000'
%{INT:10,20} -> '19' | [
"Returns",
"a",
"random",
"int",
"between",
"-",
"sys",
".",
"maxint",
"and",
"sys",
".",
"maxint",
"INT"
] | train | https://github.com/cstockton/py-gensend/blob/8c8e911f8e8c386bea42967350beb4636fc19240/gensend/providers/common.py#L250-L258 |
fotonauts/fwissr-python | fwissr/source/file.py | File.merge_conf_file | def merge_conf_file(self, result, conf_file_path):
"Merge a configuration in file with current configuration"
conf = parse_conf_file(conf_file_path)
conf_file_name = os.path.splitext(os.path.basename(conf_file_path))[0]
result_part = result
if not conf_file_name in File.TOP_LEVE... | python | def merge_conf_file(self, result, conf_file_path):
"Merge a configuration in file with current configuration"
conf = parse_conf_file(conf_file_path)
conf_file_name = os.path.splitext(os.path.basename(conf_file_path))[0]
result_part = result
if not conf_file_name in File.TOP_LEVE... | [
"def",
"merge_conf_file",
"(",
"self",
",",
"result",
",",
"conf_file_path",
")",
":",
"conf",
"=",
"parse_conf_file",
"(",
"conf_file_path",
")",
"conf_file_name",
"=",
"os",
".",
"path",
".",
"splitext",
"(",
"os",
".",
"path",
".",
"basename",
"(",
"con... | Merge a configuration in file with current configuration | [
"Merge",
"a",
"configuration",
"in",
"file",
"with",
"current",
"configuration"
] | train | https://github.com/fotonauts/fwissr-python/blob/4314aa53ca45b4534cd312f6343a88596b4416d4/fwissr/source/file.py#L63-L78 |
cbrand/vpnchooser | src/vpnchooser/helpers/decorators.py | require_login | def require_login(func):
"""
Function wrapper to signalize that a login is required.
"""
@wraps(func)
def decorated(*args, **kwargs):
auth = request.authorization
if not auth:
return authenticate()
user = session.query(User).filter(
User.name == auth... | python | def require_login(func):
"""
Function wrapper to signalize that a login is required.
"""
@wraps(func)
def decorated(*args, **kwargs):
auth = request.authorization
if not auth:
return authenticate()
user = session.query(User).filter(
User.name == auth... | [
"def",
"require_login",
"(",
"func",
")",
":",
"@",
"wraps",
"(",
"func",
")",
"def",
"decorated",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"auth",
"=",
"request",
".",
"authorization",
"if",
"not",
"auth",
":",
"return",
"authenticate",
... | Function wrapper to signalize that a login is required. | [
"Function",
"wrapper",
"to",
"signalize",
"that",
"a",
"login",
"is",
"required",
"."
] | train | https://github.com/cbrand/vpnchooser/blob/d153e3d05555c23cf5e8e15e507eecad86465923/src/vpnchooser/helpers/decorators.py#L21-L41 |
cbrand/vpnchooser | src/vpnchooser/helpers/decorators.py | require_admin | def require_admin(func):
"""
Requires an admin user to access this resource.
"""
@wraps(func)
@require_login
def decorated(*args, **kwargs):
user = current_user()
if user and user.is_admin:
return func(*args, **kwargs)
else:
return Response(
... | python | def require_admin(func):
"""
Requires an admin user to access this resource.
"""
@wraps(func)
@require_login
def decorated(*args, **kwargs):
user = current_user()
if user and user.is_admin:
return func(*args, **kwargs)
else:
return Response(
... | [
"def",
"require_admin",
"(",
"func",
")",
":",
"@",
"wraps",
"(",
"func",
")",
"@",
"require_login",
"def",
"decorated",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"user",
"=",
"current_user",
"(",
")",
"if",
"user",
"and",
"user",
".",
"... | Requires an admin user to access this resource. | [
"Requires",
"an",
"admin",
"user",
"to",
"access",
"this",
"resource",
"."
] | train | https://github.com/cbrand/vpnchooser/blob/d153e3d05555c23cf5e8e15e507eecad86465923/src/vpnchooser/helpers/decorators.py#L44-L60 |
abe-winter/pg13-py | pg13/syncschema.py | detect_change_mode | def detect_change_mode(text,change):
"returns 'add' 'delete' or 'internal'. see comments to update_changes for more details."
# warning: some wacky diff logic (in python, probably in JS too) is making some adds / deletes look like replacements (see notes at bottom of diff.py)
if len(change.deltas)>1: return 'i... | python | def detect_change_mode(text,change):
"returns 'add' 'delete' or 'internal'. see comments to update_changes for more details."
# warning: some wacky diff logic (in python, probably in JS too) is making some adds / deletes look like replacements (see notes at bottom of diff.py)
if len(change.deltas)>1: return 'i... | [
"def",
"detect_change_mode",
"(",
"text",
",",
"change",
")",
":",
"# warning: some wacky diff logic (in python, probably in JS too) is making some adds / deletes look like replacements (see notes at bottom of diff.py)\r",
"if",
"len",
"(",
"change",
".",
"deltas",
")",
">",
"1",
... | returns 'add' 'delete' or 'internal'. see comments to update_changes for more details. | [
"returns",
"add",
"delete",
"or",
"internal",
".",
"see",
"comments",
"to",
"update_changes",
"for",
"more",
"details",
"."
] | train | https://github.com/abe-winter/pg13-py/blob/c78806f99f35541a8756987e86edca3438aa97f5/pg13/syncschema.py#L52-L61 |
abe-winter/pg13-py | pg13/syncschema.py | mkchange | def mkchange(text0,text1,version,mtime):
"return a Change diffing the two strings"
return Change(version,mtime,ucrc(text1),diff.word_diff(text0,text1)) | python | def mkchange(text0,text1,version,mtime):
"return a Change diffing the two strings"
return Change(version,mtime,ucrc(text1),diff.word_diff(text0,text1)) | [
"def",
"mkchange",
"(",
"text0",
",",
"text1",
",",
"version",
",",
"mtime",
")",
":",
"return",
"Change",
"(",
"version",
",",
"mtime",
",",
"ucrc",
"(",
"text1",
")",
",",
"diff",
".",
"word_diff",
"(",
"text0",
",",
"text1",
")",
")"
] | return a Change diffing the two strings | [
"return",
"a",
"Change",
"diffing",
"the",
"two",
"strings"
] | train | https://github.com/abe-winter/pg13-py/blob/c78806f99f35541a8756987e86edca3438aa97f5/pg13/syncschema.py#L64-L66 |
abe-winter/pg13-py | pg13/syncschema.py | update_changes | def update_changes(changes,newtext,change):
"decide whether to compact the newest change into the old last; return new change list. assumes changes is safe to mutate.\
note: newtext MUST be the result of applying change to changes, and is only passed to save doing the computation again."
# the criteria for a n... | python | def update_changes(changes,newtext,change):
"decide whether to compact the newest change into the old last; return new change list. assumes changes is safe to mutate.\
note: newtext MUST be the result of applying change to changes, and is only passed to save doing the computation again."
# the criteria for a n... | [
"def",
"update_changes",
"(",
"changes",
",",
"newtext",
",",
"change",
")",
":",
"# the criteria for a new version are:\r",
"# 1. mode change (modes are adding to end, deleting from end, internal edits)\r",
"# 2. length changed by more than 256 chars (why power of 2? why not)\r",
"# 3. ti... | decide whether to compact the newest change into the old last; return new change list. assumes changes is safe to mutate.\
note: newtext MUST be the result of applying change to changes, and is only passed to save doing the computation again. | [
"decide",
"whether",
"to",
"compact",
"the",
"newest",
"change",
"into",
"the",
"old",
"last",
";",
"return",
"new",
"change",
"list",
".",
"assumes",
"changes",
"is",
"safe",
"to",
"mutate",
".",
"\\",
"note",
":",
"newtext",
"MUST",
"be",
"the",
"resul... | train | https://github.com/abe-winter/pg13-py/blob/c78806f99f35541a8756987e86edca3438aa97f5/pg13/syncschema.py#L68-L86 |
abe-winter/pg13-py | pg13/syncschema.py | apply_splice | def apply_splice(a,splice):
"mutate a *and* return it. a as list, splice as diff.Delta."
a[splice.a:splice.b]=splice.text # text isn't always text. See diff comments.
return a | python | def apply_splice(a,splice):
"mutate a *and* return it. a as list, splice as diff.Delta."
a[splice.a:splice.b]=splice.text # text isn't always text. See diff comments.
return a | [
"def",
"apply_splice",
"(",
"a",
",",
"splice",
")",
":",
"a",
"[",
"splice",
".",
"a",
":",
"splice",
".",
"b",
"]",
"=",
"splice",
".",
"text",
"# text isn't always text. See diff comments.\r",
"return",
"a"
] | mutate a *and* return it. a as list, splice as diff.Delta. | [
"mutate",
"a",
"*",
"and",
"*",
"return",
"it",
".",
"a",
"as",
"list",
"splice",
"as",
"diff",
".",
"Delta",
"."
] | train | https://github.com/abe-winter/pg13-py/blob/c78806f99f35541a8756987e86edca3438aa97f5/pg13/syncschema.py#L155-L158 |
abe-winter/pg13-py | pg13/syncschema.py | RefKey.pkeys | def pkeys(self,parent,field):
"returns a list of pkey tuples by combining parent[field] with our attrs"
template=[(parent[k] if k is not None else None) for k in self.pkey]
inull=template.index(None)
def mk(x):
"helper for constructing pkey tuples in a list comp"
template[inull]=x
... | python | def pkeys(self,parent,field):
"returns a list of pkey tuples by combining parent[field] with our attrs"
template=[(parent[k] if k is not None else None) for k in self.pkey]
inull=template.index(None)
def mk(x):
"helper for constructing pkey tuples in a list comp"
template[inull]=x
... | [
"def",
"pkeys",
"(",
"self",
",",
"parent",
",",
"field",
")",
":",
"template",
"=",
"[",
"(",
"parent",
"[",
"k",
"]",
"if",
"k",
"is",
"not",
"None",
"else",
"None",
")",
"for",
"k",
"in",
"self",
".",
"pkey",
"]",
"inull",
"=",
"template",
"... | returns a list of pkey tuples by combining parent[field] with our attrs | [
"returns",
"a",
"list",
"of",
"pkey",
"tuples",
"by",
"combining",
"parent",
"[",
"field",
"]",
"with",
"our",
"attrs"
] | train | https://github.com/abe-winter/pg13-py/blob/c78806f99f35541a8756987e86edca3438aa97f5/pg13/syncschema.py#L39-L50 |
abe-winter/pg13-py | pg13/syncschema.py | VDList.apply | def apply(self,vbase,deltas,utc=None):
"this doesn't modify the object -- it returns a new one (because of how pg.Row.update works)"
if vbase!=len(self.increments): raise BadBaseV(vbase,len(self.increments))
if not all(isinstance(d,diff.Delta) for d in deltas): raise TypeError('not_delta')
utc=utc o... | python | def apply(self,vbase,deltas,utc=None):
"this doesn't modify the object -- it returns a new one (because of how pg.Row.update works)"
if vbase!=len(self.increments): raise BadBaseV(vbase,len(self.increments))
if not all(isinstance(d,diff.Delta) for d in deltas): raise TypeError('not_delta')
utc=utc o... | [
"def",
"apply",
"(",
"self",
",",
"vbase",
",",
"deltas",
",",
"utc",
"=",
"None",
")",
":",
"if",
"vbase",
"!=",
"len",
"(",
"self",
".",
"increments",
")",
":",
"raise",
"BadBaseV",
"(",
"vbase",
",",
"len",
"(",
"self",
".",
"increments",
")",
... | this doesn't modify the object -- it returns a new one (because of how pg.Row.update works) | [
"this",
"doesn",
"t",
"modify",
"the",
"object",
"--",
"it",
"returns",
"a",
"new",
"one",
"(",
"because",
"of",
"how",
"pg",
".",
"Row",
".",
"update",
"works",
")"
] | train | https://github.com/abe-winter/pg13-py/blob/c78806f99f35541a8756987e86edca3438aa97f5/pg13/syncschema.py#L162-L169 |
nens/turn | turn/tools.py | find_resources | def find_resources(client):
""" Detect dispensers and return corresponding resources. """
wildcard = Keys.DISPENSER.format('*')
pattern = re.compile(Keys.DISPENSER.format('(.*)'))
return [pattern.match(d).group(1)
for d in client.scan_iter(wildcard)] | python | def find_resources(client):
""" Detect dispensers and return corresponding resources. """
wildcard = Keys.DISPENSER.format('*')
pattern = re.compile(Keys.DISPENSER.format('(.*)'))
return [pattern.match(d).group(1)
for d in client.scan_iter(wildcard)] | [
"def",
"find_resources",
"(",
"client",
")",
":",
"wildcard",
"=",
"Keys",
".",
"DISPENSER",
".",
"format",
"(",
"'*'",
")",
"pattern",
"=",
"re",
".",
"compile",
"(",
"Keys",
".",
"DISPENSER",
".",
"format",
"(",
"'(.*)'",
")",
")",
"return",
"[",
"... | Detect dispensers and return corresponding resources. | [
"Detect",
"dispensers",
"and",
"return",
"corresponding",
"resources",
"."
] | train | https://github.com/nens/turn/blob/98e806a0749ada0ddfd04b3c29fb04c15bf5ac18/turn/tools.py#L28-L33 |
nens/turn | turn/tools.py | follow | def follow(resources, **kwargs):
""" Follow publications involved with resources. """
# subscribe
client = redis.Redis(decode_responses=True, **kwargs)
resources = resources if resources else find_resources(client)
channels = [Keys.EXTERNAL.format(resource) for resource in resources]
if resource... | python | def follow(resources, **kwargs):
""" Follow publications involved with resources. """
# subscribe
client = redis.Redis(decode_responses=True, **kwargs)
resources = resources if resources else find_resources(client)
channels = [Keys.EXTERNAL.format(resource) for resource in resources]
if resource... | [
"def",
"follow",
"(",
"resources",
",",
"*",
"*",
"kwargs",
")",
":",
"# subscribe",
"client",
"=",
"redis",
".",
"Redis",
"(",
"decode_responses",
"=",
"True",
",",
"*",
"*",
"kwargs",
")",
"resources",
"=",
"resources",
"if",
"resources",
"else",
"find... | Follow publications involved with resources. | [
"Follow",
"publications",
"involved",
"with",
"resources",
"."
] | train | https://github.com/nens/turn/blob/98e806a0749ada0ddfd04b3c29fb04c15bf5ac18/turn/tools.py#L37-L53 |
nens/turn | turn/tools.py | lock | def lock(resources, *args, **kwargs):
""" Lock resources from the command line, for example for maintenance. """
# all resources are locked if nothing is specified
if not resources:
client = redis.Redis(decode_responses=True, **kwargs)
resources = find_resources(client)
if not resources... | python | def lock(resources, *args, **kwargs):
""" Lock resources from the command line, for example for maintenance. """
# all resources are locked if nothing is specified
if not resources:
client = redis.Redis(decode_responses=True, **kwargs)
resources = find_resources(client)
if not resources... | [
"def",
"lock",
"(",
"resources",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"# all resources are locked if nothing is specified",
"if",
"not",
"resources",
":",
"client",
"=",
"redis",
".",
"Redis",
"(",
"decode_responses",
"=",
"True",
",",
"*",
"... | Lock resources from the command line, for example for maintenance. | [
"Lock",
"resources",
"from",
"the",
"command",
"line",
"for",
"example",
"for",
"maintenance",
"."
] | train | https://github.com/nens/turn/blob/98e806a0749ada0ddfd04b3c29fb04c15bf5ac18/turn/tools.py#L56-L83 |
nens/turn | turn/tools.py | reset | def reset(resources, *args, **kwargs):
""" Remove dispensers and indicators for idle resources. """
test = kwargs.pop('test', False)
client = redis.Redis(decode_responses=True, **kwargs)
resources = resources if resources else find_resources(client)
for resource in resources:
# investigate ... | python | def reset(resources, *args, **kwargs):
""" Remove dispensers and indicators for idle resources. """
test = kwargs.pop('test', False)
client = redis.Redis(decode_responses=True, **kwargs)
resources = resources if resources else find_resources(client)
for resource in resources:
# investigate ... | [
"def",
"reset",
"(",
"resources",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"test",
"=",
"kwargs",
".",
"pop",
"(",
"'test'",
",",
"False",
")",
"client",
"=",
"redis",
".",
"Redis",
"(",
"decode_responses",
"=",
"True",
",",
"*",
"*",
... | Remove dispensers and indicators for idle resources. | [
"Remove",
"dispensers",
"and",
"indicators",
"for",
"idle",
"resources",
"."
] | train | https://github.com/nens/turn/blob/98e806a0749ada0ddfd04b3c29fb04c15bf5ac18/turn/tools.py#L86-L123 |
nens/turn | turn/tools.py | status | def status(resources, *args, **kwargs):
"""
Print status report for zero or more resources.
"""
template = '{:<50}{:>10}'
client = redis.Redis(decode_responses=True, **kwargs)
# resource details
for loop, resource in enumerate(resources):
# blank between resources
if loop:
... | python | def status(resources, *args, **kwargs):
"""
Print status report for zero or more resources.
"""
template = '{:<50}{:>10}'
client = redis.Redis(decode_responses=True, **kwargs)
# resource details
for loop, resource in enumerate(resources):
# blank between resources
if loop:
... | [
"def",
"status",
"(",
"resources",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"template",
"=",
"'{:<50}{:>10}'",
"client",
"=",
"redis",
".",
"Redis",
"(",
"decode_responses",
"=",
"True",
",",
"*",
"*",
"kwargs",
")",
"# resource details",
"fo... | Print status report for zero or more resources. | [
"Print",
"status",
"report",
"for",
"zero",
"or",
"more",
"resources",
"."
] | train | https://github.com/nens/turn/blob/98e806a0749ada0ddfd04b3c29fb04c15bf5ac18/turn/tools.py#L126-L174 |
mohamedattahri/PyXMLi | pyxmli/__init__.py | XMLiElement._create_text_node | def _create_text_node(self, root, name, value, cdata=False):
'''
Creates and adds a text node
@param root:Element Root element
@param name:str Tag name
@param value:object Text value
@param cdata:bool A value indicating whether to use CDATA or not.
@return:Node
... | python | def _create_text_node(self, root, name, value, cdata=False):
'''
Creates and adds a text node
@param root:Element Root element
@param name:str Tag name
@param value:object Text value
@param cdata:bool A value indicating whether to use CDATA or not.
@return:Node
... | [
"def",
"_create_text_node",
"(",
"self",
",",
"root",
",",
"name",
",",
"value",
",",
"cdata",
"=",
"False",
")",
":",
"if",
"is_empty_or_none",
"(",
"value",
")",
":",
"return",
"if",
"type",
"(",
"value",
")",
"==",
"date",
":",
"value",
"=",
"date... | Creates and adds a text node
@param root:Element Root element
@param name:str Tag name
@param value:object Text value
@param cdata:bool A value indicating whether to use CDATA or not.
@return:Node | [
"Creates",
"and",
"adds",
"a",
"text",
"node"
] | train | https://github.com/mohamedattahri/PyXMLi/blob/a81a245be822d62f1a20c734ca14b42c786ae81e/pyxmli/__init__.py#L212-L240 |
mohamedattahri/PyXMLi | pyxmli/__init__.py | XMLiElement.to_string | def to_string(self, indent="", newl="", addindent=""):
'''
Returns a string representation of the XMLi element.
@return: str
'''
buf = StringIO()
self.to_xml().writexml(buf, indent=indent, addindent=addindent,
newl=newl)
return buf.g... | python | def to_string(self, indent="", newl="", addindent=""):
'''
Returns a string representation of the XMLi element.
@return: str
'''
buf = StringIO()
self.to_xml().writexml(buf, indent=indent, addindent=addindent,
newl=newl)
return buf.g... | [
"def",
"to_string",
"(",
"self",
",",
"indent",
"=",
"\"\"",
",",
"newl",
"=",
"\"\"",
",",
"addindent",
"=",
"\"\"",
")",
":",
"buf",
"=",
"StringIO",
"(",
")",
"self",
".",
"to_xml",
"(",
")",
".",
"writexml",
"(",
"buf",
",",
"indent",
"=",
"i... | Returns a string representation of the XMLi element.
@return: str | [
"Returns",
"a",
"string",
"representation",
"of",
"the",
"XMLi",
"element",
"."
] | train | https://github.com/mohamedattahri/PyXMLi/blob/a81a245be822d62f1a20c734ca14b42c786ae81e/pyxmli/__init__.py#L256-L264 |
mohamedattahri/PyXMLi | pyxmli/__init__.py | ExtensibleXMLiElement.__createElementNS | def __createElementNS(self, root, uri, name, value):
'''
Creates and returns an element with a qualified name and a name space
@param root:Element Parent element
@param uri:str Namespace URI
@param tag:str Tag name.
'''
tag = root.ownerDocument.createElementNS(to_... | python | def __createElementNS(self, root, uri, name, value):
'''
Creates and returns an element with a qualified name and a name space
@param root:Element Parent element
@param uri:str Namespace URI
@param tag:str Tag name.
'''
tag = root.ownerDocument.createElementNS(to_... | [
"def",
"__createElementNS",
"(",
"self",
",",
"root",
",",
"uri",
",",
"name",
",",
"value",
")",
":",
"tag",
"=",
"root",
".",
"ownerDocument",
".",
"createElementNS",
"(",
"to_unicode",
"(",
"uri",
")",
",",
"to_unicode",
"(",
"name",
")",
")",
"tag"... | Creates and returns an element with a qualified name and a name space
@param root:Element Parent element
@param uri:str Namespace URI
@param tag:str Tag name. | [
"Creates",
"and",
"returns",
"an",
"element",
"with",
"a",
"qualified",
"name",
"and",
"a",
"name",
"space"
] | train | https://github.com/mohamedattahri/PyXMLi/blob/a81a245be822d62f1a20c734ca14b42c786ae81e/pyxmli/__init__.py#L310-L321 |
mohamedattahri/PyXMLi | pyxmli/__init__.py | ExtensibleXMLiElement.to_xml | def to_xml(self, root):
'''
Returns a DOM element contaning the XML representation of the
ExtensibleXMLiElement
@param root:Element Root XML element.
@return: Element
'''
if not len(self.__custom_elements):
return
for uri, tags in self.__custo... | python | def to_xml(self, root):
'''
Returns a DOM element contaning the XML representation of the
ExtensibleXMLiElement
@param root:Element Root XML element.
@return: Element
'''
if not len(self.__custom_elements):
return
for uri, tags in self.__custo... | [
"def",
"to_xml",
"(",
"self",
",",
"root",
")",
":",
"if",
"not",
"len",
"(",
"self",
".",
"__custom_elements",
")",
":",
"return",
"for",
"uri",
",",
"tags",
"in",
"self",
".",
"__custom_elements",
".",
"items",
"(",
")",
":",
"prefix",
",",
"url",
... | Returns a DOM element contaning the XML representation of the
ExtensibleXMLiElement
@param root:Element Root XML element.
@return: Element | [
"Returns",
"a",
"DOM",
"element",
"contaning",
"the",
"XML",
"representation",
"of",
"the",
"ExtensibleXMLiElement"
] | train | https://github.com/mohamedattahri/PyXMLi/blob/a81a245be822d62f1a20c734ca14b42c786ae81e/pyxmli/__init__.py#L323-L338 |
mohamedattahri/PyXMLi | pyxmli/__init__.py | Address.duplicate | def duplicate(self):
'''
Returns a copy of the current address.
@returns: Address
'''
return self.__class__(street_address=self.street_address,
city=self.city, zipcode=self.zipcode,
state=self.state, country=self.country... | python | def duplicate(self):
'''
Returns a copy of the current address.
@returns: Address
'''
return self.__class__(street_address=self.street_address,
city=self.city, zipcode=self.zipcode,
state=self.state, country=self.country... | [
"def",
"duplicate",
"(",
"self",
")",
":",
"return",
"self",
".",
"__class__",
"(",
"street_address",
"=",
"self",
".",
"street_address",
",",
"city",
"=",
"self",
".",
"city",
",",
"zipcode",
"=",
"self",
".",
"zipcode",
",",
"state",
"=",
"self",
"."... | Returns a copy of the current address.
@returns: Address | [
"Returns",
"a",
"copy",
"of",
"the",
"current",
"address",
"."
] | train | https://github.com/mohamedattahri/PyXMLi/blob/a81a245be822d62f1a20c734ca14b42c786ae81e/pyxmli/__init__.py#L414-L421 |
mohamedattahri/PyXMLi | pyxmli/__init__.py | Address.to_xml | def to_xml(self, name="address"):
'''
Returns a DOM Element containing the XML representation of the
address.
@return:Element
'''
for n, v in {"street_address": self.street_address, "city": self.city,
"country": self.country}.items():
if i... | python | def to_xml(self, name="address"):
'''
Returns a DOM Element containing the XML representation of the
address.
@return:Element
'''
for n, v in {"street_address": self.street_address, "city": self.city,
"country": self.country}.items():
if i... | [
"def",
"to_xml",
"(",
"self",
",",
"name",
"=",
"\"address\"",
")",
":",
"for",
"n",
",",
"v",
"in",
"{",
"\"street_address\"",
":",
"self",
".",
"street_address",
",",
"\"city\"",
":",
"self",
".",
"city",
",",
"\"country\"",
":",
"self",
".",
"countr... | Returns a DOM Element containing the XML representation of the
address.
@return:Element | [
"Returns",
"a",
"DOM",
"Element",
"containing",
"the",
"XML",
"representation",
"of",
"the",
"address",
"."
] | train | https://github.com/mohamedattahri/PyXMLi/blob/a81a245be822d62f1a20c734ca14b42c786ae81e/pyxmli/__init__.py#L423-L441 |
mohamedattahri/PyXMLi | pyxmli/__init__.py | Contact.duplicate | def duplicate(self):
'''
Returns a copy of the current contact element.
@returns: Contact
'''
return self.__class__(name=self.name, identifier=self.identifier,
phone=self.phone, require_id=self.__require_id,
address=self... | python | def duplicate(self):
'''
Returns a copy of the current contact element.
@returns: Contact
'''
return self.__class__(name=self.name, identifier=self.identifier,
phone=self.phone, require_id=self.__require_id,
address=self... | [
"def",
"duplicate",
"(",
"self",
")",
":",
"return",
"self",
".",
"__class__",
"(",
"name",
"=",
"self",
".",
"name",
",",
"identifier",
"=",
"self",
".",
"identifier",
",",
"phone",
"=",
"self",
".",
"phone",
",",
"require_id",
"=",
"self",
".",
"__... | Returns a copy of the current contact element.
@returns: Contact | [
"Returns",
"a",
"copy",
"of",
"the",
"current",
"contact",
"element",
"."
] | train | https://github.com/mohamedattahri/PyXMLi/blob/a81a245be822d62f1a20c734ca14b42c786ae81e/pyxmli/__init__.py#L478-L485 |
mohamedattahri/PyXMLi | pyxmli/__init__.py | Contact.to_xml | def to_xml(self, tag_name="buyer"):
'''
Returns an XMLi representation of the object.
@param tag_name:str Tag name
@return: Element
'''
for n, v in {"name": self.name, "address": self.address}.items():
if is_empty_or_none(v):
raise ValueError("... | python | def to_xml(self, tag_name="buyer"):
'''
Returns an XMLi representation of the object.
@param tag_name:str Tag name
@return: Element
'''
for n, v in {"name": self.name, "address": self.address}.items():
if is_empty_or_none(v):
raise ValueError("... | [
"def",
"to_xml",
"(",
"self",
",",
"tag_name",
"=",
"\"buyer\"",
")",
":",
"for",
"n",
",",
"v",
"in",
"{",
"\"name\"",
":",
"self",
".",
"name",
",",
"\"address\"",
":",
"self",
".",
"address",
"}",
".",
"items",
"(",
")",
":",
"if",
"is_empty_or_... | Returns an XMLi representation of the object.
@param tag_name:str Tag name
@return: Element | [
"Returns",
"an",
"XMLi",
"representation",
"of",
"the",
"object",
"."
] | train | https://github.com/mohamedattahri/PyXMLi/blob/a81a245be822d62f1a20c734ca14b42c786ae81e/pyxmli/__init__.py#L487-L507 |
mohamedattahri/PyXMLi | pyxmli/__init__.py | Shipping.to_xml | def to_xml(self):
'''
Returns an XMLi representation of the shipping details.
@return: Element
'''
for n, v in {"recipient": self.recipient}.items():
if is_empty_or_none(v):
raise ValueError("'%s' attribute cannot be empty or None." % n)
doc =... | python | def to_xml(self):
'''
Returns an XMLi representation of the shipping details.
@return: Element
'''
for n, v in {"recipient": self.recipient}.items():
if is_empty_or_none(v):
raise ValueError("'%s' attribute cannot be empty or None." % n)
doc =... | [
"def",
"to_xml",
"(",
"self",
")",
":",
"for",
"n",
",",
"v",
"in",
"{",
"\"recipient\"",
":",
"self",
".",
"recipient",
"}",
".",
"items",
"(",
")",
":",
"if",
"is_empty_or_none",
"(",
"v",
")",
":",
"raise",
"ValueError",
"(",
"\"'%s' attribute canno... | Returns an XMLi representation of the shipping details.
@return: Element | [
"Returns",
"an",
"XMLi",
"representation",
"of",
"the",
"shipping",
"details",
"."
] | train | https://github.com/mohamedattahri/PyXMLi/blob/a81a245be822d62f1a20c734ca14b42c786ae81e/pyxmli/__init__.py#L522-L534 |
mohamedattahri/PyXMLi | pyxmli/__init__.py | Invoice.__set_identifier | def __set_identifier(self, value):
'''
Sets the ID of the invoice.
@param value:str
'''
if not value or not len(value):
raise ValueError("Invalid invoice ID")
self.__identifier = value | python | def __set_identifier(self, value):
'''
Sets the ID of the invoice.
@param value:str
'''
if not value or not len(value):
raise ValueError("Invalid invoice ID")
self.__identifier = value | [
"def",
"__set_identifier",
"(",
"self",
",",
"value",
")",
":",
"if",
"not",
"value",
"or",
"not",
"len",
"(",
"value",
")",
":",
"raise",
"ValueError",
"(",
"\"Invalid invoice ID\"",
")",
"self",
".",
"__identifier",
"=",
"value"
] | Sets the ID of the invoice.
@param value:str | [
"Sets",
"the",
"ID",
"of",
"the",
"invoice",
"."
] | train | https://github.com/mohamedattahri/PyXMLi/blob/a81a245be822d62f1a20c734ca14b42c786ae81e/pyxmli/__init__.py#L624-L632 |
mohamedattahri/PyXMLi | pyxmli/__init__.py | Invoice.__set_status | def __set_status(self, value):
'''
Sets the status of the invoice.
@param value:str
'''
if value not in [INVOICE_DUE, INVOICE_PAID, INVOICE_CANCELED,
INVOICE_IRRECOVERABLE]:
raise ValueError("Invalid invoice status")
self.__status = v... | python | def __set_status(self, value):
'''
Sets the status of the invoice.
@param value:str
'''
if value not in [INVOICE_DUE, INVOICE_PAID, INVOICE_CANCELED,
INVOICE_IRRECOVERABLE]:
raise ValueError("Invalid invoice status")
self.__status = v... | [
"def",
"__set_status",
"(",
"self",
",",
"value",
")",
":",
"if",
"value",
"not",
"in",
"[",
"INVOICE_DUE",
",",
"INVOICE_PAID",
",",
"INVOICE_CANCELED",
",",
"INVOICE_IRRECOVERABLE",
"]",
":",
"raise",
"ValueError",
"(",
"\"Invalid invoice status\"",
")",
"self... | Sets the status of the invoice.
@param value:str | [
"Sets",
"the",
"status",
"of",
"the",
"invoice",
"."
] | train | https://github.com/mohamedattahri/PyXMLi/blob/a81a245be822d62f1a20c734ca14b42c786ae81e/pyxmli/__init__.py#L644-L653 |
mohamedattahri/PyXMLi | pyxmli/__init__.py | Invoice.__set_date | def __set_date(self, value):
'''
Sets the invoice date.
@param value:datetime
'''
value = date_to_datetime(value)
if value > datetime.now() + timedelta(hours=14, minutes=1): #More or less 14 hours from now in case the submitted date was local
raise ValueError(... | python | def __set_date(self, value):
'''
Sets the invoice date.
@param value:datetime
'''
value = date_to_datetime(value)
if value > datetime.now() + timedelta(hours=14, minutes=1): #More or less 14 hours from now in case the submitted date was local
raise ValueError(... | [
"def",
"__set_date",
"(",
"self",
",",
"value",
")",
":",
"value",
"=",
"date_to_datetime",
"(",
"value",
")",
"if",
"value",
">",
"datetime",
".",
"now",
"(",
")",
"+",
"timedelta",
"(",
"hours",
"=",
"14",
",",
"minutes",
"=",
"1",
")",
":",
"#Mo... | Sets the invoice date.
@param value:datetime | [
"Sets",
"the",
"invoice",
"date",
"."
] | train | https://github.com/mohamedattahri/PyXMLi/blob/a81a245be822d62f1a20c734ca14b42c786ae81e/pyxmli/__init__.py#L655-L667 |
mohamedattahri/PyXMLi | pyxmli/__init__.py | Invoice.__set_due_date | def __set_due_date(self, value):
'''
Sets the due date of the invoice.
@param value:date
'''
if type(value) != date:
raise ValueError('Due date must be an instance of date.')
if self.__date.date() and value < self.__date.date():
raise ValueError("... | python | def __set_due_date(self, value):
'''
Sets the due date of the invoice.
@param value:date
'''
if type(value) != date:
raise ValueError('Due date must be an instance of date.')
if self.__date.date() and value < self.__date.date():
raise ValueError("... | [
"def",
"__set_due_date",
"(",
"self",
",",
"value",
")",
":",
"if",
"type",
"(",
"value",
")",
"!=",
"date",
":",
"raise",
"ValueError",
"(",
"'Due date must be an instance of date.'",
")",
"if",
"self",
".",
"__date",
".",
"date",
"(",
")",
"and",
"value"... | Sets the due date of the invoice.
@param value:date | [
"Sets",
"the",
"due",
"date",
"of",
"the",
"invoice",
"."
] | train | https://github.com/mohamedattahri/PyXMLi/blob/a81a245be822d62f1a20c734ca14b42c786ae81e/pyxmli/__init__.py#L669-L681 |
mohamedattahri/PyXMLi | pyxmli/__init__.py | Invoice.compute_discounts | def compute_discounts(self, precision=None):
'''
Returns the total discounts of this group.
@param precision: int Number of decimals
@return: Decimal
'''
return sum([group.compute_discounts(precision) for group
in self.__groups]) | python | def compute_discounts(self, precision=None):
'''
Returns the total discounts of this group.
@param precision: int Number of decimals
@return: Decimal
'''
return sum([group.compute_discounts(precision) for group
in self.__groups]) | [
"def",
"compute_discounts",
"(",
"self",
",",
"precision",
"=",
"None",
")",
":",
"return",
"sum",
"(",
"[",
"group",
".",
"compute_discounts",
"(",
"precision",
")",
"for",
"group",
"in",
"self",
".",
"__groups",
"]",
")"
] | Returns the total discounts of this group.
@param precision: int Number of decimals
@return: Decimal | [
"Returns",
"the",
"total",
"discounts",
"of",
"this",
"group",
"."
] | train | https://github.com/mohamedattahri/PyXMLi/blob/a81a245be822d62f1a20c734ca14b42c786ae81e/pyxmli/__init__.py#L701-L708 |
mohamedattahri/PyXMLi | pyxmli/__init__.py | Invoice.compute_taxes | def compute_taxes(self, precision=None):
'''
Returns the total amount of taxes for this group.
@param precision: int Number of decimal places
@return: Decimal
'''
return sum([group.compute_taxes(precision) for group in self.__groups]) | python | def compute_taxes(self, precision=None):
'''
Returns the total amount of taxes for this group.
@param precision: int Number of decimal places
@return: Decimal
'''
return sum([group.compute_taxes(precision) for group in self.__groups]) | [
"def",
"compute_taxes",
"(",
"self",
",",
"precision",
"=",
"None",
")",
":",
"return",
"sum",
"(",
"[",
"group",
".",
"compute_taxes",
"(",
"precision",
")",
"for",
"group",
"in",
"self",
".",
"__groups",
"]",
")"
] | Returns the total amount of taxes for this group.
@param precision: int Number of decimal places
@return: Decimal | [
"Returns",
"the",
"total",
"amount",
"of",
"taxes",
"for",
"this",
"group",
"."
] | train | https://github.com/mohamedattahri/PyXMLi/blob/a81a245be822d62f1a20c734ca14b42c786ae81e/pyxmli/__init__.py#L718-L724 |
mohamedattahri/PyXMLi | pyxmli/__init__.py | Invoice.compute_payments | def compute_payments(self, precision=None):
'''
Returns the total amount of payments made to this invoice.
@param precision:int Number of decimal places
@return: Decimal
'''
return quantize(sum([payment.amount for payment in self.__payments]),
prec... | python | def compute_payments(self, precision=None):
'''
Returns the total amount of payments made to this invoice.
@param precision:int Number of decimal places
@return: Decimal
'''
return quantize(sum([payment.amount for payment in self.__payments]),
prec... | [
"def",
"compute_payments",
"(",
"self",
",",
"precision",
"=",
"None",
")",
":",
"return",
"quantize",
"(",
"sum",
"(",
"[",
"payment",
".",
"amount",
"for",
"payment",
"in",
"self",
".",
"__payments",
"]",
")",
",",
"precision",
")"
] | Returns the total amount of payments made to this invoice.
@param precision:int Number of decimal places
@return: Decimal | [
"Returns",
"the",
"total",
"amount",
"of",
"payments",
"made",
"to",
"this",
"invoice",
"."
] | train | https://github.com/mohamedattahri/PyXMLi/blob/a81a245be822d62f1a20c734ca14b42c786ae81e/pyxmli/__init__.py#L734-L741 |
mohamedattahri/PyXMLi | pyxmli/__init__.py | Invoice.compute_total | def compute_total(self, precision=None):
'''
Gets the total of the invoice with a defined decimal precision
@param precision: int Number of decimal places
@return: Decimal
'''
return quantize(sum([group.compute_total(precision) for group
in se... | python | def compute_total(self, precision=None):
'''
Gets the total of the invoice with a defined decimal precision
@param precision: int Number of decimal places
@return: Decimal
'''
return quantize(sum([group.compute_total(precision) for group
in se... | [
"def",
"compute_total",
"(",
"self",
",",
"precision",
"=",
"None",
")",
":",
"return",
"quantize",
"(",
"sum",
"(",
"[",
"group",
".",
"compute_total",
"(",
"precision",
")",
"for",
"group",
"in",
"self",
".",
"__groups",
"]",
")",
",",
"places",
"=",... | Gets the total of the invoice with a defined decimal precision
@param precision: int Number of decimal places
@return: Decimal | [
"Gets",
"the",
"total",
"of",
"the",
"invoice",
"with",
"a",
"defined",
"decimal",
"precision"
] | train | https://github.com/mohamedattahri/PyXMLi/blob/a81a245be822d62f1a20c734ca14b42c786ae81e/pyxmli/__init__.py#L767-L774 |
mohamedattahri/PyXMLi | pyxmli/__init__.py | Invoice.duplicate | def duplicate(self):
'''
Returns a copy of the current group, including its lines.
@returns: Group
'''
instance = self.__class__(identifier=self.identifier,
name=self.name, description=self.description,
currency=... | python | def duplicate(self):
'''
Returns a copy of the current group, including its lines.
@returns: Group
'''
instance = self.__class__(identifier=self.identifier,
name=self.name, description=self.description,
currency=... | [
"def",
"duplicate",
"(",
"self",
")",
":",
"instance",
"=",
"self",
".",
"__class__",
"(",
"identifier",
"=",
"self",
".",
"identifier",
",",
"name",
"=",
"self",
".",
"name",
",",
"description",
"=",
"self",
".",
"description",
",",
"currency",
"=",
"... | Returns a copy of the current group, including its lines.
@returns: Group | [
"Returns",
"a",
"copy",
"of",
"the",
"current",
"group",
"including",
"its",
"lines",
"."
] | train | https://github.com/mohamedattahri/PyXMLi/blob/a81a245be822d62f1a20c734ca14b42c786ae81e/pyxmli/__init__.py#L783-L804 |
mohamedattahri/PyXMLi | pyxmli/__init__.py | Invoice.to_xml | def to_xml(self):
'''
Returns a DOM element containing the XML representation of the invoice
@return:Element
'''
if not len(self.groups):
raise InvoiceError("An invoice must have at least one group " \
"of lines.")
for n, v ... | python | def to_xml(self):
'''
Returns a DOM element containing the XML representation of the invoice
@return:Element
'''
if not len(self.groups):
raise InvoiceError("An invoice must have at least one group " \
"of lines.")
for n, v ... | [
"def",
"to_xml",
"(",
"self",
")",
":",
"if",
"not",
"len",
"(",
"self",
".",
"groups",
")",
":",
"raise",
"InvoiceError",
"(",
"\"An invoice must have at least one group \"",
"\"of lines.\"",
")",
"for",
"n",
",",
"v",
"in",
"{",
"\"identifier\"",
":",
"sel... | Returns a DOM element containing the XML representation of the invoice
@return:Element | [
"Returns",
"a",
"DOM",
"element",
"containing",
"the",
"XML",
"representation",
"of",
"the",
"invoice"
] | train | https://github.com/mohamedattahri/PyXMLi/blob/a81a245be822d62f1a20c734ca14b42c786ae81e/pyxmli/__init__.py#L806-L889 |
mohamedattahri/PyXMLi | pyxmli/__init__.py | Invoice.to_signed_str | def to_signed_str(self, private, public, passphrase=None):
'''
Returns a signed version of the invoice.
@param private:file Private key file-like object
@param public:file Public key file-like object
@param passphrase:str Private key passphrase if any.
@return: str
... | python | def to_signed_str(self, private, public, passphrase=None):
'''
Returns a signed version of the invoice.
@param private:file Private key file-like object
@param public:file Public key file-like object
@param passphrase:str Private key passphrase if any.
@return: str
... | [
"def",
"to_signed_str",
"(",
"self",
",",
"private",
",",
"public",
",",
"passphrase",
"=",
"None",
")",
":",
"from",
"pyxmli",
"import",
"xmldsig",
"try",
":",
"from",
"Crypto",
".",
"PublicKey",
"import",
"RSA",
"except",
"ImportError",
":",
"raise",
"Im... | Returns a signed version of the invoice.
@param private:file Private key file-like object
@param public:file Public key file-like object
@param passphrase:str Private key passphrase if any.
@return: str | [
"Returns",
"a",
"signed",
"version",
"of",
"the",
"invoice",
"."
] | train | https://github.com/mohamedattahri/PyXMLi/blob/a81a245be822d62f1a20c734ca14b42c786ae81e/pyxmli/__init__.py#L891-L914 |
mohamedattahri/PyXMLi | pyxmli/__init__.py | DeliveryMethod.__set_method | def __set_method(self, value):
'''
Sets the method to use.
@param value: str
'''
if value not in [DELIVERY_METHOD_EMAIL, DELIVERY_METHOD_SMS,
DELIVERY_METHOD_SNAILMAIL]:
raise ValueError("Invalid deliveries method '%s'" % value)
self.... | python | def __set_method(self, value):
'''
Sets the method to use.
@param value: str
'''
if value not in [DELIVERY_METHOD_EMAIL, DELIVERY_METHOD_SMS,
DELIVERY_METHOD_SNAILMAIL]:
raise ValueError("Invalid deliveries method '%s'" % value)
self.... | [
"def",
"__set_method",
"(",
"self",
",",
"value",
")",
":",
"if",
"value",
"not",
"in",
"[",
"DELIVERY_METHOD_EMAIL",
",",
"DELIVERY_METHOD_SMS",
",",
"DELIVERY_METHOD_SNAILMAIL",
"]",
":",
"raise",
"ValueError",
"(",
"\"Invalid deliveries method '%s'\"",
"%",
"valu... | Sets the method to use.
@param value: str | [
"Sets",
"the",
"method",
"to",
"use",
"."
] | train | https://github.com/mohamedattahri/PyXMLi/blob/a81a245be822d62f1a20c734ca14b42c786ae81e/pyxmli/__init__.py#L930-L939 |
mohamedattahri/PyXMLi | pyxmli/__init__.py | DeliveryMethod.__set_status | def __set_status(self, value):
'''
Sets the deliveries status of this method.
@param value: str
'''
if value not in [DELIVERY_METHOD_STATUS_PENDING,
DELIVERY_METHOD_STATUS_SENT,
DELIVERY_METHOD_STATUS_CONFIRMED,
... | python | def __set_status(self, value):
'''
Sets the deliveries status of this method.
@param value: str
'''
if value not in [DELIVERY_METHOD_STATUS_PENDING,
DELIVERY_METHOD_STATUS_SENT,
DELIVERY_METHOD_STATUS_CONFIRMED,
... | [
"def",
"__set_status",
"(",
"self",
",",
"value",
")",
":",
"if",
"value",
"not",
"in",
"[",
"DELIVERY_METHOD_STATUS_PENDING",
",",
"DELIVERY_METHOD_STATUS_SENT",
",",
"DELIVERY_METHOD_STATUS_CONFIRMED",
",",
"DELIVERY_METHOD_STATUS_BOUNCED",
"]",
":",
"raise",
"ValueEr... | Sets the deliveries status of this method.
@param value: str | [
"Sets",
"the",
"deliveries",
"status",
"of",
"this",
"method",
"."
] | train | https://github.com/mohamedattahri/PyXMLi/blob/a81a245be822d62f1a20c734ca14b42c786ae81e/pyxmli/__init__.py#L941-L952 |
mohamedattahri/PyXMLi | pyxmli/__init__.py | DeliveryMethod.duplicate | def duplicate(self):
'''
Returns a copy of this deliveries method.
@return: DeliveryMethod
'''
return self.__class__(self.method, self.status, self.date, self.ref) | python | def duplicate(self):
'''
Returns a copy of this deliveries method.
@return: DeliveryMethod
'''
return self.__class__(self.method, self.status, self.date, self.ref) | [
"def",
"duplicate",
"(",
"self",
")",
":",
"return",
"self",
".",
"__class__",
"(",
"self",
".",
"method",
",",
"self",
".",
"status",
",",
"self",
".",
"date",
",",
"self",
".",
"ref",
")"
] | Returns a copy of this deliveries method.
@return: DeliveryMethod | [
"Returns",
"a",
"copy",
"of",
"this",
"deliveries",
"method",
"."
] | train | https://github.com/mohamedattahri/PyXMLi/blob/a81a245be822d62f1a20c734ca14b42c786ae81e/pyxmli/__init__.py#L962-L967 |
mohamedattahri/PyXMLi | pyxmli/__init__.py | DeliveryMethod.to_xml | def to_xml(self):
'''
Returns a DOM representation of the deliveries method
@returns: Element
'''
for n, v in { "method": self.method, "status": self.status,
"date":self.date}.items():
if is_empty_or_none(v):
raise DeliveryMethodEr... | python | def to_xml(self):
'''
Returns a DOM representation of the deliveries method
@returns: Element
'''
for n, v in { "method": self.method, "status": self.status,
"date":self.date}.items():
if is_empty_or_none(v):
raise DeliveryMethodEr... | [
"def",
"to_xml",
"(",
"self",
")",
":",
"for",
"n",
",",
"v",
"in",
"{",
"\"method\"",
":",
"self",
".",
"method",
",",
"\"status\"",
":",
"self",
".",
"status",
",",
"\"date\"",
":",
"self",
".",
"date",
"}",
".",
"items",
"(",
")",
":",
"if",
... | Returns a DOM representation of the deliveries method
@returns: Element | [
"Returns",
"a",
"DOM",
"representation",
"of",
"the",
"deliveries",
"method"
] | train | https://github.com/mohamedattahri/PyXMLi/blob/a81a245be822d62f1a20c734ca14b42c786ae81e/pyxmli/__init__.py#L969-L987 |
mohamedattahri/PyXMLi | pyxmli/__init__.py | Payment.__set_amount | def __set_amount(self, value):
'''
Sets the amount of the payment operation.
@param value:float
'''
try:
self.__amount = quantize(Decimal(str(value)))
except:
raise ValueError('Invalid amount value') | python | def __set_amount(self, value):
'''
Sets the amount of the payment operation.
@param value:float
'''
try:
self.__amount = quantize(Decimal(str(value)))
except:
raise ValueError('Invalid amount value') | [
"def",
"__set_amount",
"(",
"self",
",",
"value",
")",
":",
"try",
":",
"self",
".",
"__amount",
"=",
"quantize",
"(",
"Decimal",
"(",
"str",
"(",
"value",
")",
")",
")",
"except",
":",
"raise",
"ValueError",
"(",
"'Invalid amount value'",
")"
] | Sets the amount of the payment operation.
@param value:float | [
"Sets",
"the",
"amount",
"of",
"the",
"payment",
"operation",
"."
] | train | https://github.com/mohamedattahri/PyXMLi/blob/a81a245be822d62f1a20c734ca14b42c786ae81e/pyxmli/__init__.py#L1008-L1016 |
mohamedattahri/PyXMLi | pyxmli/__init__.py | Payment.__set_method | def __set_method(self, value):
'''
Sets the amount of the payment.
'''
if value not in [PAYMENT_METHOD_OTHER, PAYMENT_METHOD_CARD,
PAYMENT_METHOD_CHEQUE, PAYMENT_METHOD_CASH, ]:
raise ValueError('Invalid amount value')
self.__method = value | python | def __set_method(self, value):
'''
Sets the amount of the payment.
'''
if value not in [PAYMENT_METHOD_OTHER, PAYMENT_METHOD_CARD,
PAYMENT_METHOD_CHEQUE, PAYMENT_METHOD_CASH, ]:
raise ValueError('Invalid amount value')
self.__method = value | [
"def",
"__set_method",
"(",
"self",
",",
"value",
")",
":",
"if",
"value",
"not",
"in",
"[",
"PAYMENT_METHOD_OTHER",
",",
"PAYMENT_METHOD_CARD",
",",
"PAYMENT_METHOD_CHEQUE",
",",
"PAYMENT_METHOD_CASH",
",",
"]",
":",
"raise",
"ValueError",
"(",
"'Invalid amount v... | Sets the amount of the payment. | [
"Sets",
"the",
"amount",
"of",
"the",
"payment",
"."
] | train | https://github.com/mohamedattahri/PyXMLi/blob/a81a245be822d62f1a20c734ca14b42c786ae81e/pyxmli/__init__.py#L1018-L1026 |
mohamedattahri/PyXMLi | pyxmli/__init__.py | Payment.__set_date | def __set_date(self, value):
'''
Sets the date of the payment.
@param value:datetime
'''
if not issubclass(value.__class__, date):
raise ValueError('Invalid date value')
self.__date = value | python | def __set_date(self, value):
'''
Sets the date of the payment.
@param value:datetime
'''
if not issubclass(value.__class__, date):
raise ValueError('Invalid date value')
self.__date = value | [
"def",
"__set_date",
"(",
"self",
",",
"value",
")",
":",
"if",
"not",
"issubclass",
"(",
"value",
".",
"__class__",
",",
"date",
")",
":",
"raise",
"ValueError",
"(",
"'Invalid date value'",
")",
"self",
".",
"__date",
"=",
"value"
] | Sets the date of the payment.
@param value:datetime | [
"Sets",
"the",
"date",
"of",
"the",
"payment",
"."
] | train | https://github.com/mohamedattahri/PyXMLi/blob/a81a245be822d62f1a20c734ca14b42c786ae81e/pyxmli/__init__.py#L1028-L1036 |
mohamedattahri/PyXMLi | pyxmli/__init__.py | Payment.duplicate | def duplicate(self):
'''
Returns a copy of the current group, including its lines.
@returns: Group
'''
return self.__class__(amount=self.amount, date=self.date,
method=self.method, ref=self.ref) | python | def duplicate(self):
'''
Returns a copy of the current group, including its lines.
@returns: Group
'''
return self.__class__(amount=self.amount, date=self.date,
method=self.method, ref=self.ref) | [
"def",
"duplicate",
"(",
"self",
")",
":",
"return",
"self",
".",
"__class__",
"(",
"amount",
"=",
"self",
".",
"amount",
",",
"date",
"=",
"self",
".",
"date",
",",
"method",
"=",
"self",
".",
"method",
",",
"ref",
"=",
"self",
".",
"ref",
")"
] | Returns a copy of the current group, including its lines.
@returns: Group | [
"Returns",
"a",
"copy",
"of",
"the",
"current",
"group",
"including",
"its",
"lines",
"."
] | train | https://github.com/mohamedattahri/PyXMLi/blob/a81a245be822d62f1a20c734ca14b42c786ae81e/pyxmli/__init__.py#L1042-L1048 |
mohamedattahri/PyXMLi | pyxmli/__init__.py | Payment.to_xml | def to_xml(self):
'''
Returns a DOM representation of the payment.
@return: Element
'''
for n, v in { "amount": self.amount, "date": self.date,
"method":self.method}.items():
if is_empty_or_none(v):
raise PaymentError("'%s' attribu... | python | def to_xml(self):
'''
Returns a DOM representation of the payment.
@return: Element
'''
for n, v in { "amount": self.amount, "date": self.date,
"method":self.method}.items():
if is_empty_or_none(v):
raise PaymentError("'%s' attribu... | [
"def",
"to_xml",
"(",
"self",
")",
":",
"for",
"n",
",",
"v",
"in",
"{",
"\"amount\"",
":",
"self",
".",
"amount",
",",
"\"date\"",
":",
"self",
".",
"date",
",",
"\"method\"",
":",
"self",
".",
"method",
"}",
".",
"items",
"(",
")",
":",
"if",
... | Returns a DOM representation of the payment.
@return: Element | [
"Returns",
"a",
"DOM",
"representation",
"of",
"the",
"payment",
"."
] | train | https://github.com/mohamedattahri/PyXMLi/blob/a81a245be822d62f1a20c734ca14b42c786ae81e/pyxmli/__init__.py#L1050-L1068 |
mohamedattahri/PyXMLi | pyxmli/__init__.py | Group.compute_discounts | def compute_discounts(self, precision=None):
'''
Returns the total amount of discounts of this group.
@param precision:int Total amount of discounts
@return: Decimal
'''
return sum([line.compute_discounts(precision) for line in self.__lines]) | python | def compute_discounts(self, precision=None):
'''
Returns the total amount of discounts of this group.
@param precision:int Total amount of discounts
@return: Decimal
'''
return sum([line.compute_discounts(precision) for line in self.__lines]) | [
"def",
"compute_discounts",
"(",
"self",
",",
"precision",
"=",
"None",
")",
":",
"return",
"sum",
"(",
"[",
"line",
".",
"compute_discounts",
"(",
"precision",
")",
"for",
"line",
"in",
"self",
".",
"__lines",
"]",
")"
] | Returns the total amount of discounts of this group.
@param precision:int Total amount of discounts
@return: Decimal | [
"Returns",
"the",
"total",
"amount",
"of",
"discounts",
"of",
"this",
"group",
"."
] | train | https://github.com/mohamedattahri/PyXMLi/blob/a81a245be822d62f1a20c734ca14b42c786ae81e/pyxmli/__init__.py#L1102-L1108 |
mohamedattahri/PyXMLi | pyxmli/__init__.py | Group.compute_taxes | def compute_taxes(self, precision=None):
'''
Returns the total amount of taxes of this group.
@param precision:int Total amount of discounts
@return: Decimal
'''
return sum([line.compute_taxes(precision) for line in self.__lines]) | python | def compute_taxes(self, precision=None):
'''
Returns the total amount of taxes of this group.
@param precision:int Total amount of discounts
@return: Decimal
'''
return sum([line.compute_taxes(precision) for line in self.__lines]) | [
"def",
"compute_taxes",
"(",
"self",
",",
"precision",
"=",
"None",
")",
":",
"return",
"sum",
"(",
"[",
"line",
".",
"compute_taxes",
"(",
"precision",
")",
"for",
"line",
"in",
"self",
".",
"__lines",
"]",
")"
] | Returns the total amount of taxes of this group.
@param precision:int Total amount of discounts
@return: Decimal | [
"Returns",
"the",
"total",
"amount",
"of",
"taxes",
"of",
"this",
"group",
"."
] | train | https://github.com/mohamedattahri/PyXMLi/blob/a81a245be822d62f1a20c734ca14b42c786ae81e/pyxmli/__init__.py#L1118-L1124 |
mohamedattahri/PyXMLi | pyxmli/__init__.py | Group.compute_total | def compute_total(self, precision=None):
'''
Gets the total of the invoice with a defined decimal precision
@param precision: int Number of decimal places
@return: Decimal
'''
return quantize(sum([line.compute_total(precision) for line
in self... | python | def compute_total(self, precision=None):
'''
Gets the total of the invoice with a defined decimal precision
@param precision: int Number of decimal places
@return: Decimal
'''
return quantize(sum([line.compute_total(precision) for line
in self... | [
"def",
"compute_total",
"(",
"self",
",",
"precision",
"=",
"None",
")",
":",
"return",
"quantize",
"(",
"sum",
"(",
"[",
"line",
".",
"compute_total",
"(",
"precision",
")",
"for",
"line",
"in",
"self",
".",
"__lines",
"]",
")",
",",
"places",
"=",
... | Gets the total of the invoice with a defined decimal precision
@param precision: int Number of decimal places
@return: Decimal | [
"Gets",
"the",
"total",
"of",
"the",
"invoice",
"with",
"a",
"defined",
"decimal",
"precision"
] | train | https://github.com/mohamedattahri/PyXMLi/blob/a81a245be822d62f1a20c734ca14b42c786ae81e/pyxmli/__init__.py#L1134-L1141 |
mohamedattahri/PyXMLi | pyxmli/__init__.py | Group.duplicate | def duplicate(self):
'''
Returns a copy of the current group, including its lines.
@returns: Group
'''
instance = self.__class__(name=self.name, description=self.description)
for line in self.lines:
instance.lines.append(line.duplicate())
return instan... | python | def duplicate(self):
'''
Returns a copy of the current group, including its lines.
@returns: Group
'''
instance = self.__class__(name=self.name, description=self.description)
for line in self.lines:
instance.lines.append(line.duplicate())
return instan... | [
"def",
"duplicate",
"(",
"self",
")",
":",
"instance",
"=",
"self",
".",
"__class__",
"(",
"name",
"=",
"self",
".",
"name",
",",
"description",
"=",
"self",
".",
"description",
")",
"for",
"line",
"in",
"self",
".",
"lines",
":",
"instance",
".",
"l... | Returns a copy of the current group, including its lines.
@returns: Group | [
"Returns",
"a",
"copy",
"of",
"the",
"current",
"group",
"including",
"its",
"lines",
"."
] | train | https://github.com/mohamedattahri/PyXMLi/blob/a81a245be822d62f1a20c734ca14b42c786ae81e/pyxmli/__init__.py#L1143-L1151 |
mohamedattahri/PyXMLi | pyxmli/__init__.py | Group.to_xml | def to_xml(self):
'''
Returns a DOM representation of the group.
@return: Element
'''
if not len(self.lines):
raise GroupError("A group must at least have one line.")
doc = Document()
root = doc.createElement("group")
super(Group, self).to_xml... | python | def to_xml(self):
'''
Returns a DOM representation of the group.
@return: Element
'''
if not len(self.lines):
raise GroupError("A group must at least have one line.")
doc = Document()
root = doc.createElement("group")
super(Group, self).to_xml... | [
"def",
"to_xml",
"(",
"self",
")",
":",
"if",
"not",
"len",
"(",
"self",
".",
"lines",
")",
":",
"raise",
"GroupError",
"(",
"\"A group must at least have one line.\"",
")",
"doc",
"=",
"Document",
"(",
")",
"root",
"=",
"doc",
".",
"createElement",
"(",
... | Returns a DOM representation of the group.
@return: Element | [
"Returns",
"a",
"DOM",
"representation",
"of",
"the",
"group",
"."
] | train | https://github.com/mohamedattahri/PyXMLi/blob/a81a245be822d62f1a20c734ca14b42c786ae81e/pyxmli/__init__.py#L1153-L1176 |
mohamedattahri/PyXMLi | pyxmli/__init__.py | Line.__set_unit | def __set_unit(self, value):
'''
Sets the unit of the line.
@param value:str
'''
if value in UNITS:
value = value.upper()
self.__unit = value | python | def __set_unit(self, value):
'''
Sets the unit of the line.
@param value:str
'''
if value in UNITS:
value = value.upper()
self.__unit = value | [
"def",
"__set_unit",
"(",
"self",
",",
"value",
")",
":",
"if",
"value",
"in",
"UNITS",
":",
"value",
"=",
"value",
".",
"upper",
"(",
")",
"self",
".",
"__unit",
"=",
"value"
] | Sets the unit of the line.
@param value:str | [
"Sets",
"the",
"unit",
"of",
"the",
"line",
"."
] | train | https://github.com/mohamedattahri/PyXMLi/blob/a81a245be822d62f1a20c734ca14b42c786ae81e/pyxmli/__init__.py#L1229-L1237 |
mohamedattahri/PyXMLi | pyxmli/__init__.py | Line.__set_quantity | def __set_quantity(self, value):
'''
Sets the quantity
@param value:str
'''
try:
if value < 0:
raise ValueError()
self.__quantity = Decimal(str(value))
except ValueError:
raise ValueError("Quantity must be a positive nu... | python | def __set_quantity(self, value):
'''
Sets the quantity
@param value:str
'''
try:
if value < 0:
raise ValueError()
self.__quantity = Decimal(str(value))
except ValueError:
raise ValueError("Quantity must be a positive nu... | [
"def",
"__set_quantity",
"(",
"self",
",",
"value",
")",
":",
"try",
":",
"if",
"value",
"<",
"0",
":",
"raise",
"ValueError",
"(",
")",
"self",
".",
"__quantity",
"=",
"Decimal",
"(",
"str",
"(",
"value",
")",
")",
"except",
"ValueError",
":",
"rais... | Sets the quantity
@param value:str | [
"Sets",
"the",
"quantity"
] | train | https://github.com/mohamedattahri/PyXMLi/blob/a81a245be822d62f1a20c734ca14b42c786ae81e/pyxmli/__init__.py#L1239-L1250 |
mohamedattahri/PyXMLi | pyxmli/__init__.py | Line.__set_unit_price | def __set_unit_price(self, value):
'''
Sets the unit price
@param value:str
'''
try:
if value < 0:
raise ValueError()
self.__unit_price = Decimal(str(value))
except ValueError:
raise ValueError("Unit Price must be a pos... | python | def __set_unit_price(self, value):
'''
Sets the unit price
@param value:str
'''
try:
if value < 0:
raise ValueError()
self.__unit_price = Decimal(str(value))
except ValueError:
raise ValueError("Unit Price must be a pos... | [
"def",
"__set_unit_price",
"(",
"self",
",",
"value",
")",
":",
"try",
":",
"if",
"value",
"<",
"0",
":",
"raise",
"ValueError",
"(",
")",
"self",
".",
"__unit_price",
"=",
"Decimal",
"(",
"str",
"(",
"value",
")",
")",
"except",
"ValueError",
":",
"... | Sets the unit price
@param value:str | [
"Sets",
"the",
"unit",
"price"
] | train | https://github.com/mohamedattahri/PyXMLi/blob/a81a245be822d62f1a20c734ca14b42c786ae81e/pyxmli/__init__.py#L1252-L1263 |
mohamedattahri/PyXMLi | pyxmli/__init__.py | Line.compute_discounts | def compute_discounts(self, precision=None):
'''
Returns the total amount of discounts for this line with a specific
number of decimals.
@param precision:int number of decimal places
@return: Decimal
'''
gross = self.compute_gross(precision)
return min(gro... | python | def compute_discounts(self, precision=None):
'''
Returns the total amount of discounts for this line with a specific
number of decimals.
@param precision:int number of decimal places
@return: Decimal
'''
gross = self.compute_gross(precision)
return min(gro... | [
"def",
"compute_discounts",
"(",
"self",
",",
"precision",
"=",
"None",
")",
":",
"gross",
"=",
"self",
".",
"compute_gross",
"(",
"precision",
")",
"return",
"min",
"(",
"gross",
",",
"sum",
"(",
"[",
"d",
".",
"compute",
"(",
"gross",
",",
"precision... | Returns the total amount of discounts for this line with a specific
number of decimals.
@param precision:int number of decimal places
@return: Decimal | [
"Returns",
"the",
"total",
"amount",
"of",
"discounts",
"for",
"this",
"line",
"with",
"a",
"specific",
"number",
"of",
"decimals",
"."
] | train | https://github.com/mohamedattahri/PyXMLi/blob/a81a245be822d62f1a20c734ca14b42c786ae81e/pyxmli/__init__.py#L1289-L1298 |
mohamedattahri/PyXMLi | pyxmli/__init__.py | Line.compute_taxes | def compute_taxes(self, precision=None):
'''
Returns the total amount of taxes for this line with a specific
number of decimals
@param precision: int Number of decimal places
@return: Decimal
'''
base = self.gross - self.total_discounts
return quantize(su... | python | def compute_taxes(self, precision=None):
'''
Returns the total amount of taxes for this line with a specific
number of decimals
@param precision: int Number of decimal places
@return: Decimal
'''
base = self.gross - self.total_discounts
return quantize(su... | [
"def",
"compute_taxes",
"(",
"self",
",",
"precision",
"=",
"None",
")",
":",
"base",
"=",
"self",
".",
"gross",
"-",
"self",
".",
"total_discounts",
"return",
"quantize",
"(",
"sum",
"(",
"[",
"t",
".",
"compute",
"(",
"base",
",",
"precision",
")",
... | Returns the total amount of taxes for this line with a specific
number of decimals
@param precision: int Number of decimal places
@return: Decimal | [
"Returns",
"the",
"total",
"amount",
"of",
"taxes",
"for",
"this",
"line",
"with",
"a",
"specific",
"number",
"of",
"decimals"
] | train | https://github.com/mohamedattahri/PyXMLi/blob/a81a245be822d62f1a20c734ca14b42c786ae81e/pyxmli/__init__.py#L1308-L1317 |
mohamedattahri/PyXMLi | pyxmli/__init__.py | Line.compute_total | def compute_total(self, precision=None):
'''
Gets the total of the invoice with a defined decimal precision
@param precision: int Number of decimal places
@return: Decimal
'''
return quantize((self.compute_gross(precision) +
self.compute_taxes(prec... | python | def compute_total(self, precision=None):
'''
Gets the total of the invoice with a defined decimal precision
@param precision: int Number of decimal places
@return: Decimal
'''
return quantize((self.compute_gross(precision) +
self.compute_taxes(prec... | [
"def",
"compute_total",
"(",
"self",
",",
"precision",
"=",
"None",
")",
":",
"return",
"quantize",
"(",
"(",
"self",
".",
"compute_gross",
"(",
"precision",
")",
"+",
"self",
".",
"compute_taxes",
"(",
"precision",
")",
"-",
"self",
".",
"compute_discount... | Gets the total of the invoice with a defined decimal precision
@param precision: int Number of decimal places
@return: Decimal | [
"Gets",
"the",
"total",
"of",
"the",
"invoice",
"with",
"a",
"defined",
"decimal",
"precision"
] | train | https://github.com/mohamedattahri/PyXMLi/blob/a81a245be822d62f1a20c734ca14b42c786ae81e/pyxmli/__init__.py#L1327-L1336 |
mohamedattahri/PyXMLi | pyxmli/__init__.py | Line.duplicate | def duplicate(self):
'''
Returns a copy of the current Line, including its taxes and discounts
@returns: Line.
'''
instance = self.__class__(name=self.name, description=self.description,
unit=self.unit, quantity=self.quantity,
... | python | def duplicate(self):
'''
Returns a copy of the current Line, including its taxes and discounts
@returns: Line.
'''
instance = self.__class__(name=self.name, description=self.description,
unit=self.unit, quantity=self.quantity,
... | [
"def",
"duplicate",
"(",
"self",
")",
":",
"instance",
"=",
"self",
".",
"__class__",
"(",
"name",
"=",
"self",
".",
"name",
",",
"description",
"=",
"self",
".",
"description",
",",
"unit",
"=",
"self",
".",
"unit",
",",
"quantity",
"=",
"self",
"."... | Returns a copy of the current Line, including its taxes and discounts
@returns: Line. | [
"Returns",
"a",
"copy",
"of",
"the",
"current",
"Line",
"including",
"its",
"taxes",
"and",
"discounts"
] | train | https://github.com/mohamedattahri/PyXMLi/blob/a81a245be822d62f1a20c734ca14b42c786ae81e/pyxmli/__init__.py#L1343-L1356 |
mohamedattahri/PyXMLi | pyxmli/__init__.py | Line.to_xml | def to_xml(self):
'''
Returns a DOM representation of the line.
@return: Element
'''
for n, v in {"name": self.name, "quantity": self.quantity,
"unit_price": self.unit_price}.items():
if is_empty_or_none(v):
raise LineError("'%s' a... | python | def to_xml(self):
'''
Returns a DOM representation of the line.
@return: Element
'''
for n, v in {"name": self.name, "quantity": self.quantity,
"unit_price": self.unit_price}.items():
if is_empty_or_none(v):
raise LineError("'%s' a... | [
"def",
"to_xml",
"(",
"self",
")",
":",
"for",
"n",
",",
"v",
"in",
"{",
"\"name\"",
":",
"self",
".",
"name",
",",
"\"quantity\"",
":",
"self",
".",
"quantity",
",",
"\"unit_price\"",
":",
"self",
".",
"unit_price",
"}",
".",
"items",
"(",
")",
":... | Returns a DOM representation of the line.
@return: Element | [
"Returns",
"a",
"DOM",
"representation",
"of",
"the",
"line",
"."
] | train | https://github.com/mohamedattahri/PyXMLi/blob/a81a245be822d62f1a20c734ca14b42c786ae81e/pyxmli/__init__.py#L1358-L1403 |
mohamedattahri/PyXMLi | pyxmli/__init__.py | Treatment.__set_interval | def __set_interval(self, value):
'''
Sets the treatment interval
@param value:Interval
'''
if not isinstance(self, Interval):
raise ValueError("'value' must be of type Interval")
self.__interval = value | python | def __set_interval(self, value):
'''
Sets the treatment interval
@param value:Interval
'''
if not isinstance(self, Interval):
raise ValueError("'value' must be of type Interval")
self.__interval = value | [
"def",
"__set_interval",
"(",
"self",
",",
"value",
")",
":",
"if",
"not",
"isinstance",
"(",
"self",
",",
"Interval",
")",
":",
"raise",
"ValueError",
"(",
"\"'value' must be of type Interval\"",
")",
"self",
".",
"__interval",
"=",
"value"
] | Sets the treatment interval
@param value:Interval | [
"Sets",
"the",
"treatment",
"interval"
] | train | https://github.com/mohamedattahri/PyXMLi/blob/a81a245be822d62f1a20c734ca14b42c786ae81e/pyxmli/__init__.py#L1426-L1434 |
mohamedattahri/PyXMLi | pyxmli/__init__.py | Treatment.__set_name | def __set_name(self, value):
'''
Sets the name of the treatment.
@param value:str
'''
if not value or not len(value):
raise ValueError("Invalid name.")
self.__name = value | python | def __set_name(self, value):
'''
Sets the name of the treatment.
@param value:str
'''
if not value or not len(value):
raise ValueError("Invalid name.")
self.__name = value | [
"def",
"__set_name",
"(",
"self",
",",
"value",
")",
":",
"if",
"not",
"value",
"or",
"not",
"len",
"(",
"value",
")",
":",
"raise",
"ValueError",
"(",
"\"Invalid name.\"",
")",
"self",
".",
"__name",
"=",
"value"
] | Sets the name of the treatment.
@param value:str | [
"Sets",
"the",
"name",
"of",
"the",
"treatment",
"."
] | train | https://github.com/mohamedattahri/PyXMLi/blob/a81a245be822d62f1a20c734ca14b42c786ae81e/pyxmli/__init__.py#L1436-L1444 |
mohamedattahri/PyXMLi | pyxmli/__init__.py | Treatment.__set_rate_type | def __set_rate_type(self, value):
'''
Sets the rate type.
@param value:str
'''
if value not in [RATE_TYPE_FIXED, RATE_TYPE_PERCENTAGE]:
raise ValueError("Invalid rate type.")
self.__rate_type = value | python | def __set_rate_type(self, value):
'''
Sets the rate type.
@param value:str
'''
if value not in [RATE_TYPE_FIXED, RATE_TYPE_PERCENTAGE]:
raise ValueError("Invalid rate type.")
self.__rate_type = value | [
"def",
"__set_rate_type",
"(",
"self",
",",
"value",
")",
":",
"if",
"value",
"not",
"in",
"[",
"RATE_TYPE_FIXED",
",",
"RATE_TYPE_PERCENTAGE",
"]",
":",
"raise",
"ValueError",
"(",
"\"Invalid rate type.\"",
")",
"self",
".",
"__rate_type",
"=",
"value"
] | Sets the rate type.
@param value:str | [
"Sets",
"the",
"rate",
"type",
"."
] | train | https://github.com/mohamedattahri/PyXMLi/blob/a81a245be822d62f1a20c734ca14b42c786ae81e/pyxmli/__init__.py#L1446-L1454 |
mohamedattahri/PyXMLi | pyxmli/__init__.py | Treatment.duplicate | def duplicate(self):
'''
Returns a copy of the current treatment.
@returns: Treatment.
'''
return self.__class__(name=self.name, description=self.description,
rate_type=self.rate_type, rate=self.rate,
interval=self.inter... | python | def duplicate(self):
'''
Returns a copy of the current treatment.
@returns: Treatment.
'''
return self.__class__(name=self.name, description=self.description,
rate_type=self.rate_type, rate=self.rate,
interval=self.inter... | [
"def",
"duplicate",
"(",
"self",
")",
":",
"return",
"self",
".",
"__class__",
"(",
"name",
"=",
"self",
".",
"name",
",",
"description",
"=",
"self",
".",
"description",
",",
"rate_type",
"=",
"self",
".",
"rate_type",
",",
"rate",
"=",
"self",
".",
... | Returns a copy of the current treatment.
@returns: Treatment. | [
"Returns",
"a",
"copy",
"of",
"the",
"current",
"treatment",
"."
] | train | https://github.com/mohamedattahri/PyXMLi/blob/a81a245be822d62f1a20c734ca14b42c786ae81e/pyxmli/__init__.py#L1471-L1478 |
mohamedattahri/PyXMLi | pyxmli/__init__.py | Treatment.compute | def compute(self, base, precision=None):
'''
Computes the amount of the treatment.
@param base:float Gross
@return: Decimal
'''
if base <= ZERO:
return ZERO
if self.rate_type == RATE_TYPE_FIXED:
if not self.interval or base >= self.interva... | python | def compute(self, base, precision=None):
'''
Computes the amount of the treatment.
@param base:float Gross
@return: Decimal
'''
if base <= ZERO:
return ZERO
if self.rate_type == RATE_TYPE_FIXED:
if not self.interval or base >= self.interva... | [
"def",
"compute",
"(",
"self",
",",
"base",
",",
"precision",
"=",
"None",
")",
":",
"if",
"base",
"<=",
"ZERO",
":",
"return",
"ZERO",
"if",
"self",
".",
"rate_type",
"==",
"RATE_TYPE_FIXED",
":",
"if",
"not",
"self",
".",
"interval",
"or",
"base",
... | Computes the amount of the treatment.
@param base:float Gross
@return: Decimal | [
"Computes",
"the",
"amount",
"of",
"the",
"treatment",
"."
] | train | https://github.com/mohamedattahri/PyXMLi/blob/a81a245be822d62f1a20c734ca14b42c786ae81e/pyxmli/__init__.py#L1480-L1501 |
mohamedattahri/PyXMLi | pyxmli/__init__.py | Treatment.to_xml | def to_xml(self, name):
'''
Returns a DOM representation of the line treatment.
@return: Element
'''
for n, v in {"rate_type": self.rate_type,
"rate": self.rate,
"name": self.name,
"description": self.description}.ite... | python | def to_xml(self, name):
'''
Returns a DOM representation of the line treatment.
@return: Element
'''
for n, v in {"rate_type": self.rate_type,
"rate": self.rate,
"name": self.name,
"description": self.description}.ite... | [
"def",
"to_xml",
"(",
"self",
",",
"name",
")",
":",
"for",
"n",
",",
"v",
"in",
"{",
"\"rate_type\"",
":",
"self",
".",
"rate_type",
",",
"\"rate\"",
":",
"self",
".",
"rate",
",",
"\"name\"",
":",
"self",
".",
"name",
",",
"\"description\"",
":",
... | Returns a DOM representation of the line treatment.
@return: Element | [
"Returns",
"a",
"DOM",
"representation",
"of",
"the",
"line",
"treatment",
"."
] | train | https://github.com/mohamedattahri/PyXMLi/blob/a81a245be822d62f1a20c734ca14b42c786ae81e/pyxmli/__init__.py#L1503-L1524 |
mohamedattahri/PyXMLi | pyxmli/__init__.py | Discount.compute | def compute(self, base, *args, **kwargs):
'''
Returns the value of the discount.
@param base:float Computation base.
@return: Decimal
'''
return min(base, super(Discount, self).compute(base, *args, **kwargs)) | python | def compute(self, base, *args, **kwargs):
'''
Returns the value of the discount.
@param base:float Computation base.
@return: Decimal
'''
return min(base, super(Discount, self).compute(base, *args, **kwargs)) | [
"def",
"compute",
"(",
"self",
",",
"base",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"return",
"min",
"(",
"base",
",",
"super",
"(",
"Discount",
",",
"self",
")",
".",
"compute",
"(",
"base",
",",
"*",
"args",
",",
"*",
"*",
"kwarg... | Returns the value of the discount.
@param base:float Computation base.
@return: Decimal | [
"Returns",
"the",
"value",
"of",
"the",
"discount",
"."
] | train | https://github.com/mohamedattahri/PyXMLi/blob/a81a245be822d62f1a20c734ca14b42c786ae81e/pyxmli/__init__.py#L1550-L1556 |
emencia/emencia_paste_djangocms_3 | emencia_paste_djangocms_3/django_buildout/project/accounts/views.py | RegistrationView.register | def register(self, request, **cleaned_data):
"""
Given a username, email address and password, register a new
user account, which will initially be inactive.
Along with the new ``User`` object, a new
``registration.models.RegistrationProfile`` will be created,
tied to th... | python | def register(self, request, **cleaned_data):
"""
Given a username, email address and password, register a new
user account, which will initially be inactive.
Along with the new ``User`` object, a new
``registration.models.RegistrationProfile`` will be created,
tied to th... | [
"def",
"register",
"(",
"self",
",",
"request",
",",
"*",
"*",
"cleaned_data",
")",
":",
"if",
"Site",
".",
"_meta",
".",
"installed",
":",
"site",
"=",
"Site",
".",
"objects",
".",
"get_current",
"(",
")",
"else",
":",
"site",
"=",
"RequestSite",
"(... | Given a username, email address and password, register a new
user account, which will initially be inactive.
Along with the new ``User`` object, a new
``registration.models.RegistrationProfile`` will be created,
tied to that ``User``, containing the activation key which
will be ... | [
"Given",
"a",
"username",
"email",
"address",
"and",
"password",
"register",
"a",
"new",
"user",
"account",
"which",
"will",
"initially",
"be",
"inactive",
"."
] | train | https://github.com/emencia/emencia_paste_djangocms_3/blob/29eabbcb17e21996a6e1d99592fc719dc8833b59/emencia_paste_djangocms_3/django_buildout/project/accounts/views.py#L56-L111 |
zweifisch/biro | biro/router.py | Router.match | def match(self, method, path):
"""find handler from registered rules
Example:
handler, params = match('GET', '/path')
"""
segments = path.split('/')
while len(segments):
index = '/'.join(segments)
if index in self.__idx__:
ha... | python | def match(self, method, path):
"""find handler from registered rules
Example:
handler, params = match('GET', '/path')
"""
segments = path.split('/')
while len(segments):
index = '/'.join(segments)
if index in self.__idx__:
ha... | [
"def",
"match",
"(",
"self",
",",
"method",
",",
"path",
")",
":",
"segments",
"=",
"path",
".",
"split",
"(",
"'/'",
")",
"while",
"len",
"(",
"segments",
")",
":",
"index",
"=",
"'/'",
".",
"join",
"(",
"segments",
")",
"if",
"index",
"in",
"se... | find handler from registered rules
Example:
handler, params = match('GET', '/path') | [
"find",
"handler",
"from",
"registered",
"rules"
] | train | https://github.com/zweifisch/biro/blob/0712746de65ff1e25b4f99c669eddd1fb8d1043e/biro/router.py#L41-L58 |
zweifisch/biro | biro/router.py | Router.path_for | def path_for(self, handler, **kwargs):
"""construct path for a given handler
Example:
path = path_for(show_user, user_id=109)
"""
if type(handler) is not str:
handler = handler.__qualname__
if handler not in self.__reversedidx__:
return None
... | python | def path_for(self, handler, **kwargs):
"""construct path for a given handler
Example:
path = path_for(show_user, user_id=109)
"""
if type(handler) is not str:
handler = handler.__qualname__
if handler not in self.__reversedidx__:
return None
... | [
"def",
"path_for",
"(",
"self",
",",
"handler",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"type",
"(",
"handler",
")",
"is",
"not",
"str",
":",
"handler",
"=",
"handler",
".",
"__qualname__",
"if",
"handler",
"not",
"in",
"self",
".",
"__reversedidx__",... | construct path for a given handler
Example:
path = path_for(show_user, user_id=109) | [
"construct",
"path",
"for",
"a",
"given",
"handler"
] | train | https://github.com/zweifisch/biro/blob/0712746de65ff1e25b4f99c669eddd1fb8d1043e/biro/router.py#L69-L85 |
msfrank/cifparser | cifparser/grammar.py | calculate_indent | def calculate_indent(text):
"""
:param text:
:type text: str
:return:
"""
indent = 0
for c in text:
if c is '\t':
raise ValueError()
if c is not ' ':
return indent,text[indent:]
indent += 1
return indent,'' | python | def calculate_indent(text):
"""
:param text:
:type text: str
:return:
"""
indent = 0
for c in text:
if c is '\t':
raise ValueError()
if c is not ' ':
return indent,text[indent:]
indent += 1
return indent,'' | [
"def",
"calculate_indent",
"(",
"text",
")",
":",
"indent",
"=",
"0",
"for",
"c",
"in",
"text",
":",
"if",
"c",
"is",
"'\\t'",
":",
"raise",
"ValueError",
"(",
")",
"if",
"c",
"is",
"not",
"' '",
":",
"return",
"indent",
",",
"text",
"[",
"indent",... | :param text:
:type text: str
:return: | [
":",
"param",
"text",
":",
":",
"type",
"text",
":",
"str",
":",
"return",
":"
] | train | https://github.com/msfrank/cifparser/blob/ecd899ba2e7b990e2cec62b115742d830e7e4384/cifparser/grammar.py#L58-L71 |
msfrank/cifparser | cifparser/grammar.py | parse_line | def parse_line(text):
"""
:param text:
:type text: str
:return:
"""
indent,text = calculate_indent(text)
results = line_parser.parseString(text, parseAll=True).asList()
return indent,results[0] | python | def parse_line(text):
"""
:param text:
:type text: str
:return:
"""
indent,text = calculate_indent(text)
results = line_parser.parseString(text, parseAll=True).asList()
return indent,results[0] | [
"def",
"parse_line",
"(",
"text",
")",
":",
"indent",
",",
"text",
"=",
"calculate_indent",
"(",
"text",
")",
"results",
"=",
"line_parser",
".",
"parseString",
"(",
"text",
",",
"parseAll",
"=",
"True",
")",
".",
"asList",
"(",
")",
"return",
"indent",
... | :param text:
:type text: str
:return: | [
":",
"param",
"text",
":",
":",
"type",
"text",
":",
"str",
":",
"return",
":"
] | train | https://github.com/msfrank/cifparser/blob/ecd899ba2e7b990e2cec62b115742d830e7e4384/cifparser/grammar.py#L73-L81 |
msfrank/cifparser | cifparser/grammar.py | iter_lines | def iter_lines(f):
"""
:param f:
:type f: file
:return:
"""
linenum = 1
try:
for text in f.readlines():
# ignore lines that consist entirely of whitespace
if text.isspace():
continue
indent,value = parse_line(text)
yield... | python | def iter_lines(f):
"""
:param f:
:type f: file
:return:
"""
linenum = 1
try:
for text in f.readlines():
# ignore lines that consist entirely of whitespace
if text.isspace():
continue
indent,value = parse_line(text)
yield... | [
"def",
"iter_lines",
"(",
"f",
")",
":",
"linenum",
"=",
"1",
"try",
":",
"for",
"text",
"in",
"f",
".",
"readlines",
"(",
")",
":",
"# ignore lines that consist entirely of whitespace",
"if",
"text",
".",
"isspace",
"(",
")",
":",
"continue",
"indent",
",... | :param f:
:type f: file
:return: | [
":",
"param",
"f",
":",
":",
"type",
"f",
":",
"file",
":",
"return",
":"
] | train | https://github.com/msfrank/cifparser/blob/ecd899ba2e7b990e2cec62b115742d830e7e4384/cifparser/grammar.py#L83-L99 |
ababic/django-cogwheels | cogwheels/helpers/settings.py | BaseAppSettingsHelper._set_prefix | def _set_prefix(self):
"""
Called by ``__init()__`` to set the object's ``_prefix`` attribute,
which determines the prefix app users must use when overriding
settings associated with this helper. For example:
If the ``_prefix`` attribute were to be set to "YOURAPP", and there
... | python | def _set_prefix(self):
"""
Called by ``__init()__`` to set the object's ``_prefix`` attribute,
which determines the prefix app users must use when overriding
settings associated with this helper. For example:
If the ``_prefix`` attribute were to be set to "YOURAPP", and there
... | [
"def",
"_set_prefix",
"(",
"self",
")",
":",
"if",
"self",
".",
"prefix",
"is",
"not",
"None",
":",
"value",
"=",
"self",
".",
"prefix",
".",
"rstrip",
"(",
"'_'",
")",
"else",
":",
"module_path_parts",
"=",
"self",
".",
"__module_path_split",
"[",
":"... | Called by ``__init()__`` to set the object's ``_prefix`` attribute,
which determines the prefix app users must use when overriding
settings associated with this helper. For example:
If the ``_prefix`` attribute were to be set to "YOURAPP", and there
exists an app setting called ``SETTIN... | [
"Called",
"by",
"__init",
"()",
"__",
"to",
"set",
"the",
"object",
"s",
"_prefix",
"attribute",
"which",
"determines",
"the",
"prefix",
"app",
"users",
"must",
"use",
"when",
"overriding",
"settings",
"associated",
"with",
"this",
"helper",
".",
"For",
"exa... | train | https://github.com/ababic/django-cogwheels/blob/f185245f6ea1d6a2c23b94ff7304c1594049ca56/cogwheels/helpers/settings.py#L90-L119 |
ababic/django-cogwheels | cogwheels/helpers/settings.py | BaseAppSettingsHelper._load_defaults | def _load_defaults(self):
"""
Called by ``__init__()`` to create a dictionary of the relevant
values from the associated defaults module, and save it to the
object's ``_defaults`` attribute to improve lookup performance.
Only variables with upper-case names are included.
... | python | def _load_defaults(self):
"""
Called by ``__init__()`` to create a dictionary of the relevant
values from the associated defaults module, and save it to the
object's ``_defaults`` attribute to improve lookup performance.
Only variables with upper-case names are included.
... | [
"def",
"_load_defaults",
"(",
"self",
")",
":",
"self",
".",
"_defaults_module_path",
"=",
"self",
".",
"defaults_path",
"or",
"'.'",
".",
"join",
"(",
"self",
".",
"__module_path_split",
"[",
":",
"-",
"1",
"]",
")",
"+",
"\".defaults\"",
"module",
"=",
... | Called by ``__init__()`` to create a dictionary of the relevant
values from the associated defaults module, and save it to the
object's ``_defaults`` attribute to improve lookup performance.
Only variables with upper-case names are included.
:raises: ImportError
It is assumed t... | [
"Called",
"by",
"__init__",
"()",
"to",
"create",
"a",
"dictionary",
"of",
"the",
"relevant",
"values",
"from",
"the",
"associated",
"defaults",
"module",
"and",
"save",
"it",
"to",
"the",
"object",
"s",
"_defaults",
"attribute",
"to",
"improve",
"lookup",
"... | train | https://github.com/ababic/django-cogwheels/blob/f185245f6ea1d6a2c23b94ff7304c1594049ca56/cogwheels/helpers/settings.py#L133-L155 |
ababic/django-cogwheels | cogwheels/helpers/settings.py | BaseAppSettingsHelper._prepare_deprecation_data | def _prepare_deprecation_data(self):
"""
Cycles through the list of AppSettingDeprecation instances set on
``self.deprecations`` and prepulates two new dictionary attributes:
``self._deprecated_settings``:
Uses the deprecated setting names themselves as the keys. Used to
... | python | def _prepare_deprecation_data(self):
"""
Cycles through the list of AppSettingDeprecation instances set on
``self.deprecations`` and prepulates two new dictionary attributes:
``self._deprecated_settings``:
Uses the deprecated setting names themselves as the keys. Used to
... | [
"def",
"_prepare_deprecation_data",
"(",
"self",
")",
":",
"if",
"not",
"isinstance",
"(",
"self",
".",
"deprecations",
",",
"(",
"list",
",",
"tuple",
")",
")",
":",
"raise",
"IncorrectDeprecationsValueType",
"(",
"\"'deprecations' must be a list or tuple, not a {}.\... | Cycles through the list of AppSettingDeprecation instances set on
``self.deprecations`` and prepulates two new dictionary attributes:
``self._deprecated_settings``:
Uses the deprecated setting names themselves as the keys. Used to
check whether a request is for a deprecated sett... | [
"Cycles",
"through",
"the",
"list",
"of",
"AppSettingDeprecation",
"instances",
"set",
"on",
"self",
".",
"deprecations",
"and",
"prepulates",
"two",
"new",
"dictionary",
"attributes",
":"
] | train | https://github.com/ababic/django-cogwheels/blob/f185245f6ea1d6a2c23b94ff7304c1594049ca56/cogwheels/helpers/settings.py#L157-L223 |
ababic/django-cogwheels | cogwheels/helpers/settings.py | BaseAppSettingsHelper.reset_caches | def reset_caches(self, **kwargs):
"""
Called by ``__init__()`` to initialise the caches for a helper instance.
It is also called by Django's ``setting_changed`` signal to clear the
caches when changes to settings are made.
Although it requires slightly more memory, separate dict... | python | def reset_caches(self, **kwargs):
"""
Called by ``__init__()`` to initialise the caches for a helper instance.
It is also called by Django's ``setting_changed`` signal to clear the
caches when changes to settings are made.
Although it requires slightly more memory, separate dict... | [
"def",
"reset_caches",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"self",
".",
"_raw_cache",
"=",
"{",
"}",
"self",
".",
"_models_cache",
"=",
"{",
"}",
"self",
".",
"_modules_cache",
"=",
"{",
"}",
"self",
".",
"_objects_cache",
"=",
"{",
"}"
] | Called by ``__init__()`` to initialise the caches for a helper instance.
It is also called by Django's ``setting_changed`` signal to clear the
caches when changes to settings are made.
Although it requires slightly more memory, separate dictionaries are
used for raw values, models, modu... | [
"Called",
"by",
"__init__",
"()",
"to",
"initialise",
"the",
"caches",
"for",
"a",
"helper",
"instance",
".",
"It",
"is",
"also",
"called",
"by",
"Django",
"s",
"setting_changed",
"signal",
"to",
"clear",
"the",
"caches",
"when",
"changes",
"to",
"settings",... | train | https://github.com/ababic/django-cogwheels/blob/f185245f6ea1d6a2c23b94ff7304c1594049ca56/cogwheels/helpers/settings.py#L225-L238 |
ababic/django-cogwheels | cogwheels/helpers/settings.py | BaseAppSettingsHelper._warn_if_deprecated_setting_value_requested | def _warn_if_deprecated_setting_value_requested(
self, setting_name, warn_only_if_overridden, suppress_warnings,
warning_stacklevel,
):
"""
get(), get_object(), get_model() and get_module() must all check
whether a requested app setting is deprecated. This method allows
... | python | def _warn_if_deprecated_setting_value_requested(
self, setting_name, warn_only_if_overridden, suppress_warnings,
warning_stacklevel,
):
"""
get(), get_object(), get_model() and get_module() must all check
whether a requested app setting is deprecated. This method allows
... | [
"def",
"_warn_if_deprecated_setting_value_requested",
"(",
"self",
",",
"setting_name",
",",
"warn_only_if_overridden",
",",
"suppress_warnings",
",",
"warning_stacklevel",
",",
")",
":",
"if",
"(",
"not",
"suppress_warnings",
"and",
"not",
"warn_only_if_overridden",
"and... | get(), get_object(), get_model() and get_module() must all check
whether a requested app setting is deprecated. This method allows
the helper to do that in a DRY/consistent way. | [
"get",
"()",
"get_object",
"()",
"get_model",
"()",
"and",
"get_module",
"()",
"must",
"all",
"check",
"whether",
"a",
"requested",
"app",
"setting",
"is",
"deprecated",
".",
"This",
"method",
"allows",
"the",
"helper",
"to",
"do",
"that",
"in",
"a",
"DRY"... | train | https://github.com/ababic/django-cogwheels/blob/f185245f6ea1d6a2c23b94ff7304c1594049ca56/cogwheels/helpers/settings.py#L295-L310 |
ababic/django-cogwheels | cogwheels/helpers/settings.py | BaseAppSettingsHelper._get_raw_value | def _get_raw_value(self, setting_name, accept_deprecated='',
warn_if_overridden=False, suppress_warnings=False,
warning_stacklevel=3):
"""
Returns the original/raw value for an app setting with the name
``setting_name``, exactly as it has been define... | python | def _get_raw_value(self, setting_name, accept_deprecated='',
warn_if_overridden=False, suppress_warnings=False,
warning_stacklevel=3):
"""
Returns the original/raw value for an app setting with the name
``setting_name``, exactly as it has been define... | [
"def",
"_get_raw_value",
"(",
"self",
",",
"setting_name",
",",
"accept_deprecated",
"=",
"''",
",",
"warn_if_overridden",
"=",
"False",
",",
"suppress_warnings",
"=",
"False",
",",
"warning_stacklevel",
"=",
"3",
")",
":",
"if",
"not",
"self",
".",
"in_defaul... | Returns the original/raw value for an app setting with the name
``setting_name``, exactly as it has been defined in the defaults
module or a user's Django settings.
If the requested setting is deprecated, ``warn_if_overridden`` is
``True``, and the setting is overridden by a user, a sui... | [
"Returns",
"the",
"original",
"/",
"raw",
"value",
"for",
"an",
"app",
"setting",
"with",
"the",
"name",
"setting_name",
"exactly",
"as",
"it",
"has",
"been",
"defined",
"in",
"the",
"defaults",
"module",
"or",
"a",
"user",
"s",
"Django",
"settings",
"."
] | train | https://github.com/ababic/django-cogwheels/blob/f185245f6ea1d6a2c23b94ff7304c1594049ca56/cogwheels/helpers/settings.py#L312-L358 |
ababic/django-cogwheels | cogwheels/helpers/settings.py | BaseAppSettingsHelper.get | def get(self, setting_name, warn_only_if_overridden=False,
accept_deprecated='', suppress_warnings=False,
enforce_type=None, check_if_setting_deprecated=True,
warning_stacklevel=3):
"""
Returns a setting value for the setting named by ``setting_name``. The
ret... | python | def get(self, setting_name, warn_only_if_overridden=False,
accept_deprecated='', suppress_warnings=False,
enforce_type=None, check_if_setting_deprecated=True,
warning_stacklevel=3):
"""
Returns a setting value for the setting named by ``setting_name``. The
ret... | [
"def",
"get",
"(",
"self",
",",
"setting_name",
",",
"warn_only_if_overridden",
"=",
"False",
",",
"accept_deprecated",
"=",
"''",
",",
"suppress_warnings",
"=",
"False",
",",
"enforce_type",
"=",
"None",
",",
"check_if_setting_deprecated",
"=",
"True",
",",
"wa... | Returns a setting value for the setting named by ``setting_name``. The
returned value is actually a reference to the original setting value,
so care should be taken to avoid setting the result to a different
value.
:param setting_name:
The name of the app setting for which a... | [
"Returns",
"a",
"setting",
"value",
"for",
"the",
"setting",
"named",
"by",
"setting_name",
".",
"The",
"returned",
"value",
"is",
"actually",
"a",
"reference",
"to",
"the",
"original",
"setting",
"value",
"so",
"care",
"should",
"be",
"taken",
"to",
"avoid"... | train | https://github.com/ababic/django-cogwheels/blob/f185245f6ea1d6a2c23b94ff7304c1594049ca56/cogwheels/helpers/settings.py#L360-L472 |
ababic/django-cogwheels | cogwheels/helpers/settings.py | BaseAppSettingsHelper.get_model | def get_model(self, setting_name, warn_only_if_overridden=False,
accept_deprecated='', suppress_warnings=False,
warning_stacklevel=3):
"""
Returns a Django model referenced by an app setting where the value is
expected to be a valid 'model string' in the forma... | python | def get_model(self, setting_name, warn_only_if_overridden=False,
accept_deprecated='', suppress_warnings=False,
warning_stacklevel=3):
"""
Returns a Django model referenced by an app setting where the value is
expected to be a valid 'model string' in the forma... | [
"def",
"get_model",
"(",
"self",
",",
"setting_name",
",",
"warn_only_if_overridden",
"=",
"False",
",",
"accept_deprecated",
"=",
"''",
",",
"suppress_warnings",
"=",
"False",
",",
"warning_stacklevel",
"=",
"3",
")",
":",
"self",
".",
"_warn_if_deprecated_settin... | Returns a Django model referenced by an app setting where the value is
expected to be a valid 'model string' in the format:
"app_label.model_name".
:param setting_name:
The name of the app setting for which a value is required.
:type setting_name: str (e.g. "SETTING_NAME")
... | [
"Returns",
"a",
"Django",
"model",
"referenced",
"by",
"an",
"app",
"setting",
"where",
"the",
"value",
"is",
"expected",
"to",
"be",
"a",
"valid",
"model",
"string",
"in",
"the",
"format",
":",
"app_label",
".",
"model_name",
"."
] | train | https://github.com/ababic/django-cogwheels/blob/f185245f6ea1d6a2c23b94ff7304c1594049ca56/cogwheels/helpers/settings.py#L474-L569 |
ababic/django-cogwheels | cogwheels/helpers/settings.py | BaseAppSettingsHelper.get_module | def get_module(self, setting_name, warn_only_if_overridden=False,
accept_deprecated='', suppress_warnings=False,
warning_stacklevel=3):
"""
Returns a Python module referenced by an app setting where the value is
expected to be a valid, absolute Python import... | python | def get_module(self, setting_name, warn_only_if_overridden=False,
accept_deprecated='', suppress_warnings=False,
warning_stacklevel=3):
"""
Returns a Python module referenced by an app setting where the value is
expected to be a valid, absolute Python import... | [
"def",
"get_module",
"(",
"self",
",",
"setting_name",
",",
"warn_only_if_overridden",
"=",
"False",
",",
"accept_deprecated",
"=",
"''",
",",
"suppress_warnings",
"=",
"False",
",",
"warning_stacklevel",
"=",
"3",
")",
":",
"self",
".",
"_warn_if_deprecated_setti... | Returns a Python module referenced by an app setting where the value is
expected to be a valid, absolute Python import path, defined as a
string (e.g. "myproject.app.custom_module").
:param setting_name:
The name of the app setting for which a value is required.
:type settin... | [
"Returns",
"a",
"Python",
"module",
"referenced",
"by",
"an",
"app",
"setting",
"where",
"the",
"value",
"is",
"expected",
"to",
"be",
"a",
"valid",
"absolute",
"Python",
"import",
"path",
"defined",
"as",
"a",
"string",
"(",
"e",
".",
"g",
".",
"myproje... | train | https://github.com/ababic/django-cogwheels/blob/f185245f6ea1d6a2c23b94ff7304c1594049ca56/cogwheels/helpers/settings.py#L571-L656 |
ababic/django-cogwheels | cogwheels/helpers/settings.py | BaseAppSettingsHelper.get_object | def get_object(self, setting_name, warn_only_if_overridden=False,
accept_deprecated='', suppress_warnings=False,
warning_stacklevel=3):
"""
Returns a python class, method, or other object referenced by an app
setting where the value is expected to be a valid... | python | def get_object(self, setting_name, warn_only_if_overridden=False,
accept_deprecated='', suppress_warnings=False,
warning_stacklevel=3):
"""
Returns a python class, method, or other object referenced by an app
setting where the value is expected to be a valid... | [
"def",
"get_object",
"(",
"self",
",",
"setting_name",
",",
"warn_only_if_overridden",
"=",
"False",
",",
"accept_deprecated",
"=",
"''",
",",
"suppress_warnings",
"=",
"False",
",",
"warning_stacklevel",
"=",
"3",
")",
":",
"self",
".",
"_warn_if_deprecated_setti... | Returns a python class, method, or other object referenced by an app
setting where the value is expected to be a valid, absolute Python
import path, defined as a string (e.g. "myproject.app.module.MyClass").
:param setting_name:
The name of the app setting for which a value is requi... | [
"Returns",
"a",
"python",
"class",
"method",
"or",
"other",
"object",
"referenced",
"by",
"an",
"app",
"setting",
"where",
"the",
"value",
"is",
"expected",
"to",
"be",
"a",
"valid",
"absolute",
"Python",
"import",
"path",
"defined",
"as",
"a",
"string",
"... | train | https://github.com/ababic/django-cogwheels/blob/f185245f6ea1d6a2c23b94ff7304c1594049ca56/cogwheels/helpers/settings.py#L658-L769 |
ababic/django-cogwheels | cogwheels/helpers/settings.py | BaseAppSettingsHelper.is_value_from_deprecated_setting | def is_value_from_deprecated_setting(self, setting_name, deprecated_setting_name):
"""
Helps developers to determine where the settings helper got it's value
from when dealing with settings that replace deprecated settings.
Returns ``True`` when the new setting (with the name ``setting_... | python | def is_value_from_deprecated_setting(self, setting_name, deprecated_setting_name):
"""
Helps developers to determine where the settings helper got it's value
from when dealing with settings that replace deprecated settings.
Returns ``True`` when the new setting (with the name ``setting_... | [
"def",
"is_value_from_deprecated_setting",
"(",
"self",
",",
"setting_name",
",",
"deprecated_setting_name",
")",
":",
"if",
"not",
"self",
".",
"in_defaults",
"(",
"setting_name",
")",
":",
"self",
".",
"_raise_invalid_setting_name_error",
"(",
"setting_name",
")",
... | Helps developers to determine where the settings helper got it's value
from when dealing with settings that replace deprecated settings.
Returns ``True`` when the new setting (with the name ``setting_name``)
is a replacement for a deprecated setting (with the name
``deprecated_setting_n... | [
"Helps",
"developers",
"to",
"determine",
"where",
"the",
"settings",
"helper",
"got",
"it",
"s",
"value",
"from",
"when",
"dealing",
"with",
"settings",
"that",
"replace",
"deprecated",
"settings",
"."
] | train | https://github.com/ababic/django-cogwheels/blob/f185245f6ea1d6a2c23b94ff7304c1594049ca56/cogwheels/helpers/settings.py#L771-L803 |
redodo/formats | formats/banks.py | FormatBank.register | def register(self, type, parser, composer, **meta):
"""Registers a parser and composer of a format.
You can use this method to overwrite existing formats.
:param type: The unique name of the format
:param parser: The method to parse data as the format
:param composer: The metho... | python | def register(self, type, parser, composer, **meta):
"""Registers a parser and composer of a format.
You can use this method to overwrite existing formats.
:param type: The unique name of the format
:param parser: The method to parse data as the format
:param composer: The metho... | [
"def",
"register",
"(",
"self",
",",
"type",
",",
"parser",
",",
"composer",
",",
"*",
"*",
"meta",
")",
":",
"self",
".",
"registered_formats",
"[",
"type",
"]",
"=",
"{",
"'parser'",
":",
"parser",
",",
"'composer'",
":",
"composer",
",",
"'meta'",
... | Registers a parser and composer of a format.
You can use this method to overwrite existing formats.
:param type: The unique name of the format
:param parser: The method to parse data as the format
:param composer: The method to compose data as the format
:param meta: The extra ... | [
"Registers",
"a",
"parser",
"and",
"composer",
"of",
"a",
"format",
"."
] | train | https://github.com/redodo/formats/blob/5bc7a79a2c93ef895534edbbf83f1efe2f62e081/formats/banks.py#L18-L32 |
redodo/formats | formats/banks.py | FormatBank.register_parser | def register_parser(self, type, parser, **meta):
"""Registers a parser of a format.
:param type: The unique name of the format
:param parser: The method to parse data as the format
:param meta: The extra information associated with the format
"""
try:
self.re... | python | def register_parser(self, type, parser, **meta):
"""Registers a parser of a format.
:param type: The unique name of the format
:param parser: The method to parse data as the format
:param meta: The extra information associated with the format
"""
try:
self.re... | [
"def",
"register_parser",
"(",
"self",
",",
"type",
",",
"parser",
",",
"*",
"*",
"meta",
")",
":",
"try",
":",
"self",
".",
"registered_formats",
"[",
"type",
"]",
"[",
"'parser'",
"]",
"=",
"parser",
"except",
"KeyError",
":",
"self",
".",
"registere... | Registers a parser of a format.
:param type: The unique name of the format
:param parser: The method to parse data as the format
:param meta: The extra information associated with the format | [
"Registers",
"a",
"parser",
"of",
"a",
"format",
"."
] | train | https://github.com/redodo/formats/blob/5bc7a79a2c93ef895534edbbf83f1efe2f62e081/formats/banks.py#L34-L46 |
redodo/formats | formats/banks.py | FormatBank.register_composer | def register_composer(self, type, composer, **meta):
"""Registers a composer of a format.
:param type: The unique name of the format
:param composer: The method to compose data as the format
"""
try:
self.registered_formats[type]['composer'] = composer
except... | python | def register_composer(self, type, composer, **meta):
"""Registers a composer of a format.
:param type: The unique name of the format
:param composer: The method to compose data as the format
"""
try:
self.registered_formats[type]['composer'] = composer
except... | [
"def",
"register_composer",
"(",
"self",
",",
"type",
",",
"composer",
",",
"*",
"*",
"meta",
")",
":",
"try",
":",
"self",
".",
"registered_formats",
"[",
"type",
"]",
"[",
"'composer'",
"]",
"=",
"composer",
"except",
"KeyError",
":",
"self",
".",
"r... | Registers a composer of a format.
:param type: The unique name of the format
:param composer: The method to compose data as the format | [
"Registers",
"a",
"composer",
"of",
"a",
"format",
"."
] | train | https://github.com/redodo/formats/blob/5bc7a79a2c93ef895534edbbf83f1efe2f62e081/formats/banks.py#L48-L59 |
redodo/formats | formats/banks.py | FormatBank.register_meta | def register_meta(self, type, **meta):
"""Registers extra _meta_ information about a format.
:param type: The unique name of the format
:param meta: The extra information associated with the format
"""
try:
self.registered_formats[type]['meta'] = meta
except ... | python | def register_meta(self, type, **meta):
"""Registers extra _meta_ information about a format.
:param type: The unique name of the format
:param meta: The extra information associated with the format
"""
try:
self.registered_formats[type]['meta'] = meta
except ... | [
"def",
"register_meta",
"(",
"self",
",",
"type",
",",
"*",
"*",
"meta",
")",
":",
"try",
":",
"self",
".",
"registered_formats",
"[",
"type",
"]",
"[",
"'meta'",
"]",
"=",
"meta",
"except",
"KeyError",
":",
"self",
".",
"registered_formats",
"[",
"typ... | Registers extra _meta_ information about a format.
:param type: The unique name of the format
:param meta: The extra information associated with the format | [
"Registers",
"extra",
"_meta_",
"information",
"about",
"a",
"format",
"."
] | train | https://github.com/redodo/formats/blob/5bc7a79a2c93ef895534edbbf83f1efe2f62e081/formats/banks.py#L61-L70 |
redodo/formats | formats/banks.py | FormatBank.parser | def parser(self, type, **meta):
"""Registers the decorated method as the parser of a format.
:param type: The unique name of the format
:param meta: The extra information associated with the format
"""
def decorator(f):
self.register_parser(type, f)
if me... | python | def parser(self, type, **meta):
"""Registers the decorated method as the parser of a format.
:param type: The unique name of the format
:param meta: The extra information associated with the format
"""
def decorator(f):
self.register_parser(type, f)
if me... | [
"def",
"parser",
"(",
"self",
",",
"type",
",",
"*",
"*",
"meta",
")",
":",
"def",
"decorator",
"(",
"f",
")",
":",
"self",
".",
"register_parser",
"(",
"type",
",",
"f",
")",
"if",
"meta",
":",
"self",
".",
"register_meta",
"(",
"type",
",",
"*"... | Registers the decorated method as the parser of a format.
:param type: The unique name of the format
:param meta: The extra information associated with the format | [
"Registers",
"the",
"decorated",
"method",
"as",
"the",
"parser",
"of",
"a",
"format",
"."
] | train | https://github.com/redodo/formats/blob/5bc7a79a2c93ef895534edbbf83f1efe2f62e081/formats/banks.py#L72-L83 |
redodo/formats | formats/banks.py | FormatBank.composer | def composer(self, type, **meta):
"""Registers the decorated method as the composer of a format.
:param type: The unique name of the format
:param meta: The extra information associated with the format
"""
def decorator(f):
self.register_composer(type, f)
... | python | def composer(self, type, **meta):
"""Registers the decorated method as the composer of a format.
:param type: The unique name of the format
:param meta: The extra information associated with the format
"""
def decorator(f):
self.register_composer(type, f)
... | [
"def",
"composer",
"(",
"self",
",",
"type",
",",
"*",
"*",
"meta",
")",
":",
"def",
"decorator",
"(",
"f",
")",
":",
"self",
".",
"register_composer",
"(",
"type",
",",
"f",
")",
"if",
"meta",
":",
"self",
".",
"register_meta",
"(",
"type",
",",
... | Registers the decorated method as the composer of a format.
:param type: The unique name of the format
:param meta: The extra information associated with the format | [
"Registers",
"the",
"decorated",
"method",
"as",
"the",
"composer",
"of",
"a",
"format",
"."
] | train | https://github.com/redodo/formats/blob/5bc7a79a2c93ef895534edbbf83f1efe2f62e081/formats/banks.py#L85-L96 |
redodo/formats | formats/banks.py | FormatBank.parse | def parse(self, type, data):
"""Parse text as a format.
:param type: The unique name of the format
:param data: The text to parse as the format
"""
try:
return self.registered_formats[type]['parser'](data)
except KeyError:
raise NotImplementedErro... | python | def parse(self, type, data):
"""Parse text as a format.
:param type: The unique name of the format
:param data: The text to parse as the format
"""
try:
return self.registered_formats[type]['parser'](data)
except KeyError:
raise NotImplementedErro... | [
"def",
"parse",
"(",
"self",
",",
"type",
",",
"data",
")",
":",
"try",
":",
"return",
"self",
".",
"registered_formats",
"[",
"type",
"]",
"[",
"'parser'",
"]",
"(",
"data",
")",
"except",
"KeyError",
":",
"raise",
"NotImplementedError",
"(",
"\"No pars... | Parse text as a format.
:param type: The unique name of the format
:param data: The text to parse as the format | [
"Parse",
"text",
"as",
"a",
"format",
"."
] | train | https://github.com/redodo/formats/blob/5bc7a79a2c93ef895534edbbf83f1efe2f62e081/formats/banks.py#L98-L108 |
redodo/formats | formats/banks.py | FormatBank.compose | def compose(self, type, data):
"""Compose text as a format.
:param type: The unique name of the format
:param data: The text to compose as the format
"""
try:
return self.registered_formats[type]['composer'](data)
except KeyError:
raise NotImpleme... | python | def compose(self, type, data):
"""Compose text as a format.
:param type: The unique name of the format
:param data: The text to compose as the format
"""
try:
return self.registered_formats[type]['composer'](data)
except KeyError:
raise NotImpleme... | [
"def",
"compose",
"(",
"self",
",",
"type",
",",
"data",
")",
":",
"try",
":",
"return",
"self",
".",
"registered_formats",
"[",
"type",
"]",
"[",
"'composer'",
"]",
"(",
"data",
")",
"except",
"KeyError",
":",
"raise",
"NotImplementedError",
"(",
"\"No ... | Compose text as a format.
:param type: The unique name of the format
:param data: The text to compose as the format | [
"Compose",
"text",
"as",
"a",
"format",
"."
] | train | https://github.com/redodo/formats/blob/5bc7a79a2c93ef895534edbbf83f1efe2f62e081/formats/banks.py#L110-L120 |
redodo/formats | formats/banks.py | FormatBank.convert | def convert(self, type_from, type_to, data):
"""Parsers data from with one format and composes with another.
:param type_from: The unique name of the format to parse with
:param type_to: The unique name of the format to compose with
:param data: The text to convert
"""
t... | python | def convert(self, type_from, type_to, data):
"""Parsers data from with one format and composes with another.
:param type_from: The unique name of the format to parse with
:param type_to: The unique name of the format to compose with
:param data: The text to convert
"""
t... | [
"def",
"convert",
"(",
"self",
",",
"type_from",
",",
"type_to",
",",
"data",
")",
":",
"try",
":",
"return",
"self",
".",
"compose",
"(",
"type_to",
",",
"self",
".",
"parse",
"(",
"type_from",
",",
"data",
")",
")",
"except",
"Exception",
"as",
"e"... | Parsers data from with one format and composes with another.
:param type_from: The unique name of the format to parse with
:param type_to: The unique name of the format to compose with
:param data: The text to convert | [
"Parsers",
"data",
"from",
"with",
"one",
"format",
"and",
"composes",
"with",
"another",
"."
] | train | https://github.com/redodo/formats/blob/5bc7a79a2c93ef895534edbbf83f1efe2f62e081/formats/banks.py#L122-L139 |
redodo/formats | formats/banks.py | FormatBank.meta | def meta(self, type):
"""Retreived meta information of a format.
:param meta: The extra information associated with the format
"""
try:
return self.registered_formats[type].get('meta')
except KeyError:
raise NotImplementedError("No format registered with ... | python | def meta(self, type):
"""Retreived meta information of a format.
:param meta: The extra information associated with the format
"""
try:
return self.registered_formats[type].get('meta')
except KeyError:
raise NotImplementedError("No format registered with ... | [
"def",
"meta",
"(",
"self",
",",
"type",
")",
":",
"try",
":",
"return",
"self",
".",
"registered_formats",
"[",
"type",
"]",
".",
"get",
"(",
"'meta'",
")",
"except",
"KeyError",
":",
"raise",
"NotImplementedError",
"(",
"\"No format registered with type \"",... | Retreived meta information of a format.
:param meta: The extra information associated with the format | [
"Retreived",
"meta",
"information",
"of",
"a",
"format",
"."
] | train | https://github.com/redodo/formats/blob/5bc7a79a2c93ef895534edbbf83f1efe2f62e081/formats/banks.py#L141-L150 |
redodo/formats | formats/banks.py | FormatBank.discover | def discover(self, exclude=None):
"""Automatically discovers and registers installed formats.
If a format is already registered with an exact same name, the
discovered format will not be registered.
:param exclude: (optional) Exclude formats from registering
"""
if excl... | python | def discover(self, exclude=None):
"""Automatically discovers and registers installed formats.
If a format is already registered with an exact same name, the
discovered format will not be registered.
:param exclude: (optional) Exclude formats from registering
"""
if excl... | [
"def",
"discover",
"(",
"self",
",",
"exclude",
"=",
"None",
")",
":",
"if",
"exclude",
"is",
"None",
":",
"exclude",
"=",
"[",
"]",
"elif",
"not",
"isinstance",
"(",
"exclude",
",",
"(",
"list",
",",
"tuple",
")",
")",
":",
"exclude",
"=",
"[",
... | Automatically discovers and registers installed formats.
If a format is already registered with an exact same name, the
discovered format will not be registered.
:param exclude: (optional) Exclude formats from registering | [
"Automatically",
"discovers",
"and",
"registers",
"installed",
"formats",
"."
] | train | https://github.com/redodo/formats/blob/5bc7a79a2c93ef895534edbbf83f1efe2f62e081/formats/banks.py#L152-L168 |
redodo/formats | formats/banks.py | FormatBank.discover_json | def discover_json(self):
"""Discovers the JSON format and registers it if available.
To speed up JSON parsing and composing, install `simplejson`::
pip install simplejson
The standard library module `json` will be used by default.
"""
try:
import simple... | python | def discover_json(self):
"""Discovers the JSON format and registers it if available.
To speed up JSON parsing and composing, install `simplejson`::
pip install simplejson
The standard library module `json` will be used by default.
"""
try:
import simple... | [
"def",
"discover_json",
"(",
"self",
")",
":",
"try",
":",
"import",
"simplejson",
"as",
"json",
"except",
"ImportError",
":",
"import",
"json",
"self",
".",
"register",
"(",
"'json'",
",",
"json",
".",
"loads",
",",
"json",
".",
"dumps",
")"
] | Discovers the JSON format and registers it if available.
To speed up JSON parsing and composing, install `simplejson`::
pip install simplejson
The standard library module `json` will be used by default. | [
"Discovers",
"the",
"JSON",
"format",
"and",
"registers",
"it",
"if",
"available",
"."
] | train | https://github.com/redodo/formats/blob/5bc7a79a2c93ef895534edbbf83f1efe2f62e081/formats/banks.py#L170-L183 |
redodo/formats | formats/banks.py | FormatBank.discover_yaml | def discover_yaml(self):
"""Discovers the YAML format and registers it if available.
Install YAML support via PIP::
pip install PyYAML
"""
try:
import yaml
self.register('yaml', yaml.load, yaml.dump)
except ImportError:
pass | python | def discover_yaml(self):
"""Discovers the YAML format and registers it if available.
Install YAML support via PIP::
pip install PyYAML
"""
try:
import yaml
self.register('yaml', yaml.load, yaml.dump)
except ImportError:
pass | [
"def",
"discover_yaml",
"(",
"self",
")",
":",
"try",
":",
"import",
"yaml",
"self",
".",
"register",
"(",
"'yaml'",
",",
"yaml",
".",
"load",
",",
"yaml",
".",
"dump",
")",
"except",
"ImportError",
":",
"pass"
] | Discovers the YAML format and registers it if available.
Install YAML support via PIP::
pip install PyYAML | [
"Discovers",
"the",
"YAML",
"format",
"and",
"registers",
"it",
"if",
"available",
"."
] | train | https://github.com/redodo/formats/blob/5bc7a79a2c93ef895534edbbf83f1efe2f62e081/formats/banks.py#L185-L196 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.