repository_name stringlengths 7 55 | func_path_in_repository stringlengths 4 223 | func_name stringlengths 1 134 | whole_func_string stringlengths 75 104k | language stringclasses 1
value | func_code_string stringlengths 75 104k | func_code_tokens listlengths 19 28.4k | func_documentation_string stringlengths 1 46.9k | func_documentation_tokens listlengths 1 1.97k | split_name stringclasses 1
value | func_code_url stringlengths 87 315 |
|---|---|---|---|---|---|---|---|---|---|---|
tadashi-aikawa/owlmixin | owlmixin/owlcollections.py | TList.uniq_by | def uniq_by(self, func: Callable[[T], Any]) -> 'TList[T]':
"""
Usage:
>>> TList([1, 2, 3, -2, -1]).uniq_by(lambda x: x**2)
[1, 2, 3]
"""
rs = TList()
for e in self:
if func(e) not in rs.map(func):
rs.append(e)
return rs | python | def uniq_by(self, func: Callable[[T], Any]) -> 'TList[T]':
"""
Usage:
>>> TList([1, 2, 3, -2, -1]).uniq_by(lambda x: x**2)
[1, 2, 3]
"""
rs = TList()
for e in self:
if func(e) not in rs.map(func):
rs.append(e)
return rs | [
"def",
"uniq_by",
"(",
"self",
",",
"func",
":",
"Callable",
"[",
"[",
"T",
"]",
",",
"Any",
"]",
")",
"->",
"'TList[T]'",
":",
"rs",
"=",
"TList",
"(",
")",
"for",
"e",
"in",
"self",
":",
"if",
"func",
"(",
"e",
")",
"not",
"in",
"rs",
".",
... | Usage:
>>> TList([1, 2, 3, -2, -1]).uniq_by(lambda x: x**2)
[1, 2, 3] | [
"Usage",
":"
] | train | https://github.com/tadashi-aikawa/owlmixin/blob/7c4a042c3008abddc56a8e8e55ae930d276071f5/owlmixin/owlcollections.py#L164-L175 |
tadashi-aikawa/owlmixin | owlmixin/owlcollections.py | TList.group_by | def group_by(self, to_key):
"""
:param to_key:
:type to_key: T -> unicode
:rtype: TDict[TList[T]]
Usage:
>>> TList([1, 2, 3, 4, 5]).group_by(lambda x: x % 2).to_json()
'{"0": [2,4],"1": [1,3,5]}'
"""
ret = TDict()
for v in self:
... | python | def group_by(self, to_key):
"""
:param to_key:
:type to_key: T -> unicode
:rtype: TDict[TList[T]]
Usage:
>>> TList([1, 2, 3, 4, 5]).group_by(lambda x: x % 2).to_json()
'{"0": [2,4],"1": [1,3,5]}'
"""
ret = TDict()
for v in self:
... | [
"def",
"group_by",
"(",
"self",
",",
"to_key",
")",
":",
"ret",
"=",
"TDict",
"(",
")",
"for",
"v",
"in",
"self",
":",
"k",
"=",
"to_key",
"(",
"v",
")",
"ret",
".",
"setdefault",
"(",
"k",
",",
"TList",
"(",
")",
")",
"ret",
"[",
"k",
"]",
... | :param to_key:
:type to_key: T -> unicode
:rtype: TDict[TList[T]]
Usage:
>>> TList([1, 2, 3, 4, 5]).group_by(lambda x: x % 2).to_json()
'{"0": [2,4],"1": [1,3,5]}' | [
":",
"param",
"to_key",
":",
":",
"type",
"to_key",
":",
"T",
"-",
">",
"unicode",
":",
"rtype",
":",
"TDict",
"[",
"TList",
"[",
"T",
"]]"
] | train | https://github.com/tadashi-aikawa/owlmixin/blob/7c4a042c3008abddc56a8e8e55ae930d276071f5/owlmixin/owlcollections.py#L190-L206 |
tadashi-aikawa/owlmixin | owlmixin/owlcollections.py | TList.key_by | def key_by(self, to_key: Callable[[T], str]) -> 'TDict[T]':
"""
:param to_key: value -> key
Usage:
>>> TList(['a1', 'b2', 'c3']).key_by(lambda x: x[0]).to_json()
'{"a": "a1","b": "b2","c": "c3"}'
>>> TList([1, 2, 3, 4, 5]).key_by(lambda x: x % 2).to_json()
... | python | def key_by(self, to_key: Callable[[T], str]) -> 'TDict[T]':
"""
:param to_key: value -> key
Usage:
>>> TList(['a1', 'b2', 'c3']).key_by(lambda x: x[0]).to_json()
'{"a": "a1","b": "b2","c": "c3"}'
>>> TList([1, 2, 3, 4, 5]).key_by(lambda x: x % 2).to_json()
... | [
"def",
"key_by",
"(",
"self",
",",
"to_key",
":",
"Callable",
"[",
"[",
"T",
"]",
",",
"str",
"]",
")",
"->",
"'TDict[T]'",
":",
"return",
"TDict",
"(",
"{",
"to_key",
"(",
"x",
")",
":",
"x",
"for",
"x",
"in",
"self",
"}",
")"
] | :param to_key: value -> key
Usage:
>>> TList(['a1', 'b2', 'c3']).key_by(lambda x: x[0]).to_json()
'{"a": "a1","b": "b2","c": "c3"}'
>>> TList([1, 2, 3, 4, 5]).key_by(lambda x: x % 2).to_json()
'{"0": 4,"1": 5}' | [
":",
"param",
"to_key",
":",
"value",
"-",
">",
"key",
"Usage",
":"
] | train | https://github.com/tadashi-aikawa/owlmixin/blob/7c4a042c3008abddc56a8e8e55ae930d276071f5/owlmixin/owlcollections.py#L208-L218 |
tadashi-aikawa/owlmixin | owlmixin/owlcollections.py | TList.order_by | def order_by(self, func, reverse=False):
"""
:param func:
:type func: T -> any
:param reverse: Sort by descend order if True, else by ascend
:type reverse: bool
:rtype: TList[T]
Usage:
>>> TList([12, 25, 31, 40, 57]).order_by(lambda x: x % 10)
... | python | def order_by(self, func, reverse=False):
"""
:param func:
:type func: T -> any
:param reverse: Sort by descend order if True, else by ascend
:type reverse: bool
:rtype: TList[T]
Usage:
>>> TList([12, 25, 31, 40, 57]).order_by(lambda x: x % 10)
... | [
"def",
"order_by",
"(",
"self",
",",
"func",
",",
"reverse",
"=",
"False",
")",
":",
"return",
"TList",
"(",
"sorted",
"(",
"self",
",",
"key",
"=",
"func",
",",
"reverse",
"=",
"reverse",
")",
")"
] | :param func:
:type func: T -> any
:param reverse: Sort by descend order if True, else by ascend
:type reverse: bool
:rtype: TList[T]
Usage:
>>> TList([12, 25, 31, 40, 57]).order_by(lambda x: x % 10)
[40, 31, 12, 25, 57]
>>> TList([12, 25, 31,... | [
":",
"param",
"func",
":",
":",
"type",
"func",
":",
"T",
"-",
">",
"any",
":",
"param",
"reverse",
":",
"Sort",
"by",
"descend",
"order",
"if",
"True",
"else",
"by",
"ascend",
":",
"type",
"reverse",
":",
"bool",
":",
"rtype",
":",
"TList",
"[",
... | train | https://github.com/tadashi-aikawa/owlmixin/blob/7c4a042c3008abddc56a8e8e55ae930d276071f5/owlmixin/owlcollections.py#L220-L235 |
tadashi-aikawa/owlmixin | owlmixin/owlcollections.py | TList.concat | def concat(self, values, first=False):
"""
:param values:
:type values: TList[T]
:param first:
:type first: bool
:rtype: TList[T]
Usage:
>>> TList([1, 2]).concat(TList([3, 4]))
[1, 2, 3, 4]
>>> TList([1, 2]).concat(TList([3, 4... | python | def concat(self, values, first=False):
"""
:param values:
:type values: TList[T]
:param first:
:type first: bool
:rtype: TList[T]
Usage:
>>> TList([1, 2]).concat(TList([3, 4]))
[1, 2, 3, 4]
>>> TList([1, 2]).concat(TList([3, 4... | [
"def",
"concat",
"(",
"self",
",",
"values",
",",
"first",
"=",
"False",
")",
":",
"return",
"values",
"+",
"self",
"if",
"first",
"else",
"self",
"+",
"values"
] | :param values:
:type values: TList[T]
:param first:
:type first: bool
:rtype: TList[T]
Usage:
>>> TList([1, 2]).concat(TList([3, 4]))
[1, 2, 3, 4]
>>> TList([1, 2]).concat(TList([3, 4]), first=True)
[3, 4, 1, 2] | [
":",
"param",
"values",
":",
":",
"type",
"values",
":",
"TList",
"[",
"T",
"]",
":",
"param",
"first",
":",
":",
"type",
"first",
":",
"bool",
":",
"rtype",
":",
"TList",
"[",
"T",
"]"
] | train | https://github.com/tadashi-aikawa/owlmixin/blob/7c4a042c3008abddc56a8e8e55ae930d276071f5/owlmixin/owlcollections.py#L237-L252 |
tadashi-aikawa/owlmixin | owlmixin/owlcollections.py | TList.find | def find(self, func: Callable[[T], bool]) -> TOption[T]:
"""
Usage:
>>> TList([1, 2, 3, 4, 5]).find(lambda x: x > 3)
Option --> 4
>>> TList([1, 2, 3, 4, 5]).find(lambda x: x > 6)
Option --> None
"""
for x in self:
if func(x):
... | python | def find(self, func: Callable[[T], bool]) -> TOption[T]:
"""
Usage:
>>> TList([1, 2, 3, 4, 5]).find(lambda x: x > 3)
Option --> 4
>>> TList([1, 2, 3, 4, 5]).find(lambda x: x > 6)
Option --> None
"""
for x in self:
if func(x):
... | [
"def",
"find",
"(",
"self",
",",
"func",
":",
"Callable",
"[",
"[",
"T",
"]",
",",
"bool",
"]",
")",
"->",
"TOption",
"[",
"T",
"]",
":",
"for",
"x",
"in",
"self",
":",
"if",
"func",
"(",
"x",
")",
":",
"return",
"TOption",
"(",
"x",
")",
"... | Usage:
>>> TList([1, 2, 3, 4, 5]).find(lambda x: x > 3)
Option --> 4
>>> TList([1, 2, 3, 4, 5]).find(lambda x: x > 6)
Option --> None | [
"Usage",
":"
] | train | https://github.com/tadashi-aikawa/owlmixin/blob/7c4a042c3008abddc56a8e8e55ae930d276071f5/owlmixin/owlcollections.py#L317-L329 |
tadashi-aikawa/owlmixin | owlmixin/owlcollections.py | TDict.get | def get(self, key: K) -> TOption[T]:
"""
:param key:
Usage:
>>> TDict(k1=1, k2=2, k3=3).get("k2")
Option --> 2
>>> TDict(k1=1, k2=2, k3=3).get("unknown")
Option --> None
"""
return TOption(self[key]) if key in self else TOption(No... | python | def get(self, key: K) -> TOption[T]:
"""
:param key:
Usage:
>>> TDict(k1=1, k2=2, k3=3).get("k2")
Option --> 2
>>> TDict(k1=1, k2=2, k3=3).get("unknown")
Option --> None
"""
return TOption(self[key]) if key in self else TOption(No... | [
"def",
"get",
"(",
"self",
",",
"key",
":",
"K",
")",
"->",
"TOption",
"[",
"T",
"]",
":",
"return",
"TOption",
"(",
"self",
"[",
"key",
"]",
")",
"if",
"key",
"in",
"self",
"else",
"TOption",
"(",
"None",
")"
] | :param key:
Usage:
>>> TDict(k1=1, k2=2, k3=3).get("k2")
Option --> 2
>>> TDict(k1=1, k2=2, k3=3).get("unknown")
Option --> None | [
":",
"param",
"key",
":"
] | train | https://github.com/tadashi-aikawa/owlmixin/blob/7c4a042c3008abddc56a8e8e55ae930d276071f5/owlmixin/owlcollections.py#L404-L415 |
tadashi-aikawa/owlmixin | owlmixin/owlcollections.py | TDict.map | def map(self, func):
"""
:param func:
:type func: (K, T) -> U
:rtype: TList[U]
Usage:
>>> sorted(TDict(k1=1, k2=2, k3=3).map(lambda k, v: v*2))
[2, 4, 6]
"""
return TList([func(k, v) for k, v in self.items()]) | python | def map(self, func):
"""
:param func:
:type func: (K, T) -> U
:rtype: TList[U]
Usage:
>>> sorted(TDict(k1=1, k2=2, k3=3).map(lambda k, v: v*2))
[2, 4, 6]
"""
return TList([func(k, v) for k, v in self.items()]) | [
"def",
"map",
"(",
"self",
",",
"func",
")",
":",
"return",
"TList",
"(",
"[",
"func",
"(",
"k",
",",
"v",
")",
"for",
"k",
",",
"v",
"in",
"self",
".",
"items",
"(",
")",
"]",
")"
] | :param func:
:type func: (K, T) -> U
:rtype: TList[U]
Usage:
>>> sorted(TDict(k1=1, k2=2, k3=3).map(lambda k, v: v*2))
[2, 4, 6] | [
":",
"param",
"func",
":",
":",
"type",
"func",
":",
"(",
"K",
"T",
")",
"-",
">",
"U",
":",
"rtype",
":",
"TList",
"[",
"U",
"]"
] | train | https://github.com/tadashi-aikawa/owlmixin/blob/7c4a042c3008abddc56a8e8e55ae930d276071f5/owlmixin/owlcollections.py#L417-L428 |
tadashi-aikawa/owlmixin | owlmixin/owlcollections.py | TDict.map_values | def map_values(self, func):
"""
:param func:
:type func: T -> U
:rtype: TDict[U]
Usage:
>>> TDict(k1=1, k2=2, k3=3).map_values(lambda x: x*2) == {
... "k1": 2,
... "k2": 4,
... "k3": 6
... }
Tru... | python | def map_values(self, func):
"""
:param func:
:type func: T -> U
:rtype: TDict[U]
Usage:
>>> TDict(k1=1, k2=2, k3=3).map_values(lambda x: x*2) == {
... "k1": 2,
... "k2": 4,
... "k3": 6
... }
Tru... | [
"def",
"map_values",
"(",
"self",
",",
"func",
")",
":",
"return",
"TDict",
"(",
"{",
"k",
":",
"func",
"(",
"v",
")",
"for",
"k",
",",
"v",
"in",
"self",
".",
"items",
"(",
")",
"}",
")"
] | :param func:
:type func: T -> U
:rtype: TDict[U]
Usage:
>>> TDict(k1=1, k2=2, k3=3).map_values(lambda x: x*2) == {
... "k1": 2,
... "k2": 4,
... "k3": 6
... }
True | [
":",
"param",
"func",
":",
":",
"type",
"func",
":",
"T",
"-",
">",
"U",
":",
"rtype",
":",
"TDict",
"[",
"U",
"]"
] | train | https://github.com/tadashi-aikawa/owlmixin/blob/7c4a042c3008abddc56a8e8e55ae930d276071f5/owlmixin/owlcollections.py#L430-L445 |
tadashi-aikawa/owlmixin | owlmixin/owlcollections.py | TDict.map_values2 | def map_values2(self, func):
"""
:param func:
:type func: (K, T) -> U
:rtype: TDict[U]
Usage:
>>> TDict(k1=1, k2=2, k3=3).map_values2(lambda k, v: f'{k} -> {v*2}') == {
... "k1": "k1 -> 2",
... "k2": "k2 -> 4",
... "k3... | python | def map_values2(self, func):
"""
:param func:
:type func: (K, T) -> U
:rtype: TDict[U]
Usage:
>>> TDict(k1=1, k2=2, k3=3).map_values2(lambda k, v: f'{k} -> {v*2}') == {
... "k1": "k1 -> 2",
... "k2": "k2 -> 4",
... "k3... | [
"def",
"map_values2",
"(",
"self",
",",
"func",
")",
":",
"return",
"TDict",
"(",
"{",
"k",
":",
"func",
"(",
"k",
",",
"v",
")",
"for",
"k",
",",
"v",
"in",
"self",
".",
"items",
"(",
")",
"}",
")"
] | :param func:
:type func: (K, T) -> U
:rtype: TDict[U]
Usage:
>>> TDict(k1=1, k2=2, k3=3).map_values2(lambda k, v: f'{k} -> {v*2}') == {
... "k1": "k1 -> 2",
... "k2": "k2 -> 4",
... "k3": "k3 -> 6"
... }
True | [
":",
"param",
"func",
":",
":",
"type",
"func",
":",
"(",
"K",
"T",
")",
"-",
">",
"U",
":",
"rtype",
":",
"TDict",
"[",
"U",
"]"
] | train | https://github.com/tadashi-aikawa/owlmixin/blob/7c4a042c3008abddc56a8e8e55ae930d276071f5/owlmixin/owlcollections.py#L447-L462 |
tadashi-aikawa/owlmixin | owlmixin/owlcollections.py | TDict.filter | def filter(self, func):
"""
:param func:
:type func: (K, T) -> bool
:rtype: TList[T]
Usage:
>>> TDict(k1=1, k2=2, k3=3).filter(lambda k, v: v < 2)
[1]
"""
return TList([v for k, v in self.items() if func(k, v)]) | python | def filter(self, func):
"""
:param func:
:type func: (K, T) -> bool
:rtype: TList[T]
Usage:
>>> TDict(k1=1, k2=2, k3=3).filter(lambda k, v: v < 2)
[1]
"""
return TList([v for k, v in self.items() if func(k, v)]) | [
"def",
"filter",
"(",
"self",
",",
"func",
")",
":",
"return",
"TList",
"(",
"[",
"v",
"for",
"k",
",",
"v",
"in",
"self",
".",
"items",
"(",
")",
"if",
"func",
"(",
"k",
",",
"v",
")",
"]",
")"
] | :param func:
:type func: (K, T) -> bool
:rtype: TList[T]
Usage:
>>> TDict(k1=1, k2=2, k3=3).filter(lambda k, v: v < 2)
[1] | [
":",
"param",
"func",
":",
":",
"type",
"func",
":",
"(",
"K",
"T",
")",
"-",
">",
"bool",
":",
"rtype",
":",
"TList",
"[",
"T",
"]"
] | train | https://github.com/tadashi-aikawa/owlmixin/blob/7c4a042c3008abddc56a8e8e55ae930d276071f5/owlmixin/owlcollections.py#L464-L475 |
tadashi-aikawa/owlmixin | owlmixin/owlcollections.py | TDict.reject | def reject(self, func):
"""
:param func:
:type func: (K, T) -> bool
:rtype: TList[T]
Usage:
>>> TDict(k1=1, k2=2, k3=3).reject(lambda k, v: v < 3)
[3]
"""
return TList([v for k, v in self.items() if not func(k, v)]) | python | def reject(self, func):
"""
:param func:
:type func: (K, T) -> bool
:rtype: TList[T]
Usage:
>>> TDict(k1=1, k2=2, k3=3).reject(lambda k, v: v < 3)
[3]
"""
return TList([v for k, v in self.items() if not func(k, v)]) | [
"def",
"reject",
"(",
"self",
",",
"func",
")",
":",
"return",
"TList",
"(",
"[",
"v",
"for",
"k",
",",
"v",
"in",
"self",
".",
"items",
"(",
")",
"if",
"not",
"func",
"(",
"k",
",",
"v",
")",
"]",
")"
] | :param func:
:type func: (K, T) -> bool
:rtype: TList[T]
Usage:
>>> TDict(k1=1, k2=2, k3=3).reject(lambda k, v: v < 3)
[3] | [
":",
"param",
"func",
":",
":",
"type",
"func",
":",
"(",
"K",
"T",
")",
"-",
">",
"bool",
":",
"rtype",
":",
"TList",
"[",
"T",
"]"
] | train | https://github.com/tadashi-aikawa/owlmixin/blob/7c4a042c3008abddc56a8e8e55ae930d276071f5/owlmixin/owlcollections.py#L477-L488 |
tadashi-aikawa/owlmixin | owlmixin/owlcollections.py | TDict.find | def find(self, func: Callable[[K, T], bool]) -> TOption[T]:
"""
Usage:
>>> TDict(k1=1, k2=2, k3=3).find(lambda k, v: v == 2)
Option --> 2
>>> TDict(k1=1, k2=2, k3=3).find(lambda k, v: v == 4)
Option --> None
"""
for k, v in self.items():
... | python | def find(self, func: Callable[[K, T], bool]) -> TOption[T]:
"""
Usage:
>>> TDict(k1=1, k2=2, k3=3).find(lambda k, v: v == 2)
Option --> 2
>>> TDict(k1=1, k2=2, k3=3).find(lambda k, v: v == 4)
Option --> None
"""
for k, v in self.items():
... | [
"def",
"find",
"(",
"self",
",",
"func",
":",
"Callable",
"[",
"[",
"K",
",",
"T",
"]",
",",
"bool",
"]",
")",
"->",
"TOption",
"[",
"T",
"]",
":",
"for",
"k",
",",
"v",
"in",
"self",
".",
"items",
"(",
")",
":",
"if",
"func",
"(",
"k",
"... | Usage:
>>> TDict(k1=1, k2=2, k3=3).find(lambda k, v: v == 2)
Option --> 2
>>> TDict(k1=1, k2=2, k3=3).find(lambda k, v: v == 4)
Option --> None | [
"Usage",
":"
] | train | https://github.com/tadashi-aikawa/owlmixin/blob/7c4a042c3008abddc56a8e8e55ae930d276071f5/owlmixin/owlcollections.py#L525-L537 |
tadashi-aikawa/owlmixin | owlmixin/owlcollections.py | TDict.all | def all(self, func):
"""
:param func:
:type func: (K, T) -> bool
:rtype: bool
Usage:
>>> TDict(k1=1, k2=2, k3=3).all(lambda k, v: v > 0)
True
>>> TDict(k1=1, k2=2, k3=3).all(lambda k, v: v > 1)
False
"""
return all... | python | def all(self, func):
"""
:param func:
:type func: (K, T) -> bool
:rtype: bool
Usage:
>>> TDict(k1=1, k2=2, k3=3).all(lambda k, v: v > 0)
True
>>> TDict(k1=1, k2=2, k3=3).all(lambda k, v: v > 1)
False
"""
return all... | [
"def",
"all",
"(",
"self",
",",
"func",
")",
":",
"return",
"all",
"(",
"[",
"func",
"(",
"k",
",",
"v",
")",
"for",
"k",
",",
"v",
"in",
"self",
".",
"items",
"(",
")",
"]",
")"
] | :param func:
:type func: (K, T) -> bool
:rtype: bool
Usage:
>>> TDict(k1=1, k2=2, k3=3).all(lambda k, v: v > 0)
True
>>> TDict(k1=1, k2=2, k3=3).all(lambda k, v: v > 1)
False | [
":",
"param",
"func",
":",
":",
"type",
"func",
":",
"(",
"K",
"T",
")",
"-",
">",
"bool",
":",
"rtype",
":",
"bool"
] | train | https://github.com/tadashi-aikawa/owlmixin/blob/7c4a042c3008abddc56a8e8e55ae930d276071f5/owlmixin/owlcollections.py#L550-L563 |
tadashi-aikawa/owlmixin | owlmixin/owlcollections.py | TDict.any | def any(self, func):
"""
:param func:
:type func: (K, T) -> bool
:rtype: bool
Usage:
>>> TDict(k1=1, k2=2, k3=3).any(lambda k, v: v > 2)
True
>>> TDict(k1=1, k2=2, k3=3).any(lambda k, v: v > 3)
False
"""
return any... | python | def any(self, func):
"""
:param func:
:type func: (K, T) -> bool
:rtype: bool
Usage:
>>> TDict(k1=1, k2=2, k3=3).any(lambda k, v: v > 2)
True
>>> TDict(k1=1, k2=2, k3=3).any(lambda k, v: v > 3)
False
"""
return any... | [
"def",
"any",
"(",
"self",
",",
"func",
")",
":",
"return",
"any",
"(",
"[",
"func",
"(",
"k",
",",
"v",
")",
"for",
"k",
",",
"v",
"in",
"self",
".",
"items",
"(",
")",
"]",
")"
] | :param func:
:type func: (K, T) -> bool
:rtype: bool
Usage:
>>> TDict(k1=1, k2=2, k3=3).any(lambda k, v: v > 2)
True
>>> TDict(k1=1, k2=2, k3=3).any(lambda k, v: v > 3)
False | [
":",
"param",
"func",
":",
":",
"type",
"func",
":",
"(",
"K",
"T",
")",
"-",
">",
"bool",
":",
"rtype",
":",
"bool"
] | train | https://github.com/tadashi-aikawa/owlmixin/blob/7c4a042c3008abddc56a8e8e55ae930d276071f5/owlmixin/owlcollections.py#L565-L578 |
tadashi-aikawa/owlmixin | owlmixin/owlcollections.py | TDict.pick_by | def pick_by(self, func: Callable[[K, T], bool]) -> 'TDict[T]':
"""
Usage:
>>> TDict(k1=1, k2=2, k3=3).pick_by(lambda k, v: v > 2)
{'k3': 3}
"""
return TDict({k: v for k, v in self.items() if func(k, v)}) | python | def pick_by(self, func: Callable[[K, T], bool]) -> 'TDict[T]':
"""
Usage:
>>> TDict(k1=1, k2=2, k3=3).pick_by(lambda k, v: v > 2)
{'k3': 3}
"""
return TDict({k: v for k, v in self.items() if func(k, v)}) | [
"def",
"pick_by",
"(",
"self",
",",
"func",
":",
"Callable",
"[",
"[",
"K",
",",
"T",
"]",
",",
"bool",
"]",
")",
"->",
"'TDict[T]'",
":",
"return",
"TDict",
"(",
"{",
"k",
":",
"v",
"for",
"k",
",",
"v",
"in",
"self",
".",
"items",
"(",
")",... | Usage:
>>> TDict(k1=1, k2=2, k3=3).pick_by(lambda k, v: v > 2)
{'k3': 3} | [
"Usage",
":"
] | train | https://github.com/tadashi-aikawa/owlmixin/blob/7c4a042c3008abddc56a8e8e55ae930d276071f5/owlmixin/owlcollections.py#L593-L600 |
openstax/rhaptos.cnxmlutils | rhaptos/cnxmlutils/addsectiontags.py | docHandler.storeSectionState | def storeSectionState(self, level):
"""
Takes a header tagname (e.g. 'h1') and adjusts the
stack that remembers the headers seen.
"""
# self.document.append("<!-- storeSectionState(): " + str(len(self.header_stack)) + " open section tags. " + str(self.header_stack) + "-->\n")
... | python | def storeSectionState(self, level):
"""
Takes a header tagname (e.g. 'h1') and adjusts the
stack that remembers the headers seen.
"""
# self.document.append("<!-- storeSectionState(): " + str(len(self.header_stack)) + " open section tags. " + str(self.header_stack) + "-->\n")
... | [
"def",
"storeSectionState",
"(",
"self",
",",
"level",
")",
":",
"# self.document.append(\"<!-- storeSectionState(): \" + str(len(self.header_stack)) + \" open section tags. \" + str(self.header_stack) + \"-->\\n\")",
"try",
":",
"# special case. we are not processing an OOo XML start tag whi... | Takes a header tagname (e.g. 'h1') and adjusts the
stack that remembers the headers seen. | [
"Takes",
"a",
"header",
"tagname",
"(",
"e",
".",
"g",
".",
"h1",
")",
"and",
"adjusts",
"the",
"stack",
"that",
"remembers",
"the",
"headers",
"seen",
"."
] | train | https://github.com/openstax/rhaptos.cnxmlutils/blob/c32b1a7428dc652e8cd745f3fdf4019a20543649/rhaptos/cnxmlutils/addsectiontags.py#L129-L174 |
openstax/rhaptos.cnxmlutils | rhaptos/cnxmlutils/addsectiontags.py | docHandler.endSections | def endSections(self, level=u'0'):
"""Closes all sections of level >= sectnum. Defaults to closing all open sections"""
iSectionsClosed = self.storeSectionState(level)
self.document.append("</section>\n" * iSectionsClosed) | python | def endSections(self, level=u'0'):
"""Closes all sections of level >= sectnum. Defaults to closing all open sections"""
iSectionsClosed = self.storeSectionState(level)
self.document.append("</section>\n" * iSectionsClosed) | [
"def",
"endSections",
"(",
"self",
",",
"level",
"=",
"u'0'",
")",
":",
"iSectionsClosed",
"=",
"self",
".",
"storeSectionState",
"(",
"level",
")",
"self",
".",
"document",
".",
"append",
"(",
"\"</section>\\n\"",
"*",
"iSectionsClosed",
")"
] | Closes all sections of level >= sectnum. Defaults to closing all open sections | [
"Closes",
"all",
"sections",
"of",
"level",
">",
"=",
"sectnum",
".",
"Defaults",
"to",
"closing",
"all",
"open",
"sections"
] | train | https://github.com/openstax/rhaptos.cnxmlutils/blob/c32b1a7428dc652e8cd745f3fdf4019a20543649/rhaptos/cnxmlutils/addsectiontags.py#L176-L180 |
tadashi-aikawa/owlmixin | owlmixin/transformers.py | DictTransformer.to_dict | def to_dict(self, ignore_none: bool=True, force_value: bool=True, ignore_empty: bool=False) -> dict:
"""From instance to dict
:param ignore_none: Properties which is None are excluded if True
:param force_value: Transform to value using to_value (default: str()) of ValueTransformer which inheri... | python | def to_dict(self, ignore_none: bool=True, force_value: bool=True, ignore_empty: bool=False) -> dict:
"""From instance to dict
:param ignore_none: Properties which is None are excluded if True
:param force_value: Transform to value using to_value (default: str()) of ValueTransformer which inheri... | [
"def",
"to_dict",
"(",
"self",
",",
"ignore_none",
":",
"bool",
"=",
"True",
",",
"force_value",
":",
"bool",
"=",
"True",
",",
"ignore_empty",
":",
"bool",
"=",
"False",
")",
"->",
"dict",
":",
"return",
"traverse_dict",
"(",
"self",
".",
"_dict",
","... | From instance to dict
:param ignore_none: Properties which is None are excluded if True
:param force_value: Transform to value using to_value (default: str()) of ValueTransformer which inherited if True
:param ignore_empty: Properties which is empty are excluded if True
:return: Dict
... | [
"From",
"instance",
"to",
"dict"
] | train | https://github.com/tadashi-aikawa/owlmixin/blob/7c4a042c3008abddc56a8e8e55ae930d276071f5/owlmixin/transformers.py#L76-L123 |
tadashi-aikawa/owlmixin | owlmixin/transformers.py | DictsTransformer.to_dicts | def to_dicts(self, ignore_none: bool=True, force_value: bool=True, ignore_empty: bool=False) -> List[dict]:
"""From instance to dict
:param ignore_none: Properties which is None are excluded if True
:param force_value: Transform to value using to_value (default: str()) of ValueTransformer which... | python | def to_dicts(self, ignore_none: bool=True, force_value: bool=True, ignore_empty: bool=False) -> List[dict]:
"""From instance to dict
:param ignore_none: Properties which is None are excluded if True
:param force_value: Transform to value using to_value (default: str()) of ValueTransformer which... | [
"def",
"to_dicts",
"(",
"self",
",",
"ignore_none",
":",
"bool",
"=",
"True",
",",
"force_value",
":",
"bool",
"=",
"True",
",",
"ignore_empty",
":",
"bool",
"=",
"False",
")",
"->",
"List",
"[",
"dict",
"]",
":",
"return",
"traverse_list",
"(",
"self"... | From instance to dict
:param ignore_none: Properties which is None are excluded if True
:param force_value: Transform to value using to_value (default: str()) of ValueTransformer which inherited if True
:param ignore_empty: Properties which is empty are excluded if True
:return: List[Di... | [
"From",
"instance",
"to",
"dict"
] | train | https://github.com/tadashi-aikawa/owlmixin/blob/7c4a042c3008abddc56a8e8e55ae930d276071f5/owlmixin/transformers.py#L130-L187 |
tadashi-aikawa/owlmixin | owlmixin/transformers.py | JsonTransformer.to_json | def to_json(self, indent: int=None, ignore_none: bool=True, ignore_empty: bool=False) -> str:
"""From instance to json string
:param indent: Number of indentation
:param ignore_none: Properties which is None are excluded if True
:param ignore_empty: Properties which is empty are exclude... | python | def to_json(self, indent: int=None, ignore_none: bool=True, ignore_empty: bool=False) -> str:
"""From instance to json string
:param indent: Number of indentation
:param ignore_none: Properties which is None are excluded if True
:param ignore_empty: Properties which is empty are exclude... | [
"def",
"to_json",
"(",
"self",
",",
"indent",
":",
"int",
"=",
"None",
",",
"ignore_none",
":",
"bool",
"=",
"True",
",",
"ignore_empty",
":",
"bool",
"=",
"False",
")",
"->",
"str",
":",
"return",
"util",
".",
"dump_json",
"(",
"traverse",
"(",
"sel... | From instance to json string
:param indent: Number of indentation
:param ignore_none: Properties which is None are excluded if True
:param ignore_empty: Properties which is empty are excluded if True
:return: Json string
Usage:
>>> from owlmixin.samples import Huma... | [
"From",
"instance",
"to",
"json",
"string"
] | train | https://github.com/tadashi-aikawa/owlmixin/blob/7c4a042c3008abddc56a8e8e55ae930d276071f5/owlmixin/transformers.py#L194-L216 |
tadashi-aikawa/owlmixin | owlmixin/transformers.py | JsonTransformer.to_jsonf | def to_jsonf(self, fpath: str, encoding: str='utf8', indent: int=None, ignore_none: bool=True, ignore_empty: bool=False) -> str:
"""From instance to json file
:param fpath: Json file path
:param encoding: Json file encoding
:param indent: Number of indentation
:param ignore_none... | python | def to_jsonf(self, fpath: str, encoding: str='utf8', indent: int=None, ignore_none: bool=True, ignore_empty: bool=False) -> str:
"""From instance to json file
:param fpath: Json file path
:param encoding: Json file encoding
:param indent: Number of indentation
:param ignore_none... | [
"def",
"to_jsonf",
"(",
"self",
",",
"fpath",
":",
"str",
",",
"encoding",
":",
"str",
"=",
"'utf8'",
",",
"indent",
":",
"int",
"=",
"None",
",",
"ignore_none",
":",
"bool",
"=",
"True",
",",
"ignore_empty",
":",
"bool",
"=",
"False",
")",
"->",
"... | From instance to json file
:param fpath: Json file path
:param encoding: Json file encoding
:param indent: Number of indentation
:param ignore_none: Properties which is None are excluded if True
:param ignore_empty: Properties which is empty are excluded if True
:return:... | [
"From",
"instance",
"to",
"json",
"file"
] | train | https://github.com/tadashi-aikawa/owlmixin/blob/7c4a042c3008abddc56a8e8e55ae930d276071f5/owlmixin/transformers.py#L218-L228 |
tadashi-aikawa/owlmixin | owlmixin/transformers.py | JsonTransformer.to_pretty_json | def to_pretty_json(self, ignore_none: bool=True, ignore_empty: bool=False) -> str:
"""From instance to pretty json string
:param ignore_none: Properties which is None are excluded if True
:param ignore_empty: Properties which is empty are excluded if True
:return: Json string
U... | python | def to_pretty_json(self, ignore_none: bool=True, ignore_empty: bool=False) -> str:
"""From instance to pretty json string
:param ignore_none: Properties which is None are excluded if True
:param ignore_empty: Properties which is empty are excluded if True
:return: Json string
U... | [
"def",
"to_pretty_json",
"(",
"self",
",",
"ignore_none",
":",
"bool",
"=",
"True",
",",
"ignore_empty",
":",
"bool",
"=",
"False",
")",
"->",
"str",
":",
"return",
"self",
".",
"to_json",
"(",
"4",
",",
"ignore_none",
",",
"ignore_empty",
")"
] | From instance to pretty json string
:param ignore_none: Properties which is None are excluded if True
:param ignore_empty: Properties which is empty are excluded if True
:return: Json string
Usage:
>>> from owlmixin.samples import Human
>>> human = Human.from_d... | [
"From",
"instance",
"to",
"pretty",
"json",
"string"
] | train | https://github.com/tadashi-aikawa/owlmixin/blob/7c4a042c3008abddc56a8e8e55ae930d276071f5/owlmixin/transformers.py#L230-L266 |
tadashi-aikawa/owlmixin | owlmixin/transformers.py | YamlTransformer.to_yaml | def to_yaml(self, ignore_none: bool=True, ignore_empty: bool=False) -> str:
"""From instance to yaml string
:param ignore_none: Properties which is None are excluded if True
:param ignore_empty: Properties which is empty are excluded if True
:return: Yaml string
Usage:
... | python | def to_yaml(self, ignore_none: bool=True, ignore_empty: bool=False) -> str:
"""From instance to yaml string
:param ignore_none: Properties which is None are excluded if True
:param ignore_empty: Properties which is empty are excluded if True
:return: Yaml string
Usage:
... | [
"def",
"to_yaml",
"(",
"self",
",",
"ignore_none",
":",
"bool",
"=",
"True",
",",
"ignore_empty",
":",
"bool",
"=",
"False",
")",
"->",
"str",
":",
"return",
"util",
".",
"dump_yaml",
"(",
"traverse",
"(",
"self",
",",
"ignore_none",
",",
"force_value",
... | From instance to yaml string
:param ignore_none: Properties which is None are excluded if True
:param ignore_empty: Properties which is empty are excluded if True
:return: Yaml string
Usage:
>>> from owlmixin.samples import Human
>>> human = Human.from_dict({
... | [
"From",
"instance",
"to",
"yaml",
"string"
] | train | https://github.com/tadashi-aikawa/owlmixin/blob/7c4a042c3008abddc56a8e8e55ae930d276071f5/owlmixin/transformers.py#L273-L302 |
tadashi-aikawa/owlmixin | owlmixin/transformers.py | YamlTransformer.to_yamlf | def to_yamlf(self, fpath: str, encoding: str='utf8', ignore_none: bool=True, ignore_empty: bool=False) -> str:
"""From instance to yaml file
:param ignore_none: Properties which is None are excluded if True
:param fpath: Yaml file path
:param encoding: Yaml file encoding
:return... | python | def to_yamlf(self, fpath: str, encoding: str='utf8', ignore_none: bool=True, ignore_empty: bool=False) -> str:
"""From instance to yaml file
:param ignore_none: Properties which is None are excluded if True
:param fpath: Yaml file path
:param encoding: Yaml file encoding
:return... | [
"def",
"to_yamlf",
"(",
"self",
",",
"fpath",
":",
"str",
",",
"encoding",
":",
"str",
"=",
"'utf8'",
",",
"ignore_none",
":",
"bool",
"=",
"True",
",",
"ignore_empty",
":",
"bool",
"=",
"False",
")",
"->",
"str",
":",
"return",
"util",
".",
"save_ya... | From instance to yaml file
:param ignore_none: Properties which is None are excluded if True
:param fpath: Yaml file path
:param encoding: Yaml file encoding
:return: Yaml file path | [
"From",
"instance",
"to",
"yaml",
"file"
] | train | https://github.com/tadashi-aikawa/owlmixin/blob/7c4a042c3008abddc56a8e8e55ae930d276071f5/owlmixin/transformers.py#L304-L312 |
tadashi-aikawa/owlmixin | owlmixin/transformers.py | CsvTransformer.to_csv | def to_csv(self, fieldnames: Sequence[str], with_header: bool=False, crlf: bool=False, tsv: bool=False) -> str:
"""From sequence of text to csv string
:param fieldnames: Order of columns by property name
:param with_header: Add headers at the first line if True
:param crlf: Add CRLF lin... | python | def to_csv(self, fieldnames: Sequence[str], with_header: bool=False, crlf: bool=False, tsv: bool=False) -> str:
"""From sequence of text to csv string
:param fieldnames: Order of columns by property name
:param with_header: Add headers at the first line if True
:param crlf: Add CRLF lin... | [
"def",
"to_csv",
"(",
"self",
",",
"fieldnames",
":",
"Sequence",
"[",
"str",
"]",
",",
"with_header",
":",
"bool",
"=",
"False",
",",
"crlf",
":",
"bool",
"=",
"False",
",",
"tsv",
":",
"bool",
"=",
"False",
")",
"->",
"str",
":",
"return",
"util"... | From sequence of text to csv string
:param fieldnames: Order of columns by property name
:param with_header: Add headers at the first line if True
:param crlf: Add CRLF line break at the end of line if True, else add LF
:param tsv: Use tabs as separator if True, else use comma
:... | [
"From",
"sequence",
"of",
"text",
"to",
"csv",
"string"
] | train | https://github.com/tadashi-aikawa/owlmixin/blob/7c4a042c3008abddc56a8e8e55ae930d276071f5/owlmixin/transformers.py#L319-L345 |
tadashi-aikawa/owlmixin | owlmixin/transformers.py | CsvTransformer.to_csvf | def to_csvf(self, fpath: str, fieldnames: Sequence[str], encoding: str='utf8',
with_header: bool=False, crlf: bool=False, tsv: bool=False) -> str:
"""From instance to yaml file
:param fpath: Csv file path
:param fieldnames: Order of columns by property name
:param encodi... | python | def to_csvf(self, fpath: str, fieldnames: Sequence[str], encoding: str='utf8',
with_header: bool=False, crlf: bool=False, tsv: bool=False) -> str:
"""From instance to yaml file
:param fpath: Csv file path
:param fieldnames: Order of columns by property name
:param encodi... | [
"def",
"to_csvf",
"(",
"self",
",",
"fpath",
":",
"str",
",",
"fieldnames",
":",
"Sequence",
"[",
"str",
"]",
",",
"encoding",
":",
"str",
"=",
"'utf8'",
",",
"with_header",
":",
"bool",
"=",
"False",
",",
"crlf",
":",
"bool",
"=",
"False",
",",
"t... | From instance to yaml file
:param fpath: Csv file path
:param fieldnames: Order of columns by property name
:param encoding: Csv file encoding
:param with_header: Add headers at the first line if True
:param crlf: Add CRLF line break at the end of line if True, else add LF
... | [
"From",
"instance",
"to",
"yaml",
"file"
] | train | https://github.com/tadashi-aikawa/owlmixin/blob/7c4a042c3008abddc56a8e8e55ae930d276071f5/owlmixin/transformers.py#L347-L359 |
tadashi-aikawa/owlmixin | owlmixin/transformers.py | TableTransformer.to_table | def to_table(self, fieldnames: Sequence[str]) -> str:
"""From sequence of text to csv string
:param fieldnames: Order of columns by property name
:return: Table string
Usage:
>>> from owlmixin.samples import Human
>>> humans = Human.from_dicts([
...... | python | def to_table(self, fieldnames: Sequence[str]) -> str:
"""From sequence of text to csv string
:param fieldnames: Order of columns by property name
:return: Table string
Usage:
>>> from owlmixin.samples import Human
>>> humans = Human.from_dicts([
...... | [
"def",
"to_table",
"(",
"self",
",",
"fieldnames",
":",
"Sequence",
"[",
"str",
"]",
")",
"->",
"str",
":",
"return",
"util",
".",
"dump_table",
"(",
"traverse",
"(",
"self",
",",
"force_value",
"=",
"True",
")",
",",
"fieldnames",
")"
] | From sequence of text to csv string
:param fieldnames: Order of columns by property name
:return: Table string
Usage:
>>> from owlmixin.samples import Human
>>> humans = Human.from_dicts([
... {"id": 1, "name": "Tom", "favorites": [{"name": "Apple"}]},
... | [
"From",
"sequence",
"of",
"text",
"to",
"csv",
"string"
] | train | https://github.com/tadashi-aikawa/owlmixin/blob/7c4a042c3008abddc56a8e8e55ae930d276071f5/owlmixin/transformers.py#L366-L386 |
openstax/rhaptos.cnxmlutils | rhaptos/cnxmlutils/utils.py | _pre_tidy | def _pre_tidy(html):
""" This method transforms a few things before tidy runs. When we get rid
of tidy, this can go away. """
tree = etree.fromstring(html, etree.HTMLParser())
for el in tree.xpath('//u'):
el.tag = 'em'
c = el.attrib.get('class', '').split()
if 'underline' not... | python | def _pre_tidy(html):
""" This method transforms a few things before tidy runs. When we get rid
of tidy, this can go away. """
tree = etree.fromstring(html, etree.HTMLParser())
for el in tree.xpath('//u'):
el.tag = 'em'
c = el.attrib.get('class', '').split()
if 'underline' not... | [
"def",
"_pre_tidy",
"(",
"html",
")",
":",
"tree",
"=",
"etree",
".",
"fromstring",
"(",
"html",
",",
"etree",
".",
"HTMLParser",
"(",
")",
")",
"for",
"el",
"in",
"tree",
".",
"xpath",
"(",
"'//u'",
")",
":",
"el",
".",
"tag",
"=",
"'em'",
"c",
... | This method transforms a few things before tidy runs. When we get rid
of tidy, this can go away. | [
"This",
"method",
"transforms",
"a",
"few",
"things",
"before",
"tidy",
"runs",
".",
"When",
"we",
"get",
"rid",
"of",
"tidy",
"this",
"can",
"go",
"away",
"."
] | train | https://github.com/openstax/rhaptos.cnxmlutils/blob/c32b1a7428dc652e8cd745f3fdf4019a20543649/rhaptos/cnxmlutils/utils.py#L43-L54 |
openstax/rhaptos.cnxmlutils | rhaptos/cnxmlutils/utils.py | _post_tidy | def _post_tidy(html):
""" This method transforms post tidy. Will go away when tidy goes away. """
tree = etree.fromstring(html)
ems = tree.xpath(
"//xh:em[@class='underline']|//xh:em[contains(@class, ' underline ')]",
namespaces={'xh': 'http://www.w3.org/1999/xhtml'})
for el in ems:
... | python | def _post_tidy(html):
""" This method transforms post tidy. Will go away when tidy goes away. """
tree = etree.fromstring(html)
ems = tree.xpath(
"//xh:em[@class='underline']|//xh:em[contains(@class, ' underline ')]",
namespaces={'xh': 'http://www.w3.org/1999/xhtml'})
for el in ems:
... | [
"def",
"_post_tidy",
"(",
"html",
")",
":",
"tree",
"=",
"etree",
".",
"fromstring",
"(",
"html",
")",
"ems",
"=",
"tree",
".",
"xpath",
"(",
"\"//xh:em[@class='underline']|//xh:em[contains(@class, ' underline ')]\"",
",",
"namespaces",
"=",
"{",
"'xh'",
":",
"'... | This method transforms post tidy. Will go away when tidy goes away. | [
"This",
"method",
"transforms",
"post",
"tidy",
".",
"Will",
"go",
"away",
"when",
"tidy",
"goes",
"away",
"."
] | train | https://github.com/openstax/rhaptos.cnxmlutils/blob/c32b1a7428dc652e8cd745f3fdf4019a20543649/rhaptos/cnxmlutils/utils.py#L57-L72 |
openstax/rhaptos.cnxmlutils | rhaptos/cnxmlutils/utils.py | _tidy2xhtml5 | def _tidy2xhtml5(html):
"""Tidy up a html4/5 soup to a parsable valid XHTML5.
Requires tidy-html5 from https://github.com/w3c/tidy-html5
Installation: http://goo.gl/FG27n
"""
html = _io2string(html)
html = _pre_tidy(html) # Pre-process
xhtml5, errors =\
tidy_document(html,
... | python | def _tidy2xhtml5(html):
"""Tidy up a html4/5 soup to a parsable valid XHTML5.
Requires tidy-html5 from https://github.com/w3c/tidy-html5
Installation: http://goo.gl/FG27n
"""
html = _io2string(html)
html = _pre_tidy(html) # Pre-process
xhtml5, errors =\
tidy_document(html,
... | [
"def",
"_tidy2xhtml5",
"(",
"html",
")",
":",
"html",
"=",
"_io2string",
"(",
"html",
")",
"html",
"=",
"_pre_tidy",
"(",
"html",
")",
"# Pre-process",
"xhtml5",
",",
"errors",
"=",
"tidy_document",
"(",
"html",
",",
"options",
"=",
"{",
"# do not merge ne... | Tidy up a html4/5 soup to a parsable valid XHTML5.
Requires tidy-html5 from https://github.com/w3c/tidy-html5
Installation: http://goo.gl/FG27n | [
"Tidy",
"up",
"a",
"html4",
"/",
"5",
"soup",
"to",
"a",
"parsable",
"valid",
"XHTML5",
".",
"Requires",
"tidy",
"-",
"html5",
"from",
"https",
":",
"//",
"github",
".",
"com",
"/",
"w3c",
"/",
"tidy",
"-",
"html5",
"Installation",
":",
"http",
":",
... | train | https://github.com/openstax/rhaptos.cnxmlutils/blob/c32b1a7428dc652e8cd745f3fdf4019a20543649/rhaptos/cnxmlutils/utils.py#L76-L160 |
openstax/rhaptos.cnxmlutils | rhaptos/cnxmlutils/utils.py | _make_xsl | def _make_xsl(filename):
"""Helper that creates a XSLT stylesheet """
path = pkg_resources.resource_filename('rhaptos.cnxmlutils.xsl', filename)
xml = etree.parse(path)
return etree.XSLT(xml) | python | def _make_xsl(filename):
"""Helper that creates a XSLT stylesheet """
path = pkg_resources.resource_filename('rhaptos.cnxmlutils.xsl', filename)
xml = etree.parse(path)
return etree.XSLT(xml) | [
"def",
"_make_xsl",
"(",
"filename",
")",
":",
"path",
"=",
"pkg_resources",
".",
"resource_filename",
"(",
"'rhaptos.cnxmlutils.xsl'",
",",
"filename",
")",
"xml",
"=",
"etree",
".",
"parse",
"(",
"path",
")",
"return",
"etree",
".",
"XSLT",
"(",
"xml",
"... | Helper that creates a XSLT stylesheet | [
"Helper",
"that",
"creates",
"a",
"XSLT",
"stylesheet"
] | train | https://github.com/openstax/rhaptos.cnxmlutils/blob/c32b1a7428dc652e8cd745f3fdf4019a20543649/rhaptos/cnxmlutils/utils.py#L180-L184 |
openstax/rhaptos.cnxmlutils | rhaptos/cnxmlutils/utils.py | _transform | def _transform(xsl_filename, xml, **kwargs):
"""Transforms the xml using the specifiec xsl file."""
xslt = _make_xsl(xsl_filename)
xml = xslt(xml, **kwargs)
return xml | python | def _transform(xsl_filename, xml, **kwargs):
"""Transforms the xml using the specifiec xsl file."""
xslt = _make_xsl(xsl_filename)
xml = xslt(xml, **kwargs)
return xml | [
"def",
"_transform",
"(",
"xsl_filename",
",",
"xml",
",",
"*",
"*",
"kwargs",
")",
":",
"xslt",
"=",
"_make_xsl",
"(",
"xsl_filename",
")",
"xml",
"=",
"xslt",
"(",
"xml",
",",
"*",
"*",
"kwargs",
")",
"return",
"xml"
] | Transforms the xml using the specifiec xsl file. | [
"Transforms",
"the",
"xml",
"using",
"the",
"specifiec",
"xsl",
"file",
"."
] | train | https://github.com/openstax/rhaptos.cnxmlutils/blob/c32b1a7428dc652e8cd745f3fdf4019a20543649/rhaptos/cnxmlutils/utils.py#L187-L191 |
openstax/rhaptos.cnxmlutils | rhaptos/cnxmlutils/utils.py | _unescape_math | def _unescape_math(xml):
"""Unescapes Math from Mathjax to MathML."""
xpath_math_script = etree.XPath(
'//x:script[@type="math/mml"]',
namespaces={'x': 'http://www.w3.org/1999/xhtml'})
math_script_list = xpath_math_script(xml)
for mathscript in math_script_list:
math = ma... | python | def _unescape_math(xml):
"""Unescapes Math from Mathjax to MathML."""
xpath_math_script = etree.XPath(
'//x:script[@type="math/mml"]',
namespaces={'x': 'http://www.w3.org/1999/xhtml'})
math_script_list = xpath_math_script(xml)
for mathscript in math_script_list:
math = ma... | [
"def",
"_unescape_math",
"(",
"xml",
")",
":",
"xpath_math_script",
"=",
"etree",
".",
"XPath",
"(",
"'//x:script[@type=\"math/mml\"]'",
",",
"namespaces",
"=",
"{",
"'x'",
":",
"'http://www.w3.org/1999/xhtml'",
"}",
")",
"math_script_list",
"=",
"xpath_math_script",
... | Unescapes Math from Mathjax to MathML. | [
"Unescapes",
"Math",
"from",
"Mathjax",
"to",
"MathML",
"."
] | train | https://github.com/openstax/rhaptos.cnxmlutils/blob/c32b1a7428dc652e8cd745f3fdf4019a20543649/rhaptos/cnxmlutils/utils.py#L194-L208 |
openstax/rhaptos.cnxmlutils | rhaptos/cnxmlutils/utils.py | cnxml_to_html | def cnxml_to_html(cnxml_source):
"""Transform the CNXML source to HTML"""
source = _string2io(cnxml_source)
xml = etree.parse(source)
# Run the CNXML to HTML transform
xml = _transform('cnxml-to-html5.xsl', xml,
version='"{}"'.format(version))
xml = XHTML_MODULE_BODY_XPATH(x... | python | def cnxml_to_html(cnxml_source):
"""Transform the CNXML source to HTML"""
source = _string2io(cnxml_source)
xml = etree.parse(source)
# Run the CNXML to HTML transform
xml = _transform('cnxml-to-html5.xsl', xml,
version='"{}"'.format(version))
xml = XHTML_MODULE_BODY_XPATH(x... | [
"def",
"cnxml_to_html",
"(",
"cnxml_source",
")",
":",
"source",
"=",
"_string2io",
"(",
"cnxml_source",
")",
"xml",
"=",
"etree",
".",
"parse",
"(",
"source",
")",
"# Run the CNXML to HTML transform",
"xml",
"=",
"_transform",
"(",
"'cnxml-to-html5.xsl'",
",",
... | Transform the CNXML source to HTML | [
"Transform",
"the",
"CNXML",
"source",
"to",
"HTML"
] | train | https://github.com/openstax/rhaptos.cnxmlutils/blob/c32b1a7428dc652e8cd745f3fdf4019a20543649/rhaptos/cnxmlutils/utils.py#L211-L219 |
openstax/rhaptos.cnxmlutils | rhaptos/cnxmlutils/utils.py | aloha_to_etree | def aloha_to_etree(html_source):
""" Converts HTML5 from Aloha editor output to a lxml etree. """
xml = _tidy2xhtml5(html_source)
for i, transform in enumerate(ALOHA2HTML_TRANSFORM_PIPELINE):
xml = transform(xml)
return xml | python | def aloha_to_etree(html_source):
""" Converts HTML5 from Aloha editor output to a lxml etree. """
xml = _tidy2xhtml5(html_source)
for i, transform in enumerate(ALOHA2HTML_TRANSFORM_PIPELINE):
xml = transform(xml)
return xml | [
"def",
"aloha_to_etree",
"(",
"html_source",
")",
":",
"xml",
"=",
"_tidy2xhtml5",
"(",
"html_source",
")",
"for",
"i",
",",
"transform",
"in",
"enumerate",
"(",
"ALOHA2HTML_TRANSFORM_PIPELINE",
")",
":",
"xml",
"=",
"transform",
"(",
"xml",
")",
"return",
"... | Converts HTML5 from Aloha editor output to a lxml etree. | [
"Converts",
"HTML5",
"from",
"Aloha",
"editor",
"output",
"to",
"a",
"lxml",
"etree",
"."
] | train | https://github.com/openstax/rhaptos.cnxmlutils/blob/c32b1a7428dc652e8cd745f3fdf4019a20543649/rhaptos/cnxmlutils/utils.py#L233-L238 |
openstax/rhaptos.cnxmlutils | rhaptos/cnxmlutils/utils.py | aloha_to_html | def aloha_to_html(html_source):
"""Converts HTML5 from Aloha to a more structured HTML5"""
xml = aloha_to_etree(html_source)
return etree.tostring(xml, pretty_print=True) | python | def aloha_to_html(html_source):
"""Converts HTML5 from Aloha to a more structured HTML5"""
xml = aloha_to_etree(html_source)
return etree.tostring(xml, pretty_print=True) | [
"def",
"aloha_to_html",
"(",
"html_source",
")",
":",
"xml",
"=",
"aloha_to_etree",
"(",
"html_source",
")",
"return",
"etree",
".",
"tostring",
"(",
"xml",
",",
"pretty_print",
"=",
"True",
")"
] | Converts HTML5 from Aloha to a more structured HTML5 | [
"Converts",
"HTML5",
"from",
"Aloha",
"to",
"a",
"more",
"structured",
"HTML5"
] | train | https://github.com/openstax/rhaptos.cnxmlutils/blob/c32b1a7428dc652e8cd745f3fdf4019a20543649/rhaptos/cnxmlutils/utils.py#L241-L244 |
openstax/rhaptos.cnxmlutils | rhaptos/cnxmlutils/utils.py | html_to_cnxml | def html_to_cnxml(html_source, cnxml_source):
"""Transform the HTML to CNXML. We need the original CNXML content in
order to preserve the metadata in the CNXML document.
"""
source = _string2io(html_source)
xml = etree.parse(source)
cnxml = etree.parse(_string2io(cnxml_source))
# Run the HTM... | python | def html_to_cnxml(html_source, cnxml_source):
"""Transform the HTML to CNXML. We need the original CNXML content in
order to preserve the metadata in the CNXML document.
"""
source = _string2io(html_source)
xml = etree.parse(source)
cnxml = etree.parse(_string2io(cnxml_source))
# Run the HTM... | [
"def",
"html_to_cnxml",
"(",
"html_source",
",",
"cnxml_source",
")",
":",
"source",
"=",
"_string2io",
"(",
"html_source",
")",
"xml",
"=",
"etree",
".",
"parse",
"(",
"source",
")",
"cnxml",
"=",
"etree",
".",
"parse",
"(",
"_string2io",
"(",
"cnxml_sour... | Transform the HTML to CNXML. We need the original CNXML content in
order to preserve the metadata in the CNXML document. | [
"Transform",
"the",
"HTML",
"to",
"CNXML",
".",
"We",
"need",
"the",
"original",
"CNXML",
"content",
"in",
"order",
"to",
"preserve",
"the",
"metadata",
"in",
"the",
"CNXML",
"document",
"."
] | train | https://github.com/openstax/rhaptos.cnxmlutils/blob/c32b1a7428dc652e8cd745f3fdf4019a20543649/rhaptos/cnxmlutils/utils.py#L247-L262 |
openstax/rhaptos.cnxmlutils | rhaptos/cnxmlutils/utils.py | html_to_valid_cnxml | def html_to_valid_cnxml(html_source):
"""Transform the HTML to valid CNXML (used for OERPUB).
No original CNXML is needed. If HTML is from Aloha please use
aloha_to_html before using this method
"""
source = _string2io(html_source)
xml = etree.parse(source)
return etree_to_valid_cnxml(xml, ... | python | def html_to_valid_cnxml(html_source):
"""Transform the HTML to valid CNXML (used for OERPUB).
No original CNXML is needed. If HTML is from Aloha please use
aloha_to_html before using this method
"""
source = _string2io(html_source)
xml = etree.parse(source)
return etree_to_valid_cnxml(xml, ... | [
"def",
"html_to_valid_cnxml",
"(",
"html_source",
")",
":",
"source",
"=",
"_string2io",
"(",
"html_source",
")",
"xml",
"=",
"etree",
".",
"parse",
"(",
"source",
")",
"return",
"etree_to_valid_cnxml",
"(",
"xml",
",",
"pretty_print",
"=",
"True",
")"
] | Transform the HTML to valid CNXML (used for OERPUB).
No original CNXML is needed. If HTML is from Aloha please use
aloha_to_html before using this method | [
"Transform",
"the",
"HTML",
"to",
"valid",
"CNXML",
"(",
"used",
"for",
"OERPUB",
")",
".",
"No",
"original",
"CNXML",
"is",
"needed",
".",
"If",
"HTML",
"is",
"from",
"Aloha",
"please",
"use",
"aloha_to_html",
"before",
"using",
"this",
"method"
] | train | https://github.com/openstax/rhaptos.cnxmlutils/blob/c32b1a7428dc652e8cd745f3fdf4019a20543649/rhaptos/cnxmlutils/utils.py#L281-L288 |
tadashi-aikawa/owlmixin | owlmixin/owloption.py | TOption.get_or | def get_or(self, default: T) -> T:
"""
Usage:
>>> TOption(3).get_or(999)
3
>>> TOption(0).get_or(999)
0
>>> TOption(None).get_or(999)
999
"""
return default if self.value is None else self.value | python | def get_or(self, default: T) -> T:
"""
Usage:
>>> TOption(3).get_or(999)
3
>>> TOption(0).get_or(999)
0
>>> TOption(None).get_or(999)
999
"""
return default if self.value is None else self.value | [
"def",
"get_or",
"(",
"self",
",",
"default",
":",
"T",
")",
"->",
"T",
":",
"return",
"default",
"if",
"self",
".",
"value",
"is",
"None",
"else",
"self",
".",
"value"
] | Usage:
>>> TOption(3).get_or(999)
3
>>> TOption(0).get_or(999)
0
>>> TOption(None).get_or(999)
999 | [
"Usage",
":"
] | train | https://github.com/tadashi-aikawa/owlmixin/blob/7c4a042c3008abddc56a8e8e55ae930d276071f5/owlmixin/owloption.py#L25-L36 |
tadashi-aikawa/owlmixin | owlmixin/owloption.py | TOption.map | def map(self, func: Callable[[T], U]) -> 'TOption[T]':
"""
Usage:
>>> TOption(3).map(lambda x: x+1).get()
4
>>> TOption(None).map(lambda x: x+1).get_or(999)
999
"""
return self if self.is_none() else TOption(func(self.value)) | python | def map(self, func: Callable[[T], U]) -> 'TOption[T]':
"""
Usage:
>>> TOption(3).map(lambda x: x+1).get()
4
>>> TOption(None).map(lambda x: x+1).get_or(999)
999
"""
return self if self.is_none() else TOption(func(self.value)) | [
"def",
"map",
"(",
"self",
",",
"func",
":",
"Callable",
"[",
"[",
"T",
"]",
",",
"U",
"]",
")",
"->",
"'TOption[T]'",
":",
"return",
"self",
"if",
"self",
".",
"is_none",
"(",
")",
"else",
"TOption",
"(",
"func",
"(",
"self",
".",
"value",
")",
... | Usage:
>>> TOption(3).map(lambda x: x+1).get()
4
>>> TOption(None).map(lambda x: x+1).get_or(999)
999 | [
"Usage",
":"
] | train | https://github.com/tadashi-aikawa/owlmixin/blob/7c4a042c3008abddc56a8e8e55ae930d276071f5/owlmixin/owloption.py#L64-L73 |
tadashi-aikawa/owlmixin | owlmixin/owloption.py | TOption.flat_map | def flat_map(self, func: Callable[[T], 'TOption[T]']) -> 'TOption[T]':
"""
Usage:
>>> TOption(3).flat_map(lambda x: TOption(x+1)).get()
4
>>> TOption(3).flat_map(lambda x: TOption(None)).get_or(999)
999
>>> TOption(None).flat_map(lambda x: TOp... | python | def flat_map(self, func: Callable[[T], 'TOption[T]']) -> 'TOption[T]':
"""
Usage:
>>> TOption(3).flat_map(lambda x: TOption(x+1)).get()
4
>>> TOption(3).flat_map(lambda x: TOption(None)).get_or(999)
999
>>> TOption(None).flat_map(lambda x: TOp... | [
"def",
"flat_map",
"(",
"self",
",",
"func",
":",
"Callable",
"[",
"[",
"T",
"]",
",",
"'TOption[T]'",
"]",
")",
"->",
"'TOption[T]'",
":",
"return",
"self",
"if",
"self",
".",
"is_none",
"(",
")",
"else",
"TOption",
"(",
"func",
"(",
"self",
".",
... | Usage:
>>> TOption(3).flat_map(lambda x: TOption(x+1)).get()
4
>>> TOption(3).flat_map(lambda x: TOption(None)).get_or(999)
999
>>> TOption(None).flat_map(lambda x: TOption(x+1)).get_or(999)
999 | [
"Usage",
":"
] | train | https://github.com/tadashi-aikawa/owlmixin/blob/7c4a042c3008abddc56a8e8e55ae930d276071f5/owlmixin/owloption.py#L75-L86 |
openstax/rhaptos.cnxmlutils | rhaptos/cnxmlutils/symbols.py | replace | def replace(text):
"""Replace both the hex and decimal versions of symbols in an XML string"""
for hex, value in UNICODE_DICTIONARY.items():
num = int(hex[3:-1], 16)
#uni = unichr(num)
decimal = '&#' + str(num) + ';'
for key in [ hex, decimal ]: #uni
text = text.replace(key, value)
return te... | python | def replace(text):
"""Replace both the hex and decimal versions of symbols in an XML string"""
for hex, value in UNICODE_DICTIONARY.items():
num = int(hex[3:-1], 16)
#uni = unichr(num)
decimal = '&#' + str(num) + ';'
for key in [ hex, decimal ]: #uni
text = text.replace(key, value)
return te... | [
"def",
"replace",
"(",
"text",
")",
":",
"for",
"hex",
",",
"value",
"in",
"UNICODE_DICTIONARY",
".",
"items",
"(",
")",
":",
"num",
"=",
"int",
"(",
"hex",
"[",
"3",
":",
"-",
"1",
"]",
",",
"16",
")",
"#uni = unichr(num)",
"decimal",
"=",
"'&#'",... | Replace both the hex and decimal versions of symbols in an XML string | [
"Replace",
"both",
"the",
"hex",
"and",
"decimal",
"versions",
"of",
"symbols",
"in",
"an",
"XML",
"string"
] | train | https://github.com/openstax/rhaptos.cnxmlutils/blob/c32b1a7428dc652e8cd745f3fdf4019a20543649/rhaptos/cnxmlutils/symbols.py#L219-L227 |
tadashi-aikawa/owlmixin | owlmixin/util.py | replace_keys | def replace_keys(d, keymap, force_snake_case):
"""
:param dict d:
:param Dict[unicode, unicode] keymap:
:param bool force_snake_case:
:rtype: Dict[unicode, unicode]
"""
return {
to_snake(keymap.get(k, k)) if force_snake_case else keymap.get(k, k):
v for k, v in d.items()
... | python | def replace_keys(d, keymap, force_snake_case):
"""
:param dict d:
:param Dict[unicode, unicode] keymap:
:param bool force_snake_case:
:rtype: Dict[unicode, unicode]
"""
return {
to_snake(keymap.get(k, k)) if force_snake_case else keymap.get(k, k):
v for k, v in d.items()
... | [
"def",
"replace_keys",
"(",
"d",
",",
"keymap",
",",
"force_snake_case",
")",
":",
"return",
"{",
"to_snake",
"(",
"keymap",
".",
"get",
"(",
"k",
",",
"k",
")",
")",
"if",
"force_snake_case",
"else",
"keymap",
".",
"get",
"(",
"k",
",",
"k",
")",
... | :param dict d:
:param Dict[unicode, unicode] keymap:
:param bool force_snake_case:
:rtype: Dict[unicode, unicode] | [
":",
"param",
"dict",
"d",
":",
":",
"param",
"Dict",
"[",
"unicode",
"unicode",
"]",
"keymap",
":",
":",
"param",
"bool",
"force_snake_case",
":",
":",
"rtype",
":",
"Dict",
"[",
"unicode",
"unicode",
"]"
] | train | https://github.com/tadashi-aikawa/owlmixin/blob/7c4a042c3008abddc56a8e8e55ae930d276071f5/owlmixin/util.py#L81-L91 |
tadashi-aikawa/owlmixin | owlmixin/util.py | load_jsonf | def load_jsonf(fpath, encoding):
"""
:param unicode fpath:
:param unicode encoding:
:rtype: dict | list
"""
with codecs.open(fpath, encoding=encoding) as f:
return json.load(f) | python | def load_jsonf(fpath, encoding):
"""
:param unicode fpath:
:param unicode encoding:
:rtype: dict | list
"""
with codecs.open(fpath, encoding=encoding) as f:
return json.load(f) | [
"def",
"load_jsonf",
"(",
"fpath",
",",
"encoding",
")",
":",
"with",
"codecs",
".",
"open",
"(",
"fpath",
",",
"encoding",
"=",
"encoding",
")",
"as",
"f",
":",
"return",
"json",
".",
"load",
"(",
"f",
")"
] | :param unicode fpath:
:param unicode encoding:
:rtype: dict | list | [
":",
"param",
"unicode",
"fpath",
":",
":",
"param",
"unicode",
"encoding",
":",
":",
"rtype",
":",
"dict",
"|",
"list"
] | train | https://github.com/tadashi-aikawa/owlmixin/blob/7c4a042c3008abddc56a8e8e55ae930d276071f5/owlmixin/util.py#L111-L118 |
tadashi-aikawa/owlmixin | owlmixin/util.py | load_yamlf | def load_yamlf(fpath, encoding):
"""
:param unicode fpath:
:param unicode encoding:
:rtype: dict | list
"""
with codecs.open(fpath, encoding=encoding) as f:
return yaml.safe_load(f) | python | def load_yamlf(fpath, encoding):
"""
:param unicode fpath:
:param unicode encoding:
:rtype: dict | list
"""
with codecs.open(fpath, encoding=encoding) as f:
return yaml.safe_load(f) | [
"def",
"load_yamlf",
"(",
"fpath",
",",
"encoding",
")",
":",
"with",
"codecs",
".",
"open",
"(",
"fpath",
",",
"encoding",
"=",
"encoding",
")",
"as",
"f",
":",
"return",
"yaml",
".",
"safe_load",
"(",
"f",
")"
] | :param unicode fpath:
:param unicode encoding:
:rtype: dict | list | [
":",
"param",
"unicode",
"fpath",
":",
":",
"param",
"unicode",
"encoding",
":",
":",
"rtype",
":",
"dict",
"|",
"list"
] | train | https://github.com/tadashi-aikawa/owlmixin/blob/7c4a042c3008abddc56a8e8e55ae930d276071f5/owlmixin/util.py#L129-L136 |
tadashi-aikawa/owlmixin | owlmixin/util.py | load_csvf | def load_csvf(fpath, fieldnames, encoding):
"""
:param unicode fpath:
:param Optional[list[unicode]] fieldnames:
:param unicode encoding:
:rtype: List[dict]
"""
with open(fpath, mode='r', encoding=encoding) as f:
snippet = f.read(8192)
f.seek(0)
dialect = csv.Sniffer... | python | def load_csvf(fpath, fieldnames, encoding):
"""
:param unicode fpath:
:param Optional[list[unicode]] fieldnames:
:param unicode encoding:
:rtype: List[dict]
"""
with open(fpath, mode='r', encoding=encoding) as f:
snippet = f.read(8192)
f.seek(0)
dialect = csv.Sniffer... | [
"def",
"load_csvf",
"(",
"fpath",
",",
"fieldnames",
",",
"encoding",
")",
":",
"with",
"open",
"(",
"fpath",
",",
"mode",
"=",
"'r'",
",",
"encoding",
"=",
"encoding",
")",
"as",
"f",
":",
"snippet",
"=",
"f",
".",
"read",
"(",
"8192",
")",
"f",
... | :param unicode fpath:
:param Optional[list[unicode]] fieldnames:
:param unicode encoding:
:rtype: List[dict] | [
":",
"param",
"unicode",
"fpath",
":",
":",
"param",
"Optional",
"[",
"list",
"[",
"unicode",
"]]",
"fieldnames",
":",
":",
"param",
"unicode",
"encoding",
":",
":",
"rtype",
":",
"List",
"[",
"dict",
"]"
] | train | https://github.com/tadashi-aikawa/owlmixin/blob/7c4a042c3008abddc56a8e8e55ae930d276071f5/owlmixin/util.py#L139-L152 |
tadashi-aikawa/owlmixin | owlmixin/util.py | dump_csv | def dump_csv(data: List[dict], fieldnames: Sequence[str], with_header: bool = False, crlf: bool = False,
tsv: bool = False) -> str:
"""
:param data:
:param fieldnames:
:param with_header:
:param crlf:
:param tsv:
:return: unicode
"""
def force_str(v):
# XXX: Dou... | python | def dump_csv(data: List[dict], fieldnames: Sequence[str], with_header: bool = False, crlf: bool = False,
tsv: bool = False) -> str:
"""
:param data:
:param fieldnames:
:param with_header:
:param crlf:
:param tsv:
:return: unicode
"""
def force_str(v):
# XXX: Dou... | [
"def",
"dump_csv",
"(",
"data",
":",
"List",
"[",
"dict",
"]",
",",
"fieldnames",
":",
"Sequence",
"[",
"str",
"]",
",",
"with_header",
":",
"bool",
"=",
"False",
",",
"crlf",
":",
"bool",
"=",
"False",
",",
"tsv",
":",
"bool",
"=",
"False",
")",
... | :param data:
:param fieldnames:
:param with_header:
:param crlf:
:param tsv:
:return: unicode | [
":",
"param",
"data",
":",
":",
"param",
"fieldnames",
":",
":",
"param",
"with_header",
":",
":",
"param",
"crlf",
":",
":",
"param",
"tsv",
":",
":",
"return",
":",
"unicode"
] | train | https://github.com/tadashi-aikawa/owlmixin/blob/7c4a042c3008abddc56a8e8e55ae930d276071f5/owlmixin/util.py#L163-L186 |
tadashi-aikawa/owlmixin | owlmixin/util.py | save_csvf | def save_csvf(data: list, fieldnames: Sequence[str], fpath: str, encoding: str, with_header: bool = False,
crlf: bool = False, tsv: bool = False) -> str:
"""
:param data:
:param fieldnames:
:param fpath: write path
:param encoding: encoding
:param with_header:
:param crlf:
... | python | def save_csvf(data: list, fieldnames: Sequence[str], fpath: str, encoding: str, with_header: bool = False,
crlf: bool = False, tsv: bool = False) -> str:
"""
:param data:
:param fieldnames:
:param fpath: write path
:param encoding: encoding
:param with_header:
:param crlf:
... | [
"def",
"save_csvf",
"(",
"data",
":",
"list",
",",
"fieldnames",
":",
"Sequence",
"[",
"str",
"]",
",",
"fpath",
":",
"str",
",",
"encoding",
":",
"str",
",",
"with_header",
":",
"bool",
"=",
"False",
",",
"crlf",
":",
"bool",
"=",
"False",
",",
"t... | :param data:
:param fieldnames:
:param fpath: write path
:param encoding: encoding
:param with_header:
:param crlf:
:param tsv:
:return: written path | [
":",
"param",
"data",
":",
":",
"param",
"fieldnames",
":",
":",
"param",
"fpath",
":",
"write",
"path",
":",
"param",
"encoding",
":",
"encoding",
":",
"param",
"with_header",
":",
":",
"param",
"crlf",
":",
":",
"param",
"tsv",
":",
":",
"return",
... | train | https://github.com/tadashi-aikawa/owlmixin/blob/7c4a042c3008abddc56a8e8e55ae930d276071f5/owlmixin/util.py#L189-L203 |
tadashi-aikawa/owlmixin | owlmixin/util.py | dump_json | def dump_json(data, indent=None):
"""
:param list | dict data:
:param Optional[int] indent:
:rtype: unicode
"""
return json.dumps(data,
indent=indent,
ensure_ascii=False,
sort_keys=True,
separators=(',', ': '... | python | def dump_json(data, indent=None):
"""
:param list | dict data:
:param Optional[int] indent:
:rtype: unicode
"""
return json.dumps(data,
indent=indent,
ensure_ascii=False,
sort_keys=True,
separators=(',', ': '... | [
"def",
"dump_json",
"(",
"data",
",",
"indent",
"=",
"None",
")",
":",
"return",
"json",
".",
"dumps",
"(",
"data",
",",
"indent",
"=",
"indent",
",",
"ensure_ascii",
"=",
"False",
",",
"sort_keys",
"=",
"True",
",",
"separators",
"=",
"(",
"','",
",... | :param list | dict data:
:param Optional[int] indent:
:rtype: unicode | [
":",
"param",
"list",
"|",
"dict",
"data",
":",
":",
"param",
"Optional",
"[",
"int",
"]",
"indent",
":",
":",
"rtype",
":",
"unicode"
] | train | https://github.com/tadashi-aikawa/owlmixin/blob/7c4a042c3008abddc56a8e8e55ae930d276071f5/owlmixin/util.py#L206-L216 |
tadashi-aikawa/owlmixin | owlmixin/util.py | save_jsonf | def save_jsonf(data: Union[list, dict], fpath: str, encoding: str, indent=None) -> str:
"""
:param data: list | dict data
:param fpath: write path
:param encoding: encoding
:param indent:
:rtype: written path
"""
with codecs.open(fpath, mode='w', encoding=encoding) as f:
f.write(... | python | def save_jsonf(data: Union[list, dict], fpath: str, encoding: str, indent=None) -> str:
"""
:param data: list | dict data
:param fpath: write path
:param encoding: encoding
:param indent:
:rtype: written path
"""
with codecs.open(fpath, mode='w', encoding=encoding) as f:
f.write(... | [
"def",
"save_jsonf",
"(",
"data",
":",
"Union",
"[",
"list",
",",
"dict",
"]",
",",
"fpath",
":",
"str",
",",
"encoding",
":",
"str",
",",
"indent",
"=",
"None",
")",
"->",
"str",
":",
"with",
"codecs",
".",
"open",
"(",
"fpath",
",",
"mode",
"="... | :param data: list | dict data
:param fpath: write path
:param encoding: encoding
:param indent:
:rtype: written path | [
":",
"param",
"data",
":",
"list",
"|",
"dict",
"data",
":",
"param",
"fpath",
":",
"write",
"path",
":",
"param",
"encoding",
":",
"encoding",
":",
"param",
"indent",
":",
":",
"rtype",
":",
"written",
"path"
] | train | https://github.com/tadashi-aikawa/owlmixin/blob/7c4a042c3008abddc56a8e8e55ae930d276071f5/owlmixin/util.py#L219-L229 |
tadashi-aikawa/owlmixin | owlmixin/util.py | dump_yaml | def dump_yaml(data):
"""
:param list | dict data:
:rtype: unicode
"""
return yaml.dump(data,
indent=2,
encoding=None,
allow_unicode=True,
default_flow_style=False,
Dumper=MyDumper) | python | def dump_yaml(data):
"""
:param list | dict data:
:rtype: unicode
"""
return yaml.dump(data,
indent=2,
encoding=None,
allow_unicode=True,
default_flow_style=False,
Dumper=MyDumper) | [
"def",
"dump_yaml",
"(",
"data",
")",
":",
"return",
"yaml",
".",
"dump",
"(",
"data",
",",
"indent",
"=",
"2",
",",
"encoding",
"=",
"None",
",",
"allow_unicode",
"=",
"True",
",",
"default_flow_style",
"=",
"False",
",",
"Dumper",
"=",
"MyDumper",
")... | :param list | dict data:
:rtype: unicode | [
":",
"param",
"list",
"|",
"dict",
"data",
":",
":",
"rtype",
":",
"unicode"
] | train | https://github.com/tadashi-aikawa/owlmixin/blob/7c4a042c3008abddc56a8e8e55ae930d276071f5/owlmixin/util.py#L232-L242 |
tadashi-aikawa/owlmixin | owlmixin/util.py | save_yamlf | def save_yamlf(data: Union[list, dict], fpath: str, encoding: str) -> str:
"""
:param data: list | dict data
:param fpath: write path
:param encoding: encoding
:rtype: written path
"""
with codecs.open(fpath, mode='w', encoding=encoding) as f:
f.write(dump_yaml(data))
return ... | python | def save_yamlf(data: Union[list, dict], fpath: str, encoding: str) -> str:
"""
:param data: list | dict data
:param fpath: write path
:param encoding: encoding
:rtype: written path
"""
with codecs.open(fpath, mode='w', encoding=encoding) as f:
f.write(dump_yaml(data))
return ... | [
"def",
"save_yamlf",
"(",
"data",
":",
"Union",
"[",
"list",
",",
"dict",
"]",
",",
"fpath",
":",
"str",
",",
"encoding",
":",
"str",
")",
"->",
"str",
":",
"with",
"codecs",
".",
"open",
"(",
"fpath",
",",
"mode",
"=",
"'w'",
",",
"encoding",
"=... | :param data: list | dict data
:param fpath: write path
:param encoding: encoding
:rtype: written path | [
":",
"param",
"data",
":",
"list",
"|",
"dict",
"data",
":",
"param",
"fpath",
":",
"write",
"path",
":",
"param",
"encoding",
":",
"encoding",
":",
"rtype",
":",
"written",
"path"
] | train | https://github.com/tadashi-aikawa/owlmixin/blob/7c4a042c3008abddc56a8e8e55ae930d276071f5/owlmixin/util.py#L245-L254 |
tadashi-aikawa/owlmixin | owlmixin/util.py | dump_table | def dump_table(data: List[dict], fieldnames: Sequence[str]) -> str:
"""
:param data:
:param fieldnames:
:return: Table string
"""
def min3(num: int) -> int:
return 3 if num < 4 else num
width_by_col: Dict[str, int] = {
f: min3(max([string_width(str(d.get(f))) for d in data]... | python | def dump_table(data: List[dict], fieldnames: Sequence[str]) -> str:
"""
:param data:
:param fieldnames:
:return: Table string
"""
def min3(num: int) -> int:
return 3 if num < 4 else num
width_by_col: Dict[str, int] = {
f: min3(max([string_width(str(d.get(f))) for d in data]... | [
"def",
"dump_table",
"(",
"data",
":",
"List",
"[",
"dict",
"]",
",",
"fieldnames",
":",
"Sequence",
"[",
"str",
"]",
")",
"->",
"str",
":",
"def",
"min3",
"(",
"num",
":",
"int",
")",
"->",
"int",
":",
"return",
"3",
"if",
"num",
"<",
"4",
"el... | :param data:
:param fieldnames:
:return: Table string | [
":",
"param",
"data",
":",
":",
"param",
"fieldnames",
":",
":",
"return",
":",
"Table",
"string"
] | train | https://github.com/tadashi-aikawa/owlmixin/blob/7c4a042c3008abddc56a8e8e55ae930d276071f5/owlmixin/util.py#L257-L284 |
tadashi-aikawa/owlmixin | owlmixin/util.py | string_width | def string_width(word: str) -> int:
"""
:param word:
:return: Widths of word
Usage:
>>> string_width('abc')
3
>>> string_width('Abしー')
7
>>> string_width('')
0
"""
return sum(map(lambda x: 2 if east_asian_width(x) in 'FWA' else 1, word)) | python | def string_width(word: str) -> int:
"""
:param word:
:return: Widths of word
Usage:
>>> string_width('abc')
3
>>> string_width('Abしー')
7
>>> string_width('')
0
"""
return sum(map(lambda x: 2 if east_asian_width(x) in 'FWA' else 1, word)) | [
"def",
"string_width",
"(",
"word",
":",
"str",
")",
"->",
"int",
":",
"return",
"sum",
"(",
"map",
"(",
"lambda",
"x",
":",
"2",
"if",
"east_asian_width",
"(",
"x",
")",
"in",
"'FWA'",
"else",
"1",
",",
"word",
")",
")"
] | :param word:
:return: Widths of word
Usage:
>>> string_width('abc')
3
>>> string_width('Abしー')
7
>>> string_width('')
0 | [
":",
"param",
"word",
":",
":",
"return",
":",
"Widths",
"of",
"word"
] | train | https://github.com/tadashi-aikawa/owlmixin/blob/7c4a042c3008abddc56a8e8e55ae930d276071f5/owlmixin/util.py#L287-L301 |
openstax/rhaptos.cnxmlutils | rhaptos/cnxmlutils/odt2cnxml.py | writeXMLFile | def writeXMLFile(filename, content):
""" Used only for debugging to write out intermediate files"""
xmlfile = open(filename, 'w')
# pretty print
content = etree.tostring(content, pretty_print=True)
xmlfile.write(content)
xmlfile.close() | python | def writeXMLFile(filename, content):
""" Used only for debugging to write out intermediate files"""
xmlfile = open(filename, 'w')
# pretty print
content = etree.tostring(content, pretty_print=True)
xmlfile.write(content)
xmlfile.close() | [
"def",
"writeXMLFile",
"(",
"filename",
",",
"content",
")",
":",
"xmlfile",
"=",
"open",
"(",
"filename",
",",
"'w'",
")",
"# pretty print",
"content",
"=",
"etree",
".",
"tostring",
"(",
"content",
",",
"pretty_print",
"=",
"True",
")",
"xmlfile",
".",
... | Used only for debugging to write out intermediate files | [
"Used",
"only",
"for",
"debugging",
"to",
"write",
"out",
"intermediate",
"files"
] | train | https://github.com/openstax/rhaptos.cnxmlutils/blob/c32b1a7428dc652e8cd745f3fdf4019a20543649/rhaptos/cnxmlutils/odt2cnxml.py#L56-L62 |
openstax/rhaptos.cnxmlutils | rhaptos/cnxmlutils/odt2cnxml.py | transform | def transform(odtfile, debug=False, parsable=False, outputdir=None):
""" Given an ODT file this returns a tuple containing
the cnxml, a dictionary of filename -> data, and a list of errors """
# Store mapping of images extracted from the ODT file (and their bits)
images = {}
# Log of Errors and ... | python | def transform(odtfile, debug=False, parsable=False, outputdir=None):
""" Given an ODT file this returns a tuple containing
the cnxml, a dictionary of filename -> data, and a list of errors """
# Store mapping of images extracted from the ODT file (and their bits)
images = {}
# Log of Errors and ... | [
"def",
"transform",
"(",
"odtfile",
",",
"debug",
"=",
"False",
",",
"parsable",
"=",
"False",
",",
"outputdir",
"=",
"None",
")",
":",
"# Store mapping of images extracted from the ODT file (and their bits)",
"images",
"=",
"{",
"}",
"# Log of Errors and Warnings gener... | Given an ODT file this returns a tuple containing
the cnxml, a dictionary of filename -> data, and a list of errors | [
"Given",
"an",
"ODT",
"file",
"this",
"returns",
"a",
"tuple",
"containing",
"the",
"cnxml",
"a",
"dictionary",
"of",
"filename",
"-",
">",
"data",
"and",
"a",
"list",
"of",
"errors"
] | train | https://github.com/openstax/rhaptos.cnxmlutils/blob/c32b1a7428dc652e8cd745f3fdf4019a20543649/rhaptos/cnxmlutils/odt2cnxml.py#L64-L277 |
tadashi-aikawa/owlmixin | owlmixin/owlenum.py | OwlObjectEnum.from_value | def from_value(cls, value: str) -> T:
"""Create instance from symbol
:param value: unique symbol
:return: This instance
Usage:
>>> from owlmixin.samples import Animal
>>> Animal.from_value('cat').crow()
mewing
"""
return [x for x in c... | python | def from_value(cls, value: str) -> T:
"""Create instance from symbol
:param value: unique symbol
:return: This instance
Usage:
>>> from owlmixin.samples import Animal
>>> Animal.from_value('cat').crow()
mewing
"""
return [x for x in c... | [
"def",
"from_value",
"(",
"cls",
",",
"value",
":",
"str",
")",
"->",
"T",
":",
"return",
"[",
"x",
"for",
"x",
"in",
"cls",
".",
"__members__",
".",
"values",
"(",
")",
"if",
"x",
".",
"value",
"[",
"0",
"]",
"==",
"value",
"]",
"[",
"0",
"]... | Create instance from symbol
:param value: unique symbol
:return: This instance
Usage:
>>> from owlmixin.samples import Animal
>>> Animal.from_value('cat').crow()
mewing | [
"Create",
"instance",
"from",
"symbol",
":",
"param",
"value",
":",
"unique",
"symbol",
":",
"return",
":",
"This",
"instance"
] | train | https://github.com/tadashi-aikawa/owlmixin/blob/7c4a042c3008abddc56a8e8e55ae930d276071f5/owlmixin/owlenum.py#L43-L54 |
Autodesk/aomi | aomi/seed_action.py | auto_thaw | def auto_thaw(vault_client, opt):
"""Will thaw into a temporary location"""
icefile = opt.thaw_from
if not os.path.exists(icefile):
raise aomi.exceptions.IceFile("%s missing" % icefile)
thaw(vault_client, icefile, opt)
return opt | python | def auto_thaw(vault_client, opt):
"""Will thaw into a temporary location"""
icefile = opt.thaw_from
if not os.path.exists(icefile):
raise aomi.exceptions.IceFile("%s missing" % icefile)
thaw(vault_client, icefile, opt)
return opt | [
"def",
"auto_thaw",
"(",
"vault_client",
",",
"opt",
")",
":",
"icefile",
"=",
"opt",
".",
"thaw_from",
"if",
"not",
"os",
".",
"path",
".",
"exists",
"(",
"icefile",
")",
":",
"raise",
"aomi",
".",
"exceptions",
".",
"IceFile",
"(",
"\"%s missing\"",
... | Will thaw into a temporary location | [
"Will",
"thaw",
"into",
"a",
"temporary",
"location"
] | train | https://github.com/Autodesk/aomi/blob/84da2dfb0424837adf9c4ddc1aa352e942bb7a4a/aomi/seed_action.py#L26-L33 |
Autodesk/aomi | aomi/seed_action.py | seed | def seed(vault_client, opt):
"""Will provision vault based on the definition within a Secretfile"""
if opt.thaw_from:
opt.secrets = tempfile.mkdtemp('aomi-thaw')
auto_thaw(vault_client, opt)
Context.load(get_secretfile(opt), opt) \
.fetch(vault_client) \
.sync(vault_cl... | python | def seed(vault_client, opt):
"""Will provision vault based on the definition within a Secretfile"""
if opt.thaw_from:
opt.secrets = tempfile.mkdtemp('aomi-thaw')
auto_thaw(vault_client, opt)
Context.load(get_secretfile(opt), opt) \
.fetch(vault_client) \
.sync(vault_cl... | [
"def",
"seed",
"(",
"vault_client",
",",
"opt",
")",
":",
"if",
"opt",
".",
"thaw_from",
":",
"opt",
".",
"secrets",
"=",
"tempfile",
".",
"mkdtemp",
"(",
"'aomi-thaw'",
")",
"auto_thaw",
"(",
"vault_client",
",",
"opt",
")",
"Context",
".",
"load",
"(... | Will provision vault based on the definition within a Secretfile | [
"Will",
"provision",
"vault",
"based",
"on",
"the",
"definition",
"within",
"a",
"Secretfile"
] | train | https://github.com/Autodesk/aomi/blob/84da2dfb0424837adf9c4ddc1aa352e942bb7a4a/aomi/seed_action.py#L36-L47 |
Autodesk/aomi | aomi/seed_action.py | render | def render(directory, opt):
"""Render any provided template. This includes the Secretfile,
Vault policies, and inline AWS roles"""
if not os.path.exists(directory) and not os.path.isdir(directory):
os.mkdir(directory)
a_secretfile = render_secretfile(opt)
s_path = "%s/Secretfile" % director... | python | def render(directory, opt):
"""Render any provided template. This includes the Secretfile,
Vault policies, and inline AWS roles"""
if not os.path.exists(directory) and not os.path.isdir(directory):
os.mkdir(directory)
a_secretfile = render_secretfile(opt)
s_path = "%s/Secretfile" % director... | [
"def",
"render",
"(",
"directory",
",",
"opt",
")",
":",
"if",
"not",
"os",
".",
"path",
".",
"exists",
"(",
"directory",
")",
"and",
"not",
"os",
".",
"path",
".",
"isdir",
"(",
"directory",
")",
":",
"os",
".",
"mkdir",
"(",
"directory",
")",
"... | Render any provided template. This includes the Secretfile,
Vault policies, and inline AWS roles | [
"Render",
"any",
"provided",
"template",
".",
"This",
"includes",
"the",
"Secretfile",
"Vault",
"policies",
"and",
"inline",
"AWS",
"roles"
] | train | https://github.com/Autodesk/aomi/blob/84da2dfb0424837adf9c4ddc1aa352e942bb7a4a/aomi/seed_action.py#L50-L82 |
Autodesk/aomi | aomi/seed_action.py | export | def export(vault_client, opt):
"""Export contents of a Secretfile from the Vault server
into a specified directory."""
ctx = Context.load(get_secretfile(opt), opt) \
.fetch(vault_client)
for resource in ctx.resources():
resource.export(opt.directory) | python | def export(vault_client, opt):
"""Export contents of a Secretfile from the Vault server
into a specified directory."""
ctx = Context.load(get_secretfile(opt), opt) \
.fetch(vault_client)
for resource in ctx.resources():
resource.export(opt.directory) | [
"def",
"export",
"(",
"vault_client",
",",
"opt",
")",
":",
"ctx",
"=",
"Context",
".",
"load",
"(",
"get_secretfile",
"(",
"opt",
")",
",",
"opt",
")",
".",
"fetch",
"(",
"vault_client",
")",
"for",
"resource",
"in",
"ctx",
".",
"resources",
"(",
")... | Export contents of a Secretfile from the Vault server
into a specified directory. | [
"Export",
"contents",
"of",
"a",
"Secretfile",
"from",
"the",
"Vault",
"server",
"into",
"a",
"specified",
"directory",
"."
] | train | https://github.com/Autodesk/aomi/blob/84da2dfb0424837adf9c4ddc1aa352e942bb7a4a/aomi/seed_action.py#L85-L91 |
Autodesk/aomi | aomi/seed_action.py | maybe_colored | def maybe_colored(msg, color, opt):
"""Maybe it will render in color maybe it will not!"""
if opt.monochrome:
return msg
return colored(msg, color) | python | def maybe_colored(msg, color, opt):
"""Maybe it will render in color maybe it will not!"""
if opt.monochrome:
return msg
return colored(msg, color) | [
"def",
"maybe_colored",
"(",
"msg",
",",
"color",
",",
"opt",
")",
":",
"if",
"opt",
".",
"monochrome",
":",
"return",
"msg",
"return",
"colored",
"(",
"msg",
",",
"color",
")"
] | Maybe it will render in color maybe it will not! | [
"Maybe",
"it",
"will",
"render",
"in",
"color",
"maybe",
"it",
"will",
"not!"
] | train | https://github.com/Autodesk/aomi/blob/84da2dfb0424837adf9c4ddc1aa352e942bb7a4a/aomi/seed_action.py#L94-L99 |
Autodesk/aomi | aomi/seed_action.py | normalize_val | def normalize_val(val):
"""Normalize JSON/YAML derived values as they pertain
to Vault resources and comparison operations """
if is_unicode(val) and val.isdigit():
return int(val)
elif isinstance(val, list):
return ','.join(val)
elif val is None:
return ''
return val | python | def normalize_val(val):
"""Normalize JSON/YAML derived values as they pertain
to Vault resources and comparison operations """
if is_unicode(val) and val.isdigit():
return int(val)
elif isinstance(val, list):
return ','.join(val)
elif val is None:
return ''
return val | [
"def",
"normalize_val",
"(",
"val",
")",
":",
"if",
"is_unicode",
"(",
"val",
")",
"and",
"val",
".",
"isdigit",
"(",
")",
":",
"return",
"int",
"(",
"val",
")",
"elif",
"isinstance",
"(",
"val",
",",
"list",
")",
":",
"return",
"','",
".",
"join",... | Normalize JSON/YAML derived values as they pertain
to Vault resources and comparison operations | [
"Normalize",
"JSON",
"/",
"YAML",
"derived",
"values",
"as",
"they",
"pertain",
"to",
"Vault",
"resources",
"and",
"comparison",
"operations"
] | train | https://github.com/Autodesk/aomi/blob/84da2dfb0424837adf9c4ddc1aa352e942bb7a4a/aomi/seed_action.py#L102-L112 |
Autodesk/aomi | aomi/seed_action.py | details_dict | def details_dict(obj, existing, ignore_missing, opt):
"""Output the changes, if any, for a dict"""
existing = dict_unicodeize(existing)
obj = dict_unicodeize(obj)
for ex_k, ex_v in iteritems(existing):
new_value = normalize_val(obj.get(ex_k))
og_value = normalize_val(ex_v)
if ex_... | python | def details_dict(obj, existing, ignore_missing, opt):
"""Output the changes, if any, for a dict"""
existing = dict_unicodeize(existing)
obj = dict_unicodeize(obj)
for ex_k, ex_v in iteritems(existing):
new_value = normalize_val(obj.get(ex_k))
og_value = normalize_val(ex_v)
if ex_... | [
"def",
"details_dict",
"(",
"obj",
",",
"existing",
",",
"ignore_missing",
",",
"opt",
")",
":",
"existing",
"=",
"dict_unicodeize",
"(",
"existing",
")",
"obj",
"=",
"dict_unicodeize",
"(",
"obj",
")",
"for",
"ex_k",
",",
"ex_v",
"in",
"iteritems",
"(",
... | Output the changes, if any, for a dict | [
"Output",
"the",
"changes",
"if",
"any",
"for",
"a",
"dict"
] | train | https://github.com/Autodesk/aomi/blob/84da2dfb0424837adf9c4ddc1aa352e942bb7a4a/aomi/seed_action.py#L115-L138 |
Autodesk/aomi | aomi/seed_action.py | maybe_details | def maybe_details(resource, opt):
"""At the first level of verbosity this will print out detailed
change information on for the specified Vault resource"""
if opt.verbose == 0:
return
if not resource.present:
return
obj = None
existing = None
if isinstance(resource, Resour... | python | def maybe_details(resource, opt):
"""At the first level of verbosity this will print out detailed
change information on for the specified Vault resource"""
if opt.verbose == 0:
return
if not resource.present:
return
obj = None
existing = None
if isinstance(resource, Resour... | [
"def",
"maybe_details",
"(",
"resource",
",",
"opt",
")",
":",
"if",
"opt",
".",
"verbose",
"==",
"0",
":",
"return",
"if",
"not",
"resource",
".",
"present",
":",
"return",
"obj",
"=",
"None",
"existing",
"=",
"None",
"if",
"isinstance",
"(",
"resourc... | At the first level of verbosity this will print out detailed
change information on for the specified Vault resource | [
"At",
"the",
"first",
"level",
"of",
"verbosity",
"this",
"will",
"print",
"out",
"detailed",
"change",
"information",
"on",
"for",
"the",
"specified",
"Vault",
"resource"
] | train | https://github.com/Autodesk/aomi/blob/84da2dfb0424837adf9c4ddc1aa352e942bb7a4a/aomi/seed_action.py#L141-L178 |
Autodesk/aomi | aomi/seed_action.py | diff_a_thing | def diff_a_thing(thing, opt):
"""Handle the diff action for a single thing. It may be a Vault backend
implementation or it may be a Vault data resource"""
changed = thing.diff()
if changed == ADD:
print("%s %s" % (maybe_colored("+", "green", opt), str(thing)))
elif changed == DEL:
pr... | python | def diff_a_thing(thing, opt):
"""Handle the diff action for a single thing. It may be a Vault backend
implementation or it may be a Vault data resource"""
changed = thing.diff()
if changed == ADD:
print("%s %s" % (maybe_colored("+", "green", opt), str(thing)))
elif changed == DEL:
pr... | [
"def",
"diff_a_thing",
"(",
"thing",
",",
"opt",
")",
":",
"changed",
"=",
"thing",
".",
"diff",
"(",
")",
"if",
"changed",
"==",
"ADD",
":",
"print",
"(",
"\"%s %s\"",
"%",
"(",
"maybe_colored",
"(",
"\"+\"",
",",
"\"green\"",
",",
"opt",
")",
",",
... | Handle the diff action for a single thing. It may be a Vault backend
implementation or it may be a Vault data resource | [
"Handle",
"the",
"diff",
"action",
"for",
"a",
"single",
"thing",
".",
"It",
"may",
"be",
"a",
"Vault",
"backend",
"implementation",
"or",
"it",
"may",
"be",
"a",
"Vault",
"data",
"resource"
] | train | https://github.com/Autodesk/aomi/blob/84da2dfb0424837adf9c4ddc1aa352e942bb7a4a/aomi/seed_action.py#L181-L197 |
Autodesk/aomi | aomi/seed_action.py | diff | def diff(vault_client, opt):
"""Derive a comparison between what is represented in the Secretfile
and what is actually live on a Vault instance"""
if opt.thaw_from:
opt.secrets = tempfile.mkdtemp('aomi-thaw')
auto_thaw(vault_client, opt)
ctx = Context.load(get_secretfile(opt), opt) \
... | python | def diff(vault_client, opt):
"""Derive a comparison between what is represented in the Secretfile
and what is actually live on a Vault instance"""
if opt.thaw_from:
opt.secrets = tempfile.mkdtemp('aomi-thaw')
auto_thaw(vault_client, opt)
ctx = Context.load(get_secretfile(opt), opt) \
... | [
"def",
"diff",
"(",
"vault_client",
",",
"opt",
")",
":",
"if",
"opt",
".",
"thaw_from",
":",
"opt",
".",
"secrets",
"=",
"tempfile",
".",
"mkdtemp",
"(",
"'aomi-thaw'",
")",
"auto_thaw",
"(",
"vault_client",
",",
"opt",
")",
"ctx",
"=",
"Context",
"."... | Derive a comparison between what is represented in the Secretfile
and what is actually live on a Vault instance | [
"Derive",
"a",
"comparison",
"between",
"what",
"is",
"represented",
"in",
"the",
"Secretfile",
"and",
"what",
"is",
"actually",
"live",
"on",
"a",
"Vault",
"instance"
] | train | https://github.com/Autodesk/aomi/blob/84da2dfb0424837adf9c4ddc1aa352e942bb7a4a/aomi/seed_action.py#L200-L217 |
Autodesk/aomi | aomi/cli.py | help_me | def help_me(parser, opt):
"""Handle display of help and whatever diagnostics"""
print("aomi v%s" % version)
print('Get started with aomi'
' https://autodesk.github.io/aomi/quickstart')
if opt.verbose == 2:
tf_str = 'Token File,' if token_file() else ''
app_str = 'AppID File,' i... | python | def help_me(parser, opt):
"""Handle display of help and whatever diagnostics"""
print("aomi v%s" % version)
print('Get started with aomi'
' https://autodesk.github.io/aomi/quickstart')
if opt.verbose == 2:
tf_str = 'Token File,' if token_file() else ''
app_str = 'AppID File,' i... | [
"def",
"help_me",
"(",
"parser",
",",
"opt",
")",
":",
"print",
"(",
"\"aomi v%s\"",
"%",
"version",
")",
"print",
"(",
"'Get started with aomi'",
"' https://autodesk.github.io/aomi/quickstart'",
")",
"if",
"opt",
".",
"verbose",
"==",
"2",
":",
"tf_str",
"=",
... | Handle display of help and whatever diagnostics | [
"Handle",
"display",
"of",
"help",
"and",
"whatever",
"diagnostics"
] | train | https://github.com/Autodesk/aomi/blob/84da2dfb0424837adf9c4ddc1aa352e942bb7a4a/aomi/cli.py#L20-L43 |
Autodesk/aomi | aomi/cli.py | extract_file_args | def extract_file_args(subparsers):
"""Add the command line options for the extract_file operation"""
extract_parser = subparsers.add_parser('extract_file',
help='Extract a single secret from'
'Vault to a local file')
extra... | python | def extract_file_args(subparsers):
"""Add the command line options for the extract_file operation"""
extract_parser = subparsers.add_parser('extract_file',
help='Extract a single secret from'
'Vault to a local file')
extra... | [
"def",
"extract_file_args",
"(",
"subparsers",
")",
":",
"extract_parser",
"=",
"subparsers",
".",
"add_parser",
"(",
"'extract_file'",
",",
"help",
"=",
"'Extract a single secret from'",
"'Vault to a local file'",
")",
"extract_parser",
".",
"add_argument",
"(",
"'vaul... | Add the command line options for the extract_file operation | [
"Add",
"the",
"command",
"line",
"options",
"for",
"the",
"extract_file",
"operation"
] | train | https://github.com/Autodesk/aomi/blob/84da2dfb0424837adf9c4ddc1aa352e942bb7a4a/aomi/cli.py#L46-L55 |
Autodesk/aomi | aomi/cli.py | mapping_args | def mapping_args(parser):
"""Add various variable mapping command line options to the parser"""
parser.add_argument('--add-prefix',
dest='add_prefix',
help='Specify a prefix to use when '
'generating secret key names')
parser.add_argume... | python | def mapping_args(parser):
"""Add various variable mapping command line options to the parser"""
parser.add_argument('--add-prefix',
dest='add_prefix',
help='Specify a prefix to use when '
'generating secret key names')
parser.add_argume... | [
"def",
"mapping_args",
"(",
"parser",
")",
":",
"parser",
".",
"add_argument",
"(",
"'--add-prefix'",
",",
"dest",
"=",
"'add_prefix'",
",",
"help",
"=",
"'Specify a prefix to use when '",
"'generating secret key names'",
")",
"parser",
".",
"add_argument",
"(",
"'-... | Add various variable mapping command line options to the parser | [
"Add",
"various",
"variable",
"mapping",
"command",
"line",
"options",
"to",
"the",
"parser"
] | train | https://github.com/Autodesk/aomi/blob/84da2dfb0424837adf9c4ddc1aa352e942bb7a4a/aomi/cli.py#L58-L82 |
Autodesk/aomi | aomi/cli.py | aws_env_args | def aws_env_args(subparsers):
"""Add command line options for the aws_environment operation"""
env_parser = subparsers.add_parser('aws_environment')
env_parser.add_argument('vault_path',
help='Full path(s) to the AWS secret')
export_arg(env_parser)
base_args(env_parser) | python | def aws_env_args(subparsers):
"""Add command line options for the aws_environment operation"""
env_parser = subparsers.add_parser('aws_environment')
env_parser.add_argument('vault_path',
help='Full path(s) to the AWS secret')
export_arg(env_parser)
base_args(env_parser) | [
"def",
"aws_env_args",
"(",
"subparsers",
")",
":",
"env_parser",
"=",
"subparsers",
".",
"add_parser",
"(",
"'aws_environment'",
")",
"env_parser",
".",
"add_argument",
"(",
"'vault_path'",
",",
"help",
"=",
"'Full path(s) to the AWS secret'",
")",
"export_arg",
"(... | Add command line options for the aws_environment operation | [
"Add",
"command",
"line",
"options",
"for",
"the",
"aws_environment",
"operation"
] | train | https://github.com/Autodesk/aomi/blob/84da2dfb0424837adf9c4ddc1aa352e942bb7a4a/aomi/cli.py#L93-L99 |
Autodesk/aomi | aomi/cli.py | environment_args | def environment_args(subparsers):
"""Add command line options for the environment operation"""
env_parser = subparsers.add_parser('environment')
env_parser.add_argument('vault_paths',
help='Full path(s) to secret',
nargs='+')
env_parser.add_argumen... | python | def environment_args(subparsers):
"""Add command line options for the environment operation"""
env_parser = subparsers.add_parser('environment')
env_parser.add_argument('vault_paths',
help='Full path(s) to secret',
nargs='+')
env_parser.add_argumen... | [
"def",
"environment_args",
"(",
"subparsers",
")",
":",
"env_parser",
"=",
"subparsers",
".",
"add_parser",
"(",
"'environment'",
")",
"env_parser",
".",
"add_argument",
"(",
"'vault_paths'",
",",
"help",
"=",
"'Full path(s) to secret'",
",",
"nargs",
"=",
"'+'",
... | Add command line options for the environment operation | [
"Add",
"command",
"line",
"options",
"for",
"the",
"environment",
"operation"
] | train | https://github.com/Autodesk/aomi/blob/84da2dfb0424837adf9c4ddc1aa352e942bb7a4a/aomi/cli.py#L102-L114 |
Autodesk/aomi | aomi/cli.py | template_args | def template_args(subparsers):
"""Add command line options for the template operation"""
template_parser = subparsers.add_parser('template')
template_parser.add_argument('template',
help='Template source',
nargs='?')
template_parser.add_a... | python | def template_args(subparsers):
"""Add command line options for the template operation"""
template_parser = subparsers.add_parser('template')
template_parser.add_argument('template',
help='Template source',
nargs='?')
template_parser.add_a... | [
"def",
"template_args",
"(",
"subparsers",
")",
":",
"template_parser",
"=",
"subparsers",
".",
"add_parser",
"(",
"'template'",
")",
"template_parser",
".",
"add_argument",
"(",
"'template'",
",",
"help",
"=",
"'Template source'",
",",
"nargs",
"=",
"'?'",
")",... | Add command line options for the template operation | [
"Add",
"command",
"line",
"options",
"for",
"the",
"template",
"operation"
] | train | https://github.com/Autodesk/aomi/blob/84da2dfb0424837adf9c4ddc1aa352e942bb7a4a/aomi/cli.py#L117-L140 |
Autodesk/aomi | aomi/cli.py | secretfile_args | def secretfile_args(parser):
"""Add Secretfile management command line arguments to parser"""
parser.add_argument('--secrets',
dest='secrets',
help='Path where secrets are stored',
default=os.path.join(os.getcwd(), ".secrets"))
parser.a... | python | def secretfile_args(parser):
"""Add Secretfile management command line arguments to parser"""
parser.add_argument('--secrets',
dest='secrets',
help='Path where secrets are stored',
default=os.path.join(os.getcwd(), ".secrets"))
parser.a... | [
"def",
"secretfile_args",
"(",
"parser",
")",
":",
"parser",
".",
"add_argument",
"(",
"'--secrets'",
",",
"dest",
"=",
"'secrets'",
",",
"help",
"=",
"'Path where secrets are stored'",
",",
"default",
"=",
"os",
".",
"path",
".",
"join",
"(",
"os",
".",
"... | Add Secretfile management command line arguments to parser | [
"Add",
"Secretfile",
"management",
"command",
"line",
"arguments",
"to",
"parser"
] | train | https://github.com/Autodesk/aomi/blob/84da2dfb0424837adf9c4ddc1aa352e942bb7a4a/aomi/cli.py#L143-L174 |
Autodesk/aomi | aomi/cli.py | base_args | def base_args(parser):
"""Add the generic command line options"""
generic_args(parser)
parser.add_argument('--monochrome',
dest='monochrome',
help='Whether or not to use colors',
action='store_true')
parser.add_argument('--metadata'... | python | def base_args(parser):
"""Add the generic command line options"""
generic_args(parser)
parser.add_argument('--monochrome',
dest='monochrome',
help='Whether or not to use colors',
action='store_true')
parser.add_argument('--metadata'... | [
"def",
"base_args",
"(",
"parser",
")",
":",
"generic_args",
"(",
"parser",
")",
"parser",
".",
"add_argument",
"(",
"'--monochrome'",
",",
"dest",
"=",
"'monochrome'",
",",
"help",
"=",
"'Whether or not to use colors'",
",",
"action",
"=",
"'store_true'",
")",
... | Add the generic command line options | [
"Add",
"the",
"generic",
"command",
"line",
"options"
] | train | https://github.com/Autodesk/aomi/blob/84da2dfb0424837adf9c4ddc1aa352e942bb7a4a/aomi/cli.py#L187-L206 |
Autodesk/aomi | aomi/cli.py | export_args | def export_args(subparsers):
"""Add command line options for the export operation"""
export_parser = subparsers.add_parser('export')
export_parser.add_argument('directory',
help='Path where secrets will be exported into')
secretfile_args(export_parser)
vars_args(export... | python | def export_args(subparsers):
"""Add command line options for the export operation"""
export_parser = subparsers.add_parser('export')
export_parser.add_argument('directory',
help='Path where secrets will be exported into')
secretfile_args(export_parser)
vars_args(export... | [
"def",
"export_args",
"(",
"subparsers",
")",
":",
"export_parser",
"=",
"subparsers",
".",
"add_parser",
"(",
"'export'",
")",
"export_parser",
".",
"add_argument",
"(",
"'directory'",
",",
"help",
"=",
"'Path where secrets will be exported into'",
")",
"secretfile_a... | Add command line options for the export operation | [
"Add",
"command",
"line",
"options",
"for",
"the",
"export",
"operation"
] | train | https://github.com/Autodesk/aomi/blob/84da2dfb0424837adf9c4ddc1aa352e942bb7a4a/aomi/cli.py#L209-L216 |
Autodesk/aomi | aomi/cli.py | render_args | def render_args(subparsers):
"""Add command line options for the render operation"""
render_parser = subparsers.add_parser('render')
render_parser.add_argument('directory',
help='Path where Secrefile and accoutrement'
' will be rendered into')
... | python | def render_args(subparsers):
"""Add command line options for the render operation"""
render_parser = subparsers.add_parser('render')
render_parser.add_argument('directory',
help='Path where Secrefile and accoutrement'
' will be rendered into')
... | [
"def",
"render_args",
"(",
"subparsers",
")",
":",
"render_parser",
"=",
"subparsers",
".",
"add_parser",
"(",
"'render'",
")",
"render_parser",
".",
"add_argument",
"(",
"'directory'",
",",
"help",
"=",
"'Path where Secrefile and accoutrement'",
"' will be rendered int... | Add command line options for the render operation | [
"Add",
"command",
"line",
"options",
"for",
"the",
"render",
"operation"
] | train | https://github.com/Autodesk/aomi/blob/84da2dfb0424837adf9c4ddc1aa352e942bb7a4a/aomi/cli.py#L219-L228 |
Autodesk/aomi | aomi/cli.py | diff_args | def diff_args(subparsers):
"""Add command line options for the diff operation"""
diff_parser = subparsers.add_parser('diff')
secretfile_args(diff_parser)
vars_args(diff_parser)
base_args(diff_parser)
thaw_from_args(diff_parser) | python | def diff_args(subparsers):
"""Add command line options for the diff operation"""
diff_parser = subparsers.add_parser('diff')
secretfile_args(diff_parser)
vars_args(diff_parser)
base_args(diff_parser)
thaw_from_args(diff_parser) | [
"def",
"diff_args",
"(",
"subparsers",
")",
":",
"diff_parser",
"=",
"subparsers",
".",
"add_parser",
"(",
"'diff'",
")",
"secretfile_args",
"(",
"diff_parser",
")",
"vars_args",
"(",
"diff_parser",
")",
"base_args",
"(",
"diff_parser",
")",
"thaw_from_args",
"(... | Add command line options for the diff operation | [
"Add",
"command",
"line",
"options",
"for",
"the",
"diff",
"operation"
] | train | https://github.com/Autodesk/aomi/blob/84da2dfb0424837adf9c4ddc1aa352e942bb7a4a/aomi/cli.py#L231-L237 |
Autodesk/aomi | aomi/cli.py | seed_args | def seed_args(subparsers):
"""Add command line options for the seed operation"""
seed_parser = subparsers.add_parser('seed')
secretfile_args(seed_parser)
vars_args(seed_parser)
seed_parser.add_argument('--mount-only',
dest='mount_only',
help=... | python | def seed_args(subparsers):
"""Add command line options for the seed operation"""
seed_parser = subparsers.add_parser('seed')
secretfile_args(seed_parser)
vars_args(seed_parser)
seed_parser.add_argument('--mount-only',
dest='mount_only',
help=... | [
"def",
"seed_args",
"(",
"subparsers",
")",
":",
"seed_parser",
"=",
"subparsers",
".",
"add_parser",
"(",
"'seed'",
")",
"secretfile_args",
"(",
"seed_parser",
")",
"vars_args",
"(",
"seed_parser",
")",
"seed_parser",
".",
"add_argument",
"(",
"'--mount-only'",
... | Add command line options for the seed operation | [
"Add",
"command",
"line",
"options",
"for",
"the",
"seed",
"operation"
] | train | https://github.com/Autodesk/aomi/blob/84da2dfb0424837adf9c4ddc1aa352e942bb7a4a/aomi/cli.py#L240-L256 |
Autodesk/aomi | aomi/cli.py | thaw_from_args | def thaw_from_args(parser):
"""Adds command line options for things related to inline thawing
of icefiles"""
parser.add_argument('--thaw-from',
dest='thaw_from',
help='Thaw an ICE file containing secrets')
parser.add_argument('--gpg-password-path',
... | python | def thaw_from_args(parser):
"""Adds command line options for things related to inline thawing
of icefiles"""
parser.add_argument('--thaw-from',
dest='thaw_from',
help='Thaw an ICE file containing secrets')
parser.add_argument('--gpg-password-path',
... | [
"def",
"thaw_from_args",
"(",
"parser",
")",
":",
"parser",
".",
"add_argument",
"(",
"'--thaw-from'",
",",
"dest",
"=",
"'thaw_from'",
",",
"help",
"=",
"'Thaw an ICE file containing secrets'",
")",
"parser",
".",
"add_argument",
"(",
"'--gpg-password-path'",
",",
... | Adds command line options for things related to inline thawing
of icefiles | [
"Adds",
"command",
"line",
"options",
"for",
"things",
"related",
"to",
"inline",
"thawing",
"of",
"icefiles"
] | train | https://github.com/Autodesk/aomi/blob/84da2dfb0424837adf9c4ddc1aa352e942bb7a4a/aomi/cli.py#L259-L267 |
Autodesk/aomi | aomi/cli.py | thaw_args | def thaw_args(subparsers):
"""Add command line options for the thaw operation"""
thaw_parser = subparsers.add_parser('thaw')
thaw_parser.add_argument('--gpg-password-path',
dest='gpg_pass_path',
help='Vault path of GPG passphrase location')
thaw_... | python | def thaw_args(subparsers):
"""Add command line options for the thaw operation"""
thaw_parser = subparsers.add_parser('thaw')
thaw_parser.add_argument('--gpg-password-path',
dest='gpg_pass_path',
help='Vault path of GPG passphrase location')
thaw_... | [
"def",
"thaw_args",
"(",
"subparsers",
")",
":",
"thaw_parser",
"=",
"subparsers",
".",
"add_parser",
"(",
"'thaw'",
")",
"thaw_parser",
".",
"add_argument",
"(",
"'--gpg-password-path'",
",",
"dest",
"=",
"'gpg_pass_path'",
",",
"help",
"=",
"'Vault path of GPG p... | Add command line options for the thaw operation | [
"Add",
"command",
"line",
"options",
"for",
"the",
"thaw",
"operation"
] | train | https://github.com/Autodesk/aomi/blob/84da2dfb0424837adf9c4ddc1aa352e942bb7a4a/aomi/cli.py#L277-L292 |
Autodesk/aomi | aomi/cli.py | freeze_args | def freeze_args(subparsers):
"""Add command line options for the freeze operation"""
freeze_parser = subparsers.add_parser('freeze')
freeze_parser.add_argument('--icefile-prefix',
dest='icefile_prefix',
help='Prefix of icefilename')
secretfil... | python | def freeze_args(subparsers):
"""Add command line options for the freeze operation"""
freeze_parser = subparsers.add_parser('freeze')
freeze_parser.add_argument('--icefile-prefix',
dest='icefile_prefix',
help='Prefix of icefilename')
secretfil... | [
"def",
"freeze_args",
"(",
"subparsers",
")",
":",
"freeze_parser",
"=",
"subparsers",
".",
"add_parser",
"(",
"'freeze'",
")",
"freeze_parser",
".",
"add_argument",
"(",
"'--icefile-prefix'",
",",
"dest",
"=",
"'icefile_prefix'",
",",
"help",
"=",
"'Prefix of ice... | Add command line options for the freeze operation | [
"Add",
"command",
"line",
"options",
"for",
"the",
"freeze",
"operation"
] | train | https://github.com/Autodesk/aomi/blob/84da2dfb0424837adf9c4ddc1aa352e942bb7a4a/aomi/cli.py#L295-L304 |
Autodesk/aomi | aomi/cli.py | password_args | def password_args(subparsers):
"""Add command line options for the set_password operation"""
password_parser = subparsers.add_parser('set_password')
password_parser.add_argument('vault_path',
help='Path which contains password'
'secret to be ... | python | def password_args(subparsers):
"""Add command line options for the set_password operation"""
password_parser = subparsers.add_parser('set_password')
password_parser.add_argument('vault_path',
help='Path which contains password'
'secret to be ... | [
"def",
"password_args",
"(",
"subparsers",
")",
":",
"password_parser",
"=",
"subparsers",
".",
"add_parser",
"(",
"'set_password'",
")",
"password_parser",
".",
"add_argument",
"(",
"'vault_path'",
",",
"help",
"=",
"'Path which contains password'",
"'secret to be udpa... | Add command line options for the set_password operation | [
"Add",
"command",
"line",
"options",
"for",
"the",
"set_password",
"operation"
] | train | https://github.com/Autodesk/aomi/blob/84da2dfb0424837adf9c4ddc1aa352e942bb7a4a/aomi/cli.py#L307-L313 |
Autodesk/aomi | aomi/cli.py | vars_args | def vars_args(parser):
"""Add various command line options for external vars"""
parser.add_argument('--extra-vars',
dest='extra_vars',
help='Extra template variables',
default=[],
type=str,
ac... | python | def vars_args(parser):
"""Add various command line options for external vars"""
parser.add_argument('--extra-vars',
dest='extra_vars',
help='Extra template variables',
default=[],
type=str,
ac... | [
"def",
"vars_args",
"(",
"parser",
")",
":",
"parser",
".",
"add_argument",
"(",
"'--extra-vars'",
",",
"dest",
"=",
"'extra_vars'",
",",
"help",
"=",
"'Extra template variables'",
",",
"default",
"=",
"[",
"]",
",",
"type",
"=",
"str",
",",
"action",
"=",... | Add various command line options for external vars | [
"Add",
"various",
"command",
"line",
"options",
"for",
"external",
"vars"
] | train | https://github.com/Autodesk/aomi/blob/84da2dfb0424837adf9c4ddc1aa352e942bb7a4a/aomi/cli.py#L322-L335 |
Autodesk/aomi | aomi/cli.py | parser_factory | def parser_factory(fake_args=None):
"""Return a proper contextual OptionParser"""
parser = ArgumentParser(description='aomi')
subparsers = parser.add_subparsers(dest='operation',
help='Specify the data '
' or extraction operation'... | python | def parser_factory(fake_args=None):
"""Return a proper contextual OptionParser"""
parser = ArgumentParser(description='aomi')
subparsers = parser.add_subparsers(dest='operation',
help='Specify the data '
' or extraction operation'... | [
"def",
"parser_factory",
"(",
"fake_args",
"=",
"None",
")",
":",
"parser",
"=",
"ArgumentParser",
"(",
"description",
"=",
"'aomi'",
")",
"subparsers",
"=",
"parser",
".",
"add_subparsers",
"(",
"dest",
"=",
"'operation'",
",",
"help",
"=",
"'Specify the data... | Return a proper contextual OptionParser | [
"Return",
"a",
"proper",
"contextual",
"OptionParser"
] | train | https://github.com/Autodesk/aomi/blob/84da2dfb0424837adf9c4ddc1aa352e942bb7a4a/aomi/cli.py#L344-L367 |
Autodesk/aomi | aomi/cli.py | template_runner | def template_runner(client, parser, args):
"""Executes template related operations"""
if args.builtin_list:
aomi.template.builtin_list()
elif args.builtin_info:
aomi.template.builtin_info(args.builtin_info)
elif args.template and args.destination and args.vault_paths:
aomi.render... | python | def template_runner(client, parser, args):
"""Executes template related operations"""
if args.builtin_list:
aomi.template.builtin_list()
elif args.builtin_info:
aomi.template.builtin_info(args.builtin_info)
elif args.template and args.destination and args.vault_paths:
aomi.render... | [
"def",
"template_runner",
"(",
"client",
",",
"parser",
",",
"args",
")",
":",
"if",
"args",
".",
"builtin_list",
":",
"aomi",
".",
"template",
".",
"builtin_list",
"(",
")",
"elif",
"args",
".",
"builtin_info",
":",
"aomi",
".",
"template",
".",
"builti... | Executes template related operations | [
"Executes",
"template",
"related",
"operations"
] | train | https://github.com/Autodesk/aomi/blob/84da2dfb0424837adf9c4ddc1aa352e942bb7a4a/aomi/cli.py#L370-L385 |
Autodesk/aomi | aomi/cli.py | ux_actions | def ux_actions(parser, args):
"""Handle some human triggers actions"""
# cryptorito uses native logging (as aomi should tbh)
normal_fmt = '%(message)s'
if hasattr(args, 'verbose') and args.verbose and args.verbose >= 2:
logging.basicConfig(level=logging.DEBUG)
elif hasattr(args, 'verbose') a... | python | def ux_actions(parser, args):
"""Handle some human triggers actions"""
# cryptorito uses native logging (as aomi should tbh)
normal_fmt = '%(message)s'
if hasattr(args, 'verbose') and args.verbose and args.verbose >= 2:
logging.basicConfig(level=logging.DEBUG)
elif hasattr(args, 'verbose') a... | [
"def",
"ux_actions",
"(",
"parser",
",",
"args",
")",
":",
"# cryptorito uses native logging (as aomi should tbh)",
"normal_fmt",
"=",
"'%(message)s'",
"if",
"hasattr",
"(",
"args",
",",
"'verbose'",
")",
"and",
"args",
".",
"verbose",
"and",
"args",
".",
"verbose... | Handle some human triggers actions | [
"Handle",
"some",
"human",
"triggers",
"actions"
] | train | https://github.com/Autodesk/aomi/blob/84da2dfb0424837adf9c4ddc1aa352e942bb7a4a/aomi/cli.py#L388-L400 |
Autodesk/aomi | aomi/cli.py | do_thaw | def do_thaw(client, args):
"""Execute the thaw operation, pulling in an actual Vault
client if neccesary"""
vault_client = None
if args.gpg_pass_path:
vault_client = client.connect(args)
aomi.filez.thaw(vault_client, args.icefile, args)
sys.exit(0) | python | def do_thaw(client, args):
"""Execute the thaw operation, pulling in an actual Vault
client if neccesary"""
vault_client = None
if args.gpg_pass_path:
vault_client = client.connect(args)
aomi.filez.thaw(vault_client, args.icefile, args)
sys.exit(0) | [
"def",
"do_thaw",
"(",
"client",
",",
"args",
")",
":",
"vault_client",
"=",
"None",
"if",
"args",
".",
"gpg_pass_path",
":",
"vault_client",
"=",
"client",
".",
"connect",
"(",
"args",
")",
"aomi",
".",
"filez",
".",
"thaw",
"(",
"vault_client",
",",
... | Execute the thaw operation, pulling in an actual Vault
client if neccesary | [
"Execute",
"the",
"thaw",
"operation",
"pulling",
"in",
"an",
"actual",
"Vault",
"client",
"if",
"neccesary"
] | train | https://github.com/Autodesk/aomi/blob/84da2dfb0424837adf9c4ddc1aa352e942bb7a4a/aomi/cli.py#L403-L411 |
Autodesk/aomi | aomi/cli.py | action_runner | def action_runner(parser, args):
"""Run appropriate action, or throw help"""
ux_actions(parser, args)
client = aomi.vault.Client(args)
if args.operation == 'extract_file':
aomi.render.raw_file(client.connect(args),
args.vault_path, args.destination, args)
s... | python | def action_runner(parser, args):
"""Run appropriate action, or throw help"""
ux_actions(parser, args)
client = aomi.vault.Client(args)
if args.operation == 'extract_file':
aomi.render.raw_file(client.connect(args),
args.vault_path, args.destination, args)
s... | [
"def",
"action_runner",
"(",
"parser",
",",
"args",
")",
":",
"ux_actions",
"(",
"parser",
",",
"args",
")",
"client",
"=",
"aomi",
".",
"vault",
".",
"Client",
"(",
"args",
")",
"if",
"args",
".",
"operation",
"==",
"'extract_file'",
":",
"aomi",
".",... | Run appropriate action, or throw help | [
"Run",
"appropriate",
"action",
"or",
"throw",
"help"
] | train | https://github.com/Autodesk/aomi/blob/84da2dfb0424837adf9c4ddc1aa352e942bb7a4a/aomi/cli.py#L414-L460 |
Autodesk/aomi | aomi/cli.py | main | def main():
"""Entrypoint, sweet Entrypoint"""
parser, args = parser_factory()
try:
action_runner(parser, args)
# this is our uncaught handler so yes we want to actually
# catch every error. the format may vary based on the error handler tho
except Exception as uncaught: # pylint: disa... | python | def main():
"""Entrypoint, sweet Entrypoint"""
parser, args = parser_factory()
try:
action_runner(parser, args)
# this is our uncaught handler so yes we want to actually
# catch every error. the format may vary based on the error handler tho
except Exception as uncaught: # pylint: disa... | [
"def",
"main",
"(",
")",
":",
"parser",
",",
"args",
"=",
"parser_factory",
"(",
")",
"try",
":",
"action_runner",
"(",
"parser",
",",
"args",
")",
"# this is our uncaught handler so yes we want to actually",
"# catch every error. the format may vary based on the error hand... | Entrypoint, sweet Entrypoint | [
"Entrypoint",
"sweet",
"Entrypoint"
] | train | https://github.com/Autodesk/aomi/blob/84da2dfb0424837adf9c4ddc1aa352e942bb7a4a/aomi/cli.py#L463-L473 |
Autodesk/aomi | aomi/model/aws.py | grok_ttl | def grok_ttl(secret):
"""Parses the TTL information"""
ttl_obj = {}
lease_msg = ''
if 'lease' in secret:
ttl_obj['lease'] = secret['lease']
lease_msg = "lease:%s" % (ttl_obj['lease'])
if 'lease_max' in secret:
ttl_obj['lease_max'] = secret['lease_max']
elif 'lease' in tt... | python | def grok_ttl(secret):
"""Parses the TTL information"""
ttl_obj = {}
lease_msg = ''
if 'lease' in secret:
ttl_obj['lease'] = secret['lease']
lease_msg = "lease:%s" % (ttl_obj['lease'])
if 'lease_max' in secret:
ttl_obj['lease_max'] = secret['lease_max']
elif 'lease' in tt... | [
"def",
"grok_ttl",
"(",
"secret",
")",
":",
"ttl_obj",
"=",
"{",
"}",
"lease_msg",
"=",
"''",
"if",
"'lease'",
"in",
"secret",
":",
"ttl_obj",
"[",
"'lease'",
"]",
"=",
"secret",
"[",
"'lease'",
"]",
"lease_msg",
"=",
"\"lease:%s\"",
"%",
"(",
"ttl_obj... | Parses the TTL information | [
"Parses",
"the",
"TTL",
"information"
] | train | https://github.com/Autodesk/aomi/blob/84da2dfb0424837adf9c4ddc1aa352e942bb7a4a/aomi/model/aws.py#L13-L29 |
Autodesk/aomi | aomi/helpers.py | my_version | def my_version():
"""Return the version, checking both packaged and development locations"""
if os.path.exists(resource_filename(__name__, 'version')):
return resource_string(__name__, 'version')
return open(os.path.join(os.path.dirname(__file__),
"..", "version")).read... | python | def my_version():
"""Return the version, checking both packaged and development locations"""
if os.path.exists(resource_filename(__name__, 'version')):
return resource_string(__name__, 'version')
return open(os.path.join(os.path.dirname(__file__),
"..", "version")).read... | [
"def",
"my_version",
"(",
")",
":",
"if",
"os",
".",
"path",
".",
"exists",
"(",
"resource_filename",
"(",
"__name__",
",",
"'version'",
")",
")",
":",
"return",
"resource_string",
"(",
"__name__",
",",
"'version'",
")",
"return",
"open",
"(",
"os",
".",... | Return the version, checking both packaged and development locations | [
"Return",
"the",
"version",
"checking",
"both",
"packaged",
"and",
"development",
"locations"
] | train | https://github.com/Autodesk/aomi/blob/84da2dfb0424837adf9c4ddc1aa352e942bb7a4a/aomi/helpers.py#L19-L25 |
Autodesk/aomi | aomi/helpers.py | abspath | def abspath(raw):
"""Return what is hopefully a OS independent path."""
path_bits = []
if raw.find('/') != -1:
path_bits = raw.split('/')
elif raw.find('\\') != -1:
path_bits = raw.split('\\')
else:
path_bits = [raw]
return os.path.abspath(os.sep.join(path_bits)) | python | def abspath(raw):
"""Return what is hopefully a OS independent path."""
path_bits = []
if raw.find('/') != -1:
path_bits = raw.split('/')
elif raw.find('\\') != -1:
path_bits = raw.split('\\')
else:
path_bits = [raw]
return os.path.abspath(os.sep.join(path_bits)) | [
"def",
"abspath",
"(",
"raw",
")",
":",
"path_bits",
"=",
"[",
"]",
"if",
"raw",
".",
"find",
"(",
"'/'",
")",
"!=",
"-",
"1",
":",
"path_bits",
"=",
"raw",
".",
"split",
"(",
"'/'",
")",
"elif",
"raw",
".",
"find",
"(",
"'\\\\'",
")",
"!=",
... | Return what is hopefully a OS independent path. | [
"Return",
"what",
"is",
"hopefully",
"a",
"OS",
"independent",
"path",
"."
] | train | https://github.com/Autodesk/aomi/blob/84da2dfb0424837adf9c4ddc1aa352e942bb7a4a/aomi/helpers.py#L31-L41 |
Autodesk/aomi | aomi/helpers.py | hard_path | def hard_path(path, prefix_dir):
"""Returns an absolute path to either the relative or absolute file."""
relative = abspath("%s/%s" % (prefix_dir, path))
a_path = abspath(path)
if os.path.exists(relative):
LOG.debug("using relative path %s (%s)", relative, path)
return relative
LOG.... | python | def hard_path(path, prefix_dir):
"""Returns an absolute path to either the relative or absolute file."""
relative = abspath("%s/%s" % (prefix_dir, path))
a_path = abspath(path)
if os.path.exists(relative):
LOG.debug("using relative path %s (%s)", relative, path)
return relative
LOG.... | [
"def",
"hard_path",
"(",
"path",
",",
"prefix_dir",
")",
":",
"relative",
"=",
"abspath",
"(",
"\"%s/%s\"",
"%",
"(",
"prefix_dir",
",",
"path",
")",
")",
"a_path",
"=",
"abspath",
"(",
"path",
")",
"if",
"os",
".",
"path",
".",
"exists",
"(",
"relat... | Returns an absolute path to either the relative or absolute file. | [
"Returns",
"an",
"absolute",
"path",
"to",
"either",
"the",
"relative",
"or",
"absolute",
"file",
"."
] | train | https://github.com/Autodesk/aomi/blob/84da2dfb0424837adf9c4ddc1aa352e942bb7a4a/aomi/helpers.py#L44-L53 |
Autodesk/aomi | aomi/helpers.py | is_tagged | def is_tagged(required_tags, has_tags):
"""Checks if tags match"""
if not required_tags and not has_tags:
return True
elif not required_tags:
return False
found_tags = []
for tag in required_tags:
if tag in has_tags:
found_tags.append(tag)
return len(found_t... | python | def is_tagged(required_tags, has_tags):
"""Checks if tags match"""
if not required_tags and not has_tags:
return True
elif not required_tags:
return False
found_tags = []
for tag in required_tags:
if tag in has_tags:
found_tags.append(tag)
return len(found_t... | [
"def",
"is_tagged",
"(",
"required_tags",
",",
"has_tags",
")",
":",
"if",
"not",
"required_tags",
"and",
"not",
"has_tags",
":",
"return",
"True",
"elif",
"not",
"required_tags",
":",
"return",
"False",
"found_tags",
"=",
"[",
"]",
"for",
"tag",
"in",
"re... | Checks if tags match | [
"Checks",
"if",
"tags",
"match"
] | train | https://github.com/Autodesk/aomi/blob/84da2dfb0424837adf9c4ddc1aa352e942bb7a4a/aomi/helpers.py#L56-L68 |
Autodesk/aomi | aomi/helpers.py | cli_hash | def cli_hash(list_of_kv):
"""Parse out a hash from a list of key=value strings"""
ev_obj = {}
for extra_var in list_of_kv:
ev_list = extra_var.split('=')
key = ev_list[0]
val = '='.join(ev_list[1:]) # b64 and other side effects
ev_obj[key] = val
return ev_obj | python | def cli_hash(list_of_kv):
"""Parse out a hash from a list of key=value strings"""
ev_obj = {}
for extra_var in list_of_kv:
ev_list = extra_var.split('=')
key = ev_list[0]
val = '='.join(ev_list[1:]) # b64 and other side effects
ev_obj[key] = val
return ev_obj | [
"def",
"cli_hash",
"(",
"list_of_kv",
")",
":",
"ev_obj",
"=",
"{",
"}",
"for",
"extra_var",
"in",
"list_of_kv",
":",
"ev_list",
"=",
"extra_var",
".",
"split",
"(",
"'='",
")",
"key",
"=",
"ev_list",
"[",
"0",
"]",
"val",
"=",
"'='",
".",
"join",
... | Parse out a hash from a list of key=value strings | [
"Parse",
"out",
"a",
"hash",
"from",
"a",
"list",
"of",
"key",
"=",
"value",
"strings"
] | train | https://github.com/Autodesk/aomi/blob/84da2dfb0424837adf9c4ddc1aa352e942bb7a4a/aomi/helpers.py#L71-L80 |
Autodesk/aomi | aomi/helpers.py | merge_dicts | def merge_dicts(dict_a, dict_b):
"""Deep merge of two dicts"""
obj = {}
for key, value in iteritems(dict_a):
if key in dict_b:
if isinstance(dict_b[key], dict):
obj[key] = merge_dicts(value, dict_b.pop(key))
else:
obj[key] = value
for key, value i... | python | def merge_dicts(dict_a, dict_b):
"""Deep merge of two dicts"""
obj = {}
for key, value in iteritems(dict_a):
if key in dict_b:
if isinstance(dict_b[key], dict):
obj[key] = merge_dicts(value, dict_b.pop(key))
else:
obj[key] = value
for key, value i... | [
"def",
"merge_dicts",
"(",
"dict_a",
",",
"dict_b",
")",
":",
"obj",
"=",
"{",
"}",
"for",
"key",
",",
"value",
"in",
"iteritems",
"(",
"dict_a",
")",
":",
"if",
"key",
"in",
"dict_b",
":",
"if",
"isinstance",
"(",
"dict_b",
"[",
"key",
"]",
",",
... | Deep merge of two dicts | [
"Deep",
"merge",
"of",
"two",
"dicts"
] | train | https://github.com/Autodesk/aomi/blob/84da2dfb0424837adf9c4ddc1aa352e942bb7a4a/aomi/helpers.py#L83-L96 |
Autodesk/aomi | aomi/helpers.py | get_tty_password | def get_tty_password(confirm):
"""When returning a password from a TTY we assume a user
is entering it on a keyboard so we ask for confirmation."""
LOG.debug("Reading password from TTY")
new_password = getpass('Enter Password: ', stream=sys.stderr)
if not new_password:
raise aomi.exceptions.... | python | def get_tty_password(confirm):
"""When returning a password from a TTY we assume a user
is entering it on a keyboard so we ask for confirmation."""
LOG.debug("Reading password from TTY")
new_password = getpass('Enter Password: ', stream=sys.stderr)
if not new_password:
raise aomi.exceptions.... | [
"def",
"get_tty_password",
"(",
"confirm",
")",
":",
"LOG",
".",
"debug",
"(",
"\"Reading password from TTY\"",
")",
"new_password",
"=",
"getpass",
"(",
"'Enter Password: '",
",",
"stream",
"=",
"sys",
".",
"stderr",
")",
"if",
"not",
"new_password",
":",
"ra... | When returning a password from a TTY we assume a user
is entering it on a keyboard so we ask for confirmation. | [
"When",
"returning",
"a",
"password",
"from",
"a",
"TTY",
"we",
"assume",
"a",
"user",
"is",
"entering",
"it",
"on",
"a",
"keyboard",
"so",
"we",
"ask",
"for",
"confirmation",
"."
] | train | https://github.com/Autodesk/aomi/blob/84da2dfb0424837adf9c4ddc1aa352e942bb7a4a/aomi/helpers.py#L99-L114 |
Autodesk/aomi | aomi/helpers.py | path_pieces | def path_pieces(vault_path):
"""Will return a two part tuple comprising of the vault path
and the key with in the stored object"""
path_bits = vault_path.split('/')
path = '/'.join(path_bits[0:len(path_bits) - 1])
key = path_bits[len(path_bits) - 1]
return path, key | python | def path_pieces(vault_path):
"""Will return a two part tuple comprising of the vault path
and the key with in the stored object"""
path_bits = vault_path.split('/')
path = '/'.join(path_bits[0:len(path_bits) - 1])
key = path_bits[len(path_bits) - 1]
return path, key | [
"def",
"path_pieces",
"(",
"vault_path",
")",
":",
"path_bits",
"=",
"vault_path",
".",
"split",
"(",
"'/'",
")",
"path",
"=",
"'/'",
".",
"join",
"(",
"path_bits",
"[",
"0",
":",
"len",
"(",
"path_bits",
")",
"-",
"1",
"]",
")",
"key",
"=",
"path_... | Will return a two part tuple comprising of the vault path
and the key with in the stored object | [
"Will",
"return",
"a",
"two",
"part",
"tuple",
"comprising",
"of",
"the",
"vault",
"path",
"and",
"the",
"key",
"with",
"in",
"the",
"stored",
"object"
] | train | https://github.com/Autodesk/aomi/blob/84da2dfb0424837adf9c4ddc1aa352e942bb7a4a/aomi/helpers.py#L131-L137 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.