repo stringlengths 7 55 | path stringlengths 4 223 | func_name stringlengths 1 134 | original_string stringlengths 75 104k | language stringclasses 1
value | code stringlengths 75 104k | code_tokens listlengths 19 28.4k | docstring stringlengths 1 46.9k | docstring_tokens listlengths 1 1.97k | sha stringlengths 40 40 | url stringlengths 87 315 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
ergo/ziggurat_foundations | ziggurat_foundations/models/user.py | UserMixin.id | def id(self):
""" Unique identifier of user object"""
return sa.Column(sa.Integer, primary_key=True, autoincrement=True) | python | def id(self):
""" Unique identifier of user object"""
return sa.Column(sa.Integer, primary_key=True, autoincrement=True) | [
"def",
"id",
"(",
"self",
")",
":",
"return",
"sa",
".",
"Column",
"(",
"sa",
".",
"Integer",
",",
"primary_key",
"=",
"True",
",",
"autoincrement",
"=",
"True",
")"
] | Unique identifier of user object | [
"Unique",
"identifier",
"of",
"user",
"object"
] | 9eeec894d08e8d7defa60ddc04b63f69cd4cbeba | https://github.com/ergo/ziggurat_foundations/blob/9eeec894d08e8d7defa60ddc04b63f69cd4cbeba/ziggurat_foundations/models/user.py#L29-L31 | train |
ergo/ziggurat_foundations | ziggurat_foundations/models/user.py | UserMixin.last_login_date | def last_login_date(self):
""" Date of user's last login """
return sa.Column(
sa.TIMESTAMP(timezone=False),
default=lambda x: datetime.utcnow(),
server_default=sa.func.now(),
) | python | def last_login_date(self):
""" Date of user's last login """
return sa.Column(
sa.TIMESTAMP(timezone=False),
default=lambda x: datetime.utcnow(),
server_default=sa.func.now(),
) | [
"def",
"last_login_date",
"(",
"self",
")",
":",
"return",
"sa",
".",
"Column",
"(",
"sa",
".",
"TIMESTAMP",
"(",
"timezone",
"=",
"False",
")",
",",
"default",
"=",
"lambda",
"x",
":",
"datetime",
".",
"utcnow",
"(",
")",
",",
"server_default",
"=",
... | Date of user's last login | [
"Date",
"of",
"user",
"s",
"last",
"login"
] | 9eeec894d08e8d7defa60ddc04b63f69cd4cbeba | https://github.com/ergo/ziggurat_foundations/blob/9eeec894d08e8d7defa60ddc04b63f69cd4cbeba/ziggurat_foundations/models/user.py#L59-L65 | train |
ergo/ziggurat_foundations | ziggurat_foundations/models/user.py | UserMixin.security_code_date | def security_code_date(self):
""" Date of user's security code update """
return sa.Column(
sa.TIMESTAMP(timezone=False),
default=datetime(2000, 1, 1),
server_default="2000-01-01 01:01",
) | python | def security_code_date(self):
""" Date of user's security code update """
return sa.Column(
sa.TIMESTAMP(timezone=False),
default=datetime(2000, 1, 1),
server_default="2000-01-01 01:01",
) | [
"def",
"security_code_date",
"(",
"self",
")",
":",
"return",
"sa",
".",
"Column",
"(",
"sa",
".",
"TIMESTAMP",
"(",
"timezone",
"=",
"False",
")",
",",
"default",
"=",
"datetime",
"(",
"2000",
",",
"1",
",",
"1",
")",
",",
"server_default",
"=",
"\"... | Date of user's security code update | [
"Date",
"of",
"user",
"s",
"security",
"code",
"update"
] | 9eeec894d08e8d7defa60ddc04b63f69cd4cbeba | https://github.com/ergo/ziggurat_foundations/blob/9eeec894d08e8d7defa60ddc04b63f69cd4cbeba/ziggurat_foundations/models/user.py#L77-L83 | train |
ergo/ziggurat_foundations | ziggurat_foundations/models/user.py | UserMixin.groups_dynamic | def groups_dynamic(self):
""" returns dynamic relationship for groups - allowing for
filtering of data """
return sa.orm.relationship(
"Group",
secondary="users_groups",
lazy="dynamic",
passive_deletes=True,
passive_updates=True,
... | python | def groups_dynamic(self):
""" returns dynamic relationship for groups - allowing for
filtering of data """
return sa.orm.relationship(
"Group",
secondary="users_groups",
lazy="dynamic",
passive_deletes=True,
passive_updates=True,
... | [
"def",
"groups_dynamic",
"(",
"self",
")",
":",
"return",
"sa",
".",
"orm",
".",
"relationship",
"(",
"\"Group\"",
",",
"secondary",
"=",
"\"users_groups\"",
",",
"lazy",
"=",
"\"dynamic\"",
",",
"passive_deletes",
"=",
"True",
",",
"passive_updates",
"=",
"... | returns dynamic relationship for groups - allowing for
filtering of data | [
"returns",
"dynamic",
"relationship",
"for",
"groups",
"-",
"allowing",
"for",
"filtering",
"of",
"data"
] | 9eeec894d08e8d7defa60ddc04b63f69cd4cbeba | https://github.com/ergo/ziggurat_foundations/blob/9eeec894d08e8d7defa60ddc04b63f69cd4cbeba/ziggurat_foundations/models/user.py#L89-L98 | train |
ergo/ziggurat_foundations | ziggurat_foundations/models/user.py | UserMixin.resources | def resources(self):
""" Returns all resources directly owned by user, can be used to assign
ownership of new resources::
user.resources.append(resource) """
return sa.orm.relationship(
"Resource",
cascade="all",
passive_deletes=True,
... | python | def resources(self):
""" Returns all resources directly owned by user, can be used to assign
ownership of new resources::
user.resources.append(resource) """
return sa.orm.relationship(
"Resource",
cascade="all",
passive_deletes=True,
... | [
"def",
"resources",
"(",
"self",
")",
":",
"return",
"sa",
".",
"orm",
".",
"relationship",
"(",
"\"Resource\"",
",",
"cascade",
"=",
"\"all\"",
",",
"passive_deletes",
"=",
"True",
",",
"passive_updates",
"=",
"True",
",",
"backref",
"=",
"\"owner\"",
","... | Returns all resources directly owned by user, can be used to assign
ownership of new resources::
user.resources.append(resource) | [
"Returns",
"all",
"resources",
"directly",
"owned",
"by",
"user",
"can",
"be",
"used",
"to",
"assign",
"ownership",
"of",
"new",
"resources",
"::"
] | 9eeec894d08e8d7defa60ddc04b63f69cd4cbeba | https://github.com/ergo/ziggurat_foundations/blob/9eeec894d08e8d7defa60ddc04b63f69cd4cbeba/ziggurat_foundations/models/user.py#L126-L138 | train |
ergo/ziggurat_foundations | ziggurat_foundations/models/group.py | GroupMixin.resources_dynamic | def resources_dynamic(self):
""" Returns all resources directly owned by group, can be used to assign
ownership of new resources::
user.resources.append(resource) """
return sa.orm.relationship(
"Resource",
cascade="all",
passive_deletes=True,
... | python | def resources_dynamic(self):
""" Returns all resources directly owned by group, can be used to assign
ownership of new resources::
user.resources.append(resource) """
return sa.orm.relationship(
"Resource",
cascade="all",
passive_deletes=True,
... | [
"def",
"resources_dynamic",
"(",
"self",
")",
":",
"return",
"sa",
".",
"orm",
".",
"relationship",
"(",
"\"Resource\"",
",",
"cascade",
"=",
"\"all\"",
",",
"passive_deletes",
"=",
"True",
",",
"passive_updates",
"=",
"True",
",",
"lazy",
"=",
"\"dynamic\""... | Returns all resources directly owned by group, can be used to assign
ownership of new resources::
user.resources.append(resource) | [
"Returns",
"all",
"resources",
"directly",
"owned",
"by",
"group",
"can",
"be",
"used",
"to",
"assign",
"ownership",
"of",
"new",
"resources",
"::"
] | 9eeec894d08e8d7defa60ddc04b63f69cd4cbeba | https://github.com/ergo/ziggurat_foundations/blob/9eeec894d08e8d7defa60ddc04b63f69cd4cbeba/ziggurat_foundations/models/group.py#L99-L110 | train |
ergo/ziggurat_foundations | ziggurat_foundations/models/group.py | GroupMixin.validate_permission | def validate_permission(self, key, permission):
""" validates if group can get assigned with permission"""
if permission.perm_name not in self.__possible_permissions__:
raise AssertionError(
"perm_name is not one of {}".format(self.__possible_permissions__)
)
... | python | def validate_permission(self, key, permission):
""" validates if group can get assigned with permission"""
if permission.perm_name not in self.__possible_permissions__:
raise AssertionError(
"perm_name is not one of {}".format(self.__possible_permissions__)
)
... | [
"def",
"validate_permission",
"(",
"self",
",",
"key",
",",
"permission",
")",
":",
"if",
"permission",
".",
"perm_name",
"not",
"in",
"self",
".",
"__possible_permissions__",
":",
"raise",
"AssertionError",
"(",
"\"perm_name is not one of {}\"",
".",
"format",
"(... | validates if group can get assigned with permission | [
"validates",
"if",
"group",
"can",
"get",
"assigned",
"with",
"permission"
] | 9eeec894d08e8d7defa60ddc04b63f69cd4cbeba | https://github.com/ergo/ziggurat_foundations/blob/9eeec894d08e8d7defa60ddc04b63f69cd4cbeba/ziggurat_foundations/models/group.py#L113-L119 | train |
stephenmcd/gnotty | gnotty/bots/rss.py | RSSMixin.parse_feeds | def parse_feeds(self, message_channel=True):
"""
Iterates through each of the feed URLs, parses their items, and
sends any items to the channel that have not been previously
been parsed.
"""
if parse:
for feed_url in self.feeds:
feed = parse(fe... | python | def parse_feeds(self, message_channel=True):
"""
Iterates through each of the feed URLs, parses their items, and
sends any items to the channel that have not been previously
been parsed.
"""
if parse:
for feed_url in self.feeds:
feed = parse(fe... | [
"def",
"parse_feeds",
"(",
"self",
",",
"message_channel",
"=",
"True",
")",
":",
"if",
"parse",
":",
"for",
"feed_url",
"in",
"self",
".",
"feeds",
":",
"feed",
"=",
"parse",
"(",
"feed_url",
")",
"for",
"item",
"in",
"feed",
".",
"entries",
":",
"i... | Iterates through each of the feed URLs, parses their items, and
sends any items to the channel that have not been previously
been parsed. | [
"Iterates",
"through",
"each",
"of",
"the",
"feed",
"URLs",
"parses",
"their",
"items",
"and",
"sends",
"any",
"items",
"to",
"the",
"channel",
"that",
"have",
"not",
"been",
"previously",
"been",
"parsed",
"."
] | bea3762dc9cbc3cb21a5ae7224091cf027273c40 | https://github.com/stephenmcd/gnotty/blob/bea3762dc9cbc3cb21a5ae7224091cf027273c40/gnotty/bots/rss.py#L30-L45 | train |
Xython/Linq.py | linq/standard/dict.py | ChunkBy | def ChunkBy(self: dict, f=None):
"""
[
{
'self': [1, 1, 3, 3, 1, 1],
'f': lambda x: x%2,
'assert': lambda ret: ret == [[1, 1], [3, 3], [1, 1]]
}
]
"""
if f is None:
return _chunk(self.items())
if is_to_destruct(f):
f = destruct... | python | def ChunkBy(self: dict, f=None):
"""
[
{
'self': [1, 1, 3, 3, 1, 1],
'f': lambda x: x%2,
'assert': lambda ret: ret == [[1, 1], [3, 3], [1, 1]]
}
]
"""
if f is None:
return _chunk(self.items())
if is_to_destruct(f):
f = destruct... | [
"def",
"ChunkBy",
"(",
"self",
":",
"dict",
",",
"f",
"=",
"None",
")",
":",
"if",
"f",
"is",
"None",
":",
"return",
"_chunk",
"(",
"self",
".",
"items",
"(",
")",
")",
"if",
"is_to_destruct",
"(",
"f",
")",
":",
"f",
"=",
"destruct_func",
"(",
... | [
{
'self': [1, 1, 3, 3, 1, 1],
'f': lambda x: x%2,
'assert': lambda ret: ret == [[1, 1], [3, 3], [1, 1]]
}
] | [
"[",
"{",
"self",
":",
"[",
"1",
"1",
"3",
"3",
"1",
"1",
"]",
"f",
":",
"lambda",
"x",
":",
"x%2",
"assert",
":",
"lambda",
"ret",
":",
"ret",
"==",
"[[",
"1",
"1",
"]",
"[",
"3",
"3",
"]",
"[",
"1",
"1",
"]]",
"}",
"]"
] | ffb65f92f1df0d8161d5f835f5947554f6f33d72 | https://github.com/Xython/Linq.py/blob/ffb65f92f1df0d8161d5f835f5947554f6f33d72/linq/standard/dict.py#L74-L88 | train |
Xython/Linq.py | linq/standard/dict.py | GroupBy | def GroupBy(self: dict, f=None):
"""
[
{
'self': [1, 2, 3],
'f': lambda x: x%2,
'assert': lambda ret: ret[0] == [2] and ret[1] == [1, 3]
}
]
"""
if f and is_to_destruct(f):
f = destruct_func(f)
return _group_by(self.items(), f) | python | def GroupBy(self: dict, f=None):
"""
[
{
'self': [1, 2, 3],
'f': lambda x: x%2,
'assert': lambda ret: ret[0] == [2] and ret[1] == [1, 3]
}
]
"""
if f and is_to_destruct(f):
f = destruct_func(f)
return _group_by(self.items(), f) | [
"def",
"GroupBy",
"(",
"self",
":",
"dict",
",",
"f",
"=",
"None",
")",
":",
"if",
"f",
"and",
"is_to_destruct",
"(",
"f",
")",
":",
"f",
"=",
"destruct_func",
"(",
"f",
")",
"return",
"_group_by",
"(",
"self",
".",
"items",
"(",
")",
",",
"f",
... | [
{
'self': [1, 2, 3],
'f': lambda x: x%2,
'assert': lambda ret: ret[0] == [2] and ret[1] == [1, 3]
}
] | [
"[",
"{",
"self",
":",
"[",
"1",
"2",
"3",
"]",
"f",
":",
"lambda",
"x",
":",
"x%2",
"assert",
":",
"lambda",
"ret",
":",
"ret",
"[",
"0",
"]",
"==",
"[",
"2",
"]",
"and",
"ret",
"[",
"1",
"]",
"==",
"[",
"1",
"3",
"]",
"}",
"]"
] | ffb65f92f1df0d8161d5f835f5947554f6f33d72 | https://github.com/Xython/Linq.py/blob/ffb65f92f1df0d8161d5f835f5947554f6f33d72/linq/standard/dict.py#L92-L104 | train |
Xython/Linq.py | linq/standard/dict.py | Take | def Take(self: dict, n):
"""
[
{
'self': [1, 2, 3],
'n': 2,
'assert': lambda ret: list(ret) == [1, 2]
}
]
"""
for i, e in enumerate(self.items()):
if i == n:
break
yield e | python | def Take(self: dict, n):
"""
[
{
'self': [1, 2, 3],
'n': 2,
'assert': lambda ret: list(ret) == [1, 2]
}
]
"""
for i, e in enumerate(self.items()):
if i == n:
break
yield e | [
"def",
"Take",
"(",
"self",
":",
"dict",
",",
"n",
")",
":",
"for",
"i",
",",
"e",
"in",
"enumerate",
"(",
"self",
".",
"items",
"(",
")",
")",
":",
"if",
"i",
"==",
"n",
":",
"break",
"yield",
"e"
] | [
{
'self': [1, 2, 3],
'n': 2,
'assert': lambda ret: list(ret) == [1, 2]
}
] | [
"[",
"{",
"self",
":",
"[",
"1",
"2",
"3",
"]",
"n",
":",
"2",
"assert",
":",
"lambda",
"ret",
":",
"list",
"(",
"ret",
")",
"==",
"[",
"1",
"2",
"]",
"}",
"]"
] | ffb65f92f1df0d8161d5f835f5947554f6f33d72 | https://github.com/Xython/Linq.py/blob/ffb65f92f1df0d8161d5f835f5947554f6f33d72/linq/standard/dict.py#L108-L122 | train |
Xython/Linq.py | linq/standard/dict.py | TakeIf | def TakeIf(self: dict, f):
"""
[
{
'self': [1, 2, 3],
'f': lambda e: e%2,
'assert': lambda ret: list(ret) == [1, 3]
}
]
"""
if is_to_destruct(f):
f = destruct_func(f)
return (e for e in self.items() if f(e)) | python | def TakeIf(self: dict, f):
"""
[
{
'self': [1, 2, 3],
'f': lambda e: e%2,
'assert': lambda ret: list(ret) == [1, 3]
}
]
"""
if is_to_destruct(f):
f = destruct_func(f)
return (e for e in self.items() if f(e)) | [
"def",
"TakeIf",
"(",
"self",
":",
"dict",
",",
"f",
")",
":",
"if",
"is_to_destruct",
"(",
"f",
")",
":",
"f",
"=",
"destruct_func",
"(",
"f",
")",
"return",
"(",
"e",
"for",
"e",
"in",
"self",
".",
"items",
"(",
")",
"if",
"f",
"(",
"e",
")... | [
{
'self': [1, 2, 3],
'f': lambda e: e%2,
'assert': lambda ret: list(ret) == [1, 3]
}
] | [
"[",
"{",
"self",
":",
"[",
"1",
"2",
"3",
"]",
"f",
":",
"lambda",
"e",
":",
"e%2",
"assert",
":",
"lambda",
"ret",
":",
"list",
"(",
"ret",
")",
"==",
"[",
"1",
"3",
"]",
"}",
"]"
] | ffb65f92f1df0d8161d5f835f5947554f6f33d72 | https://github.com/Xython/Linq.py/blob/ffb65f92f1df0d8161d5f835f5947554f6f33d72/linq/standard/dict.py#L126-L139 | train |
Xython/Linq.py | linq/standard/dict.py | TakeWhile | def TakeWhile(self: dict, f):
"""
[
{
'self': [1, 2, 3, 4, 5],
'f': lambda x: x < 4,
'assert': lambda ret: list(ret) == [1, 2, 3]
}
]
"""
if is_to_destruct(f):
f = destruct_func(f)
for e in self.items():
if not f(e):
... | python | def TakeWhile(self: dict, f):
"""
[
{
'self': [1, 2, 3, 4, 5],
'f': lambda x: x < 4,
'assert': lambda ret: list(ret) == [1, 2, 3]
}
]
"""
if is_to_destruct(f):
f = destruct_func(f)
for e in self.items():
if not f(e):
... | [
"def",
"TakeWhile",
"(",
"self",
":",
"dict",
",",
"f",
")",
":",
"if",
"is_to_destruct",
"(",
"f",
")",
":",
"f",
"=",
"destruct_func",
"(",
"f",
")",
"for",
"e",
"in",
"self",
".",
"items",
"(",
")",
":",
"if",
"not",
"f",
"(",
"e",
")",
":... | [
{
'self': [1, 2, 3, 4, 5],
'f': lambda x: x < 4,
'assert': lambda ret: list(ret) == [1, 2, 3]
}
] | [
"[",
"{",
"self",
":",
"[",
"1",
"2",
"3",
"4",
"5",
"]",
"f",
":",
"lambda",
"x",
":",
"x",
"<",
"4",
"assert",
":",
"lambda",
"ret",
":",
"list",
"(",
"ret",
")",
"==",
"[",
"1",
"2",
"3",
"]",
"}",
"]"
] | ffb65f92f1df0d8161d5f835f5947554f6f33d72 | https://github.com/Xython/Linq.py/blob/ffb65f92f1df0d8161d5f835f5947554f6f33d72/linq/standard/dict.py#L143-L159 | train |
Xython/Linq.py | linq/standard/dict.py | Drop | def Drop(self: dict, n):
"""
[
{
'self': [1, 2, 3, 4, 5],
'n': 3,
'assert': lambda ret: list(ret) == [1, 2]
}
]
"""
n = len(self) - n
if n <= 0:
yield from self.items()
else:
for i, e in enumerate(self.items()):
... | python | def Drop(self: dict, n):
"""
[
{
'self': [1, 2, 3, 4, 5],
'n': 3,
'assert': lambda ret: list(ret) == [1, 2]
}
]
"""
n = len(self) - n
if n <= 0:
yield from self.items()
else:
for i, e in enumerate(self.items()):
... | [
"def",
"Drop",
"(",
"self",
":",
"dict",
",",
"n",
")",
":",
"n",
"=",
"len",
"(",
"self",
")",
"-",
"n",
"if",
"n",
"<=",
"0",
":",
"yield",
"from",
"self",
".",
"items",
"(",
")",
"else",
":",
"for",
"i",
",",
"e",
"in",
"enumerate",
"(",... | [
{
'self': [1, 2, 3, 4, 5],
'n': 3,
'assert': lambda ret: list(ret) == [1, 2]
}
] | [
"[",
"{",
"self",
":",
"[",
"1",
"2",
"3",
"4",
"5",
"]",
"n",
":",
"3",
"assert",
":",
"lambda",
"ret",
":",
"list",
"(",
"ret",
")",
"==",
"[",
"1",
"2",
"]",
"}",
"]"
] | ffb65f92f1df0d8161d5f835f5947554f6f33d72 | https://github.com/Xython/Linq.py/blob/ffb65f92f1df0d8161d5f835f5947554f6f33d72/linq/standard/dict.py#L163-L180 | train |
Xython/Linq.py | linq/standard/dict.py | Skip | def Skip(self: dict, n):
"""
[
{
'self': [1, 2, 3, 4, 5],
'n': 3,
'assert': lambda ret: list(ret) == [4, 5]
}
]
"""
con = self.items()
for i, _ in enumerate(con):
if i == n:
break
return... | python | def Skip(self: dict, n):
"""
[
{
'self': [1, 2, 3, 4, 5],
'n': 3,
'assert': lambda ret: list(ret) == [4, 5]
}
]
"""
con = self.items()
for i, _ in enumerate(con):
if i == n:
break
return... | [
"def",
"Skip",
"(",
"self",
":",
"dict",
",",
"n",
")",
":",
"con",
"=",
"self",
".",
"items",
"(",
")",
"for",
"i",
",",
"_",
"in",
"enumerate",
"(",
"con",
")",
":",
"if",
"i",
"==",
"n",
":",
"break",
"return",
"con"
] | [
{
'self': [1, 2, 3, 4, 5],
'n': 3,
'assert': lambda ret: list(ret) == [4, 5]
}
] | [
"[",
"{",
"self",
":",
"[",
"1",
"2",
"3",
"4",
"5",
"]",
"n",
":",
"3",
"assert",
":",
"lambda",
"ret",
":",
"list",
"(",
"ret",
")",
"==",
"[",
"4",
"5",
"]",
"}",
"]"
] | ffb65f92f1df0d8161d5f835f5947554f6f33d72 | https://github.com/Xython/Linq.py/blob/ffb65f92f1df0d8161d5f835f5947554f6f33d72/linq/standard/dict.py#L184-L199 | train |
aguinane/nem-reader | print_examples.py | print_meter_record | def print_meter_record(file_path, rows=5):
""" Output readings for specified number of rows to console """
m = nr.read_nem_file(file_path)
print('Header:', m.header)
print('Transactions:', m.transactions)
for nmi in m.readings:
for channel in m.readings[nmi]:
print(nmi, 'Channel'... | python | def print_meter_record(file_path, rows=5):
""" Output readings for specified number of rows to console """
m = nr.read_nem_file(file_path)
print('Header:', m.header)
print('Transactions:', m.transactions)
for nmi in m.readings:
for channel in m.readings[nmi]:
print(nmi, 'Channel'... | [
"def",
"print_meter_record",
"(",
"file_path",
",",
"rows",
"=",
"5",
")",
":",
"m",
"=",
"nr",
".",
"read_nem_file",
"(",
"file_path",
")",
"print",
"(",
"'Header:'",
",",
"m",
".",
"header",
")",
"print",
"(",
"'Transactions:'",
",",
"m",
".",
"trans... | Output readings for specified number of rows to console | [
"Output",
"readings",
"for",
"specified",
"number",
"of",
"rows",
"to",
"console"
] | 5405a5cba4bb8ebdad05c28455d12bb34a6d3ce5 | https://github.com/aguinane/nem-reader/blob/5405a5cba4bb8ebdad05c28455d12bb34a6d3ce5/print_examples.py#L4-L13 | train |
ergo/ziggurat_foundations | ziggurat_foundations/models/resource.py | ResourceMixin.users | def users(self):
""" returns all users that have permissions for this resource"""
return sa.orm.relationship(
"User",
secondary="users_resources_permissions",
passive_deletes=True,
passive_updates=True,
) | python | def users(self):
""" returns all users that have permissions for this resource"""
return sa.orm.relationship(
"User",
secondary="users_resources_permissions",
passive_deletes=True,
passive_updates=True,
) | [
"def",
"users",
"(",
"self",
")",
":",
"return",
"sa",
".",
"orm",
".",
"relationship",
"(",
"\"User\"",
",",
"secondary",
"=",
"\"users_resources_permissions\"",
",",
"passive_deletes",
"=",
"True",
",",
"passive_updates",
"=",
"True",
",",
")"
] | returns all users that have permissions for this resource | [
"returns",
"all",
"users",
"that",
"have",
"permissions",
"for",
"this",
"resource"
] | 9eeec894d08e8d7defa60ddc04b63f69cd4cbeba | https://github.com/ergo/ziggurat_foundations/blob/9eeec894d08e8d7defa60ddc04b63f69cd4cbeba/ziggurat_foundations/models/resource.py#L98-L105 | train |
ergo/ziggurat_foundations | ziggurat_foundations/models/services/resource_tree_postgres.py | ResourceTreeServicePostgreSQL.from_resource_deeper | def from_resource_deeper(
cls, resource_id=None, limit_depth=1000000, db_session=None, *args, **kwargs
):
"""
This returns you subtree of ordered objects relative
to the start resource_id (currently only implemented in postgresql)
:param resource_id:
:param limit_dep... | python | def from_resource_deeper(
cls, resource_id=None, limit_depth=1000000, db_session=None, *args, **kwargs
):
"""
This returns you subtree of ordered objects relative
to the start resource_id (currently only implemented in postgresql)
:param resource_id:
:param limit_dep... | [
"def",
"from_resource_deeper",
"(",
"cls",
",",
"resource_id",
"=",
"None",
",",
"limit_depth",
"=",
"1000000",
",",
"db_session",
"=",
"None",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"tablename",
"=",
"cls",
".",
"model",
".",
"__table__",
... | This returns you subtree of ordered objects relative
to the start resource_id (currently only implemented in postgresql)
:param resource_id:
:param limit_depth:
:param db_session:
:return: | [
"This",
"returns",
"you",
"subtree",
"of",
"ordered",
"objects",
"relative",
"to",
"the",
"start",
"resource_id",
"(",
"currently",
"only",
"implemented",
"in",
"postgresql",
")"
] | 9eeec894d08e8d7defa60ddc04b63f69cd4cbeba | https://github.com/ergo/ziggurat_foundations/blob/9eeec894d08e8d7defa60ddc04b63f69cd4cbeba/ziggurat_foundations/models/services/resource_tree_postgres.py#L24-L58 | train |
ergo/ziggurat_foundations | ziggurat_foundations/models/services/resource_tree_postgres.py | ResourceTreeServicePostgreSQL.delete_branch | def delete_branch(cls, resource_id=None, db_session=None, *args, **kwargs):
"""
This deletes whole branch with children starting from resource_id
:param resource_id:
:param db_session:
:return:
"""
tablename = cls.model.__table__.name
# lets lock rows to... | python | def delete_branch(cls, resource_id=None, db_session=None, *args, **kwargs):
"""
This deletes whole branch with children starting from resource_id
:param resource_id:
:param db_session:
:return:
"""
tablename = cls.model.__table__.name
# lets lock rows to... | [
"def",
"delete_branch",
"(",
"cls",
",",
"resource_id",
"=",
"None",
",",
"db_session",
"=",
"None",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"tablename",
"=",
"cls",
".",
"model",
".",
"__table__",
".",
"name",
"# lets lock rows to prevent bad... | This deletes whole branch with children starting from resource_id
:param resource_id:
:param db_session:
:return: | [
"This",
"deletes",
"whole",
"branch",
"with",
"children",
"starting",
"from",
"resource_id"
] | 9eeec894d08e8d7defa60ddc04b63f69cd4cbeba | https://github.com/ergo/ziggurat_foundations/blob/9eeec894d08e8d7defa60ddc04b63f69cd4cbeba/ziggurat_foundations/models/services/resource_tree_postgres.py#L61-L94 | train |
ergo/ziggurat_foundations | ziggurat_foundations/models/services/resource_tree_postgres.py | ResourceTreeServicePostgreSQL.from_parent_deeper | def from_parent_deeper(
cls, parent_id=None, limit_depth=1000000, db_session=None, *args, **kwargs
):
"""
This returns you subtree of ordered objects relative
to the start parent_id (currently only implemented in postgresql)
:param resource_id:
:param limit_depth:
... | python | def from_parent_deeper(
cls, parent_id=None, limit_depth=1000000, db_session=None, *args, **kwargs
):
"""
This returns you subtree of ordered objects relative
to the start parent_id (currently only implemented in postgresql)
:param resource_id:
:param limit_depth:
... | [
"def",
"from_parent_deeper",
"(",
"cls",
",",
"parent_id",
"=",
"None",
",",
"limit_depth",
"=",
"1000000",
",",
"db_session",
"=",
"None",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"parent_id",
":",
"limiting_clause",
"=",
"\"res.parent_i... | This returns you subtree of ordered objects relative
to the start parent_id (currently only implemented in postgresql)
:param resource_id:
:param limit_depth:
:param db_session:
:return: | [
"This",
"returns",
"you",
"subtree",
"of",
"ordered",
"objects",
"relative",
"to",
"the",
"start",
"parent_id",
"(",
"currently",
"only",
"implemented",
"in",
"postgresql",
")"
] | 9eeec894d08e8d7defa60ddc04b63f69cd4cbeba | https://github.com/ergo/ziggurat_foundations/blob/9eeec894d08e8d7defa60ddc04b63f69cd4cbeba/ziggurat_foundations/models/services/resource_tree_postgres.py#L97-L136 | train |
ergo/ziggurat_foundations | ziggurat_foundations/models/services/resource_tree_postgres.py | ResourceTreeServicePostgreSQL.build_subtree_strut | def build_subtree_strut(self, result, *args, **kwargs):
"""
Returns a dictionary in form of
{node:Resource, children:{node_id: Resource}}
:param result:
:return:
"""
items = list(result)
root_elem = {"node": None, "children": OrderedDict()}
if len... | python | def build_subtree_strut(self, result, *args, **kwargs):
"""
Returns a dictionary in form of
{node:Resource, children:{node_id: Resource}}
:param result:
:return:
"""
items = list(result)
root_elem = {"node": None, "children": OrderedDict()}
if len... | [
"def",
"build_subtree_strut",
"(",
"self",
",",
"result",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"items",
"=",
"list",
"(",
"result",
")",
"root_elem",
"=",
"{",
"\"node\"",
":",
"None",
",",
"\"children\"",
":",
"OrderedDict",
"(",
")",
... | Returns a dictionary in form of
{node:Resource, children:{node_id: Resource}}
:param result:
:return: | [
"Returns",
"a",
"dictionary",
"in",
"form",
"of",
"{",
"node",
":",
"Resource",
"children",
":",
"{",
"node_id",
":",
"Resource",
"}}"
] | 9eeec894d08e8d7defa60ddc04b63f69cd4cbeba | https://github.com/ergo/ziggurat_foundations/blob/9eeec894d08e8d7defa60ddc04b63f69cd4cbeba/ziggurat_foundations/models/services/resource_tree_postgres.py#L139-L160 | train |
ergo/ziggurat_foundations | ziggurat_foundations/models/services/resource_tree_postgres.py | ResourceTreeServicePostgreSQL.path_upper | def path_upper(
cls, object_id, limit_depth=1000000, db_session=None, *args, **kwargs
):
"""
This returns you path to root node starting from object_id
currently only for postgresql
:param object_id:
:param limit_depth:
:param db_session:
:return:... | python | def path_upper(
cls, object_id, limit_depth=1000000, db_session=None, *args, **kwargs
):
"""
This returns you path to root node starting from object_id
currently only for postgresql
:param object_id:
:param limit_depth:
:param db_session:
:return:... | [
"def",
"path_upper",
"(",
"cls",
",",
"object_id",
",",
"limit_depth",
"=",
"1000000",
",",
"db_session",
"=",
"None",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"tablename",
"=",
"cls",
".",
"model",
".",
"__table__",
".",
"name",
"raw_q",
... | This returns you path to root node starting from object_id
currently only for postgresql
:param object_id:
:param limit_depth:
:param db_session:
:return: | [
"This",
"returns",
"you",
"path",
"to",
"root",
"node",
"starting",
"from",
"object_id",
"currently",
"only",
"for",
"postgresql"
] | 9eeec894d08e8d7defa60ddc04b63f69cd4cbeba | https://github.com/ergo/ziggurat_foundations/blob/9eeec894d08e8d7defa60ddc04b63f69cd4cbeba/ziggurat_foundations/models/services/resource_tree_postgres.py#L163-L195 | train |
ergo/ziggurat_foundations | ziggurat_foundations/models/services/resource_tree_postgres.py | ResourceTreeServicePostgreSQL.move_to_position | def move_to_position(
cls,
resource_id,
to_position,
new_parent_id=noop,
db_session=None,
*args,
**kwargs
):
"""
Moves node to new location in the tree
:param resource_id: resource to move
:param to_position: new position
... | python | def move_to_position(
cls,
resource_id,
to_position,
new_parent_id=noop,
db_session=None,
*args,
**kwargs
):
"""
Moves node to new location in the tree
:param resource_id: resource to move
:param to_position: new position
... | [
"def",
"move_to_position",
"(",
"cls",
",",
"resource_id",
",",
"to_position",
",",
"new_parent_id",
"=",
"noop",
",",
"db_session",
"=",
"None",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"db_session",
"=",
"get_db_session",
"(",
"db_session",
"... | Moves node to new location in the tree
:param resource_id: resource to move
:param to_position: new position
:param new_parent_id: new parent id
:param db_session:
:return: | [
"Moves",
"node",
"to",
"new",
"location",
"in",
"the",
"tree"
] | 9eeec894d08e8d7defa60ddc04b63f69cd4cbeba | https://github.com/ergo/ziggurat_foundations/blob/9eeec894d08e8d7defa60ddc04b63f69cd4cbeba/ziggurat_foundations/models/services/resource_tree_postgres.py#L198-L275 | train |
ergo/ziggurat_foundations | ziggurat_foundations/models/services/resource_tree_postgres.py | ResourceTreeServicePostgreSQL.shift_ordering_up | def shift_ordering_up(cls, parent_id, position, db_session=None, *args, **kwargs):
"""
Shifts ordering to "open a gap" for node insertion,
begins the shift from given position
:param parent_id:
:param position:
:param db_session:
:return:
"""
db_s... | python | def shift_ordering_up(cls, parent_id, position, db_session=None, *args, **kwargs):
"""
Shifts ordering to "open a gap" for node insertion,
begins the shift from given position
:param parent_id:
:param position:
:param db_session:
:return:
"""
db_s... | [
"def",
"shift_ordering_up",
"(",
"cls",
",",
"parent_id",
",",
"position",
",",
"db_session",
"=",
"None",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"db_session",
"=",
"get_db_session",
"(",
"db_session",
")",
"query",
"=",
"db_session",
".",
... | Shifts ordering to "open a gap" for node insertion,
begins the shift from given position
:param parent_id:
:param position:
:param db_session:
:return: | [
"Shifts",
"ordering",
"to",
"open",
"a",
"gap",
"for",
"node",
"insertion",
"begins",
"the",
"shift",
"from",
"given",
"position"
] | 9eeec894d08e8d7defa60ddc04b63f69cd4cbeba | https://github.com/ergo/ziggurat_foundations/blob/9eeec894d08e8d7defa60ddc04b63f69cd4cbeba/ziggurat_foundations/models/services/resource_tree_postgres.py#L298-L315 | train |
ergo/ziggurat_foundations | ziggurat_foundations/models/services/resource_tree_postgres.py | ResourceTreeServicePostgreSQL.set_position | def set_position(cls, resource_id, to_position, db_session=None, *args, **kwargs):
"""
Sets node position for new node in the tree
:param resource_id: resource to move
:param to_position: new position
:param db_session:
:return:def count_children(cls, resource_id, db_ses... | python | def set_position(cls, resource_id, to_position, db_session=None, *args, **kwargs):
"""
Sets node position for new node in the tree
:param resource_id: resource to move
:param to_position: new position
:param db_session:
:return:def count_children(cls, resource_id, db_ses... | [
"def",
"set_position",
"(",
"cls",
",",
"resource_id",
",",
"to_position",
",",
"db_session",
"=",
"None",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"db_session",
"=",
"get_db_session",
"(",
"db_session",
")",
"# lets lock rows to prevent bad tree sta... | Sets node position for new node in the tree
:param resource_id: resource to move
:param to_position: new position
:param db_session:
:return:def count_children(cls, resource_id, db_session=None): | [
"Sets",
"node",
"position",
"for",
"new",
"node",
"in",
"the",
"tree"
] | 9eeec894d08e8d7defa60ddc04b63f69cd4cbeba | https://github.com/ergo/ziggurat_foundations/blob/9eeec894d08e8d7defa60ddc04b63f69cd4cbeba/ziggurat_foundations/models/services/resource_tree_postgres.py#L318-L339 | train |
ergo/ziggurat_foundations | ziggurat_foundations/models/services/resource_tree_postgres.py | ResourceTreeServicePostgreSQL.check_node_parent | def check_node_parent(
cls, resource_id, new_parent_id, db_session=None, *args, **kwargs
):
"""
Checks if parent destination is valid for node
:param resource_id:
:param new_parent_id:
:param db_session:
:return:
"""
db_session = get_db_sessio... | python | def check_node_parent(
cls, resource_id, new_parent_id, db_session=None, *args, **kwargs
):
"""
Checks if parent destination is valid for node
:param resource_id:
:param new_parent_id:
:param db_session:
:return:
"""
db_session = get_db_sessio... | [
"def",
"check_node_parent",
"(",
"cls",
",",
"resource_id",
",",
"new_parent_id",
",",
"db_session",
"=",
"None",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"db_session",
"=",
"get_db_session",
"(",
"db_session",
")",
"new_parent",
"=",
"ResourceSe... | Checks if parent destination is valid for node
:param resource_id:
:param new_parent_id:
:param db_session:
:return: | [
"Checks",
"if",
"parent",
"destination",
"is",
"valid",
"for",
"node"
] | 9eeec894d08e8d7defa60ddc04b63f69cd4cbeba | https://github.com/ergo/ziggurat_foundations/blob/9eeec894d08e8d7defa60ddc04b63f69cd4cbeba/ziggurat_foundations/models/services/resource_tree_postgres.py#L342-L366 | train |
ergo/ziggurat_foundations | ziggurat_foundations/models/services/resource_tree_postgres.py | ResourceTreeServicePostgreSQL.count_children | def count_children(cls, resource_id, db_session=None, *args, **kwargs):
"""
Counts children of resource node
:param resource_id:
:param db_session:
:return:
"""
query = db_session.query(cls.model.resource_id)
query = query.filter(cls.model.parent_id == re... | python | def count_children(cls, resource_id, db_session=None, *args, **kwargs):
"""
Counts children of resource node
:param resource_id:
:param db_session:
:return:
"""
query = db_session.query(cls.model.resource_id)
query = query.filter(cls.model.parent_id == re... | [
"def",
"count_children",
"(",
"cls",
",",
"resource_id",
",",
"db_session",
"=",
"None",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"query",
"=",
"db_session",
".",
"query",
"(",
"cls",
".",
"model",
".",
"resource_id",
")",
"query",
"=",
"... | Counts children of resource node
:param resource_id:
:param db_session:
:return: | [
"Counts",
"children",
"of",
"resource",
"node"
] | 9eeec894d08e8d7defa60ddc04b63f69cd4cbeba | https://github.com/ergo/ziggurat_foundations/blob/9eeec894d08e8d7defa60ddc04b63f69cd4cbeba/ziggurat_foundations/models/services/resource_tree_postgres.py#L369-L379 | train |
ergo/ziggurat_foundations | ziggurat_foundations/models/services/resource_tree_postgres.py | ResourceTreeServicePostgreSQL.check_node_position | def check_node_position(
cls, parent_id, position, on_same_branch, db_session=None, *args, **kwargs
):
"""
Checks if node position for given parent is valid, raises exception if
this is not the case
:param parent_id:
:param position:
:param on_same_branch: in... | python | def check_node_position(
cls, parent_id, position, on_same_branch, db_session=None, *args, **kwargs
):
"""
Checks if node position for given parent is valid, raises exception if
this is not the case
:param parent_id:
:param position:
:param on_same_branch: in... | [
"def",
"check_node_position",
"(",
"cls",
",",
"parent_id",
",",
"position",
",",
"on_same_branch",
",",
"db_session",
"=",
"None",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"db_session",
"=",
"get_db_session",
"(",
"db_session",
")",
"if",
"not... | Checks if node position for given parent is valid, raises exception if
this is not the case
:param parent_id:
:param position:
:param on_same_branch: indicates that we are checking same branch
:param db_session:
:return: | [
"Checks",
"if",
"node",
"position",
"for",
"given",
"parent",
"is",
"valid",
"raises",
"exception",
"if",
"this",
"is",
"not",
"the",
"case"
] | 9eeec894d08e8d7defa60ddc04b63f69cd4cbeba | https://github.com/ergo/ziggurat_foundations/blob/9eeec894d08e8d7defa60ddc04b63f69cd4cbeba/ziggurat_foundations/models/services/resource_tree_postgres.py#L382-L405 | train |
lapets/egcd | egcd/egcd.py | egcd | def egcd(b, n):
'''
Given two integers (b, n), returns (gcd(b, n), a, m) such that
a*b + n*m = gcd(b, n).
Adapted from several sources:
https://brilliant.org/wiki/extended-euclidean-algorithm/
https://rosettacode.org/wiki/Modular_inverse
https://en.wikibooks.org/wiki/Algorithm_Imp... | python | def egcd(b, n):
'''
Given two integers (b, n), returns (gcd(b, n), a, m) such that
a*b + n*m = gcd(b, n).
Adapted from several sources:
https://brilliant.org/wiki/extended-euclidean-algorithm/
https://rosettacode.org/wiki/Modular_inverse
https://en.wikibooks.org/wiki/Algorithm_Imp... | [
"def",
"egcd",
"(",
"b",
",",
"n",
")",
":",
"(",
"x0",
",",
"x1",
",",
"y0",
",",
"y1",
")",
"=",
"(",
"1",
",",
"0",
",",
"0",
",",
"1",
")",
"while",
"n",
"!=",
"0",
":",
"(",
"q",
",",
"b",
",",
"n",
")",
"=",
"(",
"b",
"//",
... | Given two integers (b, n), returns (gcd(b, n), a, m) such that
a*b + n*m = gcd(b, n).
Adapted from several sources:
https://brilliant.org/wiki/extended-euclidean-algorithm/
https://rosettacode.org/wiki/Modular_inverse
https://en.wikibooks.org/wiki/Algorithm_Implementation/Mathematics/Exte... | [
"Given",
"two",
"integers",
"(",
"b",
"n",
")",
"returns",
"(",
"gcd",
"(",
"b",
"n",
")",
"a",
"m",
")",
"such",
"that",
"a",
"*",
"b",
"+",
"n",
"*",
"m",
"=",
"gcd",
"(",
"b",
"n",
")",
".",
"Adapted",
"from",
"several",
"sources",
":",
... | 44fbab4a8eb04ad198526b4f14ddce6dff2bae77 | https://github.com/lapets/egcd/blob/44fbab4a8eb04ad198526b4f14ddce6dff2bae77/egcd/egcd.py#L16-L42 | train |
jucacrispim/pylint-mongoengine | pylint_mongoengine/__init__.py | register | def register(linter):
"""Add the needed transformations and supressions.
"""
linter.register_checker(MongoEngineChecker(linter))
add_transform('mongoengine')
add_transform('mongomotor')
suppress_qs_decorator_messages(linter)
suppress_fields_attrs_messages(linter) | python | def register(linter):
"""Add the needed transformations and supressions.
"""
linter.register_checker(MongoEngineChecker(linter))
add_transform('mongoengine')
add_transform('mongomotor')
suppress_qs_decorator_messages(linter)
suppress_fields_attrs_messages(linter) | [
"def",
"register",
"(",
"linter",
")",
":",
"linter",
".",
"register_checker",
"(",
"MongoEngineChecker",
"(",
"linter",
")",
")",
"add_transform",
"(",
"'mongoengine'",
")",
"add_transform",
"(",
"'mongomotor'",
")",
"suppress_qs_decorator_messages",
"(",
"linter",... | Add the needed transformations and supressions. | [
"Add",
"the",
"needed",
"transformations",
"and",
"supressions",
"."
] | b873653d1224a5748f75dd507f492f8c60d95ce3 | https://github.com/jucacrispim/pylint-mongoengine/blob/b873653d1224a5748f75dd507f492f8c60d95ce3/pylint_mongoengine/__init__.py#L25-L33 | train |
aguinane/nem-reader | nemreader/outputs.py | output_as_csv | def output_as_csv(file_name, nmi=None, output_file=None):
"""
Transpose all channels and output a csv that is easier
to read and do charting on
:param file_name: The NEM file to process
:param nmi: Which NMI to output if more than one
:param output_file: Specify different output location
:r... | python | def output_as_csv(file_name, nmi=None, output_file=None):
"""
Transpose all channels and output a csv that is easier
to read and do charting on
:param file_name: The NEM file to process
:param nmi: Which NMI to output if more than one
:param output_file: Specify different output location
:r... | [
"def",
"output_as_csv",
"(",
"file_name",
",",
"nmi",
"=",
"None",
",",
"output_file",
"=",
"None",
")",
":",
"m",
"=",
"read_nem_file",
"(",
"file_name",
")",
"if",
"nmi",
"is",
"None",
":",
"nmi",
"=",
"list",
"(",
"m",
".",
"readings",
".",
"keys"... | Transpose all channels and output a csv that is easier
to read and do charting on
:param file_name: The NEM file to process
:param nmi: Which NMI to output if more than one
:param output_file: Specify different output location
:returns: The file that was created | [
"Transpose",
"all",
"channels",
"and",
"output",
"a",
"csv",
"that",
"is",
"easier",
"to",
"read",
"and",
"do",
"charting",
"on"
] | 5405a5cba4bb8ebdad05c28455d12bb34a6d3ce5 | https://github.com/aguinane/nem-reader/blob/5405a5cba4bb8ebdad05c28455d12bb34a6d3ce5/nemreader/outputs.py#L11-L51 | train |
ergo/ziggurat_foundations | ziggurat_foundations/models/services/group.py | GroupService.get | def get(cls, group_id, db_session=None):
"""
Fetch row using primary key -
will use existing object in session if already present
:param group_id:
:param db_session:
:return:
"""
db_session = get_db_session(db_session)
return db_session.query(cls.... | python | def get(cls, group_id, db_session=None):
"""
Fetch row using primary key -
will use existing object in session if already present
:param group_id:
:param db_session:
:return:
"""
db_session = get_db_session(db_session)
return db_session.query(cls.... | [
"def",
"get",
"(",
"cls",
",",
"group_id",
",",
"db_session",
"=",
"None",
")",
":",
"db_session",
"=",
"get_db_session",
"(",
"db_session",
")",
"return",
"db_session",
".",
"query",
"(",
"cls",
".",
"model",
")",
".",
"get",
"(",
"group_id",
")"
] | Fetch row using primary key -
will use existing object in session if already present
:param group_id:
:param db_session:
:return: | [
"Fetch",
"row",
"using",
"primary",
"key",
"-",
"will",
"use",
"existing",
"object",
"in",
"session",
"if",
"already",
"present"
] | 9eeec894d08e8d7defa60ddc04b63f69cd4cbeba | https://github.com/ergo/ziggurat_foundations/blob/9eeec894d08e8d7defa60ddc04b63f69cd4cbeba/ziggurat_foundations/models/services/group.py#L19-L29 | train |
ergo/ziggurat_foundations | ziggurat_foundations/models/services/group.py | GroupService.by_group_name | def by_group_name(cls, group_name, db_session=None):
"""
fetch group by name
:param group_name:
:param db_session:
:return:
"""
db_session = get_db_session(db_session)
query = db_session.query(cls.model).filter(cls.model.group_name == group_name)
... | python | def by_group_name(cls, group_name, db_session=None):
"""
fetch group by name
:param group_name:
:param db_session:
:return:
"""
db_session = get_db_session(db_session)
query = db_session.query(cls.model).filter(cls.model.group_name == group_name)
... | [
"def",
"by_group_name",
"(",
"cls",
",",
"group_name",
",",
"db_session",
"=",
"None",
")",
":",
"db_session",
"=",
"get_db_session",
"(",
"db_session",
")",
"query",
"=",
"db_session",
".",
"query",
"(",
"cls",
".",
"model",
")",
".",
"filter",
"(",
"cl... | fetch group by name
:param group_name:
:param db_session:
:return: | [
"fetch",
"group",
"by",
"name"
] | 9eeec894d08e8d7defa60ddc04b63f69cd4cbeba | https://github.com/ergo/ziggurat_foundations/blob/9eeec894d08e8d7defa60ddc04b63f69cd4cbeba/ziggurat_foundations/models/services/group.py#L32-L42 | train |
ergo/ziggurat_foundations | ziggurat_foundations/models/services/group.py | GroupService.get_user_paginator | def get_user_paginator(
cls,
instance,
page=1,
item_count=None,
items_per_page=50,
user_ids=None,
GET_params=None,
):
"""
returns paginator over users belonging to the group
:param instance:
:param page:
:param item_cou... | python | def get_user_paginator(
cls,
instance,
page=1,
item_count=None,
items_per_page=50,
user_ids=None,
GET_params=None,
):
"""
returns paginator over users belonging to the group
:param instance:
:param page:
:param item_cou... | [
"def",
"get_user_paginator",
"(",
"cls",
",",
"instance",
",",
"page",
"=",
"1",
",",
"item_count",
"=",
"None",
",",
"items_per_page",
"=",
"50",
",",
"user_ids",
"=",
"None",
",",
"GET_params",
"=",
"None",
",",
")",
":",
"if",
"not",
"GET_params",
"... | returns paginator over users belonging to the group
:param instance:
:param page:
:param item_count:
:param items_per_page:
:param user_ids:
:param GET_params:
:return: | [
"returns",
"paginator",
"over",
"users",
"belonging",
"to",
"the",
"group"
] | 9eeec894d08e8d7defa60ddc04b63f69cd4cbeba | https://github.com/ergo/ziggurat_foundations/blob/9eeec894d08e8d7defa60ddc04b63f69cd4cbeba/ziggurat_foundations/models/services/group.py#L45-L77 | train |
ergo/ziggurat_foundations | ziggurat_foundations/models/services/group.py | GroupService.resources_with_possible_perms | def resources_with_possible_perms(
cls,
instance,
perm_names=None,
resource_ids=None,
resource_types=None,
db_session=None,
):
"""
returns list of permissions and resources for this group,
resource_ids restricts the search to specific resou... | python | def resources_with_possible_perms(
cls,
instance,
perm_names=None,
resource_ids=None,
resource_types=None,
db_session=None,
):
"""
returns list of permissions and resources for this group,
resource_ids restricts the search to specific resou... | [
"def",
"resources_with_possible_perms",
"(",
"cls",
",",
"instance",
",",
"perm_names",
"=",
"None",
",",
"resource_ids",
"=",
"None",
",",
"resource_types",
"=",
"None",
",",
"db_session",
"=",
"None",
",",
")",
":",
"db_session",
"=",
"get_db_session",
"(",
... | returns list of permissions and resources for this group,
resource_ids restricts the search to specific resources
:param instance:
:param perm_names:
:param resource_ids:
:param resource_types:
:param db_session:
:return: | [
"returns",
"list",
"of",
"permissions",
"and",
"resources",
"for",
"this",
"group",
"resource_ids",
"restricts",
"the",
"search",
"to",
"specific",
"resources"
] | 9eeec894d08e8d7defa60ddc04b63f69cd4cbeba | https://github.com/ergo/ziggurat_foundations/blob/9eeec894d08e8d7defa60ddc04b63f69cd4cbeba/ziggurat_foundations/models/services/group.py#L80-L144 | train |
zeromake/aiosqlite3 | aiosqlite3/pool.py | create_pool | def create_pool(
database,
minsize=1,
maxsize=10,
echo=False,
loop=None,
**kwargs
):
"""
创建支持上下文管理的pool
"""
coro = _create_pool(
database=database,
minsize=minsize,
maxsize=maxsize,
echo=echo,
loop=loop,
**kw... | python | def create_pool(
database,
minsize=1,
maxsize=10,
echo=False,
loop=None,
**kwargs
):
"""
创建支持上下文管理的pool
"""
coro = _create_pool(
database=database,
minsize=minsize,
maxsize=maxsize,
echo=echo,
loop=loop,
**kw... | [
"def",
"create_pool",
"(",
"database",
",",
"minsize",
"=",
"1",
",",
"maxsize",
"=",
"10",
",",
"echo",
"=",
"False",
",",
"loop",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"coro",
"=",
"_create_pool",
"(",
"database",
"=",
"database",
",",
... | 创建支持上下文管理的pool | [
"创建支持上下文管理的pool"
] | 1a74a062507e2df8f833a70885e69dca0ab3e7e7 | https://github.com/zeromake/aiosqlite3/blob/1a74a062507e2df8f833a70885e69dca0ab3e7e7/aiosqlite3/pool.py#L14-L33 | train |
zeromake/aiosqlite3 | aiosqlite3/pool.py | Pool.wait_closed | def wait_closed(self):
"""
Wait for closing all pool's connections.
"""
if self._closed:
return
if not self._closing:
raise RuntimeError(
".wait_closed() should be called "
"after .close()"
)
while self.... | python | def wait_closed(self):
"""
Wait for closing all pool's connections.
"""
if self._closed:
return
if not self._closing:
raise RuntimeError(
".wait_closed() should be called "
"after .close()"
)
while self.... | [
"def",
"wait_closed",
"(",
"self",
")",
":",
"if",
"self",
".",
"_closed",
":",
"return",
"if",
"not",
"self",
".",
"_closing",
":",
"raise",
"RuntimeError",
"(",
"\".wait_closed() should be called \"",
"\"after .close()\"",
")",
"while",
"self",
".",
"_free",
... | Wait for closing all pool's connections. | [
"Wait",
"for",
"closing",
"all",
"pool",
"s",
"connections",
"."
] | 1a74a062507e2df8f833a70885e69dca0ab3e7e7 | https://github.com/zeromake/aiosqlite3/blob/1a74a062507e2df8f833a70885e69dca0ab3e7e7/aiosqlite3/pool.py#L169-L192 | train |
zeromake/aiosqlite3 | aiosqlite3/pool.py | Pool.sync_close | def sync_close(self):
"""
同步关闭
"""
if self._closed:
return
while self._free:
conn = self._free.popleft()
if not conn.closed:
# pragma: no cover
conn.sync_close()
for conn in self._used:
if not... | python | def sync_close(self):
"""
同步关闭
"""
if self._closed:
return
while self._free:
conn = self._free.popleft()
if not conn.closed:
# pragma: no cover
conn.sync_close()
for conn in self._used:
if not... | [
"def",
"sync_close",
"(",
"self",
")",
":",
"if",
"self",
".",
"_closed",
":",
"return",
"while",
"self",
".",
"_free",
":",
"conn",
"=",
"self",
".",
"_free",
".",
"popleft",
"(",
")",
"if",
"not",
"conn",
".",
"closed",
":",
"# pragma: no cover",
"... | 同步关闭 | [
"同步关闭"
] | 1a74a062507e2df8f833a70885e69dca0ab3e7e7 | https://github.com/zeromake/aiosqlite3/blob/1a74a062507e2df8f833a70885e69dca0ab3e7e7/aiosqlite3/pool.py#L194-L211 | train |
zeromake/aiosqlite3 | aiosqlite3/pool.py | Pool._fill_free_pool | def _fill_free_pool(self, override_min):
"""
iterate over free connections and remove timeouted ones
"""
while self.size < self.minsize:
self._acquiring += 1
try:
conn = yield from connect(
database=self._database,
... | python | def _fill_free_pool(self, override_min):
"""
iterate over free connections and remove timeouted ones
"""
while self.size < self.minsize:
self._acquiring += 1
try:
conn = yield from connect(
database=self._database,
... | [
"def",
"_fill_free_pool",
"(",
"self",
",",
"override_min",
")",
":",
"while",
"self",
".",
"size",
"<",
"self",
".",
"minsize",
":",
"self",
".",
"_acquiring",
"+=",
"1",
"try",
":",
"conn",
"=",
"yield",
"from",
"connect",
"(",
"database",
"=",
"self... | iterate over free connections and remove timeouted ones | [
"iterate",
"over",
"free",
"connections",
"and",
"remove",
"timeouted",
"ones"
] | 1a74a062507e2df8f833a70885e69dca0ab3e7e7 | https://github.com/zeromake/aiosqlite3/blob/1a74a062507e2df8f833a70885e69dca0ab3e7e7/aiosqlite3/pool.py#L242-L274 | train |
stepank/pyws | src/pyws/functions/managers.py | FixedFunctionManager.add_function | def add_function(self, function):
"""
Adds the function to the list of registered functions.
"""
function = self.build_function(function)
if function.name in self.functions:
raise FunctionAlreadyRegistered(function.name)
self.functions[function.name] = functio... | python | def add_function(self, function):
"""
Adds the function to the list of registered functions.
"""
function = self.build_function(function)
if function.name in self.functions:
raise FunctionAlreadyRegistered(function.name)
self.functions[function.name] = functio... | [
"def",
"add_function",
"(",
"self",
",",
"function",
")",
":",
"function",
"=",
"self",
".",
"build_function",
"(",
"function",
")",
"if",
"function",
".",
"name",
"in",
"self",
".",
"functions",
":",
"raise",
"FunctionAlreadyRegistered",
"(",
"function",
".... | Adds the function to the list of registered functions. | [
"Adds",
"the",
"function",
"to",
"the",
"list",
"of",
"registered",
"functions",
"."
] | ff39133aabeb56bbb08d66286ac0cc8731eda7dd | https://github.com/stepank/pyws/blob/ff39133aabeb56bbb08d66286ac0cc8731eda7dd/src/pyws/functions/managers.py#L44-L51 | train |
stepank/pyws | src/pyws/functions/managers.py | FixedFunctionManager.get_one | def get_one(self, context, name):
"""
Returns a function if it is registered, the context is ignored.
"""
try:
return self.functions[name]
except KeyError:
raise FunctionNotFound(name) | python | def get_one(self, context, name):
"""
Returns a function if it is registered, the context is ignored.
"""
try:
return self.functions[name]
except KeyError:
raise FunctionNotFound(name) | [
"def",
"get_one",
"(",
"self",
",",
"context",
",",
"name",
")",
":",
"try",
":",
"return",
"self",
".",
"functions",
"[",
"name",
"]",
"except",
"KeyError",
":",
"raise",
"FunctionNotFound",
"(",
"name",
")"
] | Returns a function if it is registered, the context is ignored. | [
"Returns",
"a",
"function",
"if",
"it",
"is",
"registered",
"the",
"context",
"is",
"ignored",
"."
] | ff39133aabeb56bbb08d66286ac0cc8731eda7dd | https://github.com/stepank/pyws/blob/ff39133aabeb56bbb08d66286ac0cc8731eda7dd/src/pyws/functions/managers.py#L53-L60 | train |
opennode/waldur-core | waldur_core/core/monkeypatch.py | subfield_get | def subfield_get(self, obj, type=None):
"""
Verbatim copy from:
https://github.com/django/django/blob/1.9.13/django/db/models/fields/subclassing.py#L38
"""
if obj is None:
return self
return obj.__dict__[self.field.name] | python | def subfield_get(self, obj, type=None):
"""
Verbatim copy from:
https://github.com/django/django/blob/1.9.13/django/db/models/fields/subclassing.py#L38
"""
if obj is None:
return self
return obj.__dict__[self.field.name] | [
"def",
"subfield_get",
"(",
"self",
",",
"obj",
",",
"type",
"=",
"None",
")",
":",
"if",
"obj",
"is",
"None",
":",
"return",
"self",
"return",
"obj",
".",
"__dict__",
"[",
"self",
".",
"field",
".",
"name",
"]"
] | Verbatim copy from:
https://github.com/django/django/blob/1.9.13/django/db/models/fields/subclassing.py#L38 | [
"Verbatim",
"copy",
"from",
":",
"https",
":",
"//",
"github",
".",
"com",
"/",
"django",
"/",
"django",
"/",
"blob",
"/",
"1",
".",
"9",
".",
"13",
"/",
"django",
"/",
"db",
"/",
"models",
"/",
"fields",
"/",
"subclassing",
".",
"py#L38"
] | d6c17a9592bb6c49c33567542eef8d099605a46a | https://github.com/opennode/waldur-core/blob/d6c17a9592bb6c49c33567542eef8d099605a46a/waldur_core/core/monkeypatch.py#L14-L21 | train |
opennode/waldur-core | waldur_core/core/managers.py | GenericKeyMixin._preprocess_kwargs | def _preprocess_kwargs(self, initial_kwargs):
""" Replace generic key related attribute with filters by object_id and content_type fields """
kwargs = initial_kwargs.copy()
generic_key_related_kwargs = self._get_generic_key_related_kwargs(initial_kwargs)
for key, value in generic_key_rel... | python | def _preprocess_kwargs(self, initial_kwargs):
""" Replace generic key related attribute with filters by object_id and content_type fields """
kwargs = initial_kwargs.copy()
generic_key_related_kwargs = self._get_generic_key_related_kwargs(initial_kwargs)
for key, value in generic_key_rel... | [
"def",
"_preprocess_kwargs",
"(",
"self",
",",
"initial_kwargs",
")",
":",
"kwargs",
"=",
"initial_kwargs",
".",
"copy",
"(",
")",
"generic_key_related_kwargs",
"=",
"self",
".",
"_get_generic_key_related_kwargs",
"(",
"initial_kwargs",
")",
"for",
"key",
",",
"va... | Replace generic key related attribute with filters by object_id and content_type fields | [
"Replace",
"generic",
"key",
"related",
"attribute",
"with",
"filters",
"by",
"object_id",
"and",
"content_type",
"fields"
] | d6c17a9592bb6c49c33567542eef8d099605a46a | https://github.com/opennode/waldur-core/blob/d6c17a9592bb6c49c33567542eef8d099605a46a/waldur_core/core/managers.py#L29-L44 | train |
OpenDataScienceLab/skdata | skdata/cleaning.py | categorize | def categorize(
data, col_name: str = None, new_col_name: str = None,
categories: dict = None, max_categories: float = 0.15
):
"""
:param data:
:param col_name:
:param new_col_name:
:param categories:
:param max_categories: max proportion threshold of categories
:return: new categori... | python | def categorize(
data, col_name: str = None, new_col_name: str = None,
categories: dict = None, max_categories: float = 0.15
):
"""
:param data:
:param col_name:
:param new_col_name:
:param categories:
:param max_categories: max proportion threshold of categories
:return: new categori... | [
"def",
"categorize",
"(",
"data",
",",
"col_name",
":",
"str",
"=",
"None",
",",
"new_col_name",
":",
"str",
"=",
"None",
",",
"categories",
":",
"dict",
"=",
"None",
",",
"max_categories",
":",
"float",
"=",
"0.15",
")",
":",
"_categories",
"=",
"{",
... | :param data:
:param col_name:
:param new_col_name:
:param categories:
:param max_categories: max proportion threshold of categories
:return: new categories
:rtype dict: | [
":",
"param",
"data",
":",
":",
"param",
"col_name",
":",
":",
"param",
"new_col_name",
":",
":",
"param",
"categories",
":",
":",
"param",
"max_categories",
":",
"max",
"proportion",
"threshold",
"of",
"categories",
":",
"return",
":",
"new",
"categories",
... | 34f06845a944ff4f048b55c7babdd8420f71a6b9 | https://github.com/OpenDataScienceLab/skdata/blob/34f06845a944ff4f048b55c7babdd8420f71a6b9/skdata/cleaning.py#L4-L57 | train |
OpenDataScienceLab/skdata | skdata/cleaning.py | dropna | def dropna(data: pd.DataFrame, axis: int, **params):
"""
Remove columns with more NA values than threshold level
:param data:
:param axis:
Axes are defined for arrays with more than one dimension.
A 2-dimensional array has two corresponding axes: the first running
vertically downwards... | python | def dropna(data: pd.DataFrame, axis: int, **params):
"""
Remove columns with more NA values than threshold level
:param data:
:param axis:
Axes are defined for arrays with more than one dimension.
A 2-dimensional array has two corresponding axes: the first running
vertically downwards... | [
"def",
"dropna",
"(",
"data",
":",
"pd",
".",
"DataFrame",
",",
"axis",
":",
"int",
",",
"*",
"*",
"params",
")",
":",
"if",
"axis",
"==",
"0",
":",
"dropna_rows",
"(",
"data",
"=",
"data",
",",
"*",
"*",
"params",
")",
"else",
":",
"dropna_colum... | Remove columns with more NA values than threshold level
:param data:
:param axis:
Axes are defined for arrays with more than one dimension.
A 2-dimensional array has two corresponding axes: the first running
vertically downwards across rows (axis 0), and the second running
horizontally ... | [
"Remove",
"columns",
"with",
"more",
"NA",
"values",
"than",
"threshold",
"level"
] | 34f06845a944ff4f048b55c7babdd8420f71a6b9 | https://github.com/OpenDataScienceLab/skdata/blob/34f06845a944ff4f048b55c7babdd8420f71a6b9/skdata/cleaning.py#L60-L78 | train |
OpenDataScienceLab/skdata | skdata/cleaning.py | dropna_columns | def dropna_columns(data: pd.DataFrame, max_na_values: int=0.15):
"""
Remove columns with more NA values than threshold level
:param data:
:param max_na_values: proportion threshold of max na values
:return:
"""
size = data.shape[0]
df_na = (data.isnull().sum()/size) >= max_na_values
... | python | def dropna_columns(data: pd.DataFrame, max_na_values: int=0.15):
"""
Remove columns with more NA values than threshold level
:param data:
:param max_na_values: proportion threshold of max na values
:return:
"""
size = data.shape[0]
df_na = (data.isnull().sum()/size) >= max_na_values
... | [
"def",
"dropna_columns",
"(",
"data",
":",
"pd",
".",
"DataFrame",
",",
"max_na_values",
":",
"int",
"=",
"0.15",
")",
":",
"size",
"=",
"data",
".",
"shape",
"[",
"0",
"]",
"df_na",
"=",
"(",
"data",
".",
"isnull",
"(",
")",
".",
"sum",
"(",
")"... | Remove columns with more NA values than threshold level
:param data:
:param max_na_values: proportion threshold of max na values
:return: | [
"Remove",
"columns",
"with",
"more",
"NA",
"values",
"than",
"threshold",
"level"
] | 34f06845a944ff4f048b55c7babdd8420f71a6b9 | https://github.com/OpenDataScienceLab/skdata/blob/34f06845a944ff4f048b55c7babdd8420f71a6b9/skdata/cleaning.py#L81-L92 | train |
OpenDataScienceLab/skdata | skdata/cleaning.py | dropna_rows | def dropna_rows(data: pd.DataFrame, columns_name: str=None):
"""
Remove columns with more NA values than threshold level
:param data:
:param columns_name:
:return:
"""
params = {}
if columns_name is not None:
params.update({'subset': columns_name.split(',')})
data.dropna(in... | python | def dropna_rows(data: pd.DataFrame, columns_name: str=None):
"""
Remove columns with more NA values than threshold level
:param data:
:param columns_name:
:return:
"""
params = {}
if columns_name is not None:
params.update({'subset': columns_name.split(',')})
data.dropna(in... | [
"def",
"dropna_rows",
"(",
"data",
":",
"pd",
".",
"DataFrame",
",",
"columns_name",
":",
"str",
"=",
"None",
")",
":",
"params",
"=",
"{",
"}",
"if",
"columns_name",
"is",
"not",
"None",
":",
"params",
".",
"update",
"(",
"{",
"'subset'",
":",
"colu... | Remove columns with more NA values than threshold level
:param data:
:param columns_name:
:return: | [
"Remove",
"columns",
"with",
"more",
"NA",
"values",
"than",
"threshold",
"level"
] | 34f06845a944ff4f048b55c7babdd8420f71a6b9 | https://github.com/OpenDataScienceLab/skdata/blob/34f06845a944ff4f048b55c7babdd8420f71a6b9/skdata/cleaning.py#L95-L107 | train |
OpenDataScienceLab/skdata | skdata/cleaning.py | drop_columns_with_unique_values | def drop_columns_with_unique_values(
data: pd.DataFrame, max_unique_values: int = 0.25
):
"""
Remove columns when the proportion
of the total of unique values is more than the max_unique_values
threshold, just for columns with type as object or category
:param data:
:param max_unique_values... | python | def drop_columns_with_unique_values(
data: pd.DataFrame, max_unique_values: int = 0.25
):
"""
Remove columns when the proportion
of the total of unique values is more than the max_unique_values
threshold, just for columns with type as object or category
:param data:
:param max_unique_values... | [
"def",
"drop_columns_with_unique_values",
"(",
"data",
":",
"pd",
".",
"DataFrame",
",",
"max_unique_values",
":",
"int",
"=",
"0.25",
")",
":",
"size",
"=",
"data",
".",
"shape",
"[",
"0",
"]",
"df_uv",
"=",
"data",
".",
"apply",
"(",
"lambda",
"se",
... | Remove columns when the proportion
of the total of unique values is more than the max_unique_values
threshold, just for columns with type as object or category
:param data:
:param max_unique_values:
:return: | [
"Remove",
"columns",
"when",
"the",
"proportion",
"of",
"the",
"total",
"of",
"unique",
"values",
"is",
"more",
"than",
"the",
"max_unique_values",
"threshold",
"just",
"for",
"columns",
"with",
"type",
"as",
"object",
"or",
"category"
] | 34f06845a944ff4f048b55c7babdd8420f71a6b9 | https://github.com/OpenDataScienceLab/skdata/blob/34f06845a944ff4f048b55c7babdd8420f71a6b9/skdata/cleaning.py#L110-L130 | train |
opennode/waldur-core | waldur_core/quotas/views.py | QuotaViewSet.list | def list(self, request, *args, **kwargs):
"""
To get an actual value for object quotas limit and usage issue a **GET** request against */api/<objects>/*.
To get all quotas visible to the user issue a **GET** request against */api/quotas/*
"""
return super(QuotaViewSet, self).lis... | python | def list(self, request, *args, **kwargs):
"""
To get an actual value for object quotas limit and usage issue a **GET** request against */api/<objects>/*.
To get all quotas visible to the user issue a **GET** request against */api/quotas/*
"""
return super(QuotaViewSet, self).lis... | [
"def",
"list",
"(",
"self",
",",
"request",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"return",
"super",
"(",
"QuotaViewSet",
",",
"self",
")",
".",
"list",
"(",
"request",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")"
] | To get an actual value for object quotas limit and usage issue a **GET** request against */api/<objects>/*.
To get all quotas visible to the user issue a **GET** request against */api/quotas/* | [
"To",
"get",
"an",
"actual",
"value",
"for",
"object",
"quotas",
"limit",
"and",
"usage",
"issue",
"a",
"**",
"GET",
"**",
"request",
"against",
"*",
"/",
"api",
"/",
"<objects",
">",
"/",
"*",
"."
] | d6c17a9592bb6c49c33567542eef8d099605a46a | https://github.com/opennode/waldur-core/blob/d6c17a9592bb6c49c33567542eef8d099605a46a/waldur_core/quotas/views.py#L27-L33 | train |
opennode/waldur-core | waldur_core/quotas/views.py | QuotaViewSet.retrieve | def retrieve(self, request, *args, **kwargs):
"""
To set quota limit issue a **PUT** request against */api/quotas/<quota uuid>** with limit values.
Please note that if a quota is a cache of a backend quota (e.g. 'storage' size of an OpenStack tenant),
it will be impossible to modify it ... | python | def retrieve(self, request, *args, **kwargs):
"""
To set quota limit issue a **PUT** request against */api/quotas/<quota uuid>** with limit values.
Please note that if a quota is a cache of a backend quota (e.g. 'storage' size of an OpenStack tenant),
it will be impossible to modify it ... | [
"def",
"retrieve",
"(",
"self",
",",
"request",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"return",
"super",
"(",
"QuotaViewSet",
",",
"self",
")",
".",
"retrieve",
"(",
"request",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")"
] | To set quota limit issue a **PUT** request against */api/quotas/<quota uuid>** with limit values.
Please note that if a quota is a cache of a backend quota (e.g. 'storage' size of an OpenStack tenant),
it will be impossible to modify it through */api/quotas/<quota uuid>** endpoint.
Example of ... | [
"To",
"set",
"quota",
"limit",
"issue",
"a",
"**",
"PUT",
"**",
"request",
"against",
"*",
"/",
"api",
"/",
"quotas",
"/",
"<quota",
"uuid",
">",
"**",
"with",
"limit",
"values",
"."
] | d6c17a9592bb6c49c33567542eef8d099605a46a | https://github.com/opennode/waldur-core/blob/d6c17a9592bb6c49c33567542eef8d099605a46a/waldur_core/quotas/views.py#L35-L71 | train |
opennode/waldur-core | waldur_core/quotas/views.py | QuotaViewSet.history | def history(self, request, uuid=None):
"""
Historical data endpoints could be available for any objects (currently
implemented for quotas and events count). The data is available at *<object_endpoint>/history/*,
for example: */api/quotas/<uuid>/history/*.
There are two ways to d... | python | def history(self, request, uuid=None):
"""
Historical data endpoints could be available for any objects (currently
implemented for quotas and events count). The data is available at *<object_endpoint>/history/*,
for example: */api/quotas/<uuid>/history/*.
There are two ways to d... | [
"def",
"history",
"(",
"self",
",",
"request",
",",
"uuid",
"=",
"None",
")",
":",
"mapped",
"=",
"{",
"'start'",
":",
"request",
".",
"query_params",
".",
"get",
"(",
"'start'",
")",
",",
"'end'",
":",
"request",
".",
"query_params",
".",
"get",
"("... | Historical data endpoints could be available for any objects (currently
implemented for quotas and events count). The data is available at *<object_endpoint>/history/*,
for example: */api/quotas/<uuid>/history/*.
There are two ways to define datetime points for historical data.
1. Send... | [
"Historical",
"data",
"endpoints",
"could",
"be",
"available",
"for",
"any",
"objects",
"(",
"currently",
"implemented",
"for",
"quotas",
"and",
"events",
"count",
")",
".",
"The",
"data",
"is",
"available",
"at",
"*",
"<object_endpoint",
">",
"/",
"history",
... | d6c17a9592bb6c49c33567542eef8d099605a46a | https://github.com/opennode/waldur-core/blob/d6c17a9592bb6c49c33567542eef8d099605a46a/waldur_core/quotas/views.py#L96-L151 | train |
opennode/waldur-core | waldur_core/core/serializers.py | GenericRelatedField._get_url | def _get_url(self, obj):
"""
Gets object url
"""
format_kwargs = {
'app_label': obj._meta.app_label,
}
try:
format_kwargs['model_name'] = getattr(obj.__class__, 'get_url_name')()
except AttributeError:
format_kwargs['model_name'... | python | def _get_url(self, obj):
"""
Gets object url
"""
format_kwargs = {
'app_label': obj._meta.app_label,
}
try:
format_kwargs['model_name'] = getattr(obj.__class__, 'get_url_name')()
except AttributeError:
format_kwargs['model_name'... | [
"def",
"_get_url",
"(",
"self",
",",
"obj",
")",
":",
"format_kwargs",
"=",
"{",
"'app_label'",
":",
"obj",
".",
"_meta",
".",
"app_label",
",",
"}",
"try",
":",
"format_kwargs",
"[",
"'model_name'",
"]",
"=",
"getattr",
"(",
"obj",
".",
"__class__",
"... | Gets object url | [
"Gets",
"object",
"url"
] | d6c17a9592bb6c49c33567542eef8d099605a46a | https://github.com/opennode/waldur-core/blob/d6c17a9592bb6c49c33567542eef8d099605a46a/waldur_core/core/serializers.py#L82-L93 | train |
opennode/waldur-core | waldur_core/core/serializers.py | GenericRelatedField.to_representation | def to_representation(self, obj):
"""
Serializes any object to his url representation
"""
kwargs = None
for field in self.lookup_fields:
if hasattr(obj, field):
kwargs = {field: getattr(obj, field)}
break
if kwargs is None:
... | python | def to_representation(self, obj):
"""
Serializes any object to his url representation
"""
kwargs = None
for field in self.lookup_fields:
if hasattr(obj, field):
kwargs = {field: getattr(obj, field)}
break
if kwargs is None:
... | [
"def",
"to_representation",
"(",
"self",
",",
"obj",
")",
":",
"kwargs",
"=",
"None",
"for",
"field",
"in",
"self",
".",
"lookup_fields",
":",
"if",
"hasattr",
"(",
"obj",
",",
"field",
")",
":",
"kwargs",
"=",
"{",
"field",
":",
"getattr",
"(",
"obj... | Serializes any object to his url representation | [
"Serializes",
"any",
"object",
"to",
"his",
"url",
"representation"
] | d6c17a9592bb6c49c33567542eef8d099605a46a | https://github.com/opennode/waldur-core/blob/d6c17a9592bb6c49c33567542eef8d099605a46a/waldur_core/core/serializers.py#L101-L113 | train |
opennode/waldur-core | waldur_core/core/serializers.py | GenericRelatedField.to_internal_value | def to_internal_value(self, data):
"""
Restores model instance from its url
"""
if not data:
return None
request = self._get_request()
user = request.user
try:
obj = core_utils.instance_from_url(data, user=user)
model = obj.__cl... | python | def to_internal_value(self, data):
"""
Restores model instance from its url
"""
if not data:
return None
request = self._get_request()
user = request.user
try:
obj = core_utils.instance_from_url(data, user=user)
model = obj.__cl... | [
"def",
"to_internal_value",
"(",
"self",
",",
"data",
")",
":",
"if",
"not",
"data",
":",
"return",
"None",
"request",
"=",
"self",
".",
"_get_request",
"(",
")",
"user",
"=",
"request",
".",
"user",
"try",
":",
"obj",
"=",
"core_utils",
".",
"instance... | Restores model instance from its url | [
"Restores",
"model",
"instance",
"from",
"its",
"url"
] | d6c17a9592bb6c49c33567542eef8d099605a46a | https://github.com/opennode/waldur-core/blob/d6c17a9592bb6c49c33567542eef8d099605a46a/waldur_core/core/serializers.py#L115-L132 | train |
opennode/waldur-core | waldur_core/core/serializers.py | TimestampIntervalSerializer.validate | def validate(self, data):
"""
Check that the start is before the end.
"""
if 'start' in data and 'end' in data and data['start'] >= data['end']:
raise serializers.ValidationError(_('End must occur after start.'))
return data | python | def validate(self, data):
"""
Check that the start is before the end.
"""
if 'start' in data and 'end' in data and data['start'] >= data['end']:
raise serializers.ValidationError(_('End must occur after start.'))
return data | [
"def",
"validate",
"(",
"self",
",",
"data",
")",
":",
"if",
"'start'",
"in",
"data",
"and",
"'end'",
"in",
"data",
"and",
"data",
"[",
"'start'",
"]",
">=",
"data",
"[",
"'end'",
"]",
":",
"raise",
"serializers",
".",
"ValidationError",
"(",
"_",
"(... | Check that the start is before the end. | [
"Check",
"that",
"the",
"start",
"is",
"before",
"the",
"end",
"."
] | d6c17a9592bb6c49c33567542eef8d099605a46a | https://github.com/opennode/waldur-core/blob/d6c17a9592bb6c49c33567542eef8d099605a46a/waldur_core/core/serializers.py#L373-L379 | train |
opennode/waldur-core | waldur_core/core/tasks.py | send_task | def send_task(app_label, task_name):
""" A helper function to deal with waldur_core "high-level" tasks.
Define high-level task with explicit name using a pattern:
waldur_core.<app_label>.<task_name>
.. code-block:: python
@shared_task(name='waldur_core.openstack.provision_instan... | python | def send_task(app_label, task_name):
""" A helper function to deal with waldur_core "high-level" tasks.
Define high-level task with explicit name using a pattern:
waldur_core.<app_label>.<task_name>
.. code-block:: python
@shared_task(name='waldur_core.openstack.provision_instan... | [
"def",
"send_task",
"(",
"app_label",
",",
"task_name",
")",
":",
"def",
"delay",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"full_task_name",
"=",
"'waldur_core.%s.%s'",
"%",
"(",
"app_label",
",",
"task_name",
")",
"send_celery_task",
"(",
"ful... | A helper function to deal with waldur_core "high-level" tasks.
Define high-level task with explicit name using a pattern:
waldur_core.<app_label>.<task_name>
.. code-block:: python
@shared_task(name='waldur_core.openstack.provision_instance')
def provision_instance_fn(in... | [
"A",
"helper",
"function",
"to",
"deal",
"with",
"waldur_core",
"high",
"-",
"level",
"tasks",
".",
"Define",
"high",
"-",
"level",
"task",
"with",
"explicit",
"name",
"using",
"a",
"pattern",
":",
"waldur_core",
".",
"<app_label",
">",
".",
"<task_name",
... | d6c17a9592bb6c49c33567542eef8d099605a46a | https://github.com/opennode/waldur-core/blob/d6c17a9592bb6c49c33567542eef8d099605a46a/waldur_core/core/tasks.py#L54-L80 | train |
opennode/waldur-core | waldur_core/core/tasks.py | log_celery_task | def log_celery_task(request):
""" Add description to celery log output """
task = request.task
description = None
if isinstance(task, Task):
try:
description = task.get_description(*request.args, **request.kwargs)
except NotImplementedError:
pass
except Ex... | python | def log_celery_task(request):
""" Add description to celery log output """
task = request.task
description = None
if isinstance(task, Task):
try:
description = task.get_description(*request.args, **request.kwargs)
except NotImplementedError:
pass
except Ex... | [
"def",
"log_celery_task",
"(",
"request",
")",
":",
"task",
"=",
"request",
".",
"task",
"description",
"=",
"None",
"if",
"isinstance",
"(",
"task",
",",
"Task",
")",
":",
"try",
":",
"description",
"=",
"task",
".",
"get_description",
"(",
"*",
"reques... | Add description to celery log output | [
"Add",
"description",
"to",
"celery",
"log",
"output"
] | d6c17a9592bb6c49c33567542eef8d099605a46a | https://github.com/opennode/waldur-core/blob/d6c17a9592bb6c49c33567542eef8d099605a46a/waldur_core/core/tasks.py#L440-L458 | train |
opennode/waldur-core | waldur_core/core/tasks.py | Task.run | def run(self, serialized_instance, *args, **kwargs):
""" Deserialize input data and start backend operation execution """
try:
instance = utils.deserialize_instance(serialized_instance)
except ObjectDoesNotExist:
message = ('Cannot restore instance from serialized object ... | python | def run(self, serialized_instance, *args, **kwargs):
""" Deserialize input data and start backend operation execution """
try:
instance = utils.deserialize_instance(serialized_instance)
except ObjectDoesNotExist:
message = ('Cannot restore instance from serialized object ... | [
"def",
"run",
"(",
"self",
",",
"serialized_instance",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"try",
":",
"instance",
"=",
"utils",
".",
"deserialize_instance",
"(",
"serialized_instance",
")",
"except",
"ObjectDoesNotExist",
":",
"message",
"=... | Deserialize input data and start backend operation execution | [
"Deserialize",
"input",
"data",
"and",
"start",
"backend",
"operation",
"execution"
] | d6c17a9592bb6c49c33567542eef8d099605a46a | https://github.com/opennode/waldur-core/blob/d6c17a9592bb6c49c33567542eef8d099605a46a/waldur_core/core/tasks.py#L97-L114 | train |
opennode/waldur-core | waldur_core/core/tasks.py | BackgroundTask.is_previous_task_processing | def is_previous_task_processing(self, *args, **kwargs):
""" Return True if exist task that is equal to current and is uncompleted """
app = self._get_app()
inspect = app.control.inspect()
active = inspect.active() or {}
scheduled = inspect.scheduled() or {}
reserved = ins... | python | def is_previous_task_processing(self, *args, **kwargs):
""" Return True if exist task that is equal to current and is uncompleted """
app = self._get_app()
inspect = app.control.inspect()
active = inspect.active() or {}
scheduled = inspect.scheduled() or {}
reserved = ins... | [
"def",
"is_previous_task_processing",
"(",
"self",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"app",
"=",
"self",
".",
"_get_app",
"(",
")",
"inspect",
"=",
"app",
".",
"control",
".",
"inspect",
"(",
")",
"active",
"=",
"inspect",
".",
"ac... | Return True if exist task that is equal to current and is uncompleted | [
"Return",
"True",
"if",
"exist",
"task",
"that",
"is",
"equal",
"to",
"current",
"and",
"is",
"uncompleted"
] | d6c17a9592bb6c49c33567542eef8d099605a46a | https://github.com/opennode/waldur-core/blob/d6c17a9592bb6c49c33567542eef8d099605a46a/waldur_core/core/tasks.py#L353-L361 | train |
opennode/waldur-core | waldur_core/core/tasks.py | BackgroundTask.apply_async | def apply_async(self, args=None, kwargs=None, **options):
""" Do not run background task if previous task is uncompleted """
if self.is_previous_task_processing(*args, **kwargs):
message = 'Background task %s was not scheduled, because its predecessor is not completed yet.' % self.name
... | python | def apply_async(self, args=None, kwargs=None, **options):
""" Do not run background task if previous task is uncompleted """
if self.is_previous_task_processing(*args, **kwargs):
message = 'Background task %s was not scheduled, because its predecessor is not completed yet.' % self.name
... | [
"def",
"apply_async",
"(",
"self",
",",
"args",
"=",
"None",
",",
"kwargs",
"=",
"None",
",",
"*",
"*",
"options",
")",
":",
"if",
"self",
".",
"is_previous_task_processing",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"message",
"=",
"'Back... | Do not run background task if previous task is uncompleted | [
"Do",
"not",
"run",
"background",
"task",
"if",
"previous",
"task",
"is",
"uncompleted"
] | d6c17a9592bb6c49c33567542eef8d099605a46a | https://github.com/opennode/waldur-core/blob/d6c17a9592bb6c49c33567542eef8d099605a46a/waldur_core/core/tasks.py#L363-L370 | train |
opennode/waldur-core | waldur_core/core/tasks.py | PenalizedBackgroundTask._get_cache_key | def _get_cache_key(self, args, kwargs):
""" Returns key to be used in cache """
hash_input = json.dumps({'name': self.name, 'args': args, 'kwargs': kwargs}, sort_keys=True)
# md5 is used for internal caching, not need to care about security
return hashlib.md5(hash_input).hexdigest() | python | def _get_cache_key(self, args, kwargs):
""" Returns key to be used in cache """
hash_input = json.dumps({'name': self.name, 'args': args, 'kwargs': kwargs}, sort_keys=True)
# md5 is used for internal caching, not need to care about security
return hashlib.md5(hash_input).hexdigest() | [
"def",
"_get_cache_key",
"(",
"self",
",",
"args",
",",
"kwargs",
")",
":",
"hash_input",
"=",
"json",
".",
"dumps",
"(",
"{",
"'name'",
":",
"self",
".",
"name",
",",
"'args'",
":",
"args",
",",
"'kwargs'",
":",
"kwargs",
"}",
",",
"sort_keys",
"=",... | Returns key to be used in cache | [
"Returns",
"key",
"to",
"be",
"used",
"in",
"cache"
] | d6c17a9592bb6c49c33567542eef8d099605a46a | https://github.com/opennode/waldur-core/blob/d6c17a9592bb6c49c33567542eef8d099605a46a/waldur_core/core/tasks.py#L396-L400 | train |
opennode/waldur-core | waldur_core/core/tasks.py | PenalizedBackgroundTask.apply_async | def apply_async(self, args=None, kwargs=None, **options):
"""
Checks whether task must be skipped and decreases the counter in that case.
"""
key = self._get_cache_key(args, kwargs)
counter, penalty = cache.get(key, (0, 0))
if not counter:
return super(Penaliz... | python | def apply_async(self, args=None, kwargs=None, **options):
"""
Checks whether task must be skipped and decreases the counter in that case.
"""
key = self._get_cache_key(args, kwargs)
counter, penalty = cache.get(key, (0, 0))
if not counter:
return super(Penaliz... | [
"def",
"apply_async",
"(",
"self",
",",
"args",
"=",
"None",
",",
"kwargs",
"=",
"None",
",",
"*",
"*",
"options",
")",
":",
"key",
"=",
"self",
".",
"_get_cache_key",
"(",
"args",
",",
"kwargs",
")",
"counter",
",",
"penalty",
"=",
"cache",
".",
"... | Checks whether task must be skipped and decreases the counter in that case. | [
"Checks",
"whether",
"task",
"must",
"be",
"skipped",
"and",
"decreases",
"the",
"counter",
"in",
"that",
"case",
"."
] | d6c17a9592bb6c49c33567542eef8d099605a46a | https://github.com/opennode/waldur-core/blob/d6c17a9592bb6c49c33567542eef8d099605a46a/waldur_core/core/tasks.py#L402-L413 | train |
opennode/waldur-core | waldur_core/core/tasks.py | PenalizedBackgroundTask.on_failure | def on_failure(self, exc, task_id, args, kwargs, einfo):
"""
Increases penalty for the task and resets the counter.
"""
key = self._get_cache_key(args, kwargs)
_, penalty = cache.get(key, (0, 0))
if penalty < self.MAX_PENALTY:
penalty += 1
logger.debu... | python | def on_failure(self, exc, task_id, args, kwargs, einfo):
"""
Increases penalty for the task and resets the counter.
"""
key = self._get_cache_key(args, kwargs)
_, penalty = cache.get(key, (0, 0))
if penalty < self.MAX_PENALTY:
penalty += 1
logger.debu... | [
"def",
"on_failure",
"(",
"self",
",",
"exc",
",",
"task_id",
",",
"args",
",",
"kwargs",
",",
"einfo",
")",
":",
"key",
"=",
"self",
".",
"_get_cache_key",
"(",
"args",
",",
"kwargs",
")",
"_",
",",
"penalty",
"=",
"cache",
".",
"get",
"(",
"key",... | Increases penalty for the task and resets the counter. | [
"Increases",
"penalty",
"for",
"the",
"task",
"and",
"resets",
"the",
"counter",
"."
] | d6c17a9592bb6c49c33567542eef8d099605a46a | https://github.com/opennode/waldur-core/blob/d6c17a9592bb6c49c33567542eef8d099605a46a/waldur_core/core/tasks.py#L415-L426 | train |
opennode/waldur-core | waldur_core/core/tasks.py | PenalizedBackgroundTask.on_success | def on_success(self, retval, task_id, args, kwargs):
"""
Clears cache for the task.
"""
key = self._get_cache_key(args, kwargs)
if cache.get(key) is not None:
cache.delete(key)
logger.debug('Penalty for the task %s has been removed.' % self.name)
... | python | def on_success(self, retval, task_id, args, kwargs):
"""
Clears cache for the task.
"""
key = self._get_cache_key(args, kwargs)
if cache.get(key) is not None:
cache.delete(key)
logger.debug('Penalty for the task %s has been removed.' % self.name)
... | [
"def",
"on_success",
"(",
"self",
",",
"retval",
",",
"task_id",
",",
"args",
",",
"kwargs",
")",
":",
"key",
"=",
"self",
".",
"_get_cache_key",
"(",
"args",
",",
"kwargs",
")",
"if",
"cache",
".",
"get",
"(",
"key",
")",
"is",
"not",
"None",
":",... | Clears cache for the task. | [
"Clears",
"cache",
"for",
"the",
"task",
"."
] | d6c17a9592bb6c49c33567542eef8d099605a46a | https://github.com/opennode/waldur-core/blob/d6c17a9592bb6c49c33567542eef8d099605a46a/waldur_core/core/tasks.py#L428-L437 | train |
opennode/waldur-core | waldur_core/structure/__init__.py | log_backend_action | def log_backend_action(action=None):
""" Logging for backend method.
Expects django model instance as first argument.
"""
def decorator(func):
@functools.wraps(func)
def wrapped(self, instance, *args, **kwargs):
action_name = func.func_name.replace('_', ' ') if action is Non... | python | def log_backend_action(action=None):
""" Logging for backend method.
Expects django model instance as first argument.
"""
def decorator(func):
@functools.wraps(func)
def wrapped(self, instance, *args, **kwargs):
action_name = func.func_name.replace('_', ' ') if action is Non... | [
"def",
"log_backend_action",
"(",
"action",
"=",
"None",
")",
":",
"def",
"decorator",
"(",
"func",
")",
":",
"@",
"functools",
".",
"wraps",
"(",
"func",
")",
"def",
"wrapped",
"(",
"self",
",",
"instance",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",... | Logging for backend method.
Expects django model instance as first argument. | [
"Logging",
"for",
"backend",
"method",
"."
] | d6c17a9592bb6c49c33567542eef8d099605a46a | https://github.com/opennode/waldur-core/blob/d6c17a9592bb6c49c33567542eef8d099605a46a/waldur_core/structure/__init__.py#L417-L433 | train |
opennode/waldur-core | waldur_core/structure/__init__.py | SupportedServices.get_services | def get_services(cls, request=None):
""" Get a list of services endpoints.
{
"Oracle": "/api/oracle/",
"OpenStack": "/api/openstack/",
"GitLab": "/api/gitlab/",
"DigitalOcean": "/api/digitalocean/"
}
"""
retu... | python | def get_services(cls, request=None):
""" Get a list of services endpoints.
{
"Oracle": "/api/oracle/",
"OpenStack": "/api/openstack/",
"GitLab": "/api/gitlab/",
"DigitalOcean": "/api/digitalocean/"
}
"""
retu... | [
"def",
"get_services",
"(",
"cls",
",",
"request",
"=",
"None",
")",
":",
"return",
"{",
"service",
"[",
"'name'",
"]",
":",
"reverse",
"(",
"service",
"[",
"'list_view'",
"]",
",",
"request",
"=",
"request",
")",
"for",
"service",
"in",
"cls",
".",
... | Get a list of services endpoints.
{
"Oracle": "/api/oracle/",
"OpenStack": "/api/openstack/",
"GitLab": "/api/gitlab/",
"DigitalOcean": "/api/digitalocean/"
} | [
"Get",
"a",
"list",
"of",
"services",
"endpoints",
".",
"{",
"Oracle",
":",
"/",
"api",
"/",
"oracle",
"/",
"OpenStack",
":",
"/",
"api",
"/",
"openstack",
"/",
"GitLab",
":",
"/",
"api",
"/",
"gitlab",
"/",
"DigitalOcean",
":",
"/",
"api",
"/",
"d... | d6c17a9592bb6c49c33567542eef8d099605a46a | https://github.com/opennode/waldur-core/blob/d6c17a9592bb6c49c33567542eef8d099605a46a/waldur_core/structure/__init__.py#L161-L171 | train |
opennode/waldur-core | waldur_core/structure/__init__.py | SupportedServices.get_resources | def get_resources(cls, request=None):
""" Get a list of resources endpoints.
{
"DigitalOcean.Droplet": "/api/digitalocean-droplets/",
"Oracle.Database": "/api/oracle-databases/",
"GitLab.Group": "/api/gitlab-groups/",
"GitLab.Project": ... | python | def get_resources(cls, request=None):
""" Get a list of resources endpoints.
{
"DigitalOcean.Droplet": "/api/digitalocean-droplets/",
"Oracle.Database": "/api/oracle-databases/",
"GitLab.Group": "/api/gitlab-groups/",
"GitLab.Project": ... | [
"def",
"get_resources",
"(",
"cls",
",",
"request",
"=",
"None",
")",
":",
"return",
"{",
"'.'",
".",
"join",
"(",
"[",
"service",
"[",
"'name'",
"]",
",",
"resource",
"[",
"'name'",
"]",
"]",
")",
":",
"reverse",
"(",
"resource",
"[",
"'list_view'",... | Get a list of resources endpoints.
{
"DigitalOcean.Droplet": "/api/digitalocean-droplets/",
"Oracle.Database": "/api/oracle-databases/",
"GitLab.Group": "/api/gitlab-groups/",
"GitLab.Project": "/api/gitlab-projects/"
} | [
"Get",
"a",
"list",
"of",
"resources",
"endpoints",
".",
"{",
"DigitalOcean",
".",
"Droplet",
":",
"/",
"api",
"/",
"digitalocean",
"-",
"droplets",
"/",
"Oracle",
".",
"Database",
":",
"/",
"api",
"/",
"oracle",
"-",
"databases",
"/",
"GitLab",
".",
"... | d6c17a9592bb6c49c33567542eef8d099605a46a | https://github.com/opennode/waldur-core/blob/d6c17a9592bb6c49c33567542eef8d099605a46a/waldur_core/structure/__init__.py#L184-L195 | train |
opennode/waldur-core | waldur_core/structure/__init__.py | SupportedServices.get_services_with_resources | def get_services_with_resources(cls, request=None):
""" Get a list of services and resources endpoints.
{
...
"GitLab": {
"url": "/api/gitlab/",
"service_project_link_url": "/api/gitlab-service-project-link/",
... | python | def get_services_with_resources(cls, request=None):
""" Get a list of services and resources endpoints.
{
...
"GitLab": {
"url": "/api/gitlab/",
"service_project_link_url": "/api/gitlab-service-project-link/",
... | [
"def",
"get_services_with_resources",
"(",
"cls",
",",
"request",
"=",
"None",
")",
":",
"from",
"django",
".",
"apps",
"import",
"apps",
"data",
"=",
"{",
"}",
"for",
"service",
"in",
"cls",
".",
"_registry",
".",
"values",
"(",
")",
":",
"service_model... | Get a list of services and resources endpoints.
{
...
"GitLab": {
"url": "/api/gitlab/",
"service_project_link_url": "/api/gitlab-service-project-link/",
"resources": {
"Project": "/api/gitlab... | [
"Get",
"a",
"list",
"of",
"services",
"and",
"resources",
"endpoints",
".",
"{",
"...",
"GitLab",
":",
"{",
"url",
":",
"/",
"api",
"/",
"gitlab",
"/",
"service_project_link_url",
":",
"/",
"api",
"/",
"gitlab",
"-",
"service",
"-",
"project",
"-",
"li... | d6c17a9592bb6c49c33567542eef8d099605a46a | https://github.com/opennode/waldur-core/blob/d6c17a9592bb6c49c33567542eef8d099605a46a/waldur_core/structure/__init__.py#L216-L248 | train |
opennode/waldur-core | waldur_core/structure/__init__.py | SupportedServices.get_service_models | def get_service_models(cls):
""" Get a list of service models.
{
...
'gitlab': {
"service": nodeconductor_gitlab.models.GitLabService,
"service_project_link": nodeconductor_gitlab.models.GitLabServiceProjectLink,
... | python | def get_service_models(cls):
""" Get a list of service models.
{
...
'gitlab': {
"service": nodeconductor_gitlab.models.GitLabService,
"service_project_link": nodeconductor_gitlab.models.GitLabServiceProjectLink,
... | [
"def",
"get_service_models",
"(",
"cls",
")",
":",
"from",
"django",
".",
"apps",
"import",
"apps",
"data",
"=",
"{",
"}",
"for",
"key",
",",
"service",
"in",
"cls",
".",
"_registry",
".",
"items",
"(",
")",
":",
"service_model",
"=",
"apps",
".",
"g... | Get a list of service models.
{
...
'gitlab': {
"service": nodeconductor_gitlab.models.GitLabService,
"service_project_link": nodeconductor_gitlab.models.GitLabServiceProjectLink,
"resources": [
... | [
"Get",
"a",
"list",
"of",
"service",
"models",
".",
"{",
"...",
"gitlab",
":",
"{",
"service",
":",
"nodeconductor_gitlab",
".",
"models",
".",
"GitLabService",
"service_project_link",
":",
"nodeconductor_gitlab",
".",
"models",
".",
"GitLabServiceProjectLink",
"r... | d6c17a9592bb6c49c33567542eef8d099605a46a | https://github.com/opennode/waldur-core/blob/d6c17a9592bb6c49c33567542eef8d099605a46a/waldur_core/structure/__init__.py#L252-L281 | train |
opennode/waldur-core | waldur_core/structure/__init__.py | SupportedServices.get_resource_models | def get_resource_models(cls):
""" Get a list of resource models.
{
'DigitalOcean.Droplet': waldur_digitalocean.models.Droplet,
'JIRA.Project': waldur_jira.models.Project,
'OpenStack.Tenant': waldur_openstack.models.Tenant
}
"""
... | python | def get_resource_models(cls):
""" Get a list of resource models.
{
'DigitalOcean.Droplet': waldur_digitalocean.models.Droplet,
'JIRA.Project': waldur_jira.models.Project,
'OpenStack.Tenant': waldur_openstack.models.Tenant
}
"""
... | [
"def",
"get_resource_models",
"(",
"cls",
")",
":",
"from",
"django",
".",
"apps",
"import",
"apps",
"return",
"{",
"'.'",
".",
"join",
"(",
"[",
"service",
"[",
"'name'",
"]",
",",
"attrs",
"[",
"'name'",
"]",
"]",
")",
":",
"apps",
".",
"get_model"... | Get a list of resource models.
{
'DigitalOcean.Droplet': waldur_digitalocean.models.Droplet,
'JIRA.Project': waldur_jira.models.Project,
'OpenStack.Tenant': waldur_openstack.models.Tenant
} | [
"Get",
"a",
"list",
"of",
"resource",
"models",
".",
"{",
"DigitalOcean",
".",
"Droplet",
":",
"waldur_digitalocean",
".",
"models",
".",
"Droplet",
"JIRA",
".",
"Project",
":",
"waldur_jira",
".",
"models",
".",
"Project",
"OpenStack",
".",
"Tenant",
":",
... | d6c17a9592bb6c49c33567542eef8d099605a46a | https://github.com/opennode/waldur-core/blob/d6c17a9592bb6c49c33567542eef8d099605a46a/waldur_core/structure/__init__.py#L285-L298 | train |
opennode/waldur-core | waldur_core/structure/__init__.py | SupportedServices.get_service_resources | def get_service_resources(cls, model):
""" Get resource models by service model """
key = cls.get_model_key(model)
return cls.get_service_name_resources(key) | python | def get_service_resources(cls, model):
""" Get resource models by service model """
key = cls.get_model_key(model)
return cls.get_service_name_resources(key) | [
"def",
"get_service_resources",
"(",
"cls",
",",
"model",
")",
":",
"key",
"=",
"cls",
".",
"get_model_key",
"(",
"model",
")",
"return",
"cls",
".",
"get_service_name_resources",
"(",
"key",
")"
] | Get resource models by service model | [
"Get",
"resource",
"models",
"by",
"service",
"model"
] | d6c17a9592bb6c49c33567542eef8d099605a46a | https://github.com/opennode/waldur-core/blob/d6c17a9592bb6c49c33567542eef8d099605a46a/waldur_core/structure/__init__.py#L302-L305 | train |
opennode/waldur-core | waldur_core/structure/__init__.py | SupportedServices.get_service_name_resources | def get_service_name_resources(cls, service_name):
""" Get resource models by service name """
from django.apps import apps
resources = cls._registry[service_name]['resources'].keys()
return [apps.get_model(resource) for resource in resources] | python | def get_service_name_resources(cls, service_name):
""" Get resource models by service name """
from django.apps import apps
resources = cls._registry[service_name]['resources'].keys()
return [apps.get_model(resource) for resource in resources] | [
"def",
"get_service_name_resources",
"(",
"cls",
",",
"service_name",
")",
":",
"from",
"django",
".",
"apps",
"import",
"apps",
"resources",
"=",
"cls",
".",
"_registry",
"[",
"service_name",
"]",
"[",
"'resources'",
"]",
".",
"keys",
"(",
")",
"return",
... | Get resource models by service name | [
"Get",
"resource",
"models",
"by",
"service",
"name"
] | d6c17a9592bb6c49c33567542eef8d099605a46a | https://github.com/opennode/waldur-core/blob/d6c17a9592bb6c49c33567542eef8d099605a46a/waldur_core/structure/__init__.py#L309-L314 | train |
opennode/waldur-core | waldur_core/structure/__init__.py | SupportedServices.get_name_for_model | def get_name_for_model(cls, model):
""" Get a name for given class or model:
-- it's a service type for a service
-- it's a <service_type>.<resource_model_name> for a resource
"""
key = cls.get_model_key(model)
model_str = cls._get_model_str(model)
service... | python | def get_name_for_model(cls, model):
""" Get a name for given class or model:
-- it's a service type for a service
-- it's a <service_type>.<resource_model_name> for a resource
"""
key = cls.get_model_key(model)
model_str = cls._get_model_str(model)
service... | [
"def",
"get_name_for_model",
"(",
"cls",
",",
"model",
")",
":",
"key",
"=",
"cls",
".",
"get_model_key",
"(",
"model",
")",
"model_str",
"=",
"cls",
".",
"_get_model_str",
"(",
"model",
")",
"service",
"=",
"cls",
".",
"_registry",
"[",
"key",
"]",
"i... | Get a name for given class or model:
-- it's a service type for a service
-- it's a <service_type>.<resource_model_name> for a resource | [
"Get",
"a",
"name",
"for",
"given",
"class",
"or",
"model",
":",
"--",
"it",
"s",
"a",
"service",
"type",
"for",
"a",
"service",
"--",
"it",
"s",
"a",
"<service_type",
">",
".",
"<resource_model_name",
">",
"for",
"a",
"resource"
] | d6c17a9592bb6c49c33567542eef8d099605a46a | https://github.com/opennode/waldur-core/blob/d6c17a9592bb6c49c33567542eef8d099605a46a/waldur_core/structure/__init__.py#L317-L328 | train |
opennode/waldur-core | waldur_core/structure/__init__.py | SupportedServices.get_related_models | def get_related_models(cls, model):
""" Get a dictionary with related structure models for given class or model:
>> SupportedServices.get_related_models(gitlab_models.Project)
{
'service': nodeconductor_gitlab.models.GitLabService,
'service_project_link':... | python | def get_related_models(cls, model):
""" Get a dictionary with related structure models for given class or model:
>> SupportedServices.get_related_models(gitlab_models.Project)
{
'service': nodeconductor_gitlab.models.GitLabService,
'service_project_link':... | [
"def",
"get_related_models",
"(",
"cls",
",",
"model",
")",
":",
"from",
"waldur_core",
".",
"structure",
".",
"models",
"import",
"ServiceSettings",
"if",
"isinstance",
"(",
"model",
",",
"ServiceSettings",
")",
":",
"model_str",
"=",
"cls",
".",
"_registry",... | Get a dictionary with related structure models for given class or model:
>> SupportedServices.get_related_models(gitlab_models.Project)
{
'service': nodeconductor_gitlab.models.GitLabService,
'service_project_link': nodeconductor_gitlab.models.GitLabServiceProjec... | [
"Get",
"a",
"dictionary",
"with",
"related",
"structure",
"models",
"for",
"given",
"class",
"or",
"model",
":"
] | d6c17a9592bb6c49c33567542eef8d099605a46a | https://github.com/opennode/waldur-core/blob/d6c17a9592bb6c49c33567542eef8d099605a46a/waldur_core/structure/__init__.py#L331-L358 | train |
opennode/waldur-core | waldur_core/structure/__init__.py | SupportedServices._is_active_model | def _is_active_model(cls, model):
""" Check is model app name is in list of INSTALLED_APPS """
# We need to use such tricky way to check because of inconsistent apps names:
# some apps are included in format "<module_name>.<app_name>" like "waldur_core.openstack"
# other apps are include... | python | def _is_active_model(cls, model):
""" Check is model app name is in list of INSTALLED_APPS """
# We need to use such tricky way to check because of inconsistent apps names:
# some apps are included in format "<module_name>.<app_name>" like "waldur_core.openstack"
# other apps are include... | [
"def",
"_is_active_model",
"(",
"cls",
",",
"model",
")",
":",
"# We need to use such tricky way to check because of inconsistent apps names:",
"# some apps are included in format \"<module_name>.<app_name>\" like \"waldur_core.openstack\"",
"# other apps are included in format \"<app_name>\" li... | Check is model app name is in list of INSTALLED_APPS | [
"Check",
"is",
"model",
"app",
"name",
"is",
"in",
"list",
"of",
"INSTALLED_APPS"
] | d6c17a9592bb6c49c33567542eef8d099605a46a | https://github.com/opennode/waldur-core/blob/d6c17a9592bb6c49c33567542eef8d099605a46a/waldur_core/structure/__init__.py#L361-L367 | train |
opennode/waldur-core | waldur_core/logging/models.py | PushHook.process | def process(self, event):
""" Send events as push notification via Google Cloud Messaging.
Expected settings as follows:
# https://developers.google.com/mobile/add
WALDUR_CORE['GOOGLE_API'] = {
'NOTIFICATION_TITLE': "Waldur notification",
... | python | def process(self, event):
""" Send events as push notification via Google Cloud Messaging.
Expected settings as follows:
# https://developers.google.com/mobile/add
WALDUR_CORE['GOOGLE_API'] = {
'NOTIFICATION_TITLE': "Waldur notification",
... | [
"def",
"process",
"(",
"self",
",",
"event",
")",
":",
"conf",
"=",
"settings",
".",
"WALDUR_CORE",
".",
"get",
"(",
"'GOOGLE_API'",
")",
"or",
"{",
"}",
"keys",
"=",
"conf",
".",
"get",
"(",
"dict",
"(",
"self",
".",
"Type",
".",
"CHOICES",
")",
... | Send events as push notification via Google Cloud Messaging.
Expected settings as follows:
# https://developers.google.com/mobile/add
WALDUR_CORE['GOOGLE_API'] = {
'NOTIFICATION_TITLE': "Waldur notification",
'Android': {
... | [
"Send",
"events",
"as",
"push",
"notification",
"via",
"Google",
"Cloud",
"Messaging",
".",
"Expected",
"settings",
"as",
"follows",
":"
] | d6c17a9592bb6c49c33567542eef8d099605a46a | https://github.com/opennode/waldur-core/blob/d6c17a9592bb6c49c33567542eef8d099605a46a/waldur_core/logging/models.py#L200-L241 | train |
stepank/pyws | src/pyws/protocols/soap/__init__.py | get_context_data_from_headers | def get_context_data_from_headers(request, headers_schema):
"""
Extracts context data from request headers according to specified schema.
>>> from lxml import etree as et
>>> from datetime import date
>>> from pyws.functions.args import TypeFactory
>>> Fake = type('Fake', (object, ), {})
>>... | python | def get_context_data_from_headers(request, headers_schema):
"""
Extracts context data from request headers according to specified schema.
>>> from lxml import etree as et
>>> from datetime import date
>>> from pyws.functions.args import TypeFactory
>>> Fake = type('Fake', (object, ), {})
>>... | [
"def",
"get_context_data_from_headers",
"(",
"request",
",",
"headers_schema",
")",
":",
"if",
"not",
"headers_schema",
":",
"return",
"None",
"env",
"=",
"request",
".",
"parsed_data",
".",
"xml",
".",
"xpath",
"(",
"'/soap:Envelope'",
",",
"namespaces",
"=",
... | Extracts context data from request headers according to specified schema.
>>> from lxml import etree as et
>>> from datetime import date
>>> from pyws.functions.args import TypeFactory
>>> Fake = type('Fake', (object, ), {})
>>> request = Fake()
>>> request.parsed_data = Fake()
>>> request.... | [
"Extracts",
"context",
"data",
"from",
"request",
"headers",
"according",
"to",
"specified",
"schema",
"."
] | ff39133aabeb56bbb08d66286ac0cc8731eda7dd | https://github.com/stepank/pyws/blob/ff39133aabeb56bbb08d66286ac0cc8731eda7dd/src/pyws/protocols/soap/__init__.py#L94-L131 | train |
quora/qcore | qcore/caching.py | lazy_constant | def lazy_constant(fn):
"""Decorator to make a function that takes no arguments use the LazyConstant class."""
class NewLazyConstant(LazyConstant):
@functools.wraps(fn)
def __call__(self):
return self.get_value()
return NewLazyConstant(fn) | python | def lazy_constant(fn):
"""Decorator to make a function that takes no arguments use the LazyConstant class."""
class NewLazyConstant(LazyConstant):
@functools.wraps(fn)
def __call__(self):
return self.get_value()
return NewLazyConstant(fn) | [
"def",
"lazy_constant",
"(",
"fn",
")",
":",
"class",
"NewLazyConstant",
"(",
"LazyConstant",
")",
":",
"@",
"functools",
".",
"wraps",
"(",
"fn",
")",
"def",
"__call__",
"(",
"self",
")",
":",
"return",
"self",
".",
"get_value",
"(",
")",
"return",
"N... | Decorator to make a function that takes no arguments use the LazyConstant class. | [
"Decorator",
"to",
"make",
"a",
"function",
"that",
"takes",
"no",
"arguments",
"use",
"the",
"LazyConstant",
"class",
"."
] | fa5cd438eea554db35fd29cbc8dfbde69f09961c | https://github.com/quora/qcore/blob/fa5cd438eea554db35fd29cbc8dfbde69f09961c/qcore/caching.py#L84-L92 | train |
quora/qcore | qcore/caching.py | lru_cache | def lru_cache(maxsize=128, key_fn=None):
"""Decorator that adds an LRU cache of size maxsize to the decorated function.
maxsize is the number of different keys cache can accomodate.
key_fn is the function that builds key from args. The default key function
creates a tuple out of args and kwargs. If you... | python | def lru_cache(maxsize=128, key_fn=None):
"""Decorator that adds an LRU cache of size maxsize to the decorated function.
maxsize is the number of different keys cache can accomodate.
key_fn is the function that builds key from args. The default key function
creates a tuple out of args and kwargs. If you... | [
"def",
"lru_cache",
"(",
"maxsize",
"=",
"128",
",",
"key_fn",
"=",
"None",
")",
":",
"def",
"decorator",
"(",
"fn",
")",
":",
"cache",
"=",
"LRUCache",
"(",
"maxsize",
")",
"argspec",
"=",
"inspect2",
".",
"getfullargspec",
"(",
"fn",
")",
"arg_names"... | Decorator that adds an LRU cache of size maxsize to the decorated function.
maxsize is the number of different keys cache can accomodate.
key_fn is the function that builds key from args. The default key function
creates a tuple out of args and kwargs. If you use the default, there is no reason
not to ... | [
"Decorator",
"that",
"adds",
"an",
"LRU",
"cache",
"of",
"size",
"maxsize",
"to",
"the",
"decorated",
"function",
"."
] | fa5cd438eea554db35fd29cbc8dfbde69f09961c | https://github.com/quora/qcore/blob/fa5cd438eea554db35fd29cbc8dfbde69f09961c/qcore/caching.py#L238-L278 | train |
quora/qcore | qcore/caching.py | cached_per_instance | def cached_per_instance():
"""Decorator that adds caching to an instance method.
The cached value is stored so that it gets garbage collected together with the instance.
The cached values are not stored when the object is pickled.
"""
def cache_fun(fun):
argspec = inspect2.getfullargspec... | python | def cached_per_instance():
"""Decorator that adds caching to an instance method.
The cached value is stored so that it gets garbage collected together with the instance.
The cached values are not stored when the object is pickled.
"""
def cache_fun(fun):
argspec = inspect2.getfullargspec... | [
"def",
"cached_per_instance",
"(",
")",
":",
"def",
"cache_fun",
"(",
"fun",
")",
":",
"argspec",
"=",
"inspect2",
".",
"getfullargspec",
"(",
"fun",
")",
"arg_names",
"=",
"argspec",
".",
"args",
"[",
"1",
":",
"]",
"+",
"argspec",
".",
"kwonlyargs",
... | Decorator that adds caching to an instance method.
The cached value is stored so that it gets garbage collected together with the instance.
The cached values are not stored when the object is pickled. | [
"Decorator",
"that",
"adds",
"caching",
"to",
"an",
"instance",
"method",
"."
] | fa5cd438eea554db35fd29cbc8dfbde69f09961c | https://github.com/quora/qcore/blob/fa5cd438eea554db35fd29cbc8dfbde69f09961c/qcore/caching.py#L281-L319 | train |
quora/qcore | qcore/caching.py | get_args_tuple | def get_args_tuple(args, kwargs, arg_names, kwargs_defaults):
"""Generates a cache key from the passed in arguments."""
args_list = list(args)
args_len = len(args)
all_args_len = len(arg_names)
try:
while args_len < all_args_len:
arg_name = arg_names[args_len]
if arg_... | python | def get_args_tuple(args, kwargs, arg_names, kwargs_defaults):
"""Generates a cache key from the passed in arguments."""
args_list = list(args)
args_len = len(args)
all_args_len = len(arg_names)
try:
while args_len < all_args_len:
arg_name = arg_names[args_len]
if arg_... | [
"def",
"get_args_tuple",
"(",
"args",
",",
"kwargs",
",",
"arg_names",
",",
"kwargs_defaults",
")",
":",
"args_list",
"=",
"list",
"(",
"args",
")",
"args_len",
"=",
"len",
"(",
"args",
")",
"all_args_len",
"=",
"len",
"(",
"arg_names",
")",
"try",
":",
... | Generates a cache key from the passed in arguments. | [
"Generates",
"a",
"cache",
"key",
"from",
"the",
"passed",
"in",
"arguments",
"."
] | fa5cd438eea554db35fd29cbc8dfbde69f09961c | https://github.com/quora/qcore/blob/fa5cd438eea554db35fd29cbc8dfbde69f09961c/qcore/caching.py#L322-L337 | train |
quora/qcore | qcore/caching.py | get_kwargs_defaults | def get_kwargs_defaults(argspec):
"""Computes a kwargs_defaults dictionary for use by get_args_tuple given an argspec."""
arg_names = tuple(argspec.args)
defaults = argspec.defaults or ()
num_args = len(argspec.args) - len(defaults)
kwargs_defaults = {}
for i, default_value in enumerate(defaults... | python | def get_kwargs_defaults(argspec):
"""Computes a kwargs_defaults dictionary for use by get_args_tuple given an argspec."""
arg_names = tuple(argspec.args)
defaults = argspec.defaults or ()
num_args = len(argspec.args) - len(defaults)
kwargs_defaults = {}
for i, default_value in enumerate(defaults... | [
"def",
"get_kwargs_defaults",
"(",
"argspec",
")",
":",
"arg_names",
"=",
"tuple",
"(",
"argspec",
".",
"args",
")",
"defaults",
"=",
"argspec",
".",
"defaults",
"or",
"(",
")",
"num_args",
"=",
"len",
"(",
"argspec",
".",
"args",
")",
"-",
"len",
"(",... | Computes a kwargs_defaults dictionary for use by get_args_tuple given an argspec. | [
"Computes",
"a",
"kwargs_defaults",
"dictionary",
"for",
"use",
"by",
"get_args_tuple",
"given",
"an",
"argspec",
"."
] | fa5cd438eea554db35fd29cbc8dfbde69f09961c | https://github.com/quora/qcore/blob/fa5cd438eea554db35fd29cbc8dfbde69f09961c/qcore/caching.py#L340-L350 | train |
quora/qcore | qcore/caching.py | memoize | def memoize(fun):
"""Memoizes return values of the decorated function.
Similar to l0cache, but the cache persists for the duration of the process, unless clear_cache()
is called on the function.
"""
argspec = inspect2.getfullargspec(fun)
arg_names = argspec.args + argspec.kwonlyargs
kwargs... | python | def memoize(fun):
"""Memoizes return values of the decorated function.
Similar to l0cache, but the cache persists for the duration of the process, unless clear_cache()
is called on the function.
"""
argspec = inspect2.getfullargspec(fun)
arg_names = argspec.args + argspec.kwonlyargs
kwargs... | [
"def",
"memoize",
"(",
"fun",
")",
":",
"argspec",
"=",
"inspect2",
".",
"getfullargspec",
"(",
"fun",
")",
"arg_names",
"=",
"argspec",
".",
"args",
"+",
"argspec",
".",
"kwonlyargs",
"kwargs_defaults",
"=",
"get_kwargs_defaults",
"(",
"argspec",
")",
"def"... | Memoizes return values of the decorated function.
Similar to l0cache, but the cache persists for the duration of the process, unless clear_cache()
is called on the function. | [
"Memoizes",
"return",
"values",
"of",
"the",
"decorated",
"function",
"."
] | fa5cd438eea554db35fd29cbc8dfbde69f09961c | https://github.com/quora/qcore/blob/fa5cd438eea554db35fd29cbc8dfbde69f09961c/qcore/caching.py#L353-L380 | train |
quora/qcore | qcore/caching.py | memoize_with_ttl | def memoize_with_ttl(ttl_secs=60 * 60 * 24):
"""Memoizes return values of the decorated function for a given time-to-live.
Similar to l0cache, but the cache persists for the duration of the process, unless clear_cache()
is called on the function or the time-to-live expires. By default, the time-to-live is ... | python | def memoize_with_ttl(ttl_secs=60 * 60 * 24):
"""Memoizes return values of the decorated function for a given time-to-live.
Similar to l0cache, but the cache persists for the duration of the process, unless clear_cache()
is called on the function or the time-to-live expires. By default, the time-to-live is ... | [
"def",
"memoize_with_ttl",
"(",
"ttl_secs",
"=",
"60",
"*",
"60",
"*",
"24",
")",
":",
"error_msg",
"=",
"(",
"\"Incorrect usage of qcore.caching.memoize_with_ttl: \"",
"\"ttl_secs must be a positive integer.\"",
")",
"assert_is_instance",
"(",
"ttl_secs",
",",
"six",
"... | Memoizes return values of the decorated function for a given time-to-live.
Similar to l0cache, but the cache persists for the duration of the process, unless clear_cache()
is called on the function or the time-to-live expires. By default, the time-to-live is set to
24 hours. | [
"Memoizes",
"return",
"values",
"of",
"the",
"decorated",
"function",
"for",
"a",
"given",
"time",
"-",
"to",
"-",
"live",
"."
] | fa5cd438eea554db35fd29cbc8dfbde69f09961c | https://github.com/quora/qcore/blob/fa5cd438eea554db35fd29cbc8dfbde69f09961c/qcore/caching.py#L383-L445 | train |
quora/qcore | qcore/caching.py | LazyConstant.get_value | def get_value(self):
"""Returns the value of the constant."""
if self.value is not_computed:
self.value = self.value_provider()
if self.value is not_computed:
return None
return self.value | python | def get_value(self):
"""Returns the value of the constant."""
if self.value is not_computed:
self.value = self.value_provider()
if self.value is not_computed:
return None
return self.value | [
"def",
"get_value",
"(",
"self",
")",
":",
"if",
"self",
".",
"value",
"is",
"not_computed",
":",
"self",
".",
"value",
"=",
"self",
".",
"value_provider",
"(",
")",
"if",
"self",
".",
"value",
"is",
"not_computed",
":",
"return",
"None",
"return",
"se... | Returns the value of the constant. | [
"Returns",
"the",
"value",
"of",
"the",
"constant",
"."
] | fa5cd438eea554db35fd29cbc8dfbde69f09961c | https://github.com/quora/qcore/blob/fa5cd438eea554db35fd29cbc8dfbde69f09961c/qcore/caching.py#L64-L70 | train |
quora/qcore | qcore/caching.py | LazyConstant.compute | def compute(self):
"""Computes the value. Does not look at the cache."""
self.value = self.value_provider()
if self.value is not_computed:
return None
else:
return self.value | python | def compute(self):
"""Computes the value. Does not look at the cache."""
self.value = self.value_provider()
if self.value is not_computed:
return None
else:
return self.value | [
"def",
"compute",
"(",
"self",
")",
":",
"self",
".",
"value",
"=",
"self",
".",
"value_provider",
"(",
")",
"if",
"self",
".",
"value",
"is",
"not_computed",
":",
"return",
"None",
"else",
":",
"return",
"self",
".",
"value"
] | Computes the value. Does not look at the cache. | [
"Computes",
"the",
"value",
".",
"Does",
"not",
"look",
"at",
"the",
"cache",
"."
] | fa5cd438eea554db35fd29cbc8dfbde69f09961c | https://github.com/quora/qcore/blob/fa5cd438eea554db35fd29cbc8dfbde69f09961c/qcore/caching.py#L72-L78 | train |
quora/qcore | qcore/caching.py | LRUCache.get | def get(self, key, default=miss):
"""Return the value for given key if it exists."""
if key not in self._dict:
return default
# invokes __getitem__, which updates the item
return self[key] | python | def get(self, key, default=miss):
"""Return the value for given key if it exists."""
if key not in self._dict:
return default
# invokes __getitem__, which updates the item
return self[key] | [
"def",
"get",
"(",
"self",
",",
"key",
",",
"default",
"=",
"miss",
")",
":",
"if",
"key",
"not",
"in",
"self",
".",
"_dict",
":",
"return",
"default",
"# invokes __getitem__, which updates the item",
"return",
"self",
"[",
"key",
"]"
] | Return the value for given key if it exists. | [
"Return",
"the",
"value",
"for",
"given",
"key",
"if",
"it",
"exists",
"."
] | fa5cd438eea554db35fd29cbc8dfbde69f09961c | https://github.com/quora/qcore/blob/fa5cd438eea554db35fd29cbc8dfbde69f09961c/qcore/caching.py#L187-L193 | train |
quora/qcore | qcore/caching.py | LRUCache.clear | def clear(self, omit_item_evicted=False):
"""Empty the cache and optionally invoke item_evicted callback."""
if not omit_item_evicted:
items = self._dict.items()
for key, value in items:
self._evict_item(key, value)
self._dict.clear() | python | def clear(self, omit_item_evicted=False):
"""Empty the cache and optionally invoke item_evicted callback."""
if not omit_item_evicted:
items = self._dict.items()
for key, value in items:
self._evict_item(key, value)
self._dict.clear() | [
"def",
"clear",
"(",
"self",
",",
"omit_item_evicted",
"=",
"False",
")",
":",
"if",
"not",
"omit_item_evicted",
":",
"items",
"=",
"self",
".",
"_dict",
".",
"items",
"(",
")",
"for",
"key",
",",
"value",
"in",
"items",
":",
"self",
".",
"_evict_item"... | Empty the cache and optionally invoke item_evicted callback. | [
"Empty",
"the",
"cache",
"and",
"optionally",
"invoke",
"item_evicted",
"callback",
"."
] | fa5cd438eea554db35fd29cbc8dfbde69f09961c | https://github.com/quora/qcore/blob/fa5cd438eea554db35fd29cbc8dfbde69f09961c/qcore/caching.py#L209-L215 | train |
zeromake/aiosqlite3 | aiosqlite3/utils.py | create_future | def create_future(loop):
# pragma: no cover
"""Compatibility wrapper for the loop.create_future() call introduced in
3.5.2."""
if hasattr(loop, 'create_future'):
return loop.create_future()
return asyncio.Future(loop=loop) | python | def create_future(loop):
# pragma: no cover
"""Compatibility wrapper for the loop.create_future() call introduced in
3.5.2."""
if hasattr(loop, 'create_future'):
return loop.create_future()
return asyncio.Future(loop=loop) | [
"def",
"create_future",
"(",
"loop",
")",
":",
"# pragma: no cover",
"if",
"hasattr",
"(",
"loop",
",",
"'create_future'",
")",
":",
"return",
"loop",
".",
"create_future",
"(",
")",
"return",
"asyncio",
".",
"Future",
"(",
"loop",
"=",
"loop",
")"
] | Compatibility wrapper for the loop.create_future() call introduced in
3.5.2. | [
"Compatibility",
"wrapper",
"for",
"the",
"loop",
".",
"create_future",
"()",
"call",
"introduced",
"in",
"3",
".",
"5",
".",
"2",
"."
] | 1a74a062507e2df8f833a70885e69dca0ab3e7e7 | https://github.com/zeromake/aiosqlite3/blob/1a74a062507e2df8f833a70885e69dca0ab3e7e7/aiosqlite3/utils.py#L17-L23 | train |
zeromake/aiosqlite3 | aiosqlite3/utils.py | create_task | def create_task(coro, loop):
# pragma: no cover
"""Compatibility wrapper for the loop.create_task() call introduced in
3.4.2."""
if hasattr(loop, 'create_task'):
return loop.create_task(coro)
return asyncio.Task(coro, loop=loop) | python | def create_task(coro, loop):
# pragma: no cover
"""Compatibility wrapper for the loop.create_task() call introduced in
3.4.2."""
if hasattr(loop, 'create_task'):
return loop.create_task(coro)
return asyncio.Task(coro, loop=loop) | [
"def",
"create_task",
"(",
"coro",
",",
"loop",
")",
":",
"# pragma: no cover",
"if",
"hasattr",
"(",
"loop",
",",
"'create_task'",
")",
":",
"return",
"loop",
".",
"create_task",
"(",
"coro",
")",
"return",
"asyncio",
".",
"Task",
"(",
"coro",
",",
"loo... | Compatibility wrapper for the loop.create_task() call introduced in
3.4.2. | [
"Compatibility",
"wrapper",
"for",
"the",
"loop",
".",
"create_task",
"()",
"call",
"introduced",
"in",
"3",
".",
"4",
".",
"2",
"."
] | 1a74a062507e2df8f833a70885e69dca0ab3e7e7 | https://github.com/zeromake/aiosqlite3/blob/1a74a062507e2df8f833a70885e69dca0ab3e7e7/aiosqlite3/utils.py#L26-L32 | train |
zeromake/aiosqlite3 | aiosqlite3/utils.py | proxy_property_directly | def proxy_property_directly(bind_attr, attrs):
"""
为类添加代理属性
"""
def cls_builder(cls):
"""
添加到类
"""
for attr_name in attrs:
setattr(cls, attr_name, _make_proxy_property(bind_attr, attr_name))
return cls
return cls_builder | python | def proxy_property_directly(bind_attr, attrs):
"""
为类添加代理属性
"""
def cls_builder(cls):
"""
添加到类
"""
for attr_name in attrs:
setattr(cls, attr_name, _make_proxy_property(bind_attr, attr_name))
return cls
return cls_builder | [
"def",
"proxy_property_directly",
"(",
"bind_attr",
",",
"attrs",
")",
":",
"def",
"cls_builder",
"(",
"cls",
")",
":",
"\"\"\"\n 添加到类\n \"\"\"",
"for",
"attr_name",
"in",
"attrs",
":",
"setattr",
"(",
"cls",
",",
"attr_name",
",",
"_make_proxy_prope... | 为类添加代理属性 | [
"为类添加代理属性"
] | 1a74a062507e2df8f833a70885e69dca0ab3e7e7 | https://github.com/zeromake/aiosqlite3/blob/1a74a062507e2df8f833a70885e69dca0ab3e7e7/aiosqlite3/utils.py#L265-L276 | train |
opennode/waldur-core | waldur_core/structure/models.py | StructureLoggableMixin.get_permitted_objects_uuids | def get_permitted_objects_uuids(cls, user):
"""
Return query dictionary to search objects available to user.
"""
uuids = filter_queryset_for_user(cls.objects.all(), user).values_list('uuid', flat=True)
key = core_utils.camel_case_to_underscore(cls.__name__) + '_uuid'
retu... | python | def get_permitted_objects_uuids(cls, user):
"""
Return query dictionary to search objects available to user.
"""
uuids = filter_queryset_for_user(cls.objects.all(), user).values_list('uuid', flat=True)
key = core_utils.camel_case_to_underscore(cls.__name__) + '_uuid'
retu... | [
"def",
"get_permitted_objects_uuids",
"(",
"cls",
",",
"user",
")",
":",
"uuids",
"=",
"filter_queryset_for_user",
"(",
"cls",
".",
"objects",
".",
"all",
"(",
")",
",",
"user",
")",
".",
"values_list",
"(",
"'uuid'",
",",
"flat",
"=",
"True",
")",
"key"... | Return query dictionary to search objects available to user. | [
"Return",
"query",
"dictionary",
"to",
"search",
"objects",
"available",
"to",
"user",
"."
] | d6c17a9592bb6c49c33567542eef8d099605a46a | https://github.com/opennode/waldur-core/blob/d6c17a9592bb6c49c33567542eef8d099605a46a/waldur_core/structure/models.py#L79-L85 | train |
opennode/waldur-core | waldur_core/structure/models.py | PermissionMixin.has_user | def has_user(self, user, role=None, timestamp=False):
"""
Checks whether user has role in entity.
`timestamp` can have following values:
- False - check whether user has role in entity at the moment.
- None - check whether user has permanent role in entity.
- ... | python | def has_user(self, user, role=None, timestamp=False):
"""
Checks whether user has role in entity.
`timestamp` can have following values:
- False - check whether user has role in entity at the moment.
- None - check whether user has permanent role in entity.
- ... | [
"def",
"has_user",
"(",
"self",
",",
"user",
",",
"role",
"=",
"None",
",",
"timestamp",
"=",
"False",
")",
":",
"permissions",
"=",
"self",
".",
"permissions",
".",
"filter",
"(",
"user",
"=",
"user",
",",
"is_active",
"=",
"True",
")",
"if",
"role"... | Checks whether user has role in entity.
`timestamp` can have following values:
- False - check whether user has role in entity at the moment.
- None - check whether user has permanent role in entity.
- Datetime object - check whether user will have role in entity at specific ... | [
"Checks",
"whether",
"user",
"has",
"role",
"in",
"entity",
".",
"timestamp",
"can",
"have",
"following",
"values",
":",
"-",
"False",
"-",
"check",
"whether",
"user",
"has",
"role",
"in",
"entity",
"at",
"the",
"moment",
".",
"-",
"None",
"-",
"check",
... | d6c17a9592bb6c49c33567542eef8d099605a46a | https://github.com/opennode/waldur-core/blob/d6c17a9592bb6c49c33567542eef8d099605a46a/waldur_core/structure/models.py#L191-L209 | train |
opennode/waldur-core | waldur_core/core/magic.py | Magic.from_buffer | def from_buffer(self, buf):
"""
Identify the contents of `buf`
"""
with self.lock:
try:
# if we're on python3, convert buf to bytes
# otherwise this string is passed as wchar*
# which is not what libmagic expects
... | python | def from_buffer(self, buf):
"""
Identify the contents of `buf`
"""
with self.lock:
try:
# if we're on python3, convert buf to bytes
# otherwise this string is passed as wchar*
# which is not what libmagic expects
... | [
"def",
"from_buffer",
"(",
"self",
",",
"buf",
")",
":",
"with",
"self",
".",
"lock",
":",
"try",
":",
"# if we're on python3, convert buf to bytes",
"# otherwise this string is passed as wchar*",
"# which is not what libmagic expects",
"if",
"isinstance",
"(",
"buf",
","... | Identify the contents of `buf` | [
"Identify",
"the",
"contents",
"of",
"buf"
] | d6c17a9592bb6c49c33567542eef8d099605a46a | https://github.com/opennode/waldur-core/blob/d6c17a9592bb6c49c33567542eef8d099605a46a/waldur_core/core/magic.py#L71-L84 | train |
nuagenetworks/bambou | bambou/nurest_push_center.py | NURESTPushCenter.start | def start(self, timeout=None, root_object=None):
""" Starts listening to events.
Args:
timeout (int): number of seconds before timeout. Used for testing purpose only.
root_object (bambou.NURESTRootObject): NURESTRootObject object that is listening. Used for testing p... | python | def start(self, timeout=None, root_object=None):
""" Starts listening to events.
Args:
timeout (int): number of seconds before timeout. Used for testing purpose only.
root_object (bambou.NURESTRootObject): NURESTRootObject object that is listening. Used for testing p... | [
"def",
"start",
"(",
"self",
",",
"timeout",
"=",
"None",
",",
"root_object",
"=",
"None",
")",
":",
"if",
"self",
".",
"_is_running",
":",
"return",
"if",
"timeout",
":",
"self",
".",
"_timeout",
"=",
"timeout",
"self",
".",
"_start_time",
"=",
"int",... | Starts listening to events.
Args:
timeout (int): number of seconds before timeout. Used for testing purpose only.
root_object (bambou.NURESTRootObject): NURESTRootObject object that is listening. Used for testing purpose only. | [
"Starts",
"listening",
"to",
"events",
"."
] | d334fea23e384d3df8e552fe1849ad707941c666 | https://github.com/nuagenetworks/bambou/blob/d334fea23e384d3df8e552fe1849ad707941c666/bambou/nurest_push_center.py#L103-L128 | train |
nuagenetworks/bambou | bambou/nurest_push_center.py | NURESTPushCenter.stop | def stop(self):
""" Stops listening for events. """
if not self._is_running:
return
pushcenter_logger.debug("[NURESTPushCenter] Stopping...")
self._thread.stop()
self._thread.join()
self._is_running = False
self._current_connection = None
s... | python | def stop(self):
""" Stops listening for events. """
if not self._is_running:
return
pushcenter_logger.debug("[NURESTPushCenter] Stopping...")
self._thread.stop()
self._thread.join()
self._is_running = False
self._current_connection = None
s... | [
"def",
"stop",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"_is_running",
":",
"return",
"pushcenter_logger",
".",
"debug",
"(",
"\"[NURESTPushCenter] Stopping...\"",
")",
"self",
".",
"_thread",
".",
"stop",
"(",
")",
"self",
".",
"_thread",
".",
"jo... | Stops listening for events. | [
"Stops",
"listening",
"for",
"events",
"."
] | d334fea23e384d3df8e552fe1849ad707941c666 | https://github.com/nuagenetworks/bambou/blob/d334fea23e384d3df8e552fe1849ad707941c666/bambou/nurest_push_center.py#L130-L144 | train |
nuagenetworks/bambou | bambou/nurest_push_center.py | NURESTPushCenter.wait_until_exit | def wait_until_exit(self):
""" Wait until thread exit
Used for testing purpose only
"""
if self._timeout is None:
raise Exception("Thread will never exit. Use stop or specify timeout when starting it!")
self._thread.join()
self.stop() | python | def wait_until_exit(self):
""" Wait until thread exit
Used for testing purpose only
"""
if self._timeout is None:
raise Exception("Thread will never exit. Use stop or specify timeout when starting it!")
self._thread.join()
self.stop() | [
"def",
"wait_until_exit",
"(",
"self",
")",
":",
"if",
"self",
".",
"_timeout",
"is",
"None",
":",
"raise",
"Exception",
"(",
"\"Thread will never exit. Use stop or specify timeout when starting it!\"",
")",
"self",
".",
"_thread",
".",
"join",
"(",
")",
"self",
"... | Wait until thread exit
Used for testing purpose only | [
"Wait",
"until",
"thread",
"exit"
] | d334fea23e384d3df8e552fe1849ad707941c666 | https://github.com/nuagenetworks/bambou/blob/d334fea23e384d3df8e552fe1849ad707941c666/bambou/nurest_push_center.py#L146-L156 | train |
nuagenetworks/bambou | bambou/nurest_push_center.py | NURESTPushCenter._did_receive_event | def _did_receive_event(self, connection):
""" Receive an event from connection """
if not self._is_running:
return
if connection.has_timeouted:
return
response = connection.response
data = None
if response.status_code != 200:
pushce... | python | def _did_receive_event(self, connection):
""" Receive an event from connection """
if not self._is_running:
return
if connection.has_timeouted:
return
response = connection.response
data = None
if response.status_code != 200:
pushce... | [
"def",
"_did_receive_event",
"(",
"self",
",",
"connection",
")",
":",
"if",
"not",
"self",
".",
"_is_running",
":",
"return",
"if",
"connection",
".",
"has_timeouted",
":",
"return",
"response",
"=",
"connection",
".",
"response",
"data",
"=",
"None",
"if",... | Receive an event from connection | [
"Receive",
"an",
"event",
"from",
"connection"
] | d334fea23e384d3df8e552fe1849ad707941c666 | https://github.com/nuagenetworks/bambou/blob/d334fea23e384d3df8e552fe1849ad707941c666/bambou/nurest_push_center.py#L173-L210 | train |
nuagenetworks/bambou | bambou/nurest_push_center.py | NURESTPushCenter._listen | def _listen(self, uuid=None, session=None):
""" Listen a connection uuid """
if self.url is None:
raise Exception("NURESTPushCenter needs to have a valid URL. please use setURL: before starting it.")
events_url = "%s/events" % self.url
if uuid:
events_url = "%s?... | python | def _listen(self, uuid=None, session=None):
""" Listen a connection uuid """
if self.url is None:
raise Exception("NURESTPushCenter needs to have a valid URL. please use setURL: before starting it.")
events_url = "%s/events" % self.url
if uuid:
events_url = "%s?... | [
"def",
"_listen",
"(",
"self",
",",
"uuid",
"=",
"None",
",",
"session",
"=",
"None",
")",
":",
"if",
"self",
".",
"url",
"is",
"None",
":",
"raise",
"Exception",
"(",
"\"NURESTPushCenter needs to have a valid URL. please use setURL: before starting it.\"",
")",
"... | Listen a connection uuid | [
"Listen",
"a",
"connection",
"uuid"
] | d334fea23e384d3df8e552fe1849ad707941c666 | https://github.com/nuagenetworks/bambou/blob/d334fea23e384d3df8e552fe1849ad707941c666/bambou/nurest_push_center.py#L212-L238 | train |
nuagenetworks/bambou | bambou/nurest_push_center.py | NURESTPushCenter.add_delegate | def add_delegate(self, callback):
""" Registers a new delegate callback
The prototype should be function(data), where data will be the decoded json push
Args:
callback (function): method to trigger when push center receives events
"""
if callback in sel... | python | def add_delegate(self, callback):
""" Registers a new delegate callback
The prototype should be function(data), where data will be the decoded json push
Args:
callback (function): method to trigger when push center receives events
"""
if callback in sel... | [
"def",
"add_delegate",
"(",
"self",
",",
"callback",
")",
":",
"if",
"callback",
"in",
"self",
".",
"_delegate_methods",
":",
"return",
"self",
".",
"_delegate_methods",
".",
"append",
"(",
"callback",
")"
] | Registers a new delegate callback
The prototype should be function(data), where data will be the decoded json push
Args:
callback (function): method to trigger when push center receives events | [
"Registers",
"a",
"new",
"delegate",
"callback"
] | d334fea23e384d3df8e552fe1849ad707941c666 | https://github.com/nuagenetworks/bambou/blob/d334fea23e384d3df8e552fe1849ad707941c666/bambou/nurest_push_center.py#L240-L252 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.