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/permissions.py
permission_to_04_acls
def permission_to_04_acls(permissions): """ Legacy acl format kept for bw. compatibility :param permissions: :return: """ acls = [] for perm in permissions: if perm.type == "user": acls.append((perm.user.id, perm.perm_name)) elif perm.type == "group": ...
python
def permission_to_04_acls(permissions): """ Legacy acl format kept for bw. compatibility :param permissions: :return: """ acls = [] for perm in permissions: if perm.type == "user": acls.append((perm.user.id, perm.perm_name)) elif perm.type == "group": ...
[ "def", "permission_to_04_acls", "(", "permissions", ")", ":", "acls", "=", "[", "]", "for", "perm", "in", "permissions", ":", "if", "perm", ".", "type", "==", "\"user\"", ":", "acls", ".", "append", "(", "(", "perm", ".", "user", ".", "id", ",", "per...
Legacy acl format kept for bw. compatibility :param permissions: :return:
[ "Legacy", "acl", "format", "kept", "for", "bw", ".", "compatibility", ":", "param", "permissions", ":", ":", "return", ":" ]
9eeec894d08e8d7defa60ddc04b63f69cd4cbeba
https://github.com/ergo/ziggurat_foundations/blob/9eeec894d08e8d7defa60ddc04b63f69cd4cbeba/ziggurat_foundations/permissions.py#L189-L201
train
ergo/ziggurat_foundations
ziggurat_foundations/permissions.py
permission_to_pyramid_acls
def permission_to_pyramid_acls(permissions): """ Returns a list of permissions in a format understood by pyramid :param permissions: :return: """ acls = [] for perm in permissions: if perm.type == "user": acls.append((Allow, perm.user.id, perm.perm_name)) elif per...
python
def permission_to_pyramid_acls(permissions): """ Returns a list of permissions in a format understood by pyramid :param permissions: :return: """ acls = [] for perm in permissions: if perm.type == "user": acls.append((Allow, perm.user.id, perm.perm_name)) elif per...
[ "def", "permission_to_pyramid_acls", "(", "permissions", ")", ":", "acls", "=", "[", "]", "for", "perm", "in", "permissions", ":", "if", "perm", ".", "type", "==", "\"user\"", ":", "acls", ".", "append", "(", "(", "Allow", ",", "perm", ".", "user", "."...
Returns a list of permissions in a format understood by pyramid :param permissions: :return:
[ "Returns", "a", "list", "of", "permissions", "in", "a", "format", "understood", "by", "pyramid", ":", "param", "permissions", ":", ":", "return", ":" ]
9eeec894d08e8d7defa60ddc04b63f69cd4cbeba
https://github.com/ergo/ziggurat_foundations/blob/9eeec894d08e8d7defa60ddc04b63f69cd4cbeba/ziggurat_foundations/permissions.py#L204-L216
train
Xython/Linq.py
linq/standard/general.py
ChunkBy
def ChunkBy(self, 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) if is_to_destruct(f): f = destruct_func(f) r...
python
def ChunkBy(self, 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) if is_to_destruct(f): f = destruct_func(f) r...
[ "def", "ChunkBy", "(", "self", ",", "f", "=", "None", ")", ":", "if", "f", "is", "None", ":", "return", "_chunk", "(", "self", ")", "if", "is_to_destruct", "(", "f", ")", ":", "f", "=", "destruct_func", "(", "f", ")", "return", "_chunk", "(", "se...
[ { '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/general.py#L88-L102
train
Xython/Linq.py
linq/standard/general.py
GroupBy
def GroupBy(self: Iterable, 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, f)
python
def GroupBy(self: Iterable, 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, f)
[ "def", "GroupBy", "(", "self", ":", "Iterable", ",", "f", "=", "None", ")", ":", "if", "f", "and", "is_to_destruct", "(", "f", ")", ":", "f", "=", "destruct_func", "(", "f", ")", "return", "_group_by", "(", "self", ",", "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/general.py#L111-L123
train
Xython/Linq.py
linq/standard/general.py
Take
def Take(self: Iterable, n): """ [ { 'self': [1, 2, 3], 'n': 2, 'assert': lambda ret: list(ret) == [1, 2] } ] """ for i, e in enumerate(self): if i == n: break yield e
python
def Take(self: Iterable, n): """ [ { 'self': [1, 2, 3], 'n': 2, 'assert': lambda ret: list(ret) == [1, 2] } ] """ for i, e in enumerate(self): if i == n: break yield e
[ "def", "Take", "(", "self", ":", "Iterable", ",", "n", ")", ":", "for", "i", ",", "e", "in", "enumerate", "(", "self", ")", ":", "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/general.py#L127-L141
train
Xython/Linq.py
linq/standard/general.py
TakeIf
def TakeIf(self: Iterable, 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 if f(e))
python
def TakeIf(self: Iterable, 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 if f(e))
[ "def", "TakeIf", "(", "self", ":", "Iterable", ",", "f", ")", ":", "if", "is_to_destruct", "(", "f", ")", ":", "f", "=", "destruct_func", "(", "f", ")", "return", "(", "e", "for", "e", "in", "self", "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/general.py#L145-L158
train
Xython/Linq.py
linq/standard/general.py
TakeWhile
def TakeWhile(self: Iterable, 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: if not f(e): ...
python
def TakeWhile(self: Iterable, 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: if not f(e): ...
[ "def", "TakeWhile", "(", "self", ":", "Iterable", ",", "f", ")", ":", "if", "is_to_destruct", "(", "f", ")", ":", "f", "=", "destruct_func", "(", "f", ")", "for", "e", "in", "self", ":", "if", "not", "f", "(", "e", ")", ":", "break", "yield", "...
[ { '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/general.py#L162-L178
train
Xython/Linq.py
linq/standard/general.py
Drop
def Drop(self: Iterable, n): """ [ { 'self': [1, 2, 3, 4, 5], 'n': 3, 'assert': lambda ret: list(ret) == [1, 2] } ] """ con = tuple(self) n = len(con) - n if n <= 0: yield from con else: for i, e in enumerate(con): ...
python
def Drop(self: Iterable, n): """ [ { 'self': [1, 2, 3, 4, 5], 'n': 3, 'assert': lambda ret: list(ret) == [1, 2] } ] """ con = tuple(self) n = len(con) - n if n <= 0: yield from con else: for i, e in enumerate(con): ...
[ "def", "Drop", "(", "self", ":", "Iterable", ",", "n", ")", ":", "con", "=", "tuple", "(", "self", ")", "n", "=", "len", "(", "con", ")", "-", "n", "if", "n", "<=", "0", ":", "yield", "from", "con", "else", ":", "for", "i", ",", "e", "in", ...
[ { '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/general.py#L187-L205
train
Xython/Linq.py
linq/standard/general.py
Skip
def Skip(self: Iterable, n): """ [ { 'self': [1, 2, 3, 4, 5], 'n': 3, 'assert': lambda ret: list(ret) == [4, 5] } ] """ con = iter(self) for i, _ in enumerate(con): if i == n: break retur...
python
def Skip(self: Iterable, n): """ [ { 'self': [1, 2, 3, 4, 5], 'n': 3, 'assert': lambda ret: list(ret) == [4, 5] } ] """ con = iter(self) for i, _ in enumerate(con): if i == n: break retur...
[ "def", "Skip", "(", "self", ":", "Iterable", ",", "n", ")", ":", "con", "=", "iter", "(", "self", ")", "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/general.py#L209-L223
train
Xython/Linq.py
linq/standard/general.py
Shift
def Shift(self, n): """ [ { 'self': [1, 2, 3, 4, 5], 'n': 3, 'assert': lambda ret: list(ret) == [4, 5, 1, 2, 3] } ] """ headn = tuple(Take(self, n)) yield from self yield from headn
python
def Shift(self, n): """ [ { 'self': [1, 2, 3, 4, 5], 'n': 3, 'assert': lambda ret: list(ret) == [4, 5, 1, 2, 3] } ] """ headn = tuple(Take(self, n)) yield from self yield from headn
[ "def", "Shift", "(", "self", ",", "n", ")", ":", "headn", "=", "tuple", "(", "Take", "(", "self", ",", "n", ")", ")", "yield", "from", "self", "yield", "from", "headn" ]
[ { 'self': [1, 2, 3, 4, 5], 'n': 3, 'assert': lambda ret: list(ret) == [4, 5, 1, 2, 3] } ]
[ "[", "{", "self", ":", "[", "1", "2", "3", "4", "5", "]", "n", ":", "3", "assert", ":", "lambda", "ret", ":", "list", "(", "ret", ")", "==", "[", "4", "5", "1", "2", "3", "]", "}", "]" ]
ffb65f92f1df0d8161d5f835f5947554f6f33d72
https://github.com/Xython/Linq.py/blob/ffb65f92f1df0d8161d5f835f5947554f6f33d72/linq/standard/general.py#L227-L239
train
Xython/Linq.py
linq/standard/general.py
Concat
def Concat(self: Iterable, *others): """ [ { 'self': [1, 2, 3], ':args': [[4, 5, 6], [7, 8, 9]], 'assert': lambda ret: list(ret) == [1, 2, 3, 4, 5, 6, 7, 8, 9] } ] """ return concat_generator(self, *[unbox_if_flow(other) for other in others])
python
def Concat(self: Iterable, *others): """ [ { 'self': [1, 2, 3], ':args': [[4, 5, 6], [7, 8, 9]], 'assert': lambda ret: list(ret) == [1, 2, 3, 4, 5, 6, 7, 8, 9] } ] """ return concat_generator(self, *[unbox_if_flow(other) for other in others])
[ "def", "Concat", "(", "self", ":", "Iterable", ",", "*", "others", ")", ":", "return", "concat_generator", "(", "self", ",", "*", "[", "unbox_if_flow", "(", "other", ")", "for", "other", "in", "others", "]", ")" ]
[ { 'self': [1, 2, 3], ':args': [[4, 5, 6], [7, 8, 9]], 'assert': lambda ret: list(ret) == [1, 2, 3, 4, 5, 6, 7, 8, 9] } ]
[ "[", "{", "self", ":", "[", "1", "2", "3", "]", ":", "args", ":", "[[", "4", "5", "6", "]", "[", "7", "8", "9", "]]", "assert", ":", "lambda", "ret", ":", "list", "(", "ret", ")", "==", "[", "1", "2", "3", "4", "5", "6", "7", "8", "9"...
ffb65f92f1df0d8161d5f835f5947554f6f33d72
https://github.com/Xython/Linq.py/blob/ffb65f92f1df0d8161d5f835f5947554f6f33d72/linq/standard/general.py#L243-L253
train
jucacrispim/pylint-mongoengine
pylint_mongoengine/checkers/mongoengine.py
MongoEngineChecker._called_thru_default_qs
def _called_thru_default_qs(self, node): """Checks if an attribute is being accessed throught the default queryset manager, ie: MyClass.objects.filter(some='value')""" last_child = node.last_child() if not last_child: return False # the default qs manager is called '...
python
def _called_thru_default_qs(self, node): """Checks if an attribute is being accessed throught the default queryset manager, ie: MyClass.objects.filter(some='value')""" last_child = node.last_child() if not last_child: return False # the default qs manager is called '...
[ "def", "_called_thru_default_qs", "(", "self", ",", "node", ")", ":", "last_child", "=", "node", ".", "last_child", "(", ")", "if", "not", "last_child", ":", "return", "False", "# the default qs manager is called 'objects', we check for it here", "attrname", "=", "get...
Checks if an attribute is being accessed throught the default queryset manager, ie: MyClass.objects.filter(some='value')
[ "Checks", "if", "an", "attribute", "is", "being", "accessed", "throught", "the", "default", "queryset", "manager", "ie", ":", "MyClass", ".", "objects", ".", "filter", "(", "some", "=", "value", ")" ]
b873653d1224a5748f75dd507f492f8c60d95ce3
https://github.com/jucacrispim/pylint-mongoengine/blob/b873653d1224a5748f75dd507f492f8c60d95ce3/pylint_mongoengine/checkers/mongoengine.py#L46-L64
train
ergo/ziggurat_foundations
ziggurat_foundations/models/services/__init__.py
BaseService.all
def all(cls, klass, db_session=None): """ returns all objects of specific type - will work correctly with sqlalchemy inheritance models, you should normally use models base_query() instead of this function its for bw. compat purposes :param klass: :param db_session: ...
python
def all(cls, klass, db_session=None): """ returns all objects of specific type - will work correctly with sqlalchemy inheritance models, you should normally use models base_query() instead of this function its for bw. compat purposes :param klass: :param db_session: ...
[ "def", "all", "(", "cls", ",", "klass", ",", "db_session", "=", "None", ")", ":", "db_session", "=", "get_db_session", "(", "db_session", ")", "return", "db_session", ".", "query", "(", "klass", ")" ]
returns all objects of specific type - will work correctly with sqlalchemy inheritance models, you should normally use models base_query() instead of this function its for bw. compat purposes :param klass: :param db_session: :return:
[ "returns", "all", "objects", "of", "specific", "type", "-", "will", "work", "correctly", "with", "sqlalchemy", "inheritance", "models", "you", "should", "normally", "use", "models", "base_query", "()", "instead", "of", "this", "function", "its", "for", "bw", "...
9eeec894d08e8d7defa60ddc04b63f69cd4cbeba
https://github.com/ergo/ziggurat_foundations/blob/9eeec894d08e8d7defa60ddc04b63f69cd4cbeba/ziggurat_foundations/models/services/__init__.py#L12-L23
train
ergo/ziggurat_foundations
ziggurat_foundations/models/services/__init__.py
BaseService.base_query
def base_query(cls, db_session=None): """ returns base query for specific service :param db_session: :return: query """ db_session = get_db_session(db_session) return db_session.query(cls.model)
python
def base_query(cls, db_session=None): """ returns base query for specific service :param db_session: :return: query """ db_session = get_db_session(db_session) return db_session.query(cls.model)
[ "def", "base_query", "(", "cls", ",", "db_session", "=", "None", ")", ":", "db_session", "=", "get_db_session", "(", "db_session", ")", "return", "db_session", ".", "query", "(", "cls", ".", "model", ")" ]
returns base query for specific service :param db_session: :return: query
[ "returns", "base", "query", "for", "specific", "service" ]
9eeec894d08e8d7defa60ddc04b63f69cd4cbeba
https://github.com/ergo/ziggurat_foundations/blob/9eeec894d08e8d7defa60ddc04b63f69cd4cbeba/ziggurat_foundations/models/services/__init__.py#L26-L34
train
stephenmcd/gnotty
gnotty/bots/events.py
on
def on(event, *args, **kwargs): """ Event method wrapper for bot mixins. When a bot is constructed, its metaclass inspects all members of all base classes, and looks for methods marked with an event attribute which is assigned via this wrapper. It then stores all the methods in a dict that maps ...
python
def on(event, *args, **kwargs): """ Event method wrapper for bot mixins. When a bot is constructed, its metaclass inspects all members of all base classes, and looks for methods marked with an event attribute which is assigned via this wrapper. It then stores all the methods in a dict that maps ...
[ "def", "on", "(", "event", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "def", "wrapper", "(", "func", ")", ":", "for", "i", ",", "arg", "in", "args", ":", "kwargs", "[", "i", "]", "=", "arg", "func", ".", "event", "=", "Event", "(", ...
Event method wrapper for bot mixins. When a bot is constructed, its metaclass inspects all members of all base classes, and looks for methods marked with an event attribute which is assigned via this wrapper. It then stores all the methods in a dict that maps event names to lists of these methods, which...
[ "Event", "method", "wrapper", "for", "bot", "mixins", ".", "When", "a", "bot", "is", "constructed", "its", "metaclass", "inspects", "all", "members", "of", "all", "base", "classes", "and", "looks", "for", "methods", "marked", "with", "an", "event", "attribut...
bea3762dc9cbc3cb21a5ae7224091cf027273c40
https://github.com/stephenmcd/gnotty/blob/bea3762dc9cbc3cb21a5ae7224091cf027273c40/gnotty/bots/events.py#L8-L22
train
ergo/ziggurat_foundations
ziggurat_foundations/models/base.py
get_db_session
def get_db_session(session=None, obj=None): """ utility function that attempts to return sqlalchemy session that could have been created/passed in one of few ways: * It first tries to read session attached to instance if object argument was passed * then it tries to return session passed as...
python
def get_db_session(session=None, obj=None): """ utility function that attempts to return sqlalchemy session that could have been created/passed in one of few ways: * It first tries to read session attached to instance if object argument was passed * then it tries to return session passed as...
[ "def", "get_db_session", "(", "session", "=", "None", ",", "obj", "=", "None", ")", ":", "# try to read the session from instance", "from", "ziggurat_foundations", "import", "models", "if", "obj", ":", "return", "sa", ".", "orm", ".", "session", ".", "object_ses...
utility function that attempts to return sqlalchemy session that could have been created/passed in one of few ways: * It first tries to read session attached to instance if object argument was passed * then it tries to return session passed as argument * finally tries to read pylons-like threa...
[ "utility", "function", "that", "attempts", "to", "return", "sqlalchemy", "session", "that", "could", "have", "been", "created", "/", "passed", "in", "one", "of", "few", "ways", ":" ]
9eeec894d08e8d7defa60ddc04b63f69cd4cbeba
https://github.com/ergo/ziggurat_foundations/blob/9eeec894d08e8d7defa60ddc04b63f69cd4cbeba/ziggurat_foundations/models/base.py#L162-L191
train
ergo/ziggurat_foundations
ziggurat_foundations/models/base.py
BaseModel.get_dict
def get_dict(self, exclude_keys=None, include_keys=None): """ return dictionary of keys and values corresponding to this model's data - if include_keys is null the function will return all keys :param exclude_keys: (optional) is a list of columns from model that should not be re...
python
def get_dict(self, exclude_keys=None, include_keys=None): """ return dictionary of keys and values corresponding to this model's data - if include_keys is null the function will return all keys :param exclude_keys: (optional) is a list of columns from model that should not be re...
[ "def", "get_dict", "(", "self", ",", "exclude_keys", "=", "None", ",", "include_keys", "=", "None", ")", ":", "d", "=", "{", "}", "exclude_keys_list", "=", "exclude_keys", "or", "[", "]", "include_keys_list", "=", "include_keys", "or", "[", "]", "for", "...
return dictionary of keys and values corresponding to this model's data - if include_keys is null the function will return all keys :param exclude_keys: (optional) is a list of columns from model that should not be returned by this function :param include_keys: (optional) is a list of c...
[ "return", "dictionary", "of", "keys", "and", "values", "corresponding", "to", "this", "model", "s", "data", "-", "if", "include_keys", "is", "null", "the", "function", "will", "return", "all", "keys" ]
9eeec894d08e8d7defa60ddc04b63f69cd4cbeba
https://github.com/ergo/ziggurat_foundations/blob/9eeec894d08e8d7defa60ddc04b63f69cd4cbeba/ziggurat_foundations/models/base.py#L24-L43
train
ergo/ziggurat_foundations
ziggurat_foundations/models/base.py
BaseModel.get_appstruct
def get_appstruct(self): """ return list of tuples keys and values corresponding to this model's data """ result = [] for k in self._get_keys(): result.append((k, getattr(self, k))) return result
python
def get_appstruct(self): """ return list of tuples keys and values corresponding to this model's data """ result = [] for k in self._get_keys(): result.append((k, getattr(self, k))) return result
[ "def", "get_appstruct", "(", "self", ")", ":", "result", "=", "[", "]", "for", "k", "in", "self", ".", "_get_keys", "(", ")", ":", "result", ".", "append", "(", "(", "k", ",", "getattr", "(", "self", ",", "k", ")", ")", ")", "return", "result" ]
return list of tuples keys and values corresponding to this model's data
[ "return", "list", "of", "tuples", "keys", "and", "values", "corresponding", "to", "this", "model", "s", "data" ]
9eeec894d08e8d7defa60ddc04b63f69cd4cbeba
https://github.com/ergo/ziggurat_foundations/blob/9eeec894d08e8d7defa60ddc04b63f69cd4cbeba/ziggurat_foundations/models/base.py#L45-L51
train
ergo/ziggurat_foundations
ziggurat_foundations/models/base.py
BaseModel.populate_obj
def populate_obj(self, appstruct, exclude_keys=None, include_keys=None): """ updates instance properties *for column names that exist* for this model and are keys present in passed dictionary :param appstruct: (dictionary) :param exclude_keys: (optional) is a list of columns fro...
python
def populate_obj(self, appstruct, exclude_keys=None, include_keys=None): """ updates instance properties *for column names that exist* for this model and are keys present in passed dictionary :param appstruct: (dictionary) :param exclude_keys: (optional) is a list of columns fro...
[ "def", "populate_obj", "(", "self", ",", "appstruct", ",", "exclude_keys", "=", "None", ",", "include_keys", "=", "None", ")", ":", "exclude_keys_list", "=", "exclude_keys", "or", "[", "]", "include_keys_list", "=", "include_keys", "or", "[", "]", "for", "k"...
updates instance properties *for column names that exist* for this model and are keys present in passed dictionary :param appstruct: (dictionary) :param exclude_keys: (optional) is a list of columns from model that should not be updated by this function :param include_keys: (opt...
[ "updates", "instance", "properties", "*", "for", "column", "names", "that", "exist", "*", "for", "this", "model", "and", "are", "keys", "present", "in", "passed", "dictionary" ]
9eeec894d08e8d7defa60ddc04b63f69cd4cbeba
https://github.com/ergo/ziggurat_foundations/blob/9eeec894d08e8d7defa60ddc04b63f69cd4cbeba/ziggurat_foundations/models/base.py#L53-L73
train
ergo/ziggurat_foundations
ziggurat_foundations/models/base.py
BaseModel.populate_obj_from_obj
def populate_obj_from_obj(self, instance, exclude_keys=None, include_keys=None): """ updates instance properties *for column names that exist* for this model and are properties present in passed dictionary :param instance: :param exclude_keys: (optional) is a list of columns fro...
python
def populate_obj_from_obj(self, instance, exclude_keys=None, include_keys=None): """ updates instance properties *for column names that exist* for this model and are properties present in passed dictionary :param instance: :param exclude_keys: (optional) is a list of columns fro...
[ "def", "populate_obj_from_obj", "(", "self", ",", "instance", ",", "exclude_keys", "=", "None", ",", "include_keys", "=", "None", ")", ":", "exclude_keys_list", "=", "exclude_keys", "or", "[", "]", "include_keys_list", "=", "include_keys", "or", "[", "]", "for...
updates instance properties *for column names that exist* for this model and are properties present in passed dictionary :param instance: :param exclude_keys: (optional) is a list of columns from model that should not be updated by this function :param include_keys: (optional) i...
[ "updates", "instance", "properties", "*", "for", "column", "names", "that", "exist", "*", "for", "this", "model", "and", "are", "properties", "present", "in", "passed", "dictionary" ]
9eeec894d08e8d7defa60ddc04b63f69cd4cbeba
https://github.com/ergo/ziggurat_foundations/blob/9eeec894d08e8d7defa60ddc04b63f69cd4cbeba/ziggurat_foundations/models/base.py#L75-L95
train
ergo/ziggurat_foundations
ziggurat_foundations/models/base.py
BaseModel.delete
def delete(self, db_session=None): """ Deletes the object via session, this will permanently delete the object from storage on commit :param db_session: :return: """ db_session = get_db_session(db_session, self) db_session.delete(self)
python
def delete(self, db_session=None): """ Deletes the object via session, this will permanently delete the object from storage on commit :param db_session: :return: """ db_session = get_db_session(db_session, self) db_session.delete(self)
[ "def", "delete", "(", "self", ",", "db_session", "=", "None", ")", ":", "db_session", "=", "get_db_session", "(", "db_session", ",", "self", ")", "db_session", ".", "delete", "(", "self", ")" ]
Deletes the object via session, this will permanently delete the object from storage on commit :param db_session: :return:
[ "Deletes", "the", "object", "via", "session", "this", "will", "permanently", "delete", "the", "object", "from", "storage", "on", "commit" ]
9eeec894d08e8d7defa60ddc04b63f69cd4cbeba
https://github.com/ergo/ziggurat_foundations/blob/9eeec894d08e8d7defa60ddc04b63f69cd4cbeba/ziggurat_foundations/models/base.py#L123-L132
train
mpibpc-mroose/hx711
hx711/__init__.py
HX711.power_down
def power_down(self): """ turn off the HX711 :return: always True :rtype bool """ GPIO.output(self._pd_sck, False) GPIO.output(self._pd_sck, True) time.sleep(0.01) return True
python
def power_down(self): """ turn off the HX711 :return: always True :rtype bool """ GPIO.output(self._pd_sck, False) GPIO.output(self._pd_sck, True) time.sleep(0.01) return True
[ "def", "power_down", "(", "self", ")", ":", "GPIO", ".", "output", "(", "self", ".", "_pd_sck", ",", "False", ")", "GPIO", ".", "output", "(", "self", ".", "_pd_sck", ",", "True", ")", "time", ".", "sleep", "(", "0.01", ")", "return", "True" ]
turn off the HX711 :return: always True :rtype bool
[ "turn", "off", "the", "HX711", ":", "return", ":", "always", "True", ":", "rtype", "bool" ]
2f3a39880cdd2d2fa8ba79a7f9245d1a35d89f1d
https://github.com/mpibpc-mroose/hx711/blob/2f3a39880cdd2d2fa8ba79a7f9245d1a35d89f1d/hx711/__init__.py#L91-L100
train
mpibpc-mroose/hx711
hx711/__init__.py
HX711.power_up
def power_up(self): """ power up the HX711 :return: always True :rtype bool """ GPIO.output(self._pd_sck, False) time.sleep(0.01) return True
python
def power_up(self): """ power up the HX711 :return: always True :rtype bool """ GPIO.output(self._pd_sck, False) time.sleep(0.01) return True
[ "def", "power_up", "(", "self", ")", ":", "GPIO", ".", "output", "(", "self", ".", "_pd_sck", ",", "False", ")", "time", ".", "sleep", "(", "0.01", ")", "return", "True" ]
power up the HX711 :return: always True :rtype bool
[ "power", "up", "the", "HX711" ]
2f3a39880cdd2d2fa8ba79a7f9245d1a35d89f1d
https://github.com/mpibpc-mroose/hx711/blob/2f3a39880cdd2d2fa8ba79a7f9245d1a35d89f1d/hx711/__init__.py#L102-L111
train
mpibpc-mroose/hx711
hx711/__init__.py
HX711.reset
def reset(self): """ reset the HX711 and prepare it for the next reading :return: True on success :rtype bool :raises GenericHX711Exception """ logging.debug("power down") self.power_down() logging.debug("power up") self.power_up() ...
python
def reset(self): """ reset the HX711 and prepare it for the next reading :return: True on success :rtype bool :raises GenericHX711Exception """ logging.debug("power down") self.power_down() logging.debug("power up") self.power_up() ...
[ "def", "reset", "(", "self", ")", ":", "logging", ".", "debug", "(", "\"power down\"", ")", "self", ".", "power_down", "(", ")", "logging", ".", "debug", "(", "\"power up\"", ")", "self", ".", "power_up", "(", ")", "logging", ".", "debug", "(", "\"read...
reset the HX711 and prepare it for the next reading :return: True on success :rtype bool :raises GenericHX711Exception
[ "reset", "the", "HX711", "and", "prepare", "it", "for", "the", "next", "reading" ]
2f3a39880cdd2d2fa8ba79a7f9245d1a35d89f1d
https://github.com/mpibpc-mroose/hx711/blob/2f3a39880cdd2d2fa8ba79a7f9245d1a35d89f1d/hx711/__init__.py#L113-L130
train
mpibpc-mroose/hx711
hx711/__init__.py
HX711._validate_measure_count
def _validate_measure_count(self, times): """ check if "times" is within the borders defined in the class :param times: "times" to check :type times: int """ if not self.min_measures <= times <= self.max_measures: raise ParameterValidationError( ...
python
def _validate_measure_count(self, times): """ check if "times" is within the borders defined in the class :param times: "times" to check :type times: int """ if not self.min_measures <= times <= self.max_measures: raise ParameterValidationError( ...
[ "def", "_validate_measure_count", "(", "self", ",", "times", ")", ":", "if", "not", "self", ".", "min_measures", "<=", "times", "<=", "self", ".", "max_measures", ":", "raise", "ParameterValidationError", "(", "\"{times} is not within the borders defined in the class\""...
check if "times" is within the borders defined in the class :param times: "times" to check :type times: int
[ "check", "if", "times", "is", "within", "the", "borders", "defined", "in", "the", "class" ]
2f3a39880cdd2d2fa8ba79a7f9245d1a35d89f1d
https://github.com/mpibpc-mroose/hx711/blob/2f3a39880cdd2d2fa8ba79a7f9245d1a35d89f1d/hx711/__init__.py#L132-L144
train
mpibpc-mroose/hx711
hx711/__init__.py
HX711._validate_gain_A_value
def _validate_gain_A_value(self, gain_A): """ validate a given value for gain_A :type gain_A: int :raises: ValueError """ if gain_A not in self._valid_gains_for_channel_A: raise ParameterValidationError("{gain_A} is not a valid gain".format(gain_A=gain_A))
python
def _validate_gain_A_value(self, gain_A): """ validate a given value for gain_A :type gain_A: int :raises: ValueError """ if gain_A not in self._valid_gains_for_channel_A: raise ParameterValidationError("{gain_A} is not a valid gain".format(gain_A=gain_A))
[ "def", "_validate_gain_A_value", "(", "self", ",", "gain_A", ")", ":", "if", "gain_A", "not", "in", "self", ".", "_valid_gains_for_channel_A", ":", "raise", "ParameterValidationError", "(", "\"{gain_A} is not a valid gain\"", ".", "format", "(", "gain_A", "=", "gain...
validate a given value for gain_A :type gain_A: int :raises: ValueError
[ "validate", "a", "given", "value", "for", "gain_A" ]
2f3a39880cdd2d2fa8ba79a7f9245d1a35d89f1d
https://github.com/mpibpc-mroose/hx711/blob/2f3a39880cdd2d2fa8ba79a7f9245d1a35d89f1d/hx711/__init__.py#L155-L163
train
mpibpc-mroose/hx711
hx711/__init__.py
HX711._ready
def _ready(self): """ check if ther is som data is ready to get read. :return True if there is some date :rtype bool """ # if DOUT pin is low, data is ready for reading _is_ready = GPIO.input(self._dout) == 0 logging.debug("check data ready for reading: {r...
python
def _ready(self): """ check if ther is som data is ready to get read. :return True if there is some date :rtype bool """ # if DOUT pin is low, data is ready for reading _is_ready = GPIO.input(self._dout) == 0 logging.debug("check data ready for reading: {r...
[ "def", "_ready", "(", "self", ")", ":", "# if DOUT pin is low, data is ready for reading", "_is_ready", "=", "GPIO", ".", "input", "(", "self", ".", "_dout", ")", "==", "0", "logging", ".", "debug", "(", "\"check data ready for reading: {result}\"", ".", "format", ...
check if ther is som data is ready to get read. :return True if there is some date :rtype bool
[ "check", "if", "ther", "is", "som", "data", "is", "ready", "to", "get", "read", ".", ":", "return", "True", "if", "there", "is", "some", "date", ":", "rtype", "bool" ]
2f3a39880cdd2d2fa8ba79a7f9245d1a35d89f1d
https://github.com/mpibpc-mroose/hx711/blob/2f3a39880cdd2d2fa8ba79a7f9245d1a35d89f1d/hx711/__init__.py#L179-L190
train
mpibpc-mroose/hx711
hx711/__init__.py
HX711._set_channel_gain
def _set_channel_gain(self, num): """ Finish data transmission from HX711 by setting next required gain and channel Only called from the _read function. :param num: how often so do the set (1...3) :type num: int :return True on success :rtype bool ...
python
def _set_channel_gain(self, num): """ Finish data transmission from HX711 by setting next required gain and channel Only called from the _read function. :param num: how often so do the set (1...3) :type num: int :return True on success :rtype bool ...
[ "def", "_set_channel_gain", "(", "self", ",", "num", ")", ":", "if", "not", "1", "<=", "num", "<=", "3", ":", "raise", "AttributeError", "(", "\"\"\"\"num\" has to be in the range of 1 to 3\"\"\"", ")", "for", "_", "in", "range", "(", "num", ")", ":", "loggi...
Finish data transmission from HX711 by setting next required gain and channel Only called from the _read function. :param num: how often so do the set (1...3) :type num: int :return True on success :rtype bool
[ "Finish", "data", "transmission", "from", "HX711", "by", "setting", "next", "required", "gain", "and", "channel" ]
2f3a39880cdd2d2fa8ba79a7f9245d1a35d89f1d
https://github.com/mpibpc-mroose/hx711/blob/2f3a39880cdd2d2fa8ba79a7f9245d1a35d89f1d/hx711/__init__.py#L192-L227
train
mpibpc-mroose/hx711
hx711/__init__.py
HX711._read
def _read(self, max_tries=40): """ - read the bit stream from HX711 and convert to an int value. - validates the acquired data :param max_tries: how often to try to get data :type max_tries: int :return raw data :rtype: int """ # start by setting t...
python
def _read(self, max_tries=40): """ - read the bit stream from HX711 and convert to an int value. - validates the acquired data :param max_tries: how often to try to get data :type max_tries: int :return raw data :rtype: int """ # start by setting t...
[ "def", "_read", "(", "self", ",", "max_tries", "=", "40", ")", ":", "# start by setting the pd_sck to false", "GPIO", ".", "output", "(", "self", ".", "_pd_sck", ",", "False", ")", "# init the counter", "ready_counter", "=", "0", "# loop until HX711 is ready", "# ...
- read the bit stream from HX711 and convert to an int value. - validates the acquired data :param max_tries: how often to try to get data :type max_tries: int :return raw data :rtype: int
[ "-", "read", "the", "bit", "stream", "from", "HX711", "and", "convert", "to", "an", "int", "value", ".", "-", "validates", "the", "acquired", "data", ":", "param", "max_tries", ":", "how", "often", "to", "try", "to", "get", "data", ":", "type", "max_tr...
2f3a39880cdd2d2fa8ba79a7f9245d1a35d89f1d
https://github.com/mpibpc-mroose/hx711/blob/2f3a39880cdd2d2fa8ba79a7f9245d1a35d89f1d/hx711/__init__.py#L229-L301
train
mpibpc-mroose/hx711
hx711/__init__.py
HX711.get_raw_data
def get_raw_data(self, times=5): """ do some readings and aggregate them using the defined statistics function :param times: how many measures to aggregate :type times: int :return: the aggregate of the measured values :rtype float """ self._validate_mea...
python
def get_raw_data(self, times=5): """ do some readings and aggregate them using the defined statistics function :param times: how many measures to aggregate :type times: int :return: the aggregate of the measured values :rtype float """ self._validate_mea...
[ "def", "get_raw_data", "(", "self", ",", "times", "=", "5", ")", ":", "self", ".", "_validate_measure_count", "(", "times", ")", "data_list", "=", "[", "]", "while", "len", "(", "data_list", ")", "<", "times", ":", "data", "=", "self", ".", "_read", ...
do some readings and aggregate them using the defined statistics function :param times: how many measures to aggregate :type times: int :return: the aggregate of the measured values :rtype float
[ "do", "some", "readings", "and", "aggregate", "them", "using", "the", "defined", "statistics", "function" ]
2f3a39880cdd2d2fa8ba79a7f9245d1a35d89f1d
https://github.com/mpibpc-mroose/hx711/blob/2f3a39880cdd2d2fa8ba79a7f9245d1a35d89f1d/hx711/__init__.py#L303-L321
train
ergo/ziggurat_foundations
ziggurat_foundations/models/services/resource_tree.py
ResourceTreeService.from_resource_deeper
def from_resource_deeper( self, 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_de...
python
def from_resource_deeper( self, 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_de...
[ "def", "from_resource_deeper", "(", "self", ",", "resource_id", "=", "None", ",", "limit_depth", "=", "1000000", ",", "db_session", "=", "None", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "return", "self", ".", "service", ".", "from_resource_deep...
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.py#L16-L34
train
ergo/ziggurat_foundations
ziggurat_foundations/models/services/resource_tree.py
ResourceTreeService.delete_branch
def delete_branch(self, 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: """ return self.service.delete_branch( resource_id=resou...
python
def delete_branch(self, 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: """ return self.service.delete_branch( resource_id=resou...
[ "def", "delete_branch", "(", "self", ",", "resource_id", "=", "None", ",", "db_session", "=", "None", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "return", "self", ".", "service", ".", "delete_branch", "(", "resource_id", "=", "resource_id", ","...
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.py#L36-L46
train
ergo/ziggurat_foundations
ziggurat_foundations/models/services/resource_tree.py
ResourceTreeService.from_parent_deeper
def from_parent_deeper( self, 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( self, 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", "(", "self", ",", "parent_id", "=", "None", ",", "limit_depth", "=", "1000000", ",", "db_session", "=", "None", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "return", "self", ".", "service", ".", "from_parent_deeper", ...
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.py#L48-L66
train
ergo/ziggurat_foundations
ziggurat_foundations/models/services/resource_tree.py
ResourceTreeService.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: """ return self.service.build_subtree_strut(result=result, *args, **kwargs)
python
def build_subtree_strut(self, result, *args, **kwargs): """ Returns a dictionary in form of {node:Resource, children:{node_id: Resource}} :param result: :return: """ return self.service.build_subtree_strut(result=result, *args, **kwargs)
[ "def", "build_subtree_strut", "(", "self", ",", "result", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "return", "self", ".", "service", ".", "build_subtree_strut", "(", "result", "=", "result", ",", "*", "args", ",", "*", "*", "kwargs", ")" ]
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.py#L68-L76
train
ergo/ziggurat_foundations
ziggurat_foundations/models/services/resource_tree.py
ResourceTreeService.path_upper
def path_upper( self, 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( self, 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", "(", "self", ",", "object_id", ",", "limit_depth", "=", "1000000", ",", "db_session", "=", "None", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "return", "self", ".", "service", ".", "path_upper", "(", "object_id", "=", "ob...
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.py#L78-L96
train
ergo/ziggurat_foundations
ziggurat_foundations/models/services/resource_tree.py
ResourceTreeService.move_to_position
def move_to_position( self, 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( self, 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", "(", "self", ",", "resource_id", ",", "to_position", ",", "new_parent_id", "=", "noop", ",", "db_session", "=", "None", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "return", "self", ".", "service", ".", "move_to_position...
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.py#L98-L123
train
ergo/ziggurat_foundations
ziggurat_foundations/models/services/resource_tree.py
ResourceTreeService.shift_ordering_down
def shift_ordering_down( self, parent_id, position, db_session=None, *args, **kwargs ): """ Shifts ordering to "close gaps" after node deletion or being moved to another branch, begins the shift from given position :param parent_id: :param position: :param db...
python
def shift_ordering_down( self, parent_id, position, db_session=None, *args, **kwargs ): """ Shifts ordering to "close gaps" after node deletion or being moved to another branch, begins the shift from given position :param parent_id: :param position: :param db...
[ "def", "shift_ordering_down", "(", "self", ",", "parent_id", ",", "position", ",", "db_session", "=", "None", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "return", "self", ".", "service", ".", "shift_ordering_down", "(", "parent_id", "=", "parent_...
Shifts ordering to "close gaps" after node deletion or being moved to another branch, begins the shift from given position :param parent_id: :param position: :param db_session: :return:
[ "Shifts", "ordering", "to", "close", "gaps", "after", "node", "deletion", "or", "being", "moved", "to", "another", "branch", "begins", "the", "shift", "from", "given", "position" ]
9eeec894d08e8d7defa60ddc04b63f69cd4cbeba
https://github.com/ergo/ziggurat_foundations/blob/9eeec894d08e8d7defa60ddc04b63f69cd4cbeba/ziggurat_foundations/models/services/resource_tree.py#L125-L143
train
ergo/ziggurat_foundations
ziggurat_foundations/models/services/resource_tree.py
ResourceTreeService.shift_ordering_up
def shift_ordering_up(self, 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: """ ret...
python
def shift_ordering_up(self, 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: """ ret...
[ "def", "shift_ordering_up", "(", "self", ",", "parent_id", ",", "position", ",", "db_session", "=", "None", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "return", "self", ".", "service", ".", "shift_ordering_up", "(", "parent_id", "=", "parent_id",...
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.py#L145-L161
train
ergo/ziggurat_foundations
ziggurat_foundations/models/services/resource_tree.py
ResourceTreeService.set_position
def set_position(self, 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_se...
python
def set_position(self, 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_se...
[ "def", "set_position", "(", "self", ",", "resource_id", ",", "to_position", ",", "db_session", "=", "None", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "return", "self", ".", "service", ".", "set_position", "(", "resource_id", "=", "resource_id", ...
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.py#L163-L178
train
ergo/ziggurat_foundations
ziggurat_foundations/models/services/resource_tree.py
ResourceTreeService.check_node_parent
def check_node_parent( self, 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: """ return self.service.check...
python
def check_node_parent( self, 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: """ return self.service.check...
[ "def", "check_node_parent", "(", "self", ",", "resource_id", ",", "new_parent_id", ",", "db_session", "=", "None", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "return", "self", ".", "service", ".", "check_node_parent", "(", "resource_id", "=", "re...
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.py#L180-L197
train
ergo/ziggurat_foundations
ziggurat_foundations/models/services/resource_tree.py
ResourceTreeService.count_children
def count_children(self, resource_id, db_session=None, *args, **kwargs): """ Counts children of resource node :param resource_id: :param db_session: :return: """ return self.service.count_children( resource_id=resource_id, db_session=db_session, *args...
python
def count_children(self, resource_id, db_session=None, *args, **kwargs): """ Counts children of resource node :param resource_id: :param db_session: :return: """ return self.service.count_children( resource_id=resource_id, db_session=db_session, *args...
[ "def", "count_children", "(", "self", ",", "resource_id", ",", "db_session", "=", "None", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "return", "self", ".", "service", ".", "count_children", "(", "resource_id", "=", "resource_id", ",", "db_session...
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.py#L199-L209
train
ergo/ziggurat_foundations
ziggurat_foundations/models/services/resource_tree.py
ResourceTreeService.check_node_position
def check_node_position( self, 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: i...
python
def check_node_position( self, 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: i...
[ "def", "check_node_position", "(", "self", ",", "parent_id", ",", "position", ",", "on_same_branch", ",", "db_session", "=", "None", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "return", "self", ".", "service", ".", "check_node_position", "(", "pa...
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.py#L211-L231
train
aguinane/nem-reader
nemreader/nem_reader.py
flatten_list
def flatten_list(l: List[list]) -> list: """ takes a list of lists, l and returns a flat list """ return [v for inner_l in l for v in inner_l]
python
def flatten_list(l: List[list]) -> list: """ takes a list of lists, l and returns a flat list """ return [v for inner_l in l for v in inner_l]
[ "def", "flatten_list", "(", "l", ":", "List", "[", "list", "]", ")", "->", "list", ":", "return", "[", "v", "for", "inner_l", "in", "l", "for", "v", "in", "inner_l", "]" ]
takes a list of lists, l and returns a flat list
[ "takes", "a", "list", "of", "lists", "l", "and", "returns", "a", "flat", "list" ]
5405a5cba4bb8ebdad05c28455d12bb34a6d3ce5
https://github.com/aguinane/nem-reader/blob/5405a5cba4bb8ebdad05c28455d12bb34a6d3ce5/nemreader/nem_reader.py#L17-L20
train
aguinane/nem-reader
nemreader/nem_reader.py
read_nem_file
def read_nem_file(file_path: str) -> NEMFile: """ Read in NEM file and return meter readings named tuple :param file_path: The NEM file to process :returns: The file that was created """ _, file_extension = os.path.splitext(file_path) if file_extension.lower() == '.zip': with zipfile.Z...
python
def read_nem_file(file_path: str) -> NEMFile: """ Read in NEM file and return meter readings named tuple :param file_path: The NEM file to process :returns: The file that was created """ _, file_extension = os.path.splitext(file_path) if file_extension.lower() == '.zip': with zipfile.Z...
[ "def", "read_nem_file", "(", "file_path", ":", "str", ")", "->", "NEMFile", ":", "_", ",", "file_extension", "=", "os", ".", "path", ".", "splitext", "(", "file_path", ")", "if", "file_extension", ".", "lower", "(", ")", "==", "'.zip'", ":", "with", "z...
Read in NEM file and return meter readings named tuple :param file_path: The NEM file to process :returns: The file that was created
[ "Read", "in", "NEM", "file", "and", "return", "meter", "readings", "named", "tuple" ]
5405a5cba4bb8ebdad05c28455d12bb34a6d3ce5
https://github.com/aguinane/nem-reader/blob/5405a5cba4bb8ebdad05c28455d12bb34a6d3ce5/nemreader/nem_reader.py#L23-L42
train
aguinane/nem-reader
nemreader/nem_reader.py
parse_nem_file
def parse_nem_file(nem_file) -> NEMFile: """ Parse NEM file and return meter readings named tuple """ reader = csv.reader(nem_file, delimiter=',') return parse_nem_rows(reader, file_name=nem_file)
python
def parse_nem_file(nem_file) -> NEMFile: """ Parse NEM file and return meter readings named tuple """ reader = csv.reader(nem_file, delimiter=',') return parse_nem_rows(reader, file_name=nem_file)
[ "def", "parse_nem_file", "(", "nem_file", ")", "->", "NEMFile", ":", "reader", "=", "csv", ".", "reader", "(", "nem_file", ",", "delimiter", "=", "','", ")", "return", "parse_nem_rows", "(", "reader", ",", "file_name", "=", "nem_file", ")" ]
Parse NEM file and return meter readings named tuple
[ "Parse", "NEM", "file", "and", "return", "meter", "readings", "named", "tuple" ]
5405a5cba4bb8ebdad05c28455d12bb34a6d3ce5
https://github.com/aguinane/nem-reader/blob/5405a5cba4bb8ebdad05c28455d12bb34a6d3ce5/nemreader/nem_reader.py#L45-L48
train
aguinane/nem-reader
nemreader/nem_reader.py
parse_nem_rows
def parse_nem_rows(nem_list: Iterable, file_name=None) -> NEMFile: """ Parse NEM row iterator and return meter readings named tuple """ header = HeaderRecord(None, None, None, None, file_name) readings = dict() # readings nested by NMI then channel trans = dict() # transactions nested by NMI then cha...
python
def parse_nem_rows(nem_list: Iterable, file_name=None) -> NEMFile: """ Parse NEM row iterator and return meter readings named tuple """ header = HeaderRecord(None, None, None, None, file_name) readings = dict() # readings nested by NMI then channel trans = dict() # transactions nested by NMI then cha...
[ "def", "parse_nem_rows", "(", "nem_list", ":", "Iterable", ",", "file_name", "=", "None", ")", "->", "NEMFile", ":", "header", "=", "HeaderRecord", "(", "None", ",", "None", ",", "None", ",", "None", ",", "file_name", ")", "readings", "=", "dict", "(", ...
Parse NEM row iterator and return meter readings named tuple
[ "Parse", "NEM", "row", "iterator", "and", "return", "meter", "readings", "named", "tuple" ]
5405a5cba4bb8ebdad05c28455d12bb34a6d3ce5
https://github.com/aguinane/nem-reader/blob/5405a5cba4bb8ebdad05c28455d12bb34a6d3ce5/nemreader/nem_reader.py#L51-L140
train
aguinane/nem-reader
nemreader/nem_reader.py
calculate_manual_reading
def calculate_manual_reading(basic_data: BasicMeterData) -> Reading: """ Calculate the interval between two manual readings """ t_start = basic_data.previous_register_read_datetime t_end = basic_data.current_register_read_datetime read_start = basic_data.previous_register_read read_end = basic_data....
python
def calculate_manual_reading(basic_data: BasicMeterData) -> Reading: """ Calculate the interval between two manual readings """ t_start = basic_data.previous_register_read_datetime t_end = basic_data.current_register_read_datetime read_start = basic_data.previous_register_read read_end = basic_data....
[ "def", "calculate_manual_reading", "(", "basic_data", ":", "BasicMeterData", ")", "->", "Reading", ":", "t_start", "=", "basic_data", ".", "previous_register_read_datetime", "t_end", "=", "basic_data", ".", "current_register_read_datetime", "read_start", "=", "basic_data"...
Calculate the interval between two manual readings
[ "Calculate", "the", "interval", "between", "two", "manual", "readings" ]
5405a5cba4bb8ebdad05c28455d12bb34a6d3ce5
https://github.com/aguinane/nem-reader/blob/5405a5cba4bb8ebdad05c28455d12bb34a6d3ce5/nemreader/nem_reader.py#L143-L155
train
aguinane/nem-reader
nemreader/nem_reader.py
parse_100_row
def parse_100_row(row: list, file_name: str) -> HeaderRecord: """ Parse header record (100) """ return HeaderRecord( row[1], parse_datetime(row[2]), row[3], row[4], file_name, )
python
def parse_100_row(row: list, file_name: str) -> HeaderRecord: """ Parse header record (100) """ return HeaderRecord( row[1], parse_datetime(row[2]), row[3], row[4], file_name, )
[ "def", "parse_100_row", "(", "row", ":", "list", ",", "file_name", ":", "str", ")", "->", "HeaderRecord", ":", "return", "HeaderRecord", "(", "row", "[", "1", "]", ",", "parse_datetime", "(", "row", "[", "2", "]", ")", ",", "row", "[", "3", "]", ",...
Parse header record (100)
[ "Parse", "header", "record", "(", "100", ")" ]
5405a5cba4bb8ebdad05c28455d12bb34a6d3ce5
https://github.com/aguinane/nem-reader/blob/5405a5cba4bb8ebdad05c28455d12bb34a6d3ce5/nemreader/nem_reader.py#L158-L166
train
aguinane/nem-reader
nemreader/nem_reader.py
parse_200_row
def parse_200_row(row: list) -> NmiDetails: """ Parse NMI data details record (200) """ return NmiDetails(row[1], row[2], row[3], row[4], row[5], row[6], row[7], int(row[8]), parse_datetime(row[9]))
python
def parse_200_row(row: list) -> NmiDetails: """ Parse NMI data details record (200) """ return NmiDetails(row[1], row[2], row[3], row[4], row[5], row[6], row[7], int(row[8]), parse_datetime(row[9]))
[ "def", "parse_200_row", "(", "row", ":", "list", ")", "->", "NmiDetails", ":", "return", "NmiDetails", "(", "row", "[", "1", "]", ",", "row", "[", "2", "]", ",", "row", "[", "3", "]", ",", "row", "[", "4", "]", ",", "row", "[", "5", "]", ",",...
Parse NMI data details record (200)
[ "Parse", "NMI", "data", "details", "record", "(", "200", ")" ]
5405a5cba4bb8ebdad05c28455d12bb34a6d3ce5
https://github.com/aguinane/nem-reader/blob/5405a5cba4bb8ebdad05c28455d12bb34a6d3ce5/nemreader/nem_reader.py#L169-L172
train
aguinane/nem-reader
nemreader/nem_reader.py
parse_250_row
def parse_250_row(row: list) -> BasicMeterData: """ Parse basic meter data record (250) """ return BasicMeterData(row[1], row[2], row[3], row[4], row[5], row[6], row[7], float(row[8]), parse_datetime(row[9]), row[10], row[11], row[12], ...
python
def parse_250_row(row: list) -> BasicMeterData: """ Parse basic meter data record (250) """ return BasicMeterData(row[1], row[2], row[3], row[4], row[5], row[6], row[7], float(row[8]), parse_datetime(row[9]), row[10], row[11], row[12], ...
[ "def", "parse_250_row", "(", "row", ":", "list", ")", "->", "BasicMeterData", ":", "return", "BasicMeterData", "(", "row", "[", "1", "]", ",", "row", "[", "2", "]", ",", "row", "[", "3", "]", ",", "row", "[", "4", "]", ",", "row", "[", "5", "]"...
Parse basic meter data record (250)
[ "Parse", "basic", "meter", "data", "record", "(", "250", ")" ]
5405a5cba4bb8ebdad05c28455d12bb34a6d3ce5
https://github.com/aguinane/nem-reader/blob/5405a5cba4bb8ebdad05c28455d12bb34a6d3ce5/nemreader/nem_reader.py#L175-L183
train
aguinane/nem-reader
nemreader/nem_reader.py
parse_300_row
def parse_300_row(row: list, interval: int, uom: str) -> IntervalRecord: """ Interval data record (300) """ num_intervals = int(24 * 60 / interval) interval_date = parse_datetime(row[1]) last_interval = 2 + num_intervals quality_method = row[last_interval] interval_values = parse_interval_reco...
python
def parse_300_row(row: list, interval: int, uom: str) -> IntervalRecord: """ Interval data record (300) """ num_intervals = int(24 * 60 / interval) interval_date = parse_datetime(row[1]) last_interval = 2 + num_intervals quality_method = row[last_interval] interval_values = parse_interval_reco...
[ "def", "parse_300_row", "(", "row", ":", "list", ",", "interval", ":", "int", ",", "uom", ":", "str", ")", "->", "IntervalRecord", ":", "num_intervals", "=", "int", "(", "24", "*", "60", "/", "interval", ")", "interval_date", "=", "parse_datetime", "(", ...
Interval data record (300)
[ "Interval", "data", "record", "(", "300", ")" ]
5405a5cba4bb8ebdad05c28455d12bb34a6d3ce5
https://github.com/aguinane/nem-reader/blob/5405a5cba4bb8ebdad05c28455d12bb34a6d3ce5/nemreader/nem_reader.py#L186-L201
train
aguinane/nem-reader
nemreader/nem_reader.py
parse_interval_records
def parse_interval_records(interval_record, interval_date, interval, uom, quality_method) -> List[Reading]: """ Convert interval values into tuples with datetime """ interval_delta = timedelta(minutes=interval) return [ Reading( t_start=interval_date + (i *...
python
def parse_interval_records(interval_record, interval_date, interval, uom, quality_method) -> List[Reading]: """ Convert interval values into tuples with datetime """ interval_delta = timedelta(minutes=interval) return [ Reading( t_start=interval_date + (i *...
[ "def", "parse_interval_records", "(", "interval_record", ",", "interval_date", ",", "interval", ",", "uom", ",", "quality_method", ")", "->", "List", "[", "Reading", "]", ":", "interval_delta", "=", "timedelta", "(", "minutes", "=", "interval", ")", "return", ...
Convert interval values into tuples with datetime
[ "Convert", "interval", "values", "into", "tuples", "with", "datetime" ]
5405a5cba4bb8ebdad05c28455d12bb34a6d3ce5
https://github.com/aguinane/nem-reader/blob/5405a5cba4bb8ebdad05c28455d12bb34a6d3ce5/nemreader/nem_reader.py#L204-L221
train
aguinane/nem-reader
nemreader/nem_reader.py
parse_reading
def parse_reading(val: str) -> Optional[float]: """ Convert reading value to float (if possible) """ try: return float(val) except ValueError: logging.warning('Reading of "%s" is not a number', val) return None
python
def parse_reading(val: str) -> Optional[float]: """ Convert reading value to float (if possible) """ try: return float(val) except ValueError: logging.warning('Reading of "%s" is not a number', val) return None
[ "def", "parse_reading", "(", "val", ":", "str", ")", "->", "Optional", "[", "float", "]", ":", "try", ":", "return", "float", "(", "val", ")", "except", "ValueError", ":", "logging", ".", "warning", "(", "'Reading of \"%s\" is not a number'", ",", "val", "...
Convert reading value to float (if possible)
[ "Convert", "reading", "value", "to", "float", "(", "if", "possible", ")" ]
5405a5cba4bb8ebdad05c28455d12bb34a6d3ce5
https://github.com/aguinane/nem-reader/blob/5405a5cba4bb8ebdad05c28455d12bb34a6d3ce5/nemreader/nem_reader.py#L224-L230
train
aguinane/nem-reader
nemreader/nem_reader.py
parse_400_row
def parse_400_row(row: list) -> tuple: """ Interval event record (400) """ return EventRecord(int(row[1]), int(row[2]), row[3], row[4], row[5])
python
def parse_400_row(row: list) -> tuple: """ Interval event record (400) """ return EventRecord(int(row[1]), int(row[2]), row[3], row[4], row[5])
[ "def", "parse_400_row", "(", "row", ":", "list", ")", "->", "tuple", ":", "return", "EventRecord", "(", "int", "(", "row", "[", "1", "]", ")", ",", "int", "(", "row", "[", "2", "]", ")", ",", "row", "[", "3", "]", ",", "row", "[", "4", "]", ...
Interval event record (400)
[ "Interval", "event", "record", "(", "400", ")" ]
5405a5cba4bb8ebdad05c28455d12bb34a6d3ce5
https://github.com/aguinane/nem-reader/blob/5405a5cba4bb8ebdad05c28455d12bb34a6d3ce5/nemreader/nem_reader.py#L233-L236
train
aguinane/nem-reader
nemreader/nem_reader.py
update_reading_events
def update_reading_events(readings, event_record): """ Updates readings from a 300 row to reflect any events found in a subsequent 400 row """ # event intervals are 1-indexed for i in range(event_record.start_interval - 1, event_record.end_interval): readings[i] = Reading( t_...
python
def update_reading_events(readings, event_record): """ Updates readings from a 300 row to reflect any events found in a subsequent 400 row """ # event intervals are 1-indexed for i in range(event_record.start_interval - 1, event_record.end_interval): readings[i] = Reading( t_...
[ "def", "update_reading_events", "(", "readings", ",", "event_record", ")", ":", "# event intervals are 1-indexed", "for", "i", "in", "range", "(", "event_record", ".", "start_interval", "-", "1", ",", "event_record", ".", "end_interval", ")", ":", "readings", "[",...
Updates readings from a 300 row to reflect any events found in a subsequent 400 row
[ "Updates", "readings", "from", "a", "300", "row", "to", "reflect", "any", "events", "found", "in", "a", "subsequent", "400", "row" ]
5405a5cba4bb8ebdad05c28455d12bb34a6d3ce5
https://github.com/aguinane/nem-reader/blob/5405a5cba4bb8ebdad05c28455d12bb34a6d3ce5/nemreader/nem_reader.py#L239-L255
train
aguinane/nem-reader
nemreader/nem_reader.py
parse_datetime
def parse_datetime(record: str) -> Optional[datetime]: """ Parse a datetime string into a python datetime object """ # NEM defines Date8, DateTime12 and DateTime14 format_strings = {8: '%Y%m%d', 12: '%Y%m%d%H%M', 14: '%Y%m%d%H%M%S'} if record == '': return None return datetime.strptime(recor...
python
def parse_datetime(record: str) -> Optional[datetime]: """ Parse a datetime string into a python datetime object """ # NEM defines Date8, DateTime12 and DateTime14 format_strings = {8: '%Y%m%d', 12: '%Y%m%d%H%M', 14: '%Y%m%d%H%M%S'} if record == '': return None return datetime.strptime(recor...
[ "def", "parse_datetime", "(", "record", ":", "str", ")", "->", "Optional", "[", "datetime", "]", ":", "# NEM defines Date8, DateTime12 and DateTime14", "format_strings", "=", "{", "8", ":", "'%Y%m%d'", ",", "12", ":", "'%Y%m%d%H%M'", ",", "14", ":", "'%Y%m%d%H%M...
Parse a datetime string into a python datetime object
[ "Parse", "a", "datetime", "string", "into", "a", "python", "datetime", "object" ]
5405a5cba4bb8ebdad05c28455d12bb34a6d3ce5
https://github.com/aguinane/nem-reader/blob/5405a5cba4bb8ebdad05c28455d12bb34a6d3ce5/nemreader/nem_reader.py#L268-L275
train
stephenmcd/gnotty
gnotty/conf.py
Settings.parse_args
def parse_args(self): """ Called from ``gnotty.server.run`` and parses any CLI args provided. Also handles loading settings from the Python module specified with the ``--conf-file`` arg. CLI args take precedence over any settings defined in the Python module defined by ``...
python
def parse_args(self): """ Called from ``gnotty.server.run`` and parses any CLI args provided. Also handles loading settings from the Python module specified with the ``--conf-file`` arg. CLI args take precedence over any settings defined in the Python module defined by ``...
[ "def", "parse_args", "(", "self", ")", ":", "options", ",", "_", "=", "parser", ".", "parse_args", "(", ")", "file_settings", "=", "{", "}", "if", "options", ".", "CONF_FILE", ":", "execfile", "(", "options", ".", "CONF_FILE", ",", "{", "}", ",", "fi...
Called from ``gnotty.server.run`` and parses any CLI args provided. Also handles loading settings from the Python module specified with the ``--conf-file`` arg. CLI args take precedence over any settings defined in the Python module defined by ``--conf-file``.
[ "Called", "from", "gnotty", ".", "server", ".", "run", "and", "parses", "any", "CLI", "args", "provided", ".", "Also", "handles", "loading", "settings", "from", "the", "Python", "module", "specified", "with", "the", "--", "conf", "-", "file", "arg", ".", ...
bea3762dc9cbc3cb21a5ae7224091cf027273c40
https://github.com/stephenmcd/gnotty/blob/bea3762dc9cbc3cb21a5ae7224091cf027273c40/gnotty/conf.py#L94-L125
train
stephenmcd/gnotty
gnotty/client.py
color
def color(nickname): """ Provides a consistent color for a nickname. Uses first 6 chars of nickname's md5 hash, and then slightly darkens the rgb values for use on a light background. """ _hex = md5(nickname).hexdigest()[:6] darken = lambda s: str(int(round(int(s, 16) * .7))) return "rgb...
python
def color(nickname): """ Provides a consistent color for a nickname. Uses first 6 chars of nickname's md5 hash, and then slightly darkens the rgb values for use on a light background. """ _hex = md5(nickname).hexdigest()[:6] darken = lambda s: str(int(round(int(s, 16) * .7))) return "rgb...
[ "def", "color", "(", "nickname", ")", ":", "_hex", "=", "md5", "(", "nickname", ")", ".", "hexdigest", "(", ")", "[", ":", "6", "]", "darken", "=", "lambda", "s", ":", "str", "(", "int", "(", "round", "(", "int", "(", "s", ",", "16", ")", "*"...
Provides a consistent color for a nickname. Uses first 6 chars of nickname's md5 hash, and then slightly darkens the rgb values for use on a light background.
[ "Provides", "a", "consistent", "color", "for", "a", "nickname", ".", "Uses", "first", "6", "chars", "of", "nickname", "s", "md5", "hash", "and", "then", "slightly", "darkens", "the", "rgb", "values", "for", "use", "on", "a", "light", "background", "." ]
bea3762dc9cbc3cb21a5ae7224091cf027273c40
https://github.com/stephenmcd/gnotty/blob/bea3762dc9cbc3cb21a5ae7224091cf027273c40/gnotty/client.py#L10-L18
train
stephenmcd/gnotty
gnotty/client.py
BaseIRCClient.on_welcome
def on_welcome(self, connection, event): """ Join the channel once connected to the IRC server. """ connection.join(self.channel, key=settings.IRC_CHANNEL_KEY or "")
python
def on_welcome(self, connection, event): """ Join the channel once connected to the IRC server. """ connection.join(self.channel, key=settings.IRC_CHANNEL_KEY or "")
[ "def", "on_welcome", "(", "self", ",", "connection", ",", "event", ")", ":", "connection", ".", "join", "(", "self", ".", "channel", ",", "key", "=", "settings", ".", "IRC_CHANNEL_KEY", "or", "\"\"", ")" ]
Join the channel once connected to the IRC server.
[ "Join", "the", "channel", "once", "connected", "to", "the", "IRC", "server", "." ]
bea3762dc9cbc3cb21a5ae7224091cf027273c40
https://github.com/stephenmcd/gnotty/blob/bea3762dc9cbc3cb21a5ae7224091cf027273c40/gnotty/client.py#L64-L68
train
stephenmcd/gnotty
gnotty/client.py
BaseIRCClient.on_nicknameinuse
def on_nicknameinuse(self, connection, event): """ Increment a digit on the nickname if it's in use, and re-connect. """ digits = "" while self.nickname[-1].isdigit(): digits = self.nickname[-1] + digits self.nickname = self.nickname[:-1] d...
python
def on_nicknameinuse(self, connection, event): """ Increment a digit on the nickname if it's in use, and re-connect. """ digits = "" while self.nickname[-1].isdigit(): digits = self.nickname[-1] + digits self.nickname = self.nickname[:-1] d...
[ "def", "on_nicknameinuse", "(", "self", ",", "connection", ",", "event", ")", ":", "digits", "=", "\"\"", "while", "self", ".", "nickname", "[", "-", "1", "]", ".", "isdigit", "(", ")", ":", "digits", "=", "self", ".", "nickname", "[", "-", "1", "]...
Increment a digit on the nickname if it's in use, and re-connect.
[ "Increment", "a", "digit", "on", "the", "nickname", "if", "it", "s", "in", "use", "and", "re", "-", "connect", "." ]
bea3762dc9cbc3cb21a5ae7224091cf027273c40
https://github.com/stephenmcd/gnotty/blob/bea3762dc9cbc3cb21a5ae7224091cf027273c40/gnotty/client.py#L70-L81
train
stephenmcd/gnotty
gnotty/client.py
BaseIRCClient.message_channel
def message_channel(self, message): """ Nicer shortcut for sending a message to a channel. Also irclib doesn't handle unicode so we bypass its privmsg -> send_raw methods and use its socket directly. """ data = "PRIVMSG %s :%s\r\n" % (self.channel, message) self.c...
python
def message_channel(self, message): """ Nicer shortcut for sending a message to a channel. Also irclib doesn't handle unicode so we bypass its privmsg -> send_raw methods and use its socket directly. """ data = "PRIVMSG %s :%s\r\n" % (self.channel, message) self.c...
[ "def", "message_channel", "(", "self", ",", "message", ")", ":", "data", "=", "\"PRIVMSG %s :%s\\r\\n\"", "%", "(", "self", ".", "channel", ",", "message", ")", "self", ".", "connection", ".", "socket", ".", "send", "(", "data", ".", "encode", "(", "\"ut...
Nicer shortcut for sending a message to a channel. Also irclib doesn't handle unicode so we bypass its privmsg -> send_raw methods and use its socket directly.
[ "Nicer", "shortcut", "for", "sending", "a", "message", "to", "a", "channel", ".", "Also", "irclib", "doesn", "t", "handle", "unicode", "so", "we", "bypass", "its", "privmsg", "-", ">", "send_raw", "methods", "and", "use", "its", "socket", "directly", "." ]
bea3762dc9cbc3cb21a5ae7224091cf027273c40
https://github.com/stephenmcd/gnotty/blob/bea3762dc9cbc3cb21a5ae7224091cf027273c40/gnotty/client.py#L83-L90
train
stephenmcd/gnotty
gnotty/client.py
WebSocketIRCClient.emit_message
def emit_message(self, message): """ Send a message to the channel. We also emit the message back to the sender's WebSocket. """ try: nickname_color = self.nicknames[self.nickname] except KeyError: # Only accept messages if we've joined. ...
python
def emit_message(self, message): """ Send a message to the channel. We also emit the message back to the sender's WebSocket. """ try: nickname_color = self.nicknames[self.nickname] except KeyError: # Only accept messages if we've joined. ...
[ "def", "emit_message", "(", "self", ",", "message", ")", ":", "try", ":", "nickname_color", "=", "self", ".", "nicknames", "[", "self", ".", "nickname", "]", "except", "KeyError", ":", "# Only accept messages if we've joined.", "return", "message", "=", "message...
Send a message to the channel. We also emit the message back to the sender's WebSocket.
[ "Send", "a", "message", "to", "the", "channel", ".", "We", "also", "emit", "the", "message", "back", "to", "the", "sender", "s", "WebSocket", "." ]
bea3762dc9cbc3cb21a5ae7224091cf027273c40
https://github.com/stephenmcd/gnotty/blob/bea3762dc9cbc3cb21a5ae7224091cf027273c40/gnotty/client.py#L104-L120
train
stephenmcd/gnotty
gnotty/client.py
WebSocketIRCClient.emit_nicknames
def emit_nicknames(self): """ Send the nickname list to the Websocket. Called whenever the nicknames list changes. """ nicknames = [{"nickname": name, "color": color(name)} for name in sorted(self.nicknames.keys())] self.namespace.emit("nicknames", ni...
python
def emit_nicknames(self): """ Send the nickname list to the Websocket. Called whenever the nicknames list changes. """ nicknames = [{"nickname": name, "color": color(name)} for name in sorted(self.nicknames.keys())] self.namespace.emit("nicknames", ni...
[ "def", "emit_nicknames", "(", "self", ")", ":", "nicknames", "=", "[", "{", "\"nickname\"", ":", "name", ",", "\"color\"", ":", "color", "(", "name", ")", "}", "for", "name", "in", "sorted", "(", "self", ".", "nicknames", ".", "keys", "(", ")", ")", ...
Send the nickname list to the Websocket. Called whenever the nicknames list changes.
[ "Send", "the", "nickname", "list", "to", "the", "Websocket", ".", "Called", "whenever", "the", "nicknames", "list", "changes", "." ]
bea3762dc9cbc3cb21a5ae7224091cf027273c40
https://github.com/stephenmcd/gnotty/blob/bea3762dc9cbc3cb21a5ae7224091cf027273c40/gnotty/client.py#L122-L129
train
stephenmcd/gnotty
gnotty/client.py
WebSocketIRCClient.on_namreply
def on_namreply(self, connection, event): """ Initial list of nicknames received - remove op/voice prefixes, and send the list to the WebSocket. """ for nickname in event.arguments()[-1].split(): nickname = nickname.lstrip("@+") self.nicknames[nickname] = ...
python
def on_namreply(self, connection, event): """ Initial list of nicknames received - remove op/voice prefixes, and send the list to the WebSocket. """ for nickname in event.arguments()[-1].split(): nickname = nickname.lstrip("@+") self.nicknames[nickname] = ...
[ "def", "on_namreply", "(", "self", ",", "connection", ",", "event", ")", ":", "for", "nickname", "in", "event", ".", "arguments", "(", ")", "[", "-", "1", "]", ".", "split", "(", ")", ":", "nickname", "=", "nickname", ".", "lstrip", "(", "\"@+\"", ...
Initial list of nicknames received - remove op/voice prefixes, and send the list to the WebSocket.
[ "Initial", "list", "of", "nicknames", "received", "-", "remove", "op", "/", "voice", "prefixes", "and", "send", "the", "list", "to", "the", "WebSocket", "." ]
bea3762dc9cbc3cb21a5ae7224091cf027273c40
https://github.com/stephenmcd/gnotty/blob/bea3762dc9cbc3cb21a5ae7224091cf027273c40/gnotty/client.py#L137-L145
train
stephenmcd/gnotty
gnotty/client.py
WebSocketIRCClient.on_join
def on_join(self, connection, event): """ Someone joined the channel - send the nicknames list to the WebSocket. """ #from time import sleep; sleep(10) # Simulate a slow connection nickname = self.get_nickname(event) nickname_color = color(nickname) self....
python
def on_join(self, connection, event): """ Someone joined the channel - send the nicknames list to the WebSocket. """ #from time import sleep; sleep(10) # Simulate a slow connection nickname = self.get_nickname(event) nickname_color = color(nickname) self....
[ "def", "on_join", "(", "self", ",", "connection", ",", "event", ")", ":", "#from time import sleep; sleep(10) # Simulate a slow connection", "nickname", "=", "self", ".", "get_nickname", "(", "event", ")", "nickname_color", "=", "color", "(", "nickname", ")", "self...
Someone joined the channel - send the nicknames list to the WebSocket.
[ "Someone", "joined", "the", "channel", "-", "send", "the", "nicknames", "list", "to", "the", "WebSocket", "." ]
bea3762dc9cbc3cb21a5ae7224091cf027273c40
https://github.com/stephenmcd/gnotty/blob/bea3762dc9cbc3cb21a5ae7224091cf027273c40/gnotty/client.py#L147-L158
train
stephenmcd/gnotty
gnotty/client.py
WebSocketIRCClient.on_nick
def on_nick(self, connection, event): """ Someone changed their nickname - send the nicknames list to the WebSocket. """ old_nickname = self.get_nickname(event) old_color = self.nicknames.pop(old_nickname) new_nickname = event.target() message = "is now kn...
python
def on_nick(self, connection, event): """ Someone changed their nickname - send the nicknames list to the WebSocket. """ old_nickname = self.get_nickname(event) old_color = self.nicknames.pop(old_nickname) new_nickname = event.target() message = "is now kn...
[ "def", "on_nick", "(", "self", ",", "connection", ",", "event", ")", ":", "old_nickname", "=", "self", ".", "get_nickname", "(", "event", ")", "old_color", "=", "self", ".", "nicknames", ".", "pop", "(", "old_nickname", ")", "new_nickname", "=", "event", ...
Someone changed their nickname - send the nicknames list to the WebSocket.
[ "Someone", "changed", "their", "nickname", "-", "send", "the", "nicknames", "list", "to", "the", "WebSocket", "." ]
bea3762dc9cbc3cb21a5ae7224091cf027273c40
https://github.com/stephenmcd/gnotty/blob/bea3762dc9cbc3cb21a5ae7224091cf027273c40/gnotty/client.py#L160-L174
train
stephenmcd/gnotty
gnotty/client.py
WebSocketIRCClient.on_quit
def on_quit(self, connection, event): """ Someone left the channel - send the nicknames list to the WebSocket. """ nickname = self.get_nickname(event) nickname_color = self.nicknames[nickname] del self.nicknames[nickname] self.namespace.emit("message", nic...
python
def on_quit(self, connection, event): """ Someone left the channel - send the nicknames list to the WebSocket. """ nickname = self.get_nickname(event) nickname_color = self.nicknames[nickname] del self.nicknames[nickname] self.namespace.emit("message", nic...
[ "def", "on_quit", "(", "self", ",", "connection", ",", "event", ")", ":", "nickname", "=", "self", ".", "get_nickname", "(", "event", ")", "nickname_color", "=", "self", ".", "nicknames", "[", "nickname", "]", "del", "self", ".", "nicknames", "[", "nickn...
Someone left the channel - send the nicknames list to the WebSocket.
[ "Someone", "left", "the", "channel", "-", "send", "the", "nicknames", "list", "to", "the", "WebSocket", "." ]
bea3762dc9cbc3cb21a5ae7224091cf027273c40
https://github.com/stephenmcd/gnotty/blob/bea3762dc9cbc3cb21a5ae7224091cf027273c40/gnotty/client.py#L176-L185
train
stephenmcd/gnotty
gnotty/client.py
WebSocketIRCClient.on_pubmsg
def on_pubmsg(self, connection, event): """ Messages received in the channel - send them to the WebSocket. """ for message in event.arguments(): nickname = self.get_nickname(event) nickname_color = self.nicknames[nickname] self.namespace.emit("message"...
python
def on_pubmsg(self, connection, event): """ Messages received in the channel - send them to the WebSocket. """ for message in event.arguments(): nickname = self.get_nickname(event) nickname_color = self.nicknames[nickname] self.namespace.emit("message"...
[ "def", "on_pubmsg", "(", "self", ",", "connection", ",", "event", ")", ":", "for", "message", "in", "event", ".", "arguments", "(", ")", ":", "nickname", "=", "self", ".", "get_nickname", "(", "event", ")", "nickname_color", "=", "self", ".", "nicknames"...
Messages received in the channel - send them to the WebSocket.
[ "Messages", "received", "in", "the", "channel", "-", "send", "them", "to", "the", "WebSocket", "." ]
bea3762dc9cbc3cb21a5ae7224091cf027273c40
https://github.com/stephenmcd/gnotty/blob/bea3762dc9cbc3cb21a5ae7224091cf027273c40/gnotty/client.py#L187-L194
train
ergo/ziggurat_foundations
ziggurat_foundations/models/services/resource.py
ResourceService.get
def get(cls, resource_id, db_session=None): """ Fetch row using primary key - will use existing object in session if already present :param resource_id: :param db_session: :return: """ db_session = get_db_session(db_session) return db_session.quer...
python
def get(cls, resource_id, db_session=None): """ Fetch row using primary key - will use existing object in session if already present :param resource_id: :param db_session: :return: """ db_session = get_db_session(db_session) return db_session.quer...
[ "def", "get", "(", "cls", ",", "resource_id", ",", "db_session", "=", "None", ")", ":", "db_session", "=", "get_db_session", "(", "db_session", ")", "return", "db_session", ".", "query", "(", "cls", ".", "model", ")", ".", "get", "(", "resource_id", ")" ...
Fetch row using primary key - will use existing object in session if already present :param resource_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/resource.py#L20-L30
train
ergo/ziggurat_foundations
ziggurat_foundations/models/services/resource.py
ResourceService.perms_for_user
def perms_for_user(cls, instance, user, db_session=None): """ returns all permissions that given user has for this resource from groups and directly set ones too :param instance: :param user: :param db_session: :return: """ db_session = get_db...
python
def perms_for_user(cls, instance, user, db_session=None): """ returns all permissions that given user has for this resource from groups and directly set ones too :param instance: :param user: :param db_session: :return: """ db_session = get_db...
[ "def", "perms_for_user", "(", "cls", ",", "instance", ",", "user", ",", "db_session", "=", "None", ")", ":", "db_session", "=", "get_db_session", "(", "db_session", ",", "instance", ")", "query", "=", "db_session", ".", "query", "(", "cls", ".", "models_pr...
returns all permissions that given user has for this resource from groups and directly set ones too :param instance: :param user: :param db_session: :return:
[ "returns", "all", "permissions", "that", "given", "user", "has", "for", "this", "resource", "from", "groups", "and", "directly", "set", "ones", "too" ]
9eeec894d08e8d7defa60ddc04b63f69cd4cbeba
https://github.com/ergo/ziggurat_foundations/blob/9eeec894d08e8d7defa60ddc04b63f69cd4cbeba/ziggurat_foundations/models/services/resource.py#L33-L106
train
ergo/ziggurat_foundations
ziggurat_foundations/models/services/resource.py
ResourceService.direct_perms_for_user
def direct_perms_for_user(cls, instance, user, db_session=None): """ returns permissions that given user has for this resource without ones inherited from groups that user belongs to :param instance: :param user: :param db_session: :return: """ ...
python
def direct_perms_for_user(cls, instance, user, db_session=None): """ returns permissions that given user has for this resource without ones inherited from groups that user belongs to :param instance: :param user: :param db_session: :return: """ ...
[ "def", "direct_perms_for_user", "(", "cls", ",", "instance", ",", "user", ",", "db_session", "=", "None", ")", ":", "db_session", "=", "get_db_session", "(", "db_session", ",", "instance", ")", "query", "=", "db_session", ".", "query", "(", "cls", ".", "mo...
returns permissions that given user has for this resource without ones inherited from groups that user belongs to :param instance: :param user: :param db_session: :return:
[ "returns", "permissions", "that", "given", "user", "has", "for", "this", "resource", "without", "ones", "inherited", "from", "groups", "that", "user", "belongs", "to" ]
9eeec894d08e8d7defa60ddc04b63f69cd4cbeba
https://github.com/ergo/ziggurat_foundations/blob/9eeec894d08e8d7defa60ddc04b63f69cd4cbeba/ziggurat_foundations/models/services/resource.py#L109-L139
train
ergo/ziggurat_foundations
ziggurat_foundations/models/services/resource.py
ResourceService.group_perms_for_user
def group_perms_for_user(cls, instance, user, db_session=None): """ returns permissions that given user has for this resource that are inherited from groups :param instance: :param user: :param db_session: :return: """ db_session = get_db_sess...
python
def group_perms_for_user(cls, instance, user, db_session=None): """ returns permissions that given user has for this resource that are inherited from groups :param instance: :param user: :param db_session: :return: """ db_session = get_db_sess...
[ "def", "group_perms_for_user", "(", "cls", ",", "instance", ",", "user", ",", "db_session", "=", "None", ")", ":", "db_session", "=", "get_db_session", "(", "db_session", ",", "instance", ")", "perms", "=", "resource_permissions_for_users", "(", "cls", ".", "m...
returns permissions that given user has for this resource that are inherited from groups :param instance: :param user: :param db_session: :return:
[ "returns", "permissions", "that", "given", "user", "has", "for", "this", "resource", "that", "are", "inherited", "from", "groups" ]
9eeec894d08e8d7defa60ddc04b63f69cd4cbeba
https://github.com/ergo/ziggurat_foundations/blob/9eeec894d08e8d7defa60ddc04b63f69cd4cbeba/ziggurat_foundations/models/services/resource.py#L142-L175
train
ergo/ziggurat_foundations
ziggurat_foundations/models/services/resource.py
ResourceService.users_for_perm
def users_for_perm( cls, instance, perm_name, user_ids=None, group_ids=None, limit_group_permissions=False, skip_group_perms=False, db_session=None, ): """ return PermissionTuples for users AND groups that have given permission ...
python
def users_for_perm( cls, instance, perm_name, user_ids=None, group_ids=None, limit_group_permissions=False, skip_group_perms=False, db_session=None, ): """ return PermissionTuples for users AND groups that have given permission ...
[ "def", "users_for_perm", "(", "cls", ",", "instance", ",", "perm_name", ",", "user_ids", "=", "None", ",", "group_ids", "=", "None", ",", "limit_group_permissions", "=", "False", ",", "skip_group_perms", "=", "False", ",", "db_session", "=", "None", ",", ")"...
return PermissionTuples for users AND groups that have given permission for the resource, perm_name is __any_permission__ then users with any permission will be listed :param instance: :param perm_name: :param user_ids: limits the permissions to specific user ids :param ...
[ "return", "PermissionTuples", "for", "users", "AND", "groups", "that", "have", "given", "permission", "for", "the", "resource", "perm_name", "is", "__any_permission__", "then", "users", "with", "any", "permission", "will", "be", "listed" ]
9eeec894d08e8d7defa60ddc04b63f69cd4cbeba
https://github.com/ergo/ziggurat_foundations/blob/9eeec894d08e8d7defa60ddc04b63f69cd4cbeba/ziggurat_foundations/models/services/resource.py#L178-L235
train
ergo/ziggurat_foundations
ziggurat_foundations/models/services/resource.py
ResourceService.by_resource_id
def by_resource_id(cls, resource_id, db_session=None): """ fetch the resouce by id :param resource_id: :param db_session: :return: """ db_session = get_db_session(db_session) query = db_session.query(cls.model).filter( cls.model.resource_id ==...
python
def by_resource_id(cls, resource_id, db_session=None): """ fetch the resouce by id :param resource_id: :param db_session: :return: """ db_session = get_db_session(db_session) query = db_session.query(cls.model).filter( cls.model.resource_id ==...
[ "def", "by_resource_id", "(", "cls", ",", "resource_id", ",", "db_session", "=", "None", ")", ":", "db_session", "=", "get_db_session", "(", "db_session", ")", "query", "=", "db_session", ".", "query", "(", "cls", ".", "model", ")", ".", "filter", "(", "...
fetch the resouce by id :param resource_id: :param db_session: :return:
[ "fetch", "the", "resouce", "by", "id" ]
9eeec894d08e8d7defa60ddc04b63f69cd4cbeba
https://github.com/ergo/ziggurat_foundations/blob/9eeec894d08e8d7defa60ddc04b63f69cd4cbeba/ziggurat_foundations/models/services/resource.py#L238-L250
train
ergo/ziggurat_foundations
ziggurat_foundations/models/services/resource.py
ResourceService.perm_by_group_and_perm_name
def perm_by_group_and_perm_name( cls, resource_id, group_id, perm_name, db_session=None ): """ fetch permissions by group and permission name :param resource_id: :param group_id: :param perm_name: :param db_session: :return: """ db_ses...
python
def perm_by_group_and_perm_name( cls, resource_id, group_id, perm_name, db_session=None ): """ fetch permissions by group and permission name :param resource_id: :param group_id: :param perm_name: :param db_session: :return: """ db_ses...
[ "def", "perm_by_group_and_perm_name", "(", "cls", ",", "resource_id", ",", "group_id", ",", "perm_name", ",", "db_session", "=", "None", ")", ":", "db_session", "=", "get_db_session", "(", "db_session", ")", "query", "=", "db_session", ".", "query", "(", "cls"...
fetch permissions by group and permission name :param resource_id: :param group_id: :param perm_name: :param db_session: :return:
[ "fetch", "permissions", "by", "group", "and", "permission", "name" ]
9eeec894d08e8d7defa60ddc04b63f69cd4cbeba
https://github.com/ergo/ziggurat_foundations/blob/9eeec894d08e8d7defa60ddc04b63f69cd4cbeba/ziggurat_foundations/models/services/resource.py#L253-L276
train
ergo/ziggurat_foundations
ziggurat_foundations/models/services/resource.py
ResourceService.groups_for_perm
def groups_for_perm( cls, instance, perm_name, group_ids=None, limit_group_permissions=False, db_session=None, ): """ return PermissionTuples for groups that have given permission for the resource, perm_name is __any_permission__ then u...
python
def groups_for_perm( cls, instance, perm_name, group_ids=None, limit_group_permissions=False, db_session=None, ): """ return PermissionTuples for groups that have given permission for the resource, perm_name is __any_permission__ then u...
[ "def", "groups_for_perm", "(", "cls", ",", "instance", ",", "perm_name", ",", "group_ids", "=", "None", ",", "limit_group_permissions", "=", "False", ",", "db_session", "=", "None", ",", ")", ":", "# noqa", "db_session", "=", "get_db_session", "(", "db_session...
return PermissionTuples for groups that have given permission for the resource, perm_name is __any_permission__ then users with any permission will be listed :param instance: :param perm_name: :param group_ids: limits the permissions to specific group ids :param limit_gr...
[ "return", "PermissionTuples", "for", "groups", "that", "have", "given", "permission", "for", "the", "resource", "perm_name", "is", "__any_permission__", "then", "users", "with", "any", "permission", "will", "be", "listed" ]
9eeec894d08e8d7defa60ddc04b63f69cd4cbeba
https://github.com/ergo/ziggurat_foundations/blob/9eeec894d08e8d7defa60ddc04b63f69cd4cbeba/ziggurat_foundations/models/services/resource.py#L279-L325
train
ergo/ziggurat_foundations
ziggurat_foundations/models/services/resource.py
ResourceService.lock_resource_for_update
def lock_resource_for_update(cls, resource_id, db_session): """ Selects resource for update - locking access for other transactions :param resource_id: :param db_session: :return: """ db_session = get_db_session(db_session) query = db_session.query(cls.mo...
python
def lock_resource_for_update(cls, resource_id, db_session): """ Selects resource for update - locking access for other transactions :param resource_id: :param db_session: :return: """ db_session = get_db_session(db_session) query = db_session.query(cls.mo...
[ "def", "lock_resource_for_update", "(", "cls", ",", "resource_id", ",", "db_session", ")", ":", "db_session", "=", "get_db_session", "(", "db_session", ")", "query", "=", "db_session", ".", "query", "(", "cls", ".", "model", ")", "query", "=", "query", ".", ...
Selects resource for update - locking access for other transactions :param resource_id: :param db_session: :return:
[ "Selects", "resource", "for", "update", "-", "locking", "access", "for", "other", "transactions" ]
9eeec894d08e8d7defa60ddc04b63f69cd4cbeba
https://github.com/ergo/ziggurat_foundations/blob/9eeec894d08e8d7defa60ddc04b63f69cd4cbeba/ziggurat_foundations/models/services/resource.py#L328-L340
train
ergo/ziggurat_foundations
ziggurat_foundations/models/services/user.py
UserService.get
def get(cls, user_id, db_session=None): """ Fetch row using primary key - will use existing object in session if already present :param user_id: :param db_session: :return: """ db_session = get_db_session(db_session) return db_session.query(cls.mo...
python
def get(cls, user_id, db_session=None): """ Fetch row using primary key - will use existing object in session if already present :param user_id: :param db_session: :return: """ db_session = get_db_session(db_session) return db_session.query(cls.mo...
[ "def", "get", "(", "cls", ",", "user_id", ",", "db_session", "=", "None", ")", ":", "db_session", "=", "get_db_session", "(", "db_session", ")", "return", "db_session", ".", "query", "(", "cls", ".", "model", ")", ".", "get", "(", "user_id", ")" ]
Fetch row using primary key - will use existing object in session if already present :param user_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/user.py#L24-L34
train
ergo/ziggurat_foundations
ziggurat_foundations/models/services/user.py
UserService.permissions
def permissions(cls, instance, db_session=None): """ returns all non-resource permissions based on what groups user belongs and directly set ones for this user :param instance: :param db_session: :return: """ db_session = get_db_session(db_session, in...
python
def permissions(cls, instance, db_session=None): """ returns all non-resource permissions based on what groups user belongs and directly set ones for this user :param instance: :param db_session: :return: """ db_session = get_db_session(db_session, in...
[ "def", "permissions", "(", "cls", ",", "instance", ",", "db_session", "=", "None", ")", ":", "db_session", "=", "get_db_session", "(", "db_session", ",", "instance", ")", "query", "=", "db_session", ".", "query", "(", "cls", ".", "models_proxy", ".", "Grou...
returns all non-resource permissions based on what groups user belongs and directly set ones for this user :param instance: :param db_session: :return:
[ "returns", "all", "non", "-", "resource", "permissions", "based", "on", "what", "groups", "user", "belongs", "and", "directly", "set", "ones", "for", "this", "user" ]
9eeec894d08e8d7defa60ddc04b63f69cd4cbeba
https://github.com/ergo/ziggurat_foundations/blob/9eeec894d08e8d7defa60ddc04b63f69cd4cbeba/ziggurat_foundations/models/services/user.py#L37-L80
train
ergo/ziggurat_foundations
ziggurat_foundations/models/services/user.py
UserService.resources_with_perms
def resources_with_perms( cls, instance, perms, resource_ids=None, resource_types=None, db_session=None ): """ returns all resources that user has perms for (note that at least one perm needs to be met) :param instance: :param perms: :param resource_ids: ...
python
def resources_with_perms( cls, instance, perms, resource_ids=None, resource_types=None, db_session=None ): """ returns all resources that user has perms for (note that at least one perm needs to be met) :param instance: :param perms: :param resource_ids: ...
[ "def", "resources_with_perms", "(", "cls", ",", "instance", ",", "perms", ",", "resource_ids", "=", "None", ",", "resource_types", "=", "None", ",", "db_session", "=", "None", ")", ":", "# owned entities have ALL permissions so we return those resources too", "# even wi...
returns all resources that user has perms for (note that at least one perm needs to be met) :param instance: :param perms: :param resource_ids: restricts the search to specific resources :param resource_types: :param db_session: :return:
[ "returns", "all", "resources", "that", "user", "has", "perms", "for", "(", "note", "that", "at", "least", "one", "perm", "needs", "to", "be", "met", ")" ]
9eeec894d08e8d7defa60ddc04b63f69cd4cbeba
https://github.com/ergo/ziggurat_foundations/blob/9eeec894d08e8d7defa60ddc04b63f69cd4cbeba/ziggurat_foundations/models/services/user.py#L83-L157
train
ergo/ziggurat_foundations
ziggurat_foundations/models/services/user.py
UserService.groups_with_resources
def groups_with_resources(cls, instance): """ Returns a list of groups users belongs to with eager loaded resources owned by those groups :param instance: :return: """ return instance.groups_dynamic.options( sa.orm.eagerload(cls.models_proxy.Group.res...
python
def groups_with_resources(cls, instance): """ Returns a list of groups users belongs to with eager loaded resources owned by those groups :param instance: :return: """ return instance.groups_dynamic.options( sa.orm.eagerload(cls.models_proxy.Group.res...
[ "def", "groups_with_resources", "(", "cls", ",", "instance", ")", ":", "return", "instance", ".", "groups_dynamic", ".", "options", "(", "sa", ".", "orm", ".", "eagerload", "(", "cls", ".", "models_proxy", ".", "Group", ".", "resources", ")", ")" ]
Returns a list of groups users belongs to with eager loaded resources owned by those groups :param instance: :return:
[ "Returns", "a", "list", "of", "groups", "users", "belongs", "to", "with", "eager", "loaded", "resources", "owned", "by", "those", "groups" ]
9eeec894d08e8d7defa60ddc04b63f69cd4cbeba
https://github.com/ergo/ziggurat_foundations/blob/9eeec894d08e8d7defa60ddc04b63f69cd4cbeba/ziggurat_foundations/models/services/user.py#L160-L170
train
ergo/ziggurat_foundations
ziggurat_foundations/models/services/user.py
UserService.resources_with_possible_perms
def resources_with_possible_perms( cls, instance, resource_ids=None, resource_types=None, db_session=None ): """ returns list of permissions and resources for this user :param instance: :param resource_ids: restricts the search to specific resources :param resource_t...
python
def resources_with_possible_perms( cls, instance, resource_ids=None, resource_types=None, db_session=None ): """ returns list of permissions and resources for this user :param instance: :param resource_ids: restricts the search to specific resources :param resource_t...
[ "def", "resources_with_possible_perms", "(", "cls", ",", "instance", ",", "resource_ids", "=", "None", ",", "resource_types", "=", "None", ",", "db_session", "=", "None", ")", ":", "perms", "=", "resource_permissions_for_users", "(", "cls", ".", "models_proxy", ...
returns list of permissions and resources for this user :param instance: :param resource_ids: restricts the search to specific resources :param resource_types: restricts the search to specific resource types :param db_session: :return:
[ "returns", "list", "of", "permissions", "and", "resources", "for", "this", "user" ]
9eeec894d08e8d7defa60ddc04b63f69cd4cbeba
https://github.com/ergo/ziggurat_foundations/blob/9eeec894d08e8d7defa60ddc04b63f69cd4cbeba/ziggurat_foundations/models/services/user.py#L173-L207
train
ergo/ziggurat_foundations
ziggurat_foundations/models/services/user.py
UserService.gravatar_url
def gravatar_url(cls, instance, default="mm", **kwargs): """ returns user gravatar url :param instance: :param default: :param kwargs: :return: """ # construct the url hash = hashlib.md5(instance.email.encode("utf8").lower()).hexdigest() i...
python
def gravatar_url(cls, instance, default="mm", **kwargs): """ returns user gravatar url :param instance: :param default: :param kwargs: :return: """ # construct the url hash = hashlib.md5(instance.email.encode("utf8").lower()).hexdigest() i...
[ "def", "gravatar_url", "(", "cls", ",", "instance", ",", "default", "=", "\"mm\"", ",", "*", "*", "kwargs", ")", ":", "# construct the url", "hash", "=", "hashlib", ".", "md5", "(", "instance", ".", "email", ".", "encode", "(", "\"utf8\"", ")", ".", "l...
returns user gravatar url :param instance: :param default: :param kwargs: :return:
[ "returns", "user", "gravatar", "url" ]
9eeec894d08e8d7defa60ddc04b63f69cd4cbeba
https://github.com/ergo/ziggurat_foundations/blob/9eeec894d08e8d7defa60ddc04b63f69cd4cbeba/ziggurat_foundations/models/services/user.py#L210-L229
train
ergo/ziggurat_foundations
ziggurat_foundations/models/services/user.py
UserService.set_password
def set_password(cls, instance, raw_password): """ sets new password on a user using password manager :param instance: :param raw_password: :return: """ # support API for both passlib 1.x and 2.x hash_callable = getattr( instance.passwordmanag...
python
def set_password(cls, instance, raw_password): """ sets new password on a user using password manager :param instance: :param raw_password: :return: """ # support API for both passlib 1.x and 2.x hash_callable = getattr( instance.passwordmanag...
[ "def", "set_password", "(", "cls", ",", "instance", ",", "raw_password", ")", ":", "# support API for both passlib 1.x and 2.x", "hash_callable", "=", "getattr", "(", "instance", ".", "passwordmanager", ",", "\"hash\"", ",", "instance", ".", "passwordmanager", ".", ...
sets new password on a user using password manager :param instance: :param raw_password: :return:
[ "sets", "new", "password", "on", "a", "user", "using", "password", "manager" ]
9eeec894d08e8d7defa60ddc04b63f69cd4cbeba
https://github.com/ergo/ziggurat_foundations/blob/9eeec894d08e8d7defa60ddc04b63f69cd4cbeba/ziggurat_foundations/models/services/user.py#L232-L249
train
ergo/ziggurat_foundations
ziggurat_foundations/models/services/user.py
UserService.check_password
def check_password(cls, instance, raw_password, enable_hash_migration=True): """ checks string with users password hash using password manager :param instance: :param raw_password: :param enable_hash_migration: if legacy hashes should be migrated :return: """ ...
python
def check_password(cls, instance, raw_password, enable_hash_migration=True): """ checks string with users password hash using password manager :param instance: :param raw_password: :param enable_hash_migration: if legacy hashes should be migrated :return: """ ...
[ "def", "check_password", "(", "cls", ",", "instance", ",", "raw_password", ",", "enable_hash_migration", "=", "True", ")", ":", "verified", ",", "replacement_hash", "=", "instance", ".", "passwordmanager", ".", "verify_and_update", "(", "raw_password", ",", "insta...
checks string with users password hash using password manager :param instance: :param raw_password: :param enable_hash_migration: if legacy hashes should be migrated :return:
[ "checks", "string", "with", "users", "password", "hash", "using", "password", "manager" ]
9eeec894d08e8d7defa60ddc04b63f69cd4cbeba
https://github.com/ergo/ziggurat_foundations/blob/9eeec894d08e8d7defa60ddc04b63f69cd4cbeba/ziggurat_foundations/models/services/user.py#L252-L269
train
ergo/ziggurat_foundations
ziggurat_foundations/models/services/user.py
UserService.by_id
def by_id(cls, user_id, db_session=None): """ fetch user by user id :param user_id: :param db_session: :return: """ db_session = get_db_session(db_session) query = db_session.query(cls.model) query = query.filter(cls.model.id == user_id) q...
python
def by_id(cls, user_id, db_session=None): """ fetch user by user id :param user_id: :param db_session: :return: """ db_session = get_db_session(db_session) query = db_session.query(cls.model) query = query.filter(cls.model.id == user_id) q...
[ "def", "by_id", "(", "cls", ",", "user_id", ",", "db_session", "=", "None", ")", ":", "db_session", "=", "get_db_session", "(", "db_session", ")", "query", "=", "db_session", ".", "query", "(", "cls", ".", "model", ")", "query", "=", "query", ".", "fil...
fetch user by user id :param user_id: :param db_session: :return:
[ "fetch", "user", "by", "user", "id" ]
9eeec894d08e8d7defa60ddc04b63f69cd4cbeba
https://github.com/ergo/ziggurat_foundations/blob/9eeec894d08e8d7defa60ddc04b63f69cd4cbeba/ziggurat_foundations/models/services/user.py#L301-L313
train
ergo/ziggurat_foundations
ziggurat_foundations/models/services/user.py
UserService.by_user_name_and_security_code
def by_user_name_and_security_code(cls, user_name, security_code, db_session=None): """ fetch user objects by user name and security code :param user_name: :param security_code: :param db_session: :return: """ db_session = get_db_session(db_session) ...
python
def by_user_name_and_security_code(cls, user_name, security_code, db_session=None): """ fetch user objects by user name and security code :param user_name: :param security_code: :param db_session: :return: """ db_session = get_db_session(db_session) ...
[ "def", "by_user_name_and_security_code", "(", "cls", ",", "user_name", ",", "security_code", ",", "db_session", "=", "None", ")", ":", "db_session", "=", "get_db_session", "(", "db_session", ")", "query", "=", "db_session", ".", "query", "(", "cls", ".", "mode...
fetch user objects by user name and security code :param user_name: :param security_code: :param db_session: :return:
[ "fetch", "user", "objects", "by", "user", "name", "and", "security", "code" ]
9eeec894d08e8d7defa60ddc04b63f69cd4cbeba
https://github.com/ergo/ziggurat_foundations/blob/9eeec894d08e8d7defa60ddc04b63f69cd4cbeba/ziggurat_foundations/models/services/user.py#L333-L348
train
ergo/ziggurat_foundations
ziggurat_foundations/models/services/user.py
UserService.by_user_names
def by_user_names(cls, user_names, db_session=None): """ fetch user objects by user names :param user_names: :param db_session: :return: """ user_names = [(name or "").lower() for name in user_names] db_session = get_db_session(db_session) query =...
python
def by_user_names(cls, user_names, db_session=None): """ fetch user objects by user names :param user_names: :param db_session: :return: """ user_names = [(name or "").lower() for name in user_names] db_session = get_db_session(db_session) query =...
[ "def", "by_user_names", "(", "cls", ",", "user_names", ",", "db_session", "=", "None", ")", ":", "user_names", "=", "[", "(", "name", "or", "\"\"", ")", ".", "lower", "(", ")", "for", "name", "in", "user_names", "]", "db_session", "=", "get_db_session", ...
fetch user objects by user names :param user_names: :param db_session: :return:
[ "fetch", "user", "objects", "by", "user", "names" ]
9eeec894d08e8d7defa60ddc04b63f69cd4cbeba
https://github.com/ergo/ziggurat_foundations/blob/9eeec894d08e8d7defa60ddc04b63f69cd4cbeba/ziggurat_foundations/models/services/user.py#L351-L364
train
ergo/ziggurat_foundations
ziggurat_foundations/models/services/user.py
UserService.user_names_like
def user_names_like(cls, user_name, db_session=None): """ fetch users with similar names using LIKE clause :param user_name: :param db_session: :return: """ db_session = get_db_session(db_session) query = db_session.query(cls.model) query = query....
python
def user_names_like(cls, user_name, db_session=None): """ fetch users with similar names using LIKE clause :param user_name: :param db_session: :return: """ db_session = get_db_session(db_session) query = db_session.query(cls.model) query = query....
[ "def", "user_names_like", "(", "cls", ",", "user_name", ",", "db_session", "=", "None", ")", ":", "db_session", "=", "get_db_session", "(", "db_session", ")", "query", "=", "db_session", ".", "query", "(", "cls", ".", "model", ")", "query", "=", "query", ...
fetch users with similar names using LIKE clause :param user_name: :param db_session: :return:
[ "fetch", "users", "with", "similar", "names", "using", "LIKE", "clause" ]
9eeec894d08e8d7defa60ddc04b63f69cd4cbeba
https://github.com/ergo/ziggurat_foundations/blob/9eeec894d08e8d7defa60ddc04b63f69cd4cbeba/ziggurat_foundations/models/services/user.py#L367-L382
train
ergo/ziggurat_foundations
ziggurat_foundations/models/services/user.py
UserService.by_email
def by_email(cls, email, db_session=None): """ fetch user object by email :param email: :param db_session: :return: """ db_session = get_db_session(db_session) query = db_session.query(cls.model).filter( sa.func.lower(cls.model.email) == (emai...
python
def by_email(cls, email, db_session=None): """ fetch user object by email :param email: :param db_session: :return: """ db_session = get_db_session(db_session) query = db_session.query(cls.model).filter( sa.func.lower(cls.model.email) == (emai...
[ "def", "by_email", "(", "cls", ",", "email", ",", "db_session", "=", "None", ")", ":", "db_session", "=", "get_db_session", "(", "db_session", ")", "query", "=", "db_session", ".", "query", "(", "cls", ".", "model", ")", ".", "filter", "(", "sa", ".", ...
fetch user object by email :param email: :param db_session: :return:
[ "fetch", "user", "object", "by", "email" ]
9eeec894d08e8d7defa60ddc04b63f69cd4cbeba
https://github.com/ergo/ziggurat_foundations/blob/9eeec894d08e8d7defa60ddc04b63f69cd4cbeba/ziggurat_foundations/models/services/user.py#L385-L398
train
ergo/ziggurat_foundations
ziggurat_foundations/models/services/user.py
UserService.users_for_perms
def users_for_perms(cls, perm_names, db_session=None): """ return users hat have one of given permissions :param perm_names: :param db_session: :return: """ db_session = get_db_session(db_session) query = db_session.query(cls.model) query = query....
python
def users_for_perms(cls, perm_names, db_session=None): """ return users hat have one of given permissions :param perm_names: :param db_session: :return: """ db_session = get_db_session(db_session) query = db_session.query(cls.model) query = query....
[ "def", "users_for_perms", "(", "cls", ",", "perm_names", ",", "db_session", "=", "None", ")", ":", "db_session", "=", "get_db_session", "(", "db_session", ")", "query", "=", "db_session", ".", "query", "(", "cls", ".", "model", ")", "query", "=", "query", ...
return users hat have one of given permissions :param perm_names: :param db_session: :return:
[ "return", "users", "hat", "have", "one", "of", "given", "permissions" ]
9eeec894d08e8d7defa60ddc04b63f69cd4cbeba
https://github.com/ergo/ziggurat_foundations/blob/9eeec894d08e8d7defa60ddc04b63f69cd4cbeba/ziggurat_foundations/models/services/user.py#L419-L446
train
stephenmcd/gnotty
gnotty/bots/commands.py
CommandMixin.handle_joined
def handle_joined(self, connection, event): """ Store join times for current nicknames when we first join. """ nicknames = [s.lstrip("@+") for s in event.arguments()[-1].split()] for nickname in nicknames: self.joined[nickname] = datetime.now()
python
def handle_joined(self, connection, event): """ Store join times for current nicknames when we first join. """ nicknames = [s.lstrip("@+") for s in event.arguments()[-1].split()] for nickname in nicknames: self.joined[nickname] = datetime.now()
[ "def", "handle_joined", "(", "self", ",", "connection", ",", "event", ")", ":", "nicknames", "=", "[", "s", ".", "lstrip", "(", "\"@+\"", ")", "for", "s", "in", "event", ".", "arguments", "(", ")", "[", "-", "1", "]", ".", "split", "(", ")", "]",...
Store join times for current nicknames when we first join.
[ "Store", "join", "times", "for", "current", "nicknames", "when", "we", "first", "join", "." ]
bea3762dc9cbc3cb21a5ae7224091cf027273c40
https://github.com/stephenmcd/gnotty/blob/bea3762dc9cbc3cb21a5ae7224091cf027273c40/gnotty/bots/commands.py#L20-L26
train
stephenmcd/gnotty
gnotty/bots/commands.py
CommandMixin.handle_join
def handle_join(self, connection, event): """ Store join time for a nickname when it joins. """ nickname = self.get_nickname(event) self.joined[nickname] = datetime.now()
python
def handle_join(self, connection, event): """ Store join time for a nickname when it joins. """ nickname = self.get_nickname(event) self.joined[nickname] = datetime.now()
[ "def", "handle_join", "(", "self", ",", "connection", ",", "event", ")", ":", "nickname", "=", "self", ".", "get_nickname", "(", "event", ")", "self", ".", "joined", "[", "nickname", "]", "=", "datetime", ".", "now", "(", ")" ]
Store join time for a nickname when it joins.
[ "Store", "join", "time", "for", "a", "nickname", "when", "it", "joins", "." ]
bea3762dc9cbc3cb21a5ae7224091cf027273c40
https://github.com/stephenmcd/gnotty/blob/bea3762dc9cbc3cb21a5ae7224091cf027273c40/gnotty/bots/commands.py#L29-L34
train
stephenmcd/gnotty
gnotty/bots/commands.py
CommandMixin.handle_quit
def handle_quit(self, connection, event): """ Store quit time for a nickname when it quits. """ nickname = self.get_nickname(event) self.quit[nickname] = datetime.now() del self.joined[nickname]
python
def handle_quit(self, connection, event): """ Store quit time for a nickname when it quits. """ nickname = self.get_nickname(event) self.quit[nickname] = datetime.now() del self.joined[nickname]
[ "def", "handle_quit", "(", "self", ",", "connection", ",", "event", ")", ":", "nickname", "=", "self", ".", "get_nickname", "(", "event", ")", "self", ".", "quit", "[", "nickname", "]", "=", "datetime", ".", "now", "(", ")", "del", "self", ".", "join...
Store quit time for a nickname when it quits.
[ "Store", "quit", "time", "for", "a", "nickname", "when", "it", "quits", "." ]
bea3762dc9cbc3cb21a5ae7224091cf027273c40
https://github.com/stephenmcd/gnotty/blob/bea3762dc9cbc3cb21a5ae7224091cf027273c40/gnotty/bots/commands.py#L37-L43
train
stephenmcd/gnotty
gnotty/bots/commands.py
CommandMixin.timesince
def timesince(self, when): """ Returns human friendly version of the timespan between now and the given datetime. """ units = ( ("year", 60 * 60 * 24 * 365), ("week", 60 * 60 * 24 * 7), ("day", 60 * 60 * 24), ("hour", 60 * ...
python
def timesince(self, when): """ Returns human friendly version of the timespan between now and the given datetime. """ units = ( ("year", 60 * 60 * 24 * 365), ("week", 60 * 60 * 24 * 7), ("day", 60 * 60 * 24), ("hour", 60 * ...
[ "def", "timesince", "(", "self", ",", "when", ")", ":", "units", "=", "(", "(", "\"year\"", ",", "60", "*", "60", "*", "24", "*", "365", ")", ",", "(", "\"week\"", ",", "60", "*", "60", "*", "24", "*", "7", ")", ",", "(", "\"day\"", ",", "6...
Returns human friendly version of the timespan between now and the given datetime.
[ "Returns", "human", "friendly", "version", "of", "the", "timespan", "between", "now", "and", "the", "given", "datetime", "." ]
bea3762dc9cbc3cb21a5ae7224091cf027273c40
https://github.com/stephenmcd/gnotty/blob/bea3762dc9cbc3cb21a5ae7224091cf027273c40/gnotty/bots/commands.py#L45-L67
train
stephenmcd/gnotty
gnotty/bots/commands.py
CommandMixin.version
def version(self, event): """ Shows version information. """ name = "%s.%s" % (self.__class__.__module__, self.__class__.__name__) return "%s [%s]" % (settings.GNOTTY_VERSION_STRING, name)
python
def version(self, event): """ Shows version information. """ name = "%s.%s" % (self.__class__.__module__, self.__class__.__name__) return "%s [%s]" % (settings.GNOTTY_VERSION_STRING, name)
[ "def", "version", "(", "self", ",", "event", ")", ":", "name", "=", "\"%s.%s\"", "%", "(", "self", ".", "__class__", ".", "__module__", ",", "self", ".", "__class__", ".", "__name__", ")", "return", "\"%s [%s]\"", "%", "(", "settings", ".", "GNOTTY_VERSI...
Shows version information.
[ "Shows", "version", "information", "." ]
bea3762dc9cbc3cb21a5ae7224091cf027273c40
https://github.com/stephenmcd/gnotty/blob/bea3762dc9cbc3cb21a5ae7224091cf027273c40/gnotty/bots/commands.py#L78-L83
train
stephenmcd/gnotty
gnotty/bots/commands.py
CommandMixin.commands
def commands(self, event): """ Lists all available commands. """ commands = sorted(self.commands_dict().keys()) return "Available commands: %s" % " ".join(commands)
python
def commands(self, event): """ Lists all available commands. """ commands = sorted(self.commands_dict().keys()) return "Available commands: %s" % " ".join(commands)
[ "def", "commands", "(", "self", ",", "event", ")", ":", "commands", "=", "sorted", "(", "self", ".", "commands_dict", "(", ")", ".", "keys", "(", ")", ")", "return", "\"Available commands: %s\"", "%", "\" \"", ".", "join", "(", "commands", ")" ]
Lists all available commands.
[ "Lists", "all", "available", "commands", "." ]
bea3762dc9cbc3cb21a5ae7224091cf027273c40
https://github.com/stephenmcd/gnotty/blob/bea3762dc9cbc3cb21a5ae7224091cf027273c40/gnotty/bots/commands.py#L86-L91
train
stephenmcd/gnotty
gnotty/bots/commands.py
CommandMixin.help
def help(self, event, command_name=None): """ Shows the help message for the bot. Takes an optional command name which when given, will show help for that command. """ if command_name is None: return ("Type !commands for a list of all commands. Type " ...
python
def help(self, event, command_name=None): """ Shows the help message for the bot. Takes an optional command name which when given, will show help for that command. """ if command_name is None: return ("Type !commands for a list of all commands. Type " ...
[ "def", "help", "(", "self", ",", "event", ",", "command_name", "=", "None", ")", ":", "if", "command_name", "is", "None", ":", "return", "(", "\"Type !commands for a list of all commands. Type \"", "\"!help [command] to see help for a specific command.\"", ")", "try", "...
Shows the help message for the bot. Takes an optional command name which when given, will show help for that command.
[ "Shows", "the", "help", "message", "for", "the", "bot", ".", "Takes", "an", "optional", "command", "name", "which", "when", "given", "will", "show", "help", "for", "that", "command", "." ]
bea3762dc9cbc3cb21a5ae7224091cf027273c40
https://github.com/stephenmcd/gnotty/blob/bea3762dc9cbc3cb21a5ae7224091cf027273c40/gnotty/bots/commands.py#L94-L114
train
stephenmcd/gnotty
gnotty/bots/commands.py
CommandMixin.uptime
def uptime(self, event, nickname=None): """ Shows the amount of time since the given nickname has been in the channel. If no nickname is given, I'll use my own. """ if nickname and nickname != self.nickname: try: uptime = self.timesince(self.joined[nic...
python
def uptime(self, event, nickname=None): """ Shows the amount of time since the given nickname has been in the channel. If no nickname is given, I'll use my own. """ if nickname and nickname != self.nickname: try: uptime = self.timesince(self.joined[nic...
[ "def", "uptime", "(", "self", ",", "event", ",", "nickname", "=", "None", ")", ":", "if", "nickname", "and", "nickname", "!=", "self", ".", "nickname", ":", "try", ":", "uptime", "=", "self", ".", "timesince", "(", "self", ".", "joined", "[", "nickna...
Shows the amount of time since the given nickname has been in the channel. If no nickname is given, I'll use my own.
[ "Shows", "the", "amount", "of", "time", "since", "the", "given", "nickname", "has", "been", "in", "the", "channel", ".", "If", "no", "nickname", "is", "given", "I", "ll", "use", "my", "own", "." ]
bea3762dc9cbc3cb21a5ae7224091cf027273c40
https://github.com/stephenmcd/gnotty/blob/bea3762dc9cbc3cb21a5ae7224091cf027273c40/gnotty/bots/commands.py#L117-L134
train
stephenmcd/gnotty
gnotty/bots/commands.py
CommandMixin.seen
def seen(self, event, nickname): """ Shows the amount of time since the given nickname was last seen in the channel. """ try: self.joined[nickname] except KeyError: pass else: if nickname == self.get_nickname(event): ...
python
def seen(self, event, nickname): """ Shows the amount of time since the given nickname was last seen in the channel. """ try: self.joined[nickname] except KeyError: pass else: if nickname == self.get_nickname(event): ...
[ "def", "seen", "(", "self", ",", "event", ",", "nickname", ")", ":", "try", ":", "self", ".", "joined", "[", "nickname", "]", "except", "KeyError", ":", "pass", "else", ":", "if", "nickname", "==", "self", ".", "get_nickname", "(", "event", ")", ":",...
Shows the amount of time since the given nickname was last seen in the channel.
[ "Shows", "the", "amount", "of", "time", "since", "the", "given", "nickname", "was", "last", "seen", "in", "the", "channel", "." ]
bea3762dc9cbc3cb21a5ae7224091cf027273c40
https://github.com/stephenmcd/gnotty/blob/bea3762dc9cbc3cb21a5ae7224091cf027273c40/gnotty/bots/commands.py#L137-L157
train