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 |
|---|---|---|---|---|---|---|---|---|---|---|
bpython/curtsies | curtsies/formatstring.py | FmtStr.from_str | def from_str(cls, s):
# type: (Union[Text, bytes]) -> FmtStr
r"""
Return a FmtStr representing input.
The str() of a FmtStr is guaranteed to produced the same FmtStr.
Other input with escape sequences may not be preserved.
>>> fmtstr("|"+fmtstr("hey", fg='red', bg='blue... | python | def from_str(cls, s):
# type: (Union[Text, bytes]) -> FmtStr
r"""
Return a FmtStr representing input.
The str() of a FmtStr is guaranteed to produced the same FmtStr.
Other input with escape sequences may not be preserved.
>>> fmtstr("|"+fmtstr("hey", fg='red', bg='blue... | [
"def",
"from_str",
"(",
"cls",
",",
"s",
")",
":",
"# type: (Union[Text, bytes]) -> FmtStr",
"if",
"'\\x1b['",
"in",
"s",
":",
"try",
":",
"tokens_and_strings",
"=",
"parse",
"(",
"s",
")",
"except",
"ValueError",
":",
"return",
"FmtStr",
"(",
"Chunk",
"(",
... | r"""
Return a FmtStr representing input.
The str() of a FmtStr is guaranteed to produced the same FmtStr.
Other input with escape sequences may not be preserved.
>>> fmtstr("|"+fmtstr("hey", fg='red', bg='blue')+"|")
'|'+on_blue(red('hey'))+'|'
>>> fmtstr('|\x1b[31m\x1b... | [
"r",
"Return",
"a",
"FmtStr",
"representing",
"input",
"."
] | train | https://github.com/bpython/curtsies/blob/223e42b97fbf6c86b479ed4f0963a067333c5a63/curtsies/formatstring.py#L239-L273 |
bpython/curtsies | curtsies/formatstring.py | FmtStr.copy_with_new_str | def copy_with_new_str(self, new_str):
"""Copies the current FmtStr's attributes while changing its string."""
# What to do when there are multiple Chunks with conflicting atts?
old_atts = dict((att, value) for bfs in self.chunks
for (att, value) in bfs.atts.items())
r... | python | def copy_with_new_str(self, new_str):
"""Copies the current FmtStr's attributes while changing its string."""
# What to do when there are multiple Chunks with conflicting atts?
old_atts = dict((att, value) for bfs in self.chunks
for (att, value) in bfs.atts.items())
r... | [
"def",
"copy_with_new_str",
"(",
"self",
",",
"new_str",
")",
":",
"# What to do when there are multiple Chunks with conflicting atts?",
"old_atts",
"=",
"dict",
"(",
"(",
"att",
",",
"value",
")",
"for",
"bfs",
"in",
"self",
".",
"chunks",
"for",
"(",
"att",
",... | Copies the current FmtStr's attributes while changing its string. | [
"Copies",
"the",
"current",
"FmtStr",
"s",
"attributes",
"while",
"changing",
"its",
"string",
"."
] | train | https://github.com/bpython/curtsies/blob/223e42b97fbf6c86b479ed4f0963a067333c5a63/curtsies/formatstring.py#L275-L280 |
bpython/curtsies | curtsies/formatstring.py | FmtStr.setitem | def setitem(self, startindex, fs):
"""Shim for easily converting old __setitem__ calls"""
return self.setslice_with_length(startindex, startindex+1, fs, len(self)) | python | def setitem(self, startindex, fs):
"""Shim for easily converting old __setitem__ calls"""
return self.setslice_with_length(startindex, startindex+1, fs, len(self)) | [
"def",
"setitem",
"(",
"self",
",",
"startindex",
",",
"fs",
")",
":",
"return",
"self",
".",
"setslice_with_length",
"(",
"startindex",
",",
"startindex",
"+",
"1",
",",
"fs",
",",
"len",
"(",
"self",
")",
")"
] | Shim for easily converting old __setitem__ calls | [
"Shim",
"for",
"easily",
"converting",
"old",
"__setitem__",
"calls"
] | train | https://github.com/bpython/curtsies/blob/223e42b97fbf6c86b479ed4f0963a067333c5a63/curtsies/formatstring.py#L282-L284 |
bpython/curtsies | curtsies/formatstring.py | FmtStr.setslice_with_length | def setslice_with_length(self, startindex, endindex, fs, length):
"""Shim for easily converting old __setitem__ calls"""
if len(self) < startindex:
fs = ' '*(startindex - len(self)) + fs
if len(self) > endindex:
fs = fs + ' '*(endindex - startindex - len(fs))
... | python | def setslice_with_length(self, startindex, endindex, fs, length):
"""Shim for easily converting old __setitem__ calls"""
if len(self) < startindex:
fs = ' '*(startindex - len(self)) + fs
if len(self) > endindex:
fs = fs + ' '*(endindex - startindex - len(fs))
... | [
"def",
"setslice_with_length",
"(",
"self",
",",
"startindex",
",",
"endindex",
",",
"fs",
",",
"length",
")",
":",
"if",
"len",
"(",
"self",
")",
"<",
"startindex",
":",
"fs",
"=",
"' '",
"*",
"(",
"startindex",
"-",
"len",
"(",
"self",
")",
")",
... | Shim for easily converting old __setitem__ calls | [
"Shim",
"for",
"easily",
"converting",
"old",
"__setitem__",
"calls"
] | train | https://github.com/bpython/curtsies/blob/223e42b97fbf6c86b479ed4f0963a067333c5a63/curtsies/formatstring.py#L286-L295 |
bpython/curtsies | curtsies/formatstring.py | FmtStr.splice | def splice(self, new_str, start, end=None):
"""Returns a new FmtStr with the input string spliced into the
the original FmtStr at start and end.
If end is provided, new_str will replace the substring self.s[start:end-1].
"""
if len(new_str) == 0:
return self
n... | python | def splice(self, new_str, start, end=None):
"""Returns a new FmtStr with the input string spliced into the
the original FmtStr at start and end.
If end is provided, new_str will replace the substring self.s[start:end-1].
"""
if len(new_str) == 0:
return self
n... | [
"def",
"splice",
"(",
"self",
",",
"new_str",
",",
"start",
",",
"end",
"=",
"None",
")",
":",
"if",
"len",
"(",
"new_str",
")",
"==",
"0",
":",
"return",
"self",
"new_fs",
"=",
"new_str",
"if",
"isinstance",
"(",
"new_str",
",",
"FmtStr",
")",
"el... | Returns a new FmtStr with the input string spliced into the
the original FmtStr at start and end.
If end is provided, new_str will replace the substring self.s[start:end-1]. | [
"Returns",
"a",
"new",
"FmtStr",
"with",
"the",
"input",
"string",
"spliced",
"into",
"the",
"the",
"original",
"FmtStr",
"at",
"start",
"and",
"end",
".",
"If",
"end",
"is",
"provided",
"new_str",
"will",
"replace",
"the",
"substring",
"self",
".",
"s",
... | train | https://github.com/bpython/curtsies/blob/223e42b97fbf6c86b479ed4f0963a067333c5a63/curtsies/formatstring.py#L297-L343 |
bpython/curtsies | curtsies/formatstring.py | FmtStr.copy_with_new_atts | def copy_with_new_atts(self, **attributes):
"""Returns a new FmtStr with the same content but new formatting"""
return FmtStr(*[Chunk(bfs.s, bfs.atts.extend(attributes))
for bfs in self.chunks]) | python | def copy_with_new_atts(self, **attributes):
"""Returns a new FmtStr with the same content but new formatting"""
return FmtStr(*[Chunk(bfs.s, bfs.atts.extend(attributes))
for bfs in self.chunks]) | [
"def",
"copy_with_new_atts",
"(",
"self",
",",
"*",
"*",
"attributes",
")",
":",
"return",
"FmtStr",
"(",
"*",
"[",
"Chunk",
"(",
"bfs",
".",
"s",
",",
"bfs",
".",
"atts",
".",
"extend",
"(",
"attributes",
")",
")",
"for",
"bfs",
"in",
"self",
".",... | Returns a new FmtStr with the same content but new formatting | [
"Returns",
"a",
"new",
"FmtStr",
"with",
"the",
"same",
"content",
"but",
"new",
"formatting"
] | train | https://github.com/bpython/curtsies/blob/223e42b97fbf6c86b479ed4f0963a067333c5a63/curtsies/formatstring.py#L348-L351 |
bpython/curtsies | curtsies/formatstring.py | FmtStr.join | def join(self, iterable):
"""Joins an iterable yielding strings or FmtStrs with self as separator"""
before = []
chunks = []
for i, s in enumerate(iterable):
chunks.extend(before)
before = self.chunks
if isinstance(s, FmtStr):
chunks.ex... | python | def join(self, iterable):
"""Joins an iterable yielding strings or FmtStrs with self as separator"""
before = []
chunks = []
for i, s in enumerate(iterable):
chunks.extend(before)
before = self.chunks
if isinstance(s, FmtStr):
chunks.ex... | [
"def",
"join",
"(",
"self",
",",
"iterable",
")",
":",
"before",
"=",
"[",
"]",
"chunks",
"=",
"[",
"]",
"for",
"i",
",",
"s",
"in",
"enumerate",
"(",
"iterable",
")",
":",
"chunks",
".",
"extend",
"(",
"before",
")",
"before",
"=",
"self",
".",
... | Joins an iterable yielding strings or FmtStrs with self as separator | [
"Joins",
"an",
"iterable",
"yielding",
"strings",
"or",
"FmtStrs",
"with",
"self",
"as",
"separator"
] | train | https://github.com/bpython/curtsies/blob/223e42b97fbf6c86b479ed4f0963a067333c5a63/curtsies/formatstring.py#L353-L366 |
bpython/curtsies | curtsies/formatstring.py | FmtStr.split | def split(self, sep=None, maxsplit=None, regex=False):
"""Split based on seperator, optionally using a regex
Capture groups are ignored in regex, the whole pattern is matched
and used to split the original FmtStr."""
if maxsplit is not None:
raise NotImplementedError('no max... | python | def split(self, sep=None, maxsplit=None, regex=False):
"""Split based on seperator, optionally using a regex
Capture groups are ignored in regex, the whole pattern is matched
and used to split the original FmtStr."""
if maxsplit is not None:
raise NotImplementedError('no max... | [
"def",
"split",
"(",
"self",
",",
"sep",
"=",
"None",
",",
"maxsplit",
"=",
"None",
",",
"regex",
"=",
"False",
")",
":",
"if",
"maxsplit",
"is",
"not",
"None",
":",
"raise",
"NotImplementedError",
"(",
"'no maxsplit yet'",
")",
"s",
"=",
"self",
".",
... | Split based on seperator, optionally using a regex
Capture groups are ignored in regex, the whole pattern is matched
and used to split the original FmtStr. | [
"Split",
"based",
"on",
"seperator",
"optionally",
"using",
"a",
"regex"
] | train | https://github.com/bpython/curtsies/blob/223e42b97fbf6c86b479ed4f0963a067333c5a63/curtsies/formatstring.py#L369-L384 |
bpython/curtsies | curtsies/formatstring.py | FmtStr.splitlines | def splitlines(self, keepends=False):
"""Return a list of lines, split on newline characters,
include line boundaries, if keepends is true."""
lines = self.split('\n')
return [line+'\n' for line in lines] if keepends else (
lines if lines[-1] else lines[:-1]) | python | def splitlines(self, keepends=False):
"""Return a list of lines, split on newline characters,
include line boundaries, if keepends is true."""
lines = self.split('\n')
return [line+'\n' for line in lines] if keepends else (
lines if lines[-1] else lines[:-1]) | [
"def",
"splitlines",
"(",
"self",
",",
"keepends",
"=",
"False",
")",
":",
"lines",
"=",
"self",
".",
"split",
"(",
"'\\n'",
")",
"return",
"[",
"line",
"+",
"'\\n'",
"for",
"line",
"in",
"lines",
"]",
"if",
"keepends",
"else",
"(",
"lines",
"if",
... | Return a list of lines, split on newline characters,
include line boundaries, if keepends is true. | [
"Return",
"a",
"list",
"of",
"lines",
"split",
"on",
"newline",
"characters",
"include",
"line",
"boundaries",
"if",
"keepends",
"is",
"true",
"."
] | train | https://github.com/bpython/curtsies/blob/223e42b97fbf6c86b479ed4f0963a067333c5a63/curtsies/formatstring.py#L386-L391 |
bpython/curtsies | curtsies/formatstring.py | FmtStr.ljust | def ljust(self, width, fillchar=None):
"""S.ljust(width[, fillchar]) -> string
If a fillchar is provided, less formatting information will be preserved
"""
if fillchar is not None:
return fmtstr(self.s.ljust(width, fillchar), **self.shared_atts)
to_add = ' ' * (width... | python | def ljust(self, width, fillchar=None):
"""S.ljust(width[, fillchar]) -> string
If a fillchar is provided, less formatting information will be preserved
"""
if fillchar is not None:
return fmtstr(self.s.ljust(width, fillchar), **self.shared_atts)
to_add = ' ' * (width... | [
"def",
"ljust",
"(",
"self",
",",
"width",
",",
"fillchar",
"=",
"None",
")",
":",
"if",
"fillchar",
"is",
"not",
"None",
":",
"return",
"fmtstr",
"(",
"self",
".",
"s",
".",
"ljust",
"(",
"width",
",",
"fillchar",
")",
",",
"*",
"*",
"self",
"."... | S.ljust(width[, fillchar]) -> string
If a fillchar is provided, less formatting information will be preserved | [
"S",
".",
"ljust",
"(",
"width",
"[",
"fillchar",
"]",
")",
"-",
">",
"string"
] | train | https://github.com/bpython/curtsies/blob/223e42b97fbf6c86b479ed4f0963a067333c5a63/curtsies/formatstring.py#L395-L408 |
bpython/curtsies | curtsies/formatstring.py | FmtStr.width | def width(self):
"""The number of columns it would take to display this string"""
if self._width is not None:
return self._width
self._width = sum(fs.width for fs in self.chunks)
return self._width | python | def width(self):
"""The number of columns it would take to display this string"""
if self._width is not None:
return self._width
self._width = sum(fs.width for fs in self.chunks)
return self._width | [
"def",
"width",
"(",
"self",
")",
":",
"if",
"self",
".",
"_width",
"is",
"not",
"None",
":",
"return",
"self",
".",
"_width",
"self",
".",
"_width",
"=",
"sum",
"(",
"fs",
".",
"width",
"for",
"fs",
"in",
"self",
".",
"chunks",
")",
"return",
"s... | The number of columns it would take to display this string | [
"The",
"number",
"of",
"columns",
"it",
"would",
"take",
"to",
"display",
"this",
"string"
] | train | https://github.com/bpython/curtsies/blob/223e42b97fbf6c86b479ed4f0963a067333c5a63/curtsies/formatstring.py#L447-L452 |
bpython/curtsies | curtsies/formatstring.py | FmtStr.width_at_offset | def width_at_offset(self, n):
"""Returns the horizontal position of character n of the string"""
#TODO make more efficient?
width = wcswidth(self.s[:n])
assert width != -1
return width | python | def width_at_offset(self, n):
"""Returns the horizontal position of character n of the string"""
#TODO make more efficient?
width = wcswidth(self.s[:n])
assert width != -1
return width | [
"def",
"width_at_offset",
"(",
"self",
",",
"n",
")",
":",
"#TODO make more efficient?",
"width",
"=",
"wcswidth",
"(",
"self",
".",
"s",
"[",
":",
"n",
"]",
")",
"assert",
"width",
"!=",
"-",
"1",
"return",
"width"
] | Returns the horizontal position of character n of the string | [
"Returns",
"the",
"horizontal",
"position",
"of",
"character",
"n",
"of",
"the",
"string"
] | train | https://github.com/bpython/curtsies/blob/223e42b97fbf6c86b479ed4f0963a067333c5a63/curtsies/formatstring.py#L454-L459 |
bpython/curtsies | curtsies/formatstring.py | FmtStr.shared_atts | def shared_atts(self):
"""Gets atts shared among all nonzero length component Chunk"""
#TODO cache this, could get ugly for large FmtStrs
atts = {}
first = self.chunks[0]
for att in sorted(first.atts):
#TODO how to write this without the '???'?
if all(fs.a... | python | def shared_atts(self):
"""Gets atts shared among all nonzero length component Chunk"""
#TODO cache this, could get ugly for large FmtStrs
atts = {}
first = self.chunks[0]
for att in sorted(first.atts):
#TODO how to write this without the '???'?
if all(fs.a... | [
"def",
"shared_atts",
"(",
"self",
")",
":",
"#TODO cache this, could get ugly for large FmtStrs",
"atts",
"=",
"{",
"}",
"first",
"=",
"self",
".",
"chunks",
"[",
"0",
"]",
"for",
"att",
"in",
"sorted",
"(",
"first",
".",
"atts",
")",
":",
"#TODO how to wri... | Gets atts shared among all nonzero length component Chunk | [
"Gets",
"atts",
"shared",
"among",
"all",
"nonzero",
"length",
"component",
"Chunk"
] | train | https://github.com/bpython/curtsies/blob/223e42b97fbf6c86b479ed4f0963a067333c5a63/curtsies/formatstring.py#L494-L503 |
bpython/curtsies | curtsies/formatstring.py | FmtStr.new_with_atts_removed | def new_with_atts_removed(self, *attributes):
"""Returns a new FmtStr with the same content but some attributes removed"""
return FmtStr(*[Chunk(bfs.s, bfs.atts.remove(*attributes))
for bfs in self.chunks]) | python | def new_with_atts_removed(self, *attributes):
"""Returns a new FmtStr with the same content but some attributes removed"""
return FmtStr(*[Chunk(bfs.s, bfs.atts.remove(*attributes))
for bfs in self.chunks]) | [
"def",
"new_with_atts_removed",
"(",
"self",
",",
"*",
"attributes",
")",
":",
"return",
"FmtStr",
"(",
"*",
"[",
"Chunk",
"(",
"bfs",
".",
"s",
",",
"bfs",
".",
"atts",
".",
"remove",
"(",
"*",
"attributes",
")",
")",
"for",
"bfs",
"in",
"self",
"... | Returns a new FmtStr with the same content but some attributes removed | [
"Returns",
"a",
"new",
"FmtStr",
"with",
"the",
"same",
"content",
"but",
"some",
"attributes",
"removed"
] | train | https://github.com/bpython/curtsies/blob/223e42b97fbf6c86b479ed4f0963a067333c5a63/curtsies/formatstring.py#L505-L508 |
bpython/curtsies | curtsies/formatstring.py | FmtStr.divides | def divides(self):
"""List of indices of divisions between the constituent chunks."""
acc = [0]
for s in self.chunks:
acc.append(acc[-1] + len(s))
return acc | python | def divides(self):
"""List of indices of divisions between the constituent chunks."""
acc = [0]
for s in self.chunks:
acc.append(acc[-1] + len(s))
return acc | [
"def",
"divides",
"(",
"self",
")",
":",
"acc",
"=",
"[",
"0",
"]",
"for",
"s",
"in",
"self",
".",
"chunks",
":",
"acc",
".",
"append",
"(",
"acc",
"[",
"-",
"1",
"]",
"+",
"len",
"(",
"s",
")",
")",
"return",
"acc"
] | List of indices of divisions between the constituent chunks. | [
"List",
"of",
"indices",
"of",
"divisions",
"between",
"the",
"constituent",
"chunks",
"."
] | train | https://github.com/bpython/curtsies/blob/223e42b97fbf6c86b479ed4f0963a067333c5a63/curtsies/formatstring.py#L525-L530 |
bpython/curtsies | curtsies/formatstring.py | FmtStr.width_aware_slice | def width_aware_slice(self, index):
"""Slice based on the number of columns it would take to display the substring."""
if wcswidth(self.s) == -1:
raise ValueError('bad values for width aware slicing')
index = normalize_slice(self.width, index)
counter = 0
parts = []
... | python | def width_aware_slice(self, index):
"""Slice based on the number of columns it would take to display the substring."""
if wcswidth(self.s) == -1:
raise ValueError('bad values for width aware slicing')
index = normalize_slice(self.width, index)
counter = 0
parts = []
... | [
"def",
"width_aware_slice",
"(",
"self",
",",
"index",
")",
":",
"if",
"wcswidth",
"(",
"self",
".",
"s",
")",
"==",
"-",
"1",
":",
"raise",
"ValueError",
"(",
"'bad values for width aware slicing'",
")",
"index",
"=",
"normalize_slice",
"(",
"self",
".",
... | Slice based on the number of columns it would take to display the substring. | [
"Slice",
"based",
"on",
"the",
"number",
"of",
"columns",
"it",
"would",
"take",
"to",
"display",
"the",
"substring",
"."
] | train | https://github.com/bpython/curtsies/blob/223e42b97fbf6c86b479ed4f0963a067333c5a63/curtsies/formatstring.py#L557-L576 |
bpython/curtsies | curtsies/formatstring.py | FmtStr.width_aware_splitlines | def width_aware_splitlines(self, columns):
# type: (int) -> Iterator[FmtStr]
"""Split into lines, pushing doublewidth characters at the end of a line to the next line.
When a double-width character is pushed to the next line, a space is added to pad out the line.
"""
if columns ... | python | def width_aware_splitlines(self, columns):
# type: (int) -> Iterator[FmtStr]
"""Split into lines, pushing doublewidth characters at the end of a line to the next line.
When a double-width character is pushed to the next line, a space is added to pad out the line.
"""
if columns ... | [
"def",
"width_aware_splitlines",
"(",
"self",
",",
"columns",
")",
":",
"# type: (int) -> Iterator[FmtStr]",
"if",
"columns",
"<",
"2",
":",
"raise",
"ValueError",
"(",
"\"Column width %s is too narrow.\"",
"%",
"columns",
")",
"if",
"wcswidth",
"(",
"self",
".",
... | Split into lines, pushing doublewidth characters at the end of a line to the next line.
When a double-width character is pushed to the next line, a space is added to pad out the line. | [
"Split",
"into",
"lines",
"pushing",
"doublewidth",
"characters",
"at",
"the",
"end",
"of",
"a",
"line",
"to",
"the",
"next",
"line",
"."
] | train | https://github.com/bpython/curtsies/blob/223e42b97fbf6c86b479ed4f0963a067333c5a63/curtsies/formatstring.py#L578-L588 |
bpython/curtsies | curtsies/formatstring.py | FmtStr._getitem_normalized | def _getitem_normalized(self, index):
"""Builds the more compact fmtstrs by using fromstr( of the control sequences)"""
index = normalize_slice(len(self), index)
counter = 0
output = ''
for fs in self.chunks:
if index.start < counter + len(fs) and index.stop > counter... | python | def _getitem_normalized(self, index):
"""Builds the more compact fmtstrs by using fromstr( of the control sequences)"""
index = normalize_slice(len(self), index)
counter = 0
output = ''
for fs in self.chunks:
if index.start < counter + len(fs) and index.stop > counter... | [
"def",
"_getitem_normalized",
"(",
"self",
",",
"index",
")",
":",
"index",
"=",
"normalize_slice",
"(",
"len",
"(",
"self",
")",
",",
"index",
")",
"counter",
"=",
"0",
"output",
"=",
"''",
"for",
"fs",
"in",
"self",
".",
"chunks",
":",
"if",
"index... | Builds the more compact fmtstrs by using fromstr( of the control sequences) | [
"Builds",
"the",
"more",
"compact",
"fmtstrs",
"by",
"using",
"fromstr",
"(",
"of",
"the",
"control",
"sequences",
")"
] | train | https://github.com/bpython/curtsies/blob/223e42b97fbf6c86b479ed4f0963a067333c5a63/curtsies/formatstring.py#L613-L626 |
peterwittek/ncpol2sdpa | ncpol2sdpa/moroder_hierarchy.py | MoroderHierarchy._calculate_block_structure | def _calculate_block_structure(self, inequalities, equalities,
momentinequalities, momentequalities,
extramomentmatrix, removeequalities,
block_struct=None):
"""Calculates the block_struct array for the outp... | python | def _calculate_block_structure(self, inequalities, equalities,
momentinequalities, momentequalities,
extramomentmatrix, removeequalities,
block_struct=None):
"""Calculates the block_struct array for the outp... | [
"def",
"_calculate_block_structure",
"(",
"self",
",",
"inequalities",
",",
"equalities",
",",
"momentinequalities",
",",
"momentequalities",
",",
"extramomentmatrix",
",",
"removeequalities",
",",
"block_struct",
"=",
"None",
")",
":",
"block_struct",
"=",
"[",
"]"... | Calculates the block_struct array for the output file. | [
"Calculates",
"the",
"block_struct",
"array",
"for",
"the",
"output",
"file",
"."
] | train | https://github.com/peterwittek/ncpol2sdpa/blob/bce75d524d0b9d0093f32e3a0a5611f8589351a7/ncpol2sdpa/moroder_hierarchy.py#L81-L101 |
bpython/curtsies | examples/initial_input.py | main | def main():
"""Ideally we shouldn't lose the first second of events"""
time.sleep(1)
with Input() as input_generator:
for e in input_generator:
print(repr(e)) | python | def main():
"""Ideally we shouldn't lose the first second of events"""
time.sleep(1)
with Input() as input_generator:
for e in input_generator:
print(repr(e)) | [
"def",
"main",
"(",
")",
":",
"time",
".",
"sleep",
"(",
"1",
")",
"with",
"Input",
"(",
")",
"as",
"input_generator",
":",
"for",
"e",
"in",
"input_generator",
":",
"print",
"(",
"repr",
"(",
"e",
")",
")"
] | Ideally we shouldn't lose the first second of events | [
"Ideally",
"we",
"shouldn",
"t",
"lose",
"the",
"first",
"second",
"of",
"events"
] | train | https://github.com/bpython/curtsies/blob/223e42b97fbf6c86b479ed4f0963a067333c5a63/examples/initial_input.py#L5-L10 |
peterwittek/ncpol2sdpa | ncpol2sdpa/steering_hierarchy.py | SteeringHierarchy._process_monomial | def _process_monomial(self, monomial, n_vars):
"""Process a single monomial when building the moment matrix.
"""
coeff, monomial = monomial.as_coeff_Mul()
k = 0
# Have we seen this monomial before?
conjugate = False
try:
# If yes, then we improve spars... | python | def _process_monomial(self, monomial, n_vars):
"""Process a single monomial when building the moment matrix.
"""
coeff, monomial = monomial.as_coeff_Mul()
k = 0
# Have we seen this monomial before?
conjugate = False
try:
# If yes, then we improve spars... | [
"def",
"_process_monomial",
"(",
"self",
",",
"monomial",
",",
"n_vars",
")",
":",
"coeff",
",",
"monomial",
"=",
"monomial",
".",
"as_coeff_Mul",
"(",
")",
"k",
"=",
"0",
"# Have we seen this monomial before?",
"conjugate",
"=",
"False",
"try",
":",
"# If yes... | Process a single monomial when building the moment matrix. | [
"Process",
"a",
"single",
"monomial",
"when",
"building",
"the",
"moment",
"matrix",
"."
] | train | https://github.com/peterwittek/ncpol2sdpa/blob/bce75d524d0b9d0093f32e3a0a5611f8589351a7/ncpol2sdpa/steering_hierarchy.py#L80-L108 |
peterwittek/ncpol2sdpa | ncpol2sdpa/steering_hierarchy.py | SteeringHierarchy.__get_trace_facvar | def __get_trace_facvar(self, polynomial):
"""Return dense vector representation of a polynomial. This function is
nearly identical to __push_facvar_sparse, but instead of pushing
sparse entries to the constraint matrices, it returns a dense
vector.
"""
facvar = [0] * (sel... | python | def __get_trace_facvar(self, polynomial):
"""Return dense vector representation of a polynomial. This function is
nearly identical to __push_facvar_sparse, but instead of pushing
sparse entries to the constraint matrices, it returns a dense
vector.
"""
facvar = [0] * (sel... | [
"def",
"__get_trace_facvar",
"(",
"self",
",",
"polynomial",
")",
":",
"facvar",
"=",
"[",
"0",
"]",
"*",
"(",
"self",
".",
"n_vars",
"+",
"1",
")",
"F",
"=",
"{",
"}",
"for",
"i",
"in",
"range",
"(",
"self",
".",
"matrix_var_dim",
")",
":",
"for... | Return dense vector representation of a polynomial. This function is
nearly identical to __push_facvar_sparse, but instead of pushing
sparse entries to the constraint matrices, it returns a dense
vector. | [
"Return",
"dense",
"vector",
"representation",
"of",
"a",
"polynomial",
".",
"This",
"function",
"is",
"nearly",
"identical",
"to",
"__push_facvar_sparse",
"but",
"instead",
"of",
"pushing",
"sparse",
"entries",
"to",
"the",
"constraint",
"matrices",
"it",
"return... | train | https://github.com/peterwittek/ncpol2sdpa/blob/bce75d524d0b9d0093f32e3a0a5611f8589351a7/ncpol2sdpa/steering_hierarchy.py#L186-L219 |
peterwittek/ncpol2sdpa | ncpol2sdpa/steering_hierarchy.py | SteeringHierarchy.set_objective | def set_objective(self, objective, extraobjexpr=None):
"""Set or change the objective function of the polynomial optimization
problem.
:param objective: Describes the objective function.
:type objective: :class:`sympy.core.expr.Expr`
:param extraobjexpr: Optional parameter of a ... | python | def set_objective(self, objective, extraobjexpr=None):
"""Set or change the objective function of the polynomial optimization
problem.
:param objective: Describes the objective function.
:type objective: :class:`sympy.core.expr.Expr`
:param extraobjexpr: Optional parameter of a ... | [
"def",
"set_objective",
"(",
"self",
",",
"objective",
",",
"extraobjexpr",
"=",
"None",
")",
":",
"if",
"objective",
"is",
"not",
"None",
"and",
"self",
".",
"matrix_var_dim",
"is",
"not",
"None",
":",
"facvar",
"=",
"self",
".",
"__get_trace_facvar",
"("... | Set or change the objective function of the polynomial optimization
problem.
:param objective: Describes the objective function.
:type objective: :class:`sympy.core.expr.Expr`
:param extraobjexpr: Optional parameter of a string expression of a
linear combina... | [
"Set",
"or",
"change",
"the",
"objective",
"function",
"of",
"the",
"polynomial",
"optimization",
"problem",
"."
] | train | https://github.com/peterwittek/ncpol2sdpa/blob/bce75d524d0b9d0093f32e3a0a5611f8589351a7/ncpol2sdpa/steering_hierarchy.py#L221-L242 |
peterwittek/ncpol2sdpa | ncpol2sdpa/steering_hierarchy.py | SteeringHierarchy._calculate_block_structure | def _calculate_block_structure(self, inequalities, equalities,
momentinequalities, momentequalities,
extramomentmatrix, removeequalities,
block_struct=None):
"""Calculates the block_struct array for the outp... | python | def _calculate_block_structure(self, inequalities, equalities,
momentinequalities, momentequalities,
extramomentmatrix, removeequalities,
block_struct=None):
"""Calculates the block_struct array for the outp... | [
"def",
"_calculate_block_structure",
"(",
"self",
",",
"inequalities",
",",
"equalities",
",",
"momentinequalities",
",",
"momentequalities",
",",
"extramomentmatrix",
",",
"removeequalities",
",",
"block_struct",
"=",
"None",
")",
":",
"super",
"(",
"SteeringHierarch... | Calculates the block_struct array for the output file. | [
"Calculates",
"the",
"block_struct",
"array",
"for",
"the",
"output",
"file",
"."
] | train | https://github.com/peterwittek/ncpol2sdpa/blob/bce75d524d0b9d0093f32e3a0a5611f8589351a7/ncpol2sdpa/steering_hierarchy.py#L244-L256 |
peterwittek/ncpol2sdpa | ncpol2sdpa/steering_hierarchy.py | SteeringHierarchy.write_to_file | def write_to_file(self, filename, filetype=None):
"""Write the relaxation to a file.
:param filename: The name of the file to write to. The type can be
autodetected from the extension: .dat-s for SDPA,
.task for mosek, .csv for human readable format, or... | python | def write_to_file(self, filename, filetype=None):
"""Write the relaxation to a file.
:param filename: The name of the file to write to. The type can be
autodetected from the extension: .dat-s for SDPA,
.task for mosek, .csv for human readable format, or... | [
"def",
"write_to_file",
"(",
"self",
",",
"filename",
",",
"filetype",
"=",
"None",
")",
":",
"if",
"filetype",
"==",
"\"txt\"",
"and",
"not",
"filename",
".",
"endswith",
"(",
"\".txt\"",
")",
":",
"raise",
"Exception",
"(",
"\"TXT files must have .txt extens... | Write the relaxation to a file.
:param filename: The name of the file to write to. The type can be
autodetected from the extension: .dat-s for SDPA,
.task for mosek, .csv for human readable format, or
.txt for a symbolic export
... | [
"Write",
"the",
"relaxation",
"to",
"a",
"file",
"."
] | train | https://github.com/peterwittek/ncpol2sdpa/blob/bce75d524d0b9d0093f32e3a0a5611f8589351a7/ncpol2sdpa/steering_hierarchy.py#L268-L315 |
laike9m/ezcf | ezcf/_base.py | BaseFinder.get_outerframe_skip_importlib_frame | def get_outerframe_skip_importlib_frame(level):
"""
There's a bug in Python3.4+, see http://bugs.python.org/issue23773,
remove this and use sys._getframe(3) when bug is fixed
"""
if sys.version_info < (3, 4):
return sys._getframe(level)
else:
curre... | python | def get_outerframe_skip_importlib_frame(level):
"""
There's a bug in Python3.4+, see http://bugs.python.org/issue23773,
remove this and use sys._getframe(3) when bug is fixed
"""
if sys.version_info < (3, 4):
return sys._getframe(level)
else:
curre... | [
"def",
"get_outerframe_skip_importlib_frame",
"(",
"level",
")",
":",
"if",
"sys",
".",
"version_info",
"<",
"(",
"3",
",",
"4",
")",
":",
"return",
"sys",
".",
"_getframe",
"(",
"level",
")",
"else",
":",
"currentframe",
"=",
"inspect",
".",
"currentframe... | There's a bug in Python3.4+, see http://bugs.python.org/issue23773,
remove this and use sys._getframe(3) when bug is fixed | [
"There",
"s",
"a",
"bug",
"in",
"Python3",
".",
"4",
"+",
"see",
"http",
":",
"//",
"bugs",
".",
"python",
".",
"org",
"/",
"issue23773",
"remove",
"this",
"and",
"use",
"sys",
".",
"_getframe",
"(",
"3",
")",
"when",
"bug",
"is",
"fixed"
] | train | https://github.com/laike9m/ezcf/blob/30b0f7ecfd4062e9b9a2f8f13ae1f2fd9f21fa12/ezcf/_base.py#L46-L62 |
kmn/coincheck | coincheck/market.py | Market.public_api | def public_api(self,url):
''' template function of public api'''
try :
url in api_urls
return ast.literal_eval(requests.get(base_url + api_urls.get(url)).text)
except Exception as e:
print(e) | python | def public_api(self,url):
''' template function of public api'''
try :
url in api_urls
return ast.literal_eval(requests.get(base_url + api_urls.get(url)).text)
except Exception as e:
print(e) | [
"def",
"public_api",
"(",
"self",
",",
"url",
")",
":",
"try",
":",
"url",
"in",
"api_urls",
"return",
"ast",
".",
"literal_eval",
"(",
"requests",
".",
"get",
"(",
"base_url",
"+",
"api_urls",
".",
"get",
"(",
"url",
")",
")",
".",
"text",
")",
"e... | template function of public api | [
"template",
"function",
"of",
"public",
"api"
] | train | https://github.com/kmn/coincheck/blob/4e1062f1e564cddceec2f6fb4d70fe3a3ab645bc/coincheck/market.py#L19-L25 |
bpython/curtsies | curtsies/escseqparse.py | parse | def parse(s):
r"""
Returns a list of strings or format dictionaries to describe the strings.
May raise a ValueError if it can't be parsed.
>>> parse(">>> []")
['>>> []']
>>> #parse("\x1b[33m[\x1b[39m\x1b[33m]\x1b[39m\x1b[33m[\x1b[39m\x1b[33m]\x1b[39m\x1b[33m[\x1b[39m\x1b[33m]\x1b[39m\x1b[33m[\... | python | def parse(s):
r"""
Returns a list of strings or format dictionaries to describe the strings.
May raise a ValueError if it can't be parsed.
>>> parse(">>> []")
['>>> []']
>>> #parse("\x1b[33m[\x1b[39m\x1b[33m]\x1b[39m\x1b[33m[\x1b[39m\x1b[33m]\x1b[39m\x1b[33m[\x1b[39m\x1b[33m]\x1b[39m\x1b[33m[\... | [
"def",
"parse",
"(",
"s",
")",
":",
"stuff",
"=",
"[",
"]",
"rest",
"=",
"s",
"while",
"True",
":",
"front",
",",
"token",
",",
"rest",
"=",
"peel_off_esc_code",
"(",
"rest",
")",
"if",
"front",
":",
"stuff",
".",
"append",
"(",
"front",
")",
"if... | r"""
Returns a list of strings or format dictionaries to describe the strings.
May raise a ValueError if it can't be parsed.
>>> parse(">>> []")
['>>> []']
>>> #parse("\x1b[33m[\x1b[39m\x1b[33m]\x1b[39m\x1b[33m[\x1b[39m\x1b[33m]\x1b[39m\x1b[33m[\x1b[39m\x1b[33m]\x1b[39m\x1b[33m[\x1b[39m") | [
"r",
"Returns",
"a",
"list",
"of",
"strings",
"or",
"format",
"dictionaries",
"to",
"describe",
"the",
"strings",
"."
] | train | https://github.com/bpython/curtsies/blob/223e42b97fbf6c86b479ed4f0963a067333c5a63/curtsies/escseqparse.py#L23-L48 |
bpython/curtsies | curtsies/escseqparse.py | peel_off_esc_code | def peel_off_esc_code(s):
r"""Returns processed text, the next token, and unprocessed text
>>> front, d, rest = peel_off_esc_code('some[2Astuff')
>>> front, rest
('some', 'stuff')
>>> d == {'numbers': [2], 'command': 'A', 'intermed': '', 'private': '', 'csi': '\x1b[', 'seq': '\x1b[2A'}
True
... | python | def peel_off_esc_code(s):
r"""Returns processed text, the next token, and unprocessed text
>>> front, d, rest = peel_off_esc_code('some[2Astuff')
>>> front, rest
('some', 'stuff')
>>> d == {'numbers': [2], 'command': 'A', 'intermed': '', 'private': '', 'csi': '\x1b[', 'seq': '\x1b[2A'}
True
... | [
"def",
"peel_off_esc_code",
"(",
"s",
")",
":",
"p",
"=",
"r\"\"\"(?P<front>.*?)\n (?P<seq>\n (?P<csi>\n (?:[\u001b]\\[)\n |\n [\"\"\"",
"+",
"'\\x9b'",
"+",
"r\"\"\"])\n (?P<private>)\n ... | r"""Returns processed text, the next token, and unprocessed text
>>> front, d, rest = peel_off_esc_code('some[2Astuff')
>>> front, rest
('some', 'stuff')
>>> d == {'numbers': [2], 'command': 'A', 'intermed': '', 'private': '', 'csi': '\x1b[', 'seq': '\x1b[2A'}
True | [
"r",
"Returns",
"processed",
"text",
"the",
"next",
"token",
"and",
"unprocessed",
"text"
] | train | https://github.com/bpython/curtsies/blob/223e42b97fbf6c86b479ed4f0963a067333c5a63/curtsies/escseqparse.py#L51-L92 |
bpython/curtsies | curtsies/events.py | get_key | def get_key(bytes_, encoding, keynames='curtsies', full=False):
"""Return key pressed from bytes_ or None
Return a key name or None meaning it's an incomplete sequence of bytes
(more bytes needed to determine the key pressed)
encoding is how the bytes should be translated to unicode - it should
ma... | python | def get_key(bytes_, encoding, keynames='curtsies', full=False):
"""Return key pressed from bytes_ or None
Return a key name or None meaning it's an incomplete sequence of bytes
(more bytes needed to determine the key pressed)
encoding is how the bytes should be translated to unicode - it should
ma... | [
"def",
"get_key",
"(",
"bytes_",
",",
"encoding",
",",
"keynames",
"=",
"'curtsies'",
",",
"full",
"=",
"False",
")",
":",
"if",
"not",
"all",
"(",
"isinstance",
"(",
"c",
",",
"type",
"(",
"b''",
")",
")",
"for",
"c",
"in",
"bytes_",
")",
":",
"... | Return key pressed from bytes_ or None
Return a key name or None meaning it's an incomplete sequence of bytes
(more bytes needed to determine the key pressed)
encoding is how the bytes should be translated to unicode - it should
match the terminal encoding.
keynames is a string describing how key... | [
"Return",
"key",
"pressed",
"from",
"bytes_",
"or",
"None"
] | train | https://github.com/bpython/curtsies/blob/223e42b97fbf6c86b479ed4f0963a067333c5a63/curtsies/events.py#L142-L218 |
bpython/curtsies | curtsies/events.py | could_be_unfinished_char | def could_be_unfinished_char(seq, encoding):
"""Whether seq bytes might create a char in encoding if more bytes were added"""
if decodable(seq, encoding):
return False # any sensible encoding surely doesn't require lookahead (right?)
# (if seq bytes encoding a character, adding another byte shou... | python | def could_be_unfinished_char(seq, encoding):
"""Whether seq bytes might create a char in encoding if more bytes were added"""
if decodable(seq, encoding):
return False # any sensible encoding surely doesn't require lookahead (right?)
# (if seq bytes encoding a character, adding another byte shou... | [
"def",
"could_be_unfinished_char",
"(",
"seq",
",",
"encoding",
")",
":",
"if",
"decodable",
"(",
"seq",
",",
"encoding",
")",
":",
"return",
"False",
"# any sensible encoding surely doesn't require lookahead (right?)",
"# (if seq bytes encoding a character, adding another byte... | Whether seq bytes might create a char in encoding if more bytes were added | [
"Whether",
"seq",
"bytes",
"might",
"create",
"a",
"char",
"in",
"encoding",
"if",
"more",
"bytes",
"were",
"added"
] | train | https://github.com/bpython/curtsies/blob/223e42b97fbf6c86b479ed4f0963a067333c5a63/curtsies/events.py#L220-L231 |
bpython/curtsies | curtsies/events.py | pp_event | def pp_event(seq):
"""Returns pretty representation of an Event or keypress"""
if isinstance(seq, Event):
return str(seq)
# Get the original sequence back if seq is a pretty name already
rev_curses = dict((v, k) for k, v in CURSES_NAMES.items())
rev_curtsies = dict((v, k) for k, v in CURTS... | python | def pp_event(seq):
"""Returns pretty representation of an Event or keypress"""
if isinstance(seq, Event):
return str(seq)
# Get the original sequence back if seq is a pretty name already
rev_curses = dict((v, k) for k, v in CURSES_NAMES.items())
rev_curtsies = dict((v, k) for k, v in CURTS... | [
"def",
"pp_event",
"(",
"seq",
")",
":",
"if",
"isinstance",
"(",
"seq",
",",
"Event",
")",
":",
"return",
"str",
"(",
"seq",
")",
"# Get the original sequence back if seq is a pretty name already",
"rev_curses",
"=",
"dict",
"(",
"(",
"v",
",",
"k",
")",
"f... | Returns pretty representation of an Event or keypress | [
"Returns",
"pretty",
"representation",
"of",
"an",
"Event",
"or",
"keypress"
] | train | https://github.com/bpython/curtsies/blob/223e42b97fbf6c86b479ed4f0963a067333c5a63/curtsies/events.py#L243-L260 |
chris1610/barnum-proj | barnum/gen_data.py | create_nouns | def create_nouns(max=2):
"""
Return a string of random nouns up to max number
"""
nouns = []
for noun in range(0, max):
nouns.append(random.choice(noun_list))
return " ".join(nouns) | python | def create_nouns(max=2):
"""
Return a string of random nouns up to max number
"""
nouns = []
for noun in range(0, max):
nouns.append(random.choice(noun_list))
return " ".join(nouns) | [
"def",
"create_nouns",
"(",
"max",
"=",
"2",
")",
":",
"nouns",
"=",
"[",
"]",
"for",
"noun",
"in",
"range",
"(",
"0",
",",
"max",
")",
":",
"nouns",
".",
"append",
"(",
"random",
".",
"choice",
"(",
"noun_list",
")",
")",
"return",
"\" \"",
".",... | Return a string of random nouns up to max number | [
"Return",
"a",
"string",
"of",
"random",
"nouns",
"up",
"to",
"max",
"number"
] | train | https://github.com/chris1610/barnum-proj/blob/0a38f24bde66373553d02fbf67b733c1d55ada33/barnum/gen_data.py#L112-L119 |
chris1610/barnum-proj | barnum/gen_data.py | create_date | def create_date(past=False, max_years_future=10, max_years_past=10):
"""
Create a random valid date
If past, then dates can be in the past
If into the future, then no more than max_years into the future
If it's not, then it can't be any older than max_years_past
"""
if past:
start = ... | python | def create_date(past=False, max_years_future=10, max_years_past=10):
"""
Create a random valid date
If past, then dates can be in the past
If into the future, then no more than max_years into the future
If it's not, then it can't be any older than max_years_past
"""
if past:
start = ... | [
"def",
"create_date",
"(",
"past",
"=",
"False",
",",
"max_years_future",
"=",
"10",
",",
"max_years_past",
"=",
"10",
")",
":",
"if",
"past",
":",
"start",
"=",
"datetime",
".",
"datetime",
".",
"today",
"(",
")",
"-",
"datetime",
".",
"timedelta",
"(... | Create a random valid date
If past, then dates can be in the past
If into the future, then no more than max_years into the future
If it's not, then it can't be any older than max_years_past | [
"Create",
"a",
"random",
"valid",
"date",
"If",
"past",
"then",
"dates",
"can",
"be",
"in",
"the",
"past",
"If",
"into",
"the",
"future",
"then",
"no",
"more",
"than",
"max_years",
"into",
"the",
"future",
"If",
"it",
"s",
"not",
"then",
"it",
"can",
... | train | https://github.com/chris1610/barnum-proj/blob/0a38f24bde66373553d02fbf67b733c1d55ada33/barnum/gen_data.py#L122-L139 |
chris1610/barnum-proj | barnum/gen_data.py | create_birthday | def create_birthday(min_age=18, max_age=80):
"""
Create a random birthday fomr someone between the ages of min_age and max_age
"""
age = random.randint(min_age, max_age)
start = datetime.date.today() - datetime.timedelta(days=random.randint(0, 365))
return start - datetime.timedelta(days=age * 3... | python | def create_birthday(min_age=18, max_age=80):
"""
Create a random birthday fomr someone between the ages of min_age and max_age
"""
age = random.randint(min_age, max_age)
start = datetime.date.today() - datetime.timedelta(days=random.randint(0, 365))
return start - datetime.timedelta(days=age * 3... | [
"def",
"create_birthday",
"(",
"min_age",
"=",
"18",
",",
"max_age",
"=",
"80",
")",
":",
"age",
"=",
"random",
".",
"randint",
"(",
"min_age",
",",
"max_age",
")",
"start",
"=",
"datetime",
".",
"date",
".",
"today",
"(",
")",
"-",
"datetime",
".",
... | Create a random birthday fomr someone between the ages of min_age and max_age | [
"Create",
"a",
"random",
"birthday",
"fomr",
"someone",
"between",
"the",
"ages",
"of",
"min_age",
"and",
"max_age"
] | train | https://github.com/chris1610/barnum-proj/blob/0a38f24bde66373553d02fbf67b733c1d55ada33/barnum/gen_data.py#L142-L148 |
chris1610/barnum-proj | barnum/gen_data.py | create_pw | def create_pw(length=8, digits=2, upper=2, lower=2):
"""Create a random password
From Stackoverflow:
http://stackoverflow.com/questions/7479442/high-quality-simple-random-password-generator
Create a random password with the specified length and no. of
digit, upper and lower case letters.
:para... | python | def create_pw(length=8, digits=2, upper=2, lower=2):
"""Create a random password
From Stackoverflow:
http://stackoverflow.com/questions/7479442/high-quality-simple-random-password-generator
Create a random password with the specified length and no. of
digit, upper and lower case letters.
:para... | [
"def",
"create_pw",
"(",
"length",
"=",
"8",
",",
"digits",
"=",
"2",
",",
"upper",
"=",
"2",
",",
"lower",
"=",
"2",
")",
":",
"seed",
"(",
"time",
"(",
")",
")",
"lowercase",
"=",
"string",
".",
"ascii_lowercase",
"uppercase",
"=",
"string",
".",... | Create a random password
From Stackoverflow:
http://stackoverflow.com/questions/7479442/high-quality-simple-random-password-generator
Create a random password with the specified length and no. of
digit, upper and lower case letters.
:param length: Maximum no. of characters in the password
:typ... | [
"Create",
"a",
"random",
"password",
"From",
"Stackoverflow",
":",
"http",
":",
"//",
"stackoverflow",
".",
"com",
"/",
"questions",
"/",
"7479442",
"/",
"high",
"-",
"quality",
"-",
"simple",
"-",
"random",
"-",
"password",
"-",
"generator"
] | train | https://github.com/chris1610/barnum-proj/blob/0a38f24bde66373553d02fbf67b733c1d55ada33/barnum/gen_data.py#L189-L227 |
chris1610/barnum-proj | barnum/gen_data.py | show_examples | def show_examples():
""" Run through some simple examples
"""
first, last = create_name()
add = create_street()
zip, city, state = create_city_state_zip()
phone = create_phone(zip)
print(first, last)
print(add)
print("{0:s} {1:s} {2:s}".format(city, state, zip))
print(phone)
... | python | def show_examples():
""" Run through some simple examples
"""
first, last = create_name()
add = create_street()
zip, city, state = create_city_state_zip()
phone = create_phone(zip)
print(first, last)
print(add)
print("{0:s} {1:s} {2:s}".format(city, state, zip))
print(phone)
... | [
"def",
"show_examples",
"(",
")",
":",
"first",
",",
"last",
"=",
"create_name",
"(",
")",
"add",
"=",
"create_street",
"(",
")",
"zip",
",",
"city",
",",
"state",
"=",
"create_city_state_zip",
"(",
")",
"phone",
"=",
"create_phone",
"(",
"zip",
")",
"... | Run through some simple examples | [
"Run",
"through",
"some",
"simple",
"examples"
] | train | https://github.com/chris1610/barnum-proj/blob/0a38f24bde66373553d02fbf67b733c1d55ada33/barnum/gen_data.py#L229-L249 |
peterwittek/ncpol2sdpa | ncpol2sdpa/mosek_utils.py | convert_to_mosek_index | def convert_to_mosek_index(block_struct, row_offsets, block_offsets, row):
"""MOSEK requires a specific sparse format to define the lower-triangular
part of a symmetric matrix. This function does the conversion from the
sparse upper triangular matrix format of Ncpol2SDPA.
"""
block_index, i, j = con... | python | def convert_to_mosek_index(block_struct, row_offsets, block_offsets, row):
"""MOSEK requires a specific sparse format to define the lower-triangular
part of a symmetric matrix. This function does the conversion from the
sparse upper triangular matrix format of Ncpol2SDPA.
"""
block_index, i, j = con... | [
"def",
"convert_to_mosek_index",
"(",
"block_struct",
",",
"row_offsets",
",",
"block_offsets",
",",
"row",
")",
":",
"block_index",
",",
"i",
",",
"j",
"=",
"convert_row_to_sdpa_index",
"(",
"block_struct",
",",
"row_offsets",
",",
"row",
")",
"offset",
"=",
... | MOSEK requires a specific sparse format to define the lower-triangular
part of a symmetric matrix. This function does the conversion from the
sparse upper triangular matrix format of Ncpol2SDPA. | [
"MOSEK",
"requires",
"a",
"specific",
"sparse",
"format",
"to",
"define",
"the",
"lower",
"-",
"triangular",
"part",
"of",
"a",
"symmetric",
"matrix",
".",
"This",
"function",
"does",
"the",
"conversion",
"from",
"the",
"sparse",
"upper",
"triangular",
"matrix... | train | https://github.com/peterwittek/ncpol2sdpa/blob/bce75d524d0b9d0093f32e3a0a5611f8589351a7/ncpol2sdpa/mosek_utils.py#L102-L113 |
peterwittek/ncpol2sdpa | ncpol2sdpa/mosek_utils.py | convert_to_mosek_matrix | def convert_to_mosek_matrix(sdp):
"""Converts the entire sparse representation of the Fi constraint matrices
to sparse MOSEK matrices.
"""
barci = []
barcj = []
barcval = []
barai = []
baraj = []
baraval = []
for k in range(sdp.n_vars):
barai.append([])
baraj.appe... | python | def convert_to_mosek_matrix(sdp):
"""Converts the entire sparse representation of the Fi constraint matrices
to sparse MOSEK matrices.
"""
barci = []
barcj = []
barcval = []
barai = []
baraj = []
baraval = []
for k in range(sdp.n_vars):
barai.append([])
baraj.appe... | [
"def",
"convert_to_mosek_matrix",
"(",
"sdp",
")",
":",
"barci",
"=",
"[",
"]",
"barcj",
"=",
"[",
"]",
"barcval",
"=",
"[",
"]",
"barai",
"=",
"[",
"]",
"baraj",
"=",
"[",
"]",
"baraval",
"=",
"[",
"]",
"for",
"k",
"in",
"range",
"(",
"sdp",
"... | Converts the entire sparse representation of the Fi constraint matrices
to sparse MOSEK matrices. | [
"Converts",
"the",
"entire",
"sparse",
"representation",
"of",
"the",
"Fi",
"constraint",
"matrices",
"to",
"sparse",
"MOSEK",
"matrices",
"."
] | train | https://github.com/peterwittek/ncpol2sdpa/blob/bce75d524d0b9d0093f32e3a0a5611f8589351a7/ncpol2sdpa/mosek_utils.py#L116-L155 |
peterwittek/ncpol2sdpa | ncpol2sdpa/mosek_utils.py | convert_to_mosek | def convert_to_mosek(sdp):
"""Convert an SDP relaxation to a MOSEK task.
:param sdp: The SDP relaxation to convert.
:type sdp: :class:`ncpol2sdpa.sdp`.
:returns: :class:`mosek.Task`.
"""
import mosek
# Cheat when variables are complex and convert with PICOS
if sdp.complex_matrix:
... | python | def convert_to_mosek(sdp):
"""Convert an SDP relaxation to a MOSEK task.
:param sdp: The SDP relaxation to convert.
:type sdp: :class:`ncpol2sdpa.sdp`.
:returns: :class:`mosek.Task`.
"""
import mosek
# Cheat when variables are complex and convert with PICOS
if sdp.complex_matrix:
... | [
"def",
"convert_to_mosek",
"(",
"sdp",
")",
":",
"import",
"mosek",
"# Cheat when variables are complex and convert with PICOS",
"if",
"sdp",
".",
"complex_matrix",
":",
"from",
".",
"picos_utils",
"import",
"convert_to_picos",
"Problem",
"=",
"convert_to_picos",
"(",
"... | Convert an SDP relaxation to a MOSEK task.
:param sdp: The SDP relaxation to convert.
:type sdp: :class:`ncpol2sdpa.sdp`.
:returns: :class:`mosek.Task`. | [
"Convert",
"an",
"SDP",
"relaxation",
"to",
"a",
"MOSEK",
"task",
"."
] | train | https://github.com/peterwittek/ncpol2sdpa/blob/bce75d524d0b9d0093f32e3a0a5611f8589351a7/ncpol2sdpa/mosek_utils.py#L158-L208 |
bpython/curtsies | docs/ansi.py | ANSIColorParser._add_text | def _add_text(self, text):
"""
If ``text`` is not empty, append a new Text node to the most recent
pending node, if there is any, or to the new nodes, if there are no
pending nodes.
"""
if text:
if self.pending_nodes:
self.pending_nodes[-1].app... | python | def _add_text(self, text):
"""
If ``text`` is not empty, append a new Text node to the most recent
pending node, if there is any, or to the new nodes, if there are no
pending nodes.
"""
if text:
if self.pending_nodes:
self.pending_nodes[-1].app... | [
"def",
"_add_text",
"(",
"self",
",",
"text",
")",
":",
"if",
"text",
":",
"if",
"self",
".",
"pending_nodes",
":",
"self",
".",
"pending_nodes",
"[",
"-",
"1",
"]",
".",
"append",
"(",
"nodes",
".",
"Text",
"(",
"text",
")",
")",
"else",
":",
"s... | If ``text`` is not empty, append a new Text node to the most recent
pending node, if there is any, or to the new nodes, if there are no
pending nodes. | [
"If",
"text",
"is",
"not",
"empty",
"append",
"a",
"new",
"Text",
"node",
"to",
"the",
"most",
"recent",
"pending",
"node",
"if",
"there",
"is",
"any",
"or",
"to",
"the",
"new",
"nodes",
"if",
"there",
"are",
"no",
"pending",
"nodes",
"."
] | train | https://github.com/bpython/curtsies/blob/223e42b97fbf6c86b479ed4f0963a067333c5a63/docs/ansi.py#L96-L106 |
bpython/curtsies | setup.py | version | def version():
"""Return version string."""
with open(os.path.join('curtsies', '__init__.py')) as input_file:
for line in input_file:
if line.startswith('__version__'):
return ast.parse(line).body[0].value.s | python | def version():
"""Return version string."""
with open(os.path.join('curtsies', '__init__.py')) as input_file:
for line in input_file:
if line.startswith('__version__'):
return ast.parse(line).body[0].value.s | [
"def",
"version",
"(",
")",
":",
"with",
"open",
"(",
"os",
".",
"path",
".",
"join",
"(",
"'curtsies'",
",",
"'__init__.py'",
")",
")",
"as",
"input_file",
":",
"for",
"line",
"in",
"input_file",
":",
"if",
"line",
".",
"startswith",
"(",
"'__version_... | Return version string. | [
"Return",
"version",
"string",
"."
] | train | https://github.com/bpython/curtsies/blob/223e42b97fbf6c86b479ed4f0963a067333c5a63/setup.py#L6-L11 |
bpython/curtsies | curtsies/formatstringarray.py | fsarray | def fsarray(strings, *args, **kwargs):
"""fsarray(list_of_FmtStrs_or_strings, width=None) -> FSArray
Returns a new FSArray of width of the maximum size of the provided
strings, or width provided, and height of the number of strings provided.
If a width is provided, raises a ValueError if any of the str... | python | def fsarray(strings, *args, **kwargs):
"""fsarray(list_of_FmtStrs_or_strings, width=None) -> FSArray
Returns a new FSArray of width of the maximum size of the provided
strings, or width provided, and height of the number of strings provided.
If a width is provided, raises a ValueError if any of the str... | [
"def",
"fsarray",
"(",
"strings",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"strings",
"=",
"list",
"(",
"strings",
")",
"if",
"'width'",
"in",
"kwargs",
":",
"width",
"=",
"kwargs",
"[",
"'width'",
"]",
"del",
"kwargs",
"[",
"'width'",
... | fsarray(list_of_FmtStrs_or_strings, width=None) -> FSArray
Returns a new FSArray of width of the maximum size of the provided
strings, or width provided, and height of the number of strings provided.
If a width is provided, raises a ValueError if any of the strings
are of length greater than this width | [
"fsarray",
"(",
"list_of_FmtStrs_or_strings",
"width",
"=",
"None",
")",
"-",
">",
"FSArray"
] | train | https://github.com/bpython/curtsies/blob/223e42b97fbf6c86b479ed4f0963a067333c5a63/curtsies/formatstringarray.py#L40-L60 |
bpython/curtsies | curtsies/formatstringarray.py | FSArray.diff | def diff(cls, a, b, ignore_formatting=False):
"""Returns two FSArrays with differences underlined"""
def underline(x): return u'\x1b[4m%s\x1b[0m' % (x,)
def blink(x): return u'\x1b[5m%s\x1b[0m' % (x,)
a_rows = []
b_rows = []
max_width = max([len(row) for row in a] + [len(... | python | def diff(cls, a, b, ignore_formatting=False):
"""Returns two FSArrays with differences underlined"""
def underline(x): return u'\x1b[4m%s\x1b[0m' % (x,)
def blink(x): return u'\x1b[5m%s\x1b[0m' % (x,)
a_rows = []
b_rows = []
max_width = max([len(row) for row in a] + [len(... | [
"def",
"diff",
"(",
"cls",
",",
"a",
",",
"b",
",",
"ignore_formatting",
"=",
"False",
")",
":",
"def",
"underline",
"(",
"x",
")",
":",
"return",
"u'\\x1b[4m%s\\x1b[0m'",
"%",
"(",
"x",
",",
")",
"def",
"blink",
"(",
"x",
")",
":",
"return",
"u'\\... | Returns two FSArrays with differences underlined | [
"Returns",
"two",
"FSArrays",
"with",
"differences",
"underlined"
] | train | https://github.com/bpython/curtsies/blob/223e42b97fbf6c86b479ed4f0963a067333c5a63/curtsies/formatstringarray.py#L139-L171 |
kmn/coincheck | coincheck/order.py | Order.create | def create(self,rate, amount, order_type, pair):
''' create new order function
:param rate: float
:param amount: float
:param order_type: str; set 'buy' or 'sell'
:param pair: str; set 'btc_jpy'
'''
nonce = nounce()
payload = { 'rate': rate,
... | python | def create(self,rate, amount, order_type, pair):
''' create new order function
:param rate: float
:param amount: float
:param order_type: str; set 'buy' or 'sell'
:param pair: str; set 'btc_jpy'
'''
nonce = nounce()
payload = { 'rate': rate,
... | [
"def",
"create",
"(",
"self",
",",
"rate",
",",
"amount",
",",
"order_type",
",",
"pair",
")",
":",
"nonce",
"=",
"nounce",
"(",
")",
"payload",
"=",
"{",
"'rate'",
":",
"rate",
",",
"'amount'",
":",
"amount",
",",
"'order_type'",
":",
"order_type",
... | create new order function
:param rate: float
:param amount: float
:param order_type: str; set 'buy' or 'sell'
:param pair: str; set 'btc_jpy' | [
"create",
"new",
"order",
"function",
":",
"param",
"rate",
":",
"float",
":",
"param",
"amount",
":",
"float",
":",
"param",
"order_type",
":",
"str",
";",
"set",
"buy",
"or",
"sell",
":",
"param",
"pair",
":",
"str",
";",
"set",
"btc_jpy"
] | train | https://github.com/kmn/coincheck/blob/4e1062f1e564cddceec2f6fb4d70fe3a3ab645bc/coincheck/order.py#L20-L43 |
kmn/coincheck | coincheck/order.py | Order.cancel | def cancel(self,order_id):
''' cancel the specified order
:param order_id: order_id to be canceled
'''
url= 'https://coincheck.com/api/exchange/orders/' + order_id
headers = make_header(url,access_key=self.access_key,secret_key=self.secret_key)
r = requests.delete(url,hea... | python | def cancel(self,order_id):
''' cancel the specified order
:param order_id: order_id to be canceled
'''
url= 'https://coincheck.com/api/exchange/orders/' + order_id
headers = make_header(url,access_key=self.access_key,secret_key=self.secret_key)
r = requests.delete(url,hea... | [
"def",
"cancel",
"(",
"self",
",",
"order_id",
")",
":",
"url",
"=",
"'https://coincheck.com/api/exchange/orders/'",
"+",
"order_id",
"headers",
"=",
"make_header",
"(",
"url",
",",
"access_key",
"=",
"self",
".",
"access_key",
",",
"secret_key",
"=",
"self",
... | cancel the specified order
:param order_id: order_id to be canceled | [
"cancel",
"the",
"specified",
"order",
":",
"param",
"order_id",
":",
"order_id",
"to",
"be",
"canceled"
] | train | https://github.com/kmn/coincheck/blob/4e1062f1e564cddceec2f6fb4d70fe3a3ab645bc/coincheck/order.py#L59-L66 |
kmn/coincheck | coincheck/order.py | Order.history | def history(self):
''' show payment history
'''
url= 'https://coincheck.com/api/exchange/orders/transactions'
headers = make_header(url,access_key=self.access_key,secret_key=self.secret_key)
r = requests.get(url,headers=headers)
return json.loads(r.text) | python | def history(self):
''' show payment history
'''
url= 'https://coincheck.com/api/exchange/orders/transactions'
headers = make_header(url,access_key=self.access_key,secret_key=self.secret_key)
r = requests.get(url,headers=headers)
return json.loads(r.text) | [
"def",
"history",
"(",
"self",
")",
":",
"url",
"=",
"'https://coincheck.com/api/exchange/orders/transactions'",
"headers",
"=",
"make_header",
"(",
"url",
",",
"access_key",
"=",
"self",
".",
"access_key",
",",
"secret_key",
"=",
"self",
".",
"secret_key",
")",
... | show payment history | [
"show",
"payment",
"history"
] | train | https://github.com/kmn/coincheck/blob/4e1062f1e564cddceec2f6fb4d70fe3a3ab645bc/coincheck/order.py#L68-L74 |
mottosso/be | be/vendor/click/_termui_impl.py | _length_hint | def _length_hint(obj):
"""Returns the length hint of an object."""
try:
return len(obj)
except TypeError:
try:
get_hint = type(obj).__length_hint__
except AttributeError:
return None
try:
hint = get_hint(obj)
except TypeError:
... | python | def _length_hint(obj):
"""Returns the length hint of an object."""
try:
return len(obj)
except TypeError:
try:
get_hint = type(obj).__length_hint__
except AttributeError:
return None
try:
hint = get_hint(obj)
except TypeError:
... | [
"def",
"_length_hint",
"(",
"obj",
")",
":",
"try",
":",
"return",
"len",
"(",
"obj",
")",
"except",
"TypeError",
":",
"try",
":",
"get_hint",
"=",
"type",
"(",
"obj",
")",
".",
"__length_hint__",
"except",
"AttributeError",
":",
"return",
"None",
"try",... | Returns the length hint of an object. | [
"Returns",
"the",
"length",
"hint",
"of",
"an",
"object",
"."
] | train | https://github.com/mottosso/be/blob/0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71/be/vendor/click/_termui_impl.py#L30-L47 |
mottosso/be | be/vendor/click/_termui_impl.py | pager | def pager(text, color=None):
"""Decide what method to use for paging through text."""
stdout = _default_text_stdout()
if not isatty(sys.stdin) or not isatty(stdout):
return _nullpager(stdout, text, color)
if 'PAGER' in os.environ:
if WIN:
return _tempfilepager(text, os.enviro... | python | def pager(text, color=None):
"""Decide what method to use for paging through text."""
stdout = _default_text_stdout()
if not isatty(sys.stdin) or not isatty(stdout):
return _nullpager(stdout, text, color)
if 'PAGER' in os.environ:
if WIN:
return _tempfilepager(text, os.enviro... | [
"def",
"pager",
"(",
"text",
",",
"color",
"=",
"None",
")",
":",
"stdout",
"=",
"_default_text_stdout",
"(",
")",
"if",
"not",
"isatty",
"(",
"sys",
".",
"stdin",
")",
"or",
"not",
"isatty",
"(",
"stdout",
")",
":",
"return",
"_nullpager",
"(",
"std... | Decide what method to use for paging through text. | [
"Decide",
"what",
"method",
"to",
"use",
"for",
"paging",
"through",
"text",
"."
] | train | https://github.com/mottosso/be/blob/0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71/be/vendor/click/_termui_impl.py#L255-L279 |
mottosso/be | be/vendor/requests/packages/urllib3/util/retry.py | Retry.from_int | def from_int(cls, retries, redirect=True, default=None):
""" Backwards-compatibility for the old retries format."""
if retries is None:
retries = default if default is not None else cls.DEFAULT
if isinstance(retries, Retry):
return retries
redirect = bool(redire... | python | def from_int(cls, retries, redirect=True, default=None):
""" Backwards-compatibility for the old retries format."""
if retries is None:
retries = default if default is not None else cls.DEFAULT
if isinstance(retries, Retry):
return retries
redirect = bool(redire... | [
"def",
"from_int",
"(",
"cls",
",",
"retries",
",",
"redirect",
"=",
"True",
",",
"default",
"=",
"None",
")",
":",
"if",
"retries",
"is",
"None",
":",
"retries",
"=",
"default",
"if",
"default",
"is",
"not",
"None",
"else",
"cls",
".",
"DEFAULT",
"i... | Backwards-compatibility for the old retries format. | [
"Backwards",
"-",
"compatibility",
"for",
"the",
"old",
"retries",
"format",
"."
] | train | https://github.com/mottosso/be/blob/0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71/be/vendor/requests/packages/urllib3/util/retry.py#L145-L156 |
mottosso/be | be/vendor/requests/packages/urllib3/util/retry.py | Retry.get_backoff_time | def get_backoff_time(self):
""" Formula for computing the current backoff
:rtype: float
"""
if self._observed_errors <= 1:
return 0
backoff_value = self.backoff_factor * (2 ** (self._observed_errors - 1))
return min(self.BACKOFF_MAX, backoff_value) | python | def get_backoff_time(self):
""" Formula for computing the current backoff
:rtype: float
"""
if self._observed_errors <= 1:
return 0
backoff_value = self.backoff_factor * (2 ** (self._observed_errors - 1))
return min(self.BACKOFF_MAX, backoff_value) | [
"def",
"get_backoff_time",
"(",
"self",
")",
":",
"if",
"self",
".",
"_observed_errors",
"<=",
"1",
":",
"return",
"0",
"backoff_value",
"=",
"self",
".",
"backoff_factor",
"*",
"(",
"2",
"**",
"(",
"self",
".",
"_observed_errors",
"-",
"1",
")",
")",
... | Formula for computing the current backoff
:rtype: float | [
"Formula",
"for",
"computing",
"the",
"current",
"backoff"
] | train | https://github.com/mottosso/be/blob/0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71/be/vendor/requests/packages/urllib3/util/retry.py#L158-L167 |
mottosso/be | be/vendor/requests/packages/urllib3/util/retry.py | Retry.is_forced_retry | def is_forced_retry(self, method, status_code):
""" Is this method/status code retryable? (Based on method/codes whitelists)
"""
if self.method_whitelist and method.upper() not in self.method_whitelist:
return False
return self.status_forcelist and status_code in self.status... | python | def is_forced_retry(self, method, status_code):
""" Is this method/status code retryable? (Based on method/codes whitelists)
"""
if self.method_whitelist and method.upper() not in self.method_whitelist:
return False
return self.status_forcelist and status_code in self.status... | [
"def",
"is_forced_retry",
"(",
"self",
",",
"method",
",",
"status_code",
")",
":",
"if",
"self",
".",
"method_whitelist",
"and",
"method",
".",
"upper",
"(",
")",
"not",
"in",
"self",
".",
"method_whitelist",
":",
"return",
"False",
"return",
"self",
".",... | Is this method/status code retryable? (Based on method/codes whitelists) | [
"Is",
"this",
"method",
"/",
"status",
"code",
"retryable?",
"(",
"Based",
"on",
"method",
"/",
"codes",
"whitelists",
")"
] | train | https://github.com/mottosso/be/blob/0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71/be/vendor/requests/packages/urllib3/util/retry.py#L192-L198 |
mottosso/be | be/vendor/click/types.py | convert_type | def convert_type(ty, default=None):
"""Converts a callable or python ty into the most appropriate param
ty.
"""
if isinstance(ty, tuple):
return Tuple(ty)
if isinstance(ty, ParamType):
return ty
guessed_type = False
if ty is None and default is not None:
ty = type(def... | python | def convert_type(ty, default=None):
"""Converts a callable or python ty into the most appropriate param
ty.
"""
if isinstance(ty, tuple):
return Tuple(ty)
if isinstance(ty, ParamType):
return ty
guessed_type = False
if ty is None and default is not None:
ty = type(def... | [
"def",
"convert_type",
"(",
"ty",
",",
"default",
"=",
"None",
")",
":",
"if",
"isinstance",
"(",
"ty",
",",
"tuple",
")",
":",
"return",
"Tuple",
"(",
"ty",
")",
"if",
"isinstance",
"(",
"ty",
",",
"ParamType",
")",
":",
"return",
"ty",
"guessed_typ... | Converts a callable or python ty into the most appropriate param
ty. | [
"Converts",
"a",
"callable",
"or",
"python",
"ty",
"into",
"the",
"most",
"appropriate",
"param",
"ty",
"."
] | train | https://github.com/mottosso/be/blob/0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71/be/vendor/click/types.py#L445-L480 |
mottosso/be | be/vendor/click/formatting.py | wrap_text | def wrap_text(text, width=78, initial_indent='', subsequent_indent='',
preserve_paragraphs=False):
"""A helper function that intelligently wraps text. By default, it
assumes that it operates on a single paragraph of text but if the
`preserve_paragraphs` parameter is provided it will intellige... | python | def wrap_text(text, width=78, initial_indent='', subsequent_indent='',
preserve_paragraphs=False):
"""A helper function that intelligently wraps text. By default, it
assumes that it operates on a single paragraph of text but if the
`preserve_paragraphs` parameter is provided it will intellige... | [
"def",
"wrap_text",
"(",
"text",
",",
"width",
"=",
"78",
",",
"initial_indent",
"=",
"''",
",",
"subsequent_indent",
"=",
"''",
",",
"preserve_paragraphs",
"=",
"False",
")",
":",
"from",
".",
"_textwrap",
"import",
"TextWrapper",
"text",
"=",
"text",
"."... | A helper function that intelligently wraps text. By default, it
assumes that it operates on a single paragraph of text but if the
`preserve_paragraphs` parameter is provided it will intelligently
handle paragraphs (defined by two empty lines).
If paragraphs are handled, a paragraph can be prefixed wit... | [
"A",
"helper",
"function",
"that",
"intelligently",
"wraps",
"text",
".",
"By",
"default",
"it",
"assumes",
"that",
"it",
"operates",
"on",
"a",
"single",
"paragraph",
"of",
"text",
"but",
"if",
"the",
"preserve_paragraphs",
"parameter",
"is",
"provided",
"it"... | train | https://github.com/mottosso/be/blob/0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71/be/vendor/click/formatting.py#L27-L92 |
mottosso/be | be/vendor/click/formatting.py | HelpFormatter.write_usage | def write_usage(self, prog, args='', prefix='Usage: '):
"""Writes a usage line into the buffer.
:param prog: the program name.
:param args: whitespace separated list of arguments.
:param prefix: the prefix for the first line.
"""
prefix = '%*s%s' % (self.current_indent, ... | python | def write_usage(self, prog, args='', prefix='Usage: '):
"""Writes a usage line into the buffer.
:param prog: the program name.
:param args: whitespace separated list of arguments.
:param prefix: the prefix for the first line.
"""
prefix = '%*s%s' % (self.current_indent, ... | [
"def",
"write_usage",
"(",
"self",
",",
"prog",
",",
"args",
"=",
"''",
",",
"prefix",
"=",
"'Usage: '",
")",
":",
"prefix",
"=",
"'%*s%s'",
"%",
"(",
"self",
".",
"current_indent",
",",
"prefix",
",",
"prog",
")",
"self",
".",
"write",
"(",
"prefix"... | Writes a usage line into the buffer.
:param prog: the program name.
:param args: whitespace separated list of arguments.
:param prefix: the prefix for the first line. | [
"Writes",
"a",
"usage",
"line",
"into",
"the",
"buffer",
"."
] | train | https://github.com/mottosso/be/blob/0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71/be/vendor/click/formatting.py#L129-L145 |
mottosso/be | be/cli.py | in_ | def in_(ctx, topics, yes, as_, enter):
"""Set the current topics to `topics`
Environment:
BE_PROJECT: First topic
BE_CWD: Current `be` working directory
BE_TOPICS: Arguments to `in`
BE_DEVELOPMENTDIR: Absolute path to current development directory
BE_PROJECTROOT: Absolut... | python | def in_(ctx, topics, yes, as_, enter):
"""Set the current topics to `topics`
Environment:
BE_PROJECT: First topic
BE_CWD: Current `be` working directory
BE_TOPICS: Arguments to `in`
BE_DEVELOPMENTDIR: Absolute path to current development directory
BE_PROJECTROOT: Absolut... | [
"def",
"in_",
"(",
"ctx",
",",
"topics",
",",
"yes",
",",
"as_",
",",
"enter",
")",
":",
"topics",
"=",
"map",
"(",
"str",
",",
"topics",
")",
"# They enter as unicode",
"if",
"self",
".",
"isactive",
"(",
")",
":",
"lib",
".",
"echo",
"(",
"\"ERRO... | Set the current topics to `topics`
Environment:
BE_PROJECT: First topic
BE_CWD: Current `be` working directory
BE_TOPICS: Arguments to `in`
BE_DEVELOPMENTDIR: Absolute path to current development directory
BE_PROJECTROOT: Absolute path to current project
BE_PROJECTSR... | [
"Set",
"the",
"current",
"topics",
"to",
"topics"
] | train | https://github.com/mottosso/be/blob/0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71/be/cli.py#L77-L274 |
mottosso/be | be/cli.py | new | def new(preset, name, silent, update):
"""Create new default preset
\b
Usage:
$ be new ad
"blue_unicorn" created
$ be new film --name spiderman
"spiderman" created
"""
if self.isactive():
lib.echo("Please exit current preset before starting a new")
... | python | def new(preset, name, silent, update):
"""Create new default preset
\b
Usage:
$ be new ad
"blue_unicorn" created
$ be new film --name spiderman
"spiderman" created
"""
if self.isactive():
lib.echo("Please exit current preset before starting a new")
... | [
"def",
"new",
"(",
"preset",
",",
"name",
",",
"silent",
",",
"update",
")",
":",
"if",
"self",
".",
"isactive",
"(",
")",
":",
"lib",
".",
"echo",
"(",
"\"Please exit current preset before starting a new\"",
")",
"sys",
".",
"exit",
"(",
"lib",
".",
"US... | Create new default preset
\b
Usage:
$ be new ad
"blue_unicorn" created
$ be new film --name spiderman
"spiderman" created | [
"Create",
"new",
"default",
"preset"
] | train | https://github.com/mottosso/be/blob/0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71/be/cli.py#L284-L374 |
mottosso/be | be/cli.py | update | def update(preset, clean):
"""Update a local preset
This command will cause `be` to pull a preset already
available locally.
\b
Usage:
$ be update ad
Updating "ad"..
"""
if self.isactive():
lib.echo("ERROR: Exit current project first")
sys.exit(lib.USER_ER... | python | def update(preset, clean):
"""Update a local preset
This command will cause `be` to pull a preset already
available locally.
\b
Usage:
$ be update ad
Updating "ad"..
"""
if self.isactive():
lib.echo("ERROR: Exit current project first")
sys.exit(lib.USER_ER... | [
"def",
"update",
"(",
"preset",
",",
"clean",
")",
":",
"if",
"self",
".",
"isactive",
"(",
")",
":",
"lib",
".",
"echo",
"(",
"\"ERROR: Exit current project first\"",
")",
"sys",
".",
"exit",
"(",
"lib",
".",
"USER_ERROR",
")",
"presets",
"=",
"_extern"... | Update a local preset
This command will cause `be` to pull a preset already
available locally.
\b
Usage:
$ be update ad
Updating "ad".. | [
"Update",
"a",
"local",
"preset"
] | train | https://github.com/mottosso/be/blob/0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71/be/cli.py#L380-L427 |
mottosso/be | be/cli.py | tab | def tab(topics, complete):
"""Utility sub-command for tabcompletion
This command is meant to be called by a tab completion
function and is given a the currently entered topics,
along with a boolean indicating whether or not the
last entered argument is complete.
"""
# Discard `be tab`
... | python | def tab(topics, complete):
"""Utility sub-command for tabcompletion
This command is meant to be called by a tab completion
function and is given a the currently entered topics,
along with a boolean indicating whether or not the
last entered argument is complete.
"""
# Discard `be tab`
... | [
"def",
"tab",
"(",
"topics",
",",
"complete",
")",
":",
"# Discard `be tab`",
"topics",
"=",
"list",
"(",
"topics",
")",
"[",
"2",
":",
"]",
"# When given an incomplete argument,",
"# the argument is *sometimes* returned twice (?)",
"# .. note:: Seen in Git Bash on Windows"... | Utility sub-command for tabcompletion
This command is meant to be called by a tab completion
function and is given a the currently entered topics,
along with a boolean indicating whether or not the
last entered argument is complete. | [
"Utility",
"sub",
"-",
"command",
"for",
"tabcompletion"
] | train | https://github.com/mottosso/be/blob/0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71/be/cli.py#L433-L512 |
mottosso/be | be/cli.py | activate | def activate():
"""Enter into an environment with support for tab-completion
This command drops you into a subshell, similar to the one
generated via `be in ...`, except no topic is present and
instead it enables tab-completion for supported shells.
See documentation for further information.
h... | python | def activate():
"""Enter into an environment with support for tab-completion
This command drops you into a subshell, similar to the one
generated via `be in ...`, except no topic is present and
instead it enables tab-completion for supported shells.
See documentation for further information.
h... | [
"def",
"activate",
"(",
")",
":",
"parent",
"=",
"lib",
".",
"parent",
"(",
")",
"try",
":",
"cmd",
"=",
"lib",
".",
"cmd",
"(",
"parent",
")",
"except",
"SystemError",
"as",
"exc",
":",
"lib",
".",
"echo",
"(",
"exc",
")",
"sys",
".",
"exit",
... | Enter into an environment with support for tab-completion
This command drops you into a subshell, similar to the one
generated via `be in ...`, except no topic is present and
instead it enables tab-completion for supported shells.
See documentation for further information.
https://github.com/motto... | [
"Enter",
"into",
"an",
"environment",
"with",
"support",
"for",
"tab",
"-",
"completion"
] | train | https://github.com/mottosso/be/blob/0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71/be/cli.py#L516-L546 |
mottosso/be | be/cli.py | ls | def ls(topics):
"""List contents of current context
\b
Usage:
$ be ls
- spiderman
- hulk
$ be ls spiderman
- peter
- mjay
$ be ls spiderman seq01
- 1000
- 2000
- 2500
Return codes:
0 Normal
2 When insuffici... | python | def ls(topics):
"""List contents of current context
\b
Usage:
$ be ls
- spiderman
- hulk
$ be ls spiderman
- peter
- mjay
$ be ls spiderman seq01
- 1000
- 2000
- 2500
Return codes:
0 Normal
2 When insuffici... | [
"def",
"ls",
"(",
"topics",
")",
":",
"if",
"self",
".",
"isactive",
"(",
")",
":",
"lib",
".",
"echo",
"(",
"\"ERROR: Exit current project first\"",
")",
"sys",
".",
"exit",
"(",
"lib",
".",
"USER_ERROR",
")",
"# List projects",
"if",
"len",
"(",
"topic... | List contents of current context
\b
Usage:
$ be ls
- spiderman
- hulk
$ be ls spiderman
- peter
- mjay
$ be ls spiderman seq01
- 1000
- 2000
- 2500
Return codes:
0 Normal
2 When insufficient arguments are suppl... | [
"List",
"contents",
"of",
"current",
"context"
] | train | https://github.com/mottosso/be/blob/0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71/be/cli.py#L551-L608 |
mottosso/be | be/cli.py | mkdir | def mkdir(dir, enter):
"""Create directory with template for topic of the current environment
"""
if not os.path.exists(dir):
os.makedirs(dir) | python | def mkdir(dir, enter):
"""Create directory with template for topic of the current environment
"""
if not os.path.exists(dir):
os.makedirs(dir) | [
"def",
"mkdir",
"(",
"dir",
",",
"enter",
")",
":",
"if",
"not",
"os",
".",
"path",
".",
"exists",
"(",
"dir",
")",
":",
"os",
".",
"makedirs",
"(",
"dir",
")"
] | Create directory with template for topic of the current environment | [
"Create",
"directory",
"with",
"template",
"for",
"topic",
"of",
"the",
"current",
"environment"
] | train | https://github.com/mottosso/be/blob/0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71/be/cli.py#L614-L620 |
mottosso/be | be/cli.py | preset_ls | def preset_ls(remote):
"""List presets
\b
Usage:
$ be preset ls
- ad
- game
- film
"""
if self.isactive():
lib.echo("ERROR: Exit current project first")
sys.exit(lib.USER_ERROR)
if remote:
presets = _extern.github_presets()
else:
... | python | def preset_ls(remote):
"""List presets
\b
Usage:
$ be preset ls
- ad
- game
- film
"""
if self.isactive():
lib.echo("ERROR: Exit current project first")
sys.exit(lib.USER_ERROR)
if remote:
presets = _extern.github_presets()
else:
... | [
"def",
"preset_ls",
"(",
"remote",
")",
":",
"if",
"self",
".",
"isactive",
"(",
")",
":",
"lib",
".",
"echo",
"(",
"\"ERROR: Exit current project first\"",
")",
"sys",
".",
"exit",
"(",
"lib",
".",
"USER_ERROR",
")",
"if",
"remote",
":",
"presets",
"=",... | List presets
\b
Usage:
$ be preset ls
- ad
- game
- film | [
"List",
"presets"
] | train | https://github.com/mottosso/be/blob/0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71/be/cli.py#L630-L656 |
mottosso/be | be/cli.py | preset_find | def preset_find(query):
"""Find preset from hub
\b
$ be find ad
https://github.com/mottosso/be-ad.git
"""
if self.isactive():
lib.echo("ERROR: Exit current project first")
sys.exit(lib.USER_ERROR)
found = _extern.github_presets().get(query)
if found:
lib.echo(... | python | def preset_find(query):
"""Find preset from hub
\b
$ be find ad
https://github.com/mottosso/be-ad.git
"""
if self.isactive():
lib.echo("ERROR: Exit current project first")
sys.exit(lib.USER_ERROR)
found = _extern.github_presets().get(query)
if found:
lib.echo(... | [
"def",
"preset_find",
"(",
"query",
")",
":",
"if",
"self",
".",
"isactive",
"(",
")",
":",
"lib",
".",
"echo",
"(",
"\"ERROR: Exit current project first\"",
")",
"sys",
".",
"exit",
"(",
"lib",
".",
"USER_ERROR",
")",
"found",
"=",
"_extern",
".",
"gith... | Find preset from hub
\b
$ be find ad
https://github.com/mottosso/be-ad.git | [
"Find",
"preset",
"from",
"hub"
] | train | https://github.com/mottosso/be/blob/0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71/be/cli.py#L661-L678 |
mottosso/be | be/cli.py | dump | def dump():
"""Print current environment
Environment is outputted in a YAML-friendly format
\b
Usage:
$ be dump
Prefixed:
- BE_TOPICS=hulk bruce animation
- ...
"""
if not self.isactive():
lib.echo("ERROR: Enter a project first")
sys.exit(lib.U... | python | def dump():
"""Print current environment
Environment is outputted in a YAML-friendly format
\b
Usage:
$ be dump
Prefixed:
- BE_TOPICS=hulk bruce animation
- ...
"""
if not self.isactive():
lib.echo("ERROR: Enter a project first")
sys.exit(lib.U... | [
"def",
"dump",
"(",
")",
":",
"if",
"not",
"self",
".",
"isactive",
"(",
")",
":",
"lib",
".",
"echo",
"(",
"\"ERROR: Enter a project first\"",
")",
"sys",
".",
"exit",
"(",
"lib",
".",
"USER_ERROR",
")",
"# Print custom environment variables first",
"custom",... | Print current environment
Environment is outputted in a YAML-friendly format
\b
Usage:
$ be dump
Prefixed:
- BE_TOPICS=hulk bruce animation
- ... | [
"Print",
"current",
"environment"
] | train | https://github.com/mottosso/be/blob/0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71/be/cli.py#L682-L727 |
mottosso/be | be/cli.py | what | def what():
"""Print current topics"""
if not self.isactive():
lib.echo("No topic")
sys.exit(lib.USER_ERROR)
lib.echo(os.environ.get("BE_TOPICS", "This is a bug")) | python | def what():
"""Print current topics"""
if not self.isactive():
lib.echo("No topic")
sys.exit(lib.USER_ERROR)
lib.echo(os.environ.get("BE_TOPICS", "This is a bug")) | [
"def",
"what",
"(",
")",
":",
"if",
"not",
"self",
".",
"isactive",
"(",
")",
":",
"lib",
".",
"echo",
"(",
"\"No topic\"",
")",
"sys",
".",
"exit",
"(",
"lib",
".",
"USER_ERROR",
")",
"lib",
".",
"echo",
"(",
"os",
".",
"environ",
".",
"get",
... | Print current topics | [
"Print",
"current",
"topics"
] | train | https://github.com/mottosso/be/blob/0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71/be/cli.py#L731-L738 |
mottosso/be | be/vendor/requests/utils.py | get_netrc_auth | def get_netrc_auth(url):
"""Returns the Requests tuple auth for a given url from netrc."""
try:
from netrc import netrc, NetrcParseError
netrc_path = None
for f in NETRC_FILES:
try:
loc = os.path.expanduser('~/{0}'.format(f))
except KeyError:
... | python | def get_netrc_auth(url):
"""Returns the Requests tuple auth for a given url from netrc."""
try:
from netrc import netrc, NetrcParseError
netrc_path = None
for f in NETRC_FILES:
try:
loc = os.path.expanduser('~/{0}'.format(f))
except KeyError:
... | [
"def",
"get_netrc_auth",
"(",
"url",
")",
":",
"try",
":",
"from",
"netrc",
"import",
"netrc",
",",
"NetrcParseError",
"netrc_path",
"=",
"None",
"for",
"f",
"in",
"NETRC_FILES",
":",
"try",
":",
"loc",
"=",
"os",
".",
"path",
".",
"expanduser",
"(",
"... | Returns the Requests tuple auth for a given url from netrc. | [
"Returns",
"the",
"Requests",
"tuple",
"auth",
"for",
"a",
"given",
"url",
"from",
"netrc",
"."
] | train | https://github.com/mottosso/be/blob/0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71/be/vendor/requests/utils.py#L70-L113 |
mottosso/be | be/vendor/requests/utils.py | add_dict_to_cookiejar | def add_dict_to_cookiejar(cj, cookie_dict):
"""Returns a CookieJar from a key/value dictionary.
:param cj: CookieJar to insert cookies into.
:param cookie_dict: Dict of key/values to insert into CookieJar.
"""
cj2 = cookiejar_from_dict(cookie_dict)
cj.update(cj2)
return cj | python | def add_dict_to_cookiejar(cj, cookie_dict):
"""Returns a CookieJar from a key/value dictionary.
:param cj: CookieJar to insert cookies into.
:param cookie_dict: Dict of key/values to insert into CookieJar.
"""
cj2 = cookiejar_from_dict(cookie_dict)
cj.update(cj2)
return cj | [
"def",
"add_dict_to_cookiejar",
"(",
"cj",
",",
"cookie_dict",
")",
":",
"cj2",
"=",
"cookiejar_from_dict",
"(",
"cookie_dict",
")",
"cj",
".",
"update",
"(",
"cj2",
")",
"return",
"cj"
] | Returns a CookieJar from a key/value dictionary.
:param cj: CookieJar to insert cookies into.
:param cookie_dict: Dict of key/values to insert into CookieJar. | [
"Returns",
"a",
"CookieJar",
"from",
"a",
"key",
"/",
"value",
"dictionary",
"."
] | train | https://github.com/mottosso/be/blob/0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71/be/vendor/requests/utils.py#L276-L285 |
mottosso/be | be/vendor/requests/utils.py | should_bypass_proxies | def should_bypass_proxies(url):
"""
Returns whether we should bypass proxies or not.
"""
get_proxy = lambda k: os.environ.get(k) or os.environ.get(k.upper())
# First check whether no_proxy is defined. If it is, check that the URL
# we're getting isn't in the no_proxy list.
no_proxy = get_pr... | python | def should_bypass_proxies(url):
"""
Returns whether we should bypass proxies or not.
"""
get_proxy = lambda k: os.environ.get(k) or os.environ.get(k.upper())
# First check whether no_proxy is defined. If it is, check that the URL
# we're getting isn't in the no_proxy list.
no_proxy = get_pr... | [
"def",
"should_bypass_proxies",
"(",
"url",
")",
":",
"get_proxy",
"=",
"lambda",
"k",
":",
"os",
".",
"environ",
".",
"get",
"(",
"k",
")",
"or",
"os",
".",
"environ",
".",
"get",
"(",
"k",
".",
"upper",
"(",
")",
")",
"# First check whether no_proxy ... | Returns whether we should bypass proxies or not. | [
"Returns",
"whether",
"we",
"should",
"bypass",
"proxies",
"or",
"not",
"."
] | train | https://github.com/mottosso/be/blob/0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71/be/vendor/requests/utils.py#L487-L530 |
mottosso/be | be/vendor/requests/utils.py | default_user_agent | def default_user_agent(name="python-requests"):
"""Return a string representing the default user agent."""
_implementation = platform.python_implementation()
if _implementation == 'CPython':
_implementation_version = platform.python_version()
elif _implementation == 'PyPy':
_implementat... | python | def default_user_agent(name="python-requests"):
"""Return a string representing the default user agent."""
_implementation = platform.python_implementation()
if _implementation == 'CPython':
_implementation_version = platform.python_version()
elif _implementation == 'PyPy':
_implementat... | [
"def",
"default_user_agent",
"(",
"name",
"=",
"\"python-requests\"",
")",
":",
"_implementation",
"=",
"platform",
".",
"python_implementation",
"(",
")",
"if",
"_implementation",
"==",
"'CPython'",
":",
"_implementation_version",
"=",
"platform",
".",
"python_versio... | Return a string representing the default user agent. | [
"Return",
"a",
"string",
"representing",
"the",
"default",
"user",
"agent",
"."
] | train | https://github.com/mottosso/be/blob/0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71/be/vendor/requests/utils.py#L540-L568 |
mottosso/be | be/vendor/requests/utils.py | to_native_string | def to_native_string(string, encoding='ascii'):
"""
Given a string object, regardless of type, returns a representation of that
string in the native string type, encoding and decoding where necessary.
This assumes ASCII unless told otherwise.
"""
out = None
if isinstance(string, builtin_str... | python | def to_native_string(string, encoding='ascii'):
"""
Given a string object, regardless of type, returns a representation of that
string in the native string type, encoding and decoding where necessary.
This assumes ASCII unless told otherwise.
"""
out = None
if isinstance(string, builtin_str... | [
"def",
"to_native_string",
"(",
"string",
",",
"encoding",
"=",
"'ascii'",
")",
":",
"out",
"=",
"None",
"if",
"isinstance",
"(",
"string",
",",
"builtin_str",
")",
":",
"out",
"=",
"string",
"else",
":",
"if",
"is_py2",
":",
"out",
"=",
"string",
".",... | Given a string object, regardless of type, returns a representation of that
string in the native string type, encoding and decoding where necessary.
This assumes ASCII unless told otherwise. | [
"Given",
"a",
"string",
"object",
"regardless",
"of",
"type",
"returns",
"a",
"representation",
"of",
"that",
"string",
"in",
"the",
"native",
"string",
"type",
"encoding",
"and",
"decoding",
"where",
"necessary",
".",
"This",
"assumes",
"ASCII",
"unless",
"to... | train | https://github.com/mottosso/be/blob/0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71/be/vendor/requests/utils.py#L676-L692 |
mottosso/be | be/vendor/click/core.py | _bashcomplete | def _bashcomplete(cmd, prog_name, complete_var=None):
"""Internal handler for the bash completion support."""
if complete_var is None:
complete_var = '_%s_COMPLETE' % (prog_name.replace('-', '_')).upper()
complete_instr = os.environ.get(complete_var)
if not complete_instr:
return
fr... | python | def _bashcomplete(cmd, prog_name, complete_var=None):
"""Internal handler for the bash completion support."""
if complete_var is None:
complete_var = '_%s_COMPLETE' % (prog_name.replace('-', '_')).upper()
complete_instr = os.environ.get(complete_var)
if not complete_instr:
return
fr... | [
"def",
"_bashcomplete",
"(",
"cmd",
",",
"prog_name",
",",
"complete_var",
"=",
"None",
")",
":",
"if",
"complete_var",
"is",
"None",
":",
"complete_var",
"=",
"'_%s_COMPLETE'",
"%",
"(",
"prog_name",
".",
"replace",
"(",
"'-'",
",",
"'_'",
")",
")",
"."... | Internal handler for the bash completion support. | [
"Internal",
"handler",
"for",
"the",
"bash",
"completion",
"support",
"."
] | train | https://github.com/mottosso/be/blob/0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71/be/vendor/click/core.py#L25-L35 |
mottosso/be | be/vendor/click/core.py | Context.invoke | def invoke(*args, **kwargs):
"""Invokes a command callback in exactly the way it expects. There
are two ways to invoke this method:
1. the first argument can be a callback and all other arguments and
keyword arguments are forwarded directly to the function.
2. the first a... | python | def invoke(*args, **kwargs):
"""Invokes a command callback in exactly the way it expects. There
are two ways to invoke this method:
1. the first argument can be a callback and all other arguments and
keyword arguments are forwarded directly to the function.
2. the first a... | [
"def",
"invoke",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"self",
",",
"callback",
"=",
"args",
"[",
":",
"2",
"]",
"ctx",
"=",
"self",
"# This is just to improve the error message in cases where old",
"# code incorrectly invoked this method. This will ev... | Invokes a command callback in exactly the way it expects. There
are two ways to invoke this method:
1. the first argument can be a callback and all other arguments and
keyword arguments are forwarded directly to the function.
2. the first argument is a click command object. In t... | [
"Invokes",
"a",
"command",
"callback",
"in",
"exactly",
"the",
"way",
"it",
"expects",
".",
"There",
"are",
"two",
"ways",
"to",
"invoke",
"this",
"method",
":"
] | train | https://github.com/mottosso/be/blob/0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71/be/vendor/click/core.py#L418-L475 |
mottosso/be | be/vendor/click/core.py | BaseCommand.make_context | def make_context(self, info_name, args, parent=None, **extra):
"""This function when given an info name and arguments will kick
off the parsing and create a new :class:`Context`. It does not
invoke the actual command callback though.
:param info_name: the info name for this invokation.... | python | def make_context(self, info_name, args, parent=None, **extra):
"""This function when given an info name and arguments will kick
off the parsing and create a new :class:`Context`. It does not
invoke the actual command callback though.
:param info_name: the info name for this invokation.... | [
"def",
"make_context",
"(",
"self",
",",
"info_name",
",",
"args",
",",
"parent",
"=",
"None",
",",
"*",
"*",
"extra",
")",
":",
"for",
"key",
",",
"value",
"in",
"iteritems",
"(",
"self",
".",
"context_settings",
")",
":",
"if",
"key",
"not",
"in",
... | This function when given an info name and arguments will kick
off the parsing and create a new :class:`Context`. It does not
invoke the actual command callback though.
:param info_name: the info name for this invokation. Generally this
is the most descriptive name fo... | [
"This",
"function",
"when",
"given",
"an",
"info",
"name",
"and",
"arguments",
"will",
"kick",
"off",
"the",
"parsing",
"and",
"create",
"a",
"new",
":",
"class",
":",
"Context",
".",
"It",
"does",
"not",
"invoke",
"the",
"actual",
"command",
"callback",
... | train | https://github.com/mottosso/be/blob/0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71/be/vendor/click/core.py#L541-L561 |
mottosso/be | be/vendor/click/core.py | BaseCommand.main | def main(self, args=None, prog_name=None, complete_var=None,
standalone_mode=True, **extra):
"""This is the way to invoke a script with all the bells and
whistles as a command line application. This will always terminate
the application after a call. If this is not wanted, ``Syste... | python | def main(self, args=None, prog_name=None, complete_var=None,
standalone_mode=True, **extra):
"""This is the way to invoke a script with all the bells and
whistles as a command line application. This will always terminate
the application after a call. If this is not wanted, ``Syste... | [
"def",
"main",
"(",
"self",
",",
"args",
"=",
"None",
",",
"prog_name",
"=",
"None",
",",
"complete_var",
"=",
"None",
",",
"standalone_mode",
"=",
"True",
",",
"*",
"*",
"extra",
")",
":",
"# If we are in Python 3, we will verify that the environment is",
"# sa... | This is the way to invoke a script with all the bells and
whistles as a command line application. This will always terminate
the application after a call. If this is not wanted, ``SystemExit``
needs to be caught.
This method is also available by directly calling the instance of
... | [
"This",
"is",
"the",
"way",
"to",
"invoke",
"a",
"script",
"with",
"all",
"the",
"bells",
"and",
"whistles",
"as",
"a",
"command",
"line",
"application",
".",
"This",
"will",
"always",
"terminate",
"the",
"application",
"after",
"a",
"call",
".",
"If",
"... | train | https://github.com/mottosso/be/blob/0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71/be/vendor/click/core.py#L577-L660 |
mottosso/be | be/vendor/click/core.py | Command.make_parser | def make_parser(self, ctx):
"""Creates the underlying option parser for this command."""
parser = OptionParser(ctx)
parser.allow_interspersed_args = ctx.allow_interspersed_args
parser.ignore_unknown_options = ctx.ignore_unknown_options
for param in self.get_params(ctx):
... | python | def make_parser(self, ctx):
"""Creates the underlying option parser for this command."""
parser = OptionParser(ctx)
parser.allow_interspersed_args = ctx.allow_interspersed_args
parser.ignore_unknown_options = ctx.ignore_unknown_options
for param in self.get_params(ctx):
... | [
"def",
"make_parser",
"(",
"self",
",",
"ctx",
")",
":",
"parser",
"=",
"OptionParser",
"(",
"ctx",
")",
"parser",
".",
"allow_interspersed_args",
"=",
"ctx",
".",
"allow_interspersed_args",
"parser",
".",
"ignore_unknown_options",
"=",
"ctx",
".",
"ignore_unkno... | Creates the underlying option parser for this command. | [
"Creates",
"the",
"underlying",
"option",
"parser",
"for",
"this",
"command",
"."
] | train | https://github.com/mottosso/be/blob/0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71/be/vendor/click/core.py#L758-L765 |
mottosso/be | be/vendor/click/core.py | Command.format_help_text | def format_help_text(self, ctx, formatter):
"""Writes the help text to the formatter if it exists."""
if self.help:
formatter.write_paragraph()
with formatter.indentation():
formatter.write_text(self.help) | python | def format_help_text(self, ctx, formatter):
"""Writes the help text to the formatter if it exists."""
if self.help:
formatter.write_paragraph()
with formatter.indentation():
formatter.write_text(self.help) | [
"def",
"format_help_text",
"(",
"self",
",",
"ctx",
",",
"formatter",
")",
":",
"if",
"self",
".",
"help",
":",
"formatter",
".",
"write_paragraph",
"(",
")",
"with",
"formatter",
".",
"indentation",
"(",
")",
":",
"formatter",
".",
"write_text",
"(",
"s... | Writes the help text to the formatter if it exists. | [
"Writes",
"the",
"help",
"text",
"to",
"the",
"formatter",
"if",
"it",
"exists",
"."
] | train | https://github.com/mottosso/be/blob/0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71/be/vendor/click/core.py#L790-L795 |
mottosso/be | be/vendor/click/core.py | Group.add_command | def add_command(self, cmd, name=None):
"""Registers another :class:`Command` with this group. If the name
is not provided, the name of the command is used.
"""
name = name or cmd.name
if name is None:
raise TypeError('Command has no name.')
self.commands[name... | python | def add_command(self, cmd, name=None):
"""Registers another :class:`Command` with this group. If the name
is not provided, the name of the command is used.
"""
name = name or cmd.name
if name is None:
raise TypeError('Command has no name.')
self.commands[name... | [
"def",
"add_command",
"(",
"self",
",",
"cmd",
",",
"name",
"=",
"None",
")",
":",
"name",
"=",
"name",
"or",
"cmd",
".",
"name",
"if",
"name",
"is",
"None",
":",
"raise",
"TypeError",
"(",
"'Command has no name.'",
")",
"self",
".",
"commands",
"[",
... | Registers another :class:`Command` with this group. If the name
is not provided, the name of the command is used. | [
"Registers",
"another",
":",
"class",
":",
"Command",
"with",
"this",
"group",
".",
"If",
"the",
"name",
"is",
"not",
"provided",
"the",
"name",
"of",
"the",
"command",
"is",
"used",
"."
] | train | https://github.com/mottosso/be/blob/0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71/be/vendor/click/core.py#L1071-L1078 |
mottosso/be | be/vendor/click/decorators.py | pass_obj | def pass_obj(f):
"""Similar to :func:`pass_context`, but only pass the object on the
context onwards (:attr:`Context.obj`). This is useful if that object
represents the state of a nested system.
"""
@pass_context
def new_func(*args, **kwargs):
ctx = args[0]
return ctx.invoke(f, ... | python | def pass_obj(f):
"""Similar to :func:`pass_context`, but only pass the object on the
context onwards (:attr:`Context.obj`). This is useful if that object
represents the state of a nested system.
"""
@pass_context
def new_func(*args, **kwargs):
ctx = args[0]
return ctx.invoke(f, ... | [
"def",
"pass_obj",
"(",
"f",
")",
":",
"@",
"pass_context",
"def",
"new_func",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"ctx",
"=",
"args",
"[",
"0",
"]",
"return",
"ctx",
".",
"invoke",
"(",
"f",
",",
"ctx",
".",
"obj",
",",
"*",
... | Similar to :func:`pass_context`, but only pass the object on the
context onwards (:attr:`Context.obj`). This is useful if that object
represents the state of a nested system. | [
"Similar",
"to",
":",
"func",
":",
"pass_context",
"but",
"only",
"pass",
"the",
"object",
"on",
"the",
"context",
"onwards",
"(",
":",
"attr",
":",
"Context",
".",
"obj",
")",
".",
"This",
"is",
"useful",
"if",
"that",
"object",
"represents",
"the",
"... | train | https://github.com/mottosso/be/blob/0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71/be/vendor/click/decorators.py#L18-L27 |
mottosso/be | be/vendor/click/decorators.py | option | def option(*param_decls, **attrs):
"""Attaches an option to the command. All positional arguments are
passed as parameter declarations to :class:`Option`; all keyword
arguments are forwarded unchanged (except ``cls``).
This is equivalent to creating an :class:`Option` instance manually
and attachin... | python | def option(*param_decls, **attrs):
"""Attaches an option to the command. All positional arguments are
passed as parameter declarations to :class:`Option`; all keyword
arguments are forwarded unchanged (except ``cls``).
This is equivalent to creating an :class:`Option` instance manually
and attachin... | [
"def",
"option",
"(",
"*",
"param_decls",
",",
"*",
"*",
"attrs",
")",
":",
"def",
"decorator",
"(",
"f",
")",
":",
"if",
"'help'",
"in",
"attrs",
":",
"attrs",
"[",
"'help'",
"]",
"=",
"inspect",
".",
"cleandoc",
"(",
"attrs",
"[",
"'help'",
"]",
... | Attaches an option to the command. All positional arguments are
passed as parameter declarations to :class:`Option`; all keyword
arguments are forwarded unchanged (except ``cls``).
This is equivalent to creating an :class:`Option` instance manually
and attaching it to the :attr:`Command.params` list.
... | [
"Attaches",
"an",
"option",
"to",
"the",
"command",
".",
"All",
"positional",
"arguments",
"are",
"passed",
"as",
"parameter",
"declarations",
"to",
":",
"class",
":",
"Option",
";",
"all",
"keyword",
"arguments",
"are",
"forwarded",
"unchanged",
"(",
"except"... | train | https://github.com/mottosso/be/blob/0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71/be/vendor/click/decorators.py#L153-L169 |
mottosso/be | be/vendor/click/decorators.py | version_option | def version_option(version=None, *param_decls, **attrs):
"""Adds a ``--version`` option which immediately ends the program
printing out the version number. This is implemented as an eager
option that prints the version and exits the program in the callback.
:param version: the version number to show. ... | python | def version_option(version=None, *param_decls, **attrs):
"""Adds a ``--version`` option which immediately ends the program
printing out the version number. This is implemented as an eager
option that prints the version and exits the program in the callback.
:param version: the version number to show. ... | [
"def",
"version_option",
"(",
"version",
"=",
"None",
",",
"*",
"param_decls",
",",
"*",
"*",
"attrs",
")",
":",
"if",
"version",
"is",
"None",
":",
"module",
"=",
"sys",
".",
"_getframe",
"(",
"1",
")",
".",
"f_globals",
".",
"get",
"(",
"'__name__'... | Adds a ``--version`` option which immediately ends the program
printing out the version number. This is implemented as an eager
option that prints the version and exits the program in the callback.
:param version: the version number to show. If not provided Click
attempts an auto disc... | [
"Adds",
"a",
"--",
"version",
"option",
"which",
"immediately",
"ends",
"the",
"program",
"printing",
"out",
"the",
"version",
"number",
".",
"This",
"is",
"implemented",
"as",
"an",
"eager",
"option",
"that",
"prints",
"the",
"version",
"and",
"exits",
"the... | train | https://github.com/mottosso/be/blob/0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71/be/vendor/click/decorators.py#L222-L273 |
mottosso/be | be/vendor/requests/auth.py | _basic_auth_str | def _basic_auth_str(username, password):
"""Returns a Basic Auth string."""
authstr = 'Basic ' + to_native_string(
b64encode(('%s:%s' % (username, password)).encode('latin1')).strip()
)
return authstr | python | def _basic_auth_str(username, password):
"""Returns a Basic Auth string."""
authstr = 'Basic ' + to_native_string(
b64encode(('%s:%s' % (username, password)).encode('latin1')).strip()
)
return authstr | [
"def",
"_basic_auth_str",
"(",
"username",
",",
"password",
")",
":",
"authstr",
"=",
"'Basic '",
"+",
"to_native_string",
"(",
"b64encode",
"(",
"(",
"'%s:%s'",
"%",
"(",
"username",
",",
"password",
")",
")",
".",
"encode",
"(",
"'latin1'",
")",
")",
"... | Returns a Basic Auth string. | [
"Returns",
"a",
"Basic",
"Auth",
"string",
"."
] | train | https://github.com/mottosso/be/blob/0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71/be/vendor/requests/auth.py#L26-L33 |
mottosso/be | be/util.py | ls | def ls(*topic, **kwargs):
"""List topic from external datastore
Arguments:
topic (str): One or more topics, e.g. ("project", "item", "task")
root (str, optional): Absolute path to where projects reside,
defaults to os.getcwd()
backend (callable, optional): Function to call w... | python | def ls(*topic, **kwargs):
"""List topic from external datastore
Arguments:
topic (str): One or more topics, e.g. ("project", "item", "task")
root (str, optional): Absolute path to where projects reside,
defaults to os.getcwd()
backend (callable, optional): Function to call w... | [
"def",
"ls",
"(",
"*",
"topic",
",",
"*",
"*",
"kwargs",
")",
":",
"context",
"=",
"dump",
"(",
")",
"root",
"=",
"kwargs",
".",
"get",
"(",
"\"root\"",
")",
"or",
"context",
".",
"get",
"(",
"\"cwd\"",
")",
"or",
"os",
".",
"getcwd",
"(",
")",... | List topic from external datastore
Arguments:
topic (str): One or more topics, e.g. ("project", "item", "task")
root (str, optional): Absolute path to where projects reside,
defaults to os.getcwd()
backend (callable, optional): Function to call with absolute path as
... | [
"List",
"topic",
"from",
"external",
"datastore"
] | train | https://github.com/mottosso/be/blob/0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71/be/util.py#L7-L82 |
mottosso/be | be/util.py | dump | def dump(context=os.environ):
"""Dump current environment as a dictionary
Arguments:
context (dict, optional): Current context, defaults
to the current environment.
"""
output = {}
for key, value in context.iteritems():
if not key.startswith("BE_"):
continu... | python | def dump(context=os.environ):
"""Dump current environment as a dictionary
Arguments:
context (dict, optional): Current context, defaults
to the current environment.
"""
output = {}
for key, value in context.iteritems():
if not key.startswith("BE_"):
continu... | [
"def",
"dump",
"(",
"context",
"=",
"os",
".",
"environ",
")",
":",
"output",
"=",
"{",
"}",
"for",
"key",
",",
"value",
"in",
"context",
".",
"iteritems",
"(",
")",
":",
"if",
"not",
"key",
".",
"startswith",
"(",
"\"BE_\"",
")",
":",
"continue",
... | Dump current environment as a dictionary
Arguments:
context (dict, optional): Current context, defaults
to the current environment. | [
"Dump",
"current",
"environment",
"as",
"a",
"dictionary"
] | train | https://github.com/mottosso/be/blob/0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71/be/util.py#L100-L115 |
mottosso/be | be/_extern.py | cwd | def cwd():
"""Return the be current working directory"""
cwd = os.environ.get("BE_CWD")
if cwd and not os.path.isdir(cwd):
sys.stderr.write("ERROR: %s is not a directory" % cwd)
sys.exit(lib.USER_ERROR)
return cwd or os.getcwd().replace("\\", "/") | python | def cwd():
"""Return the be current working directory"""
cwd = os.environ.get("BE_CWD")
if cwd and not os.path.isdir(cwd):
sys.stderr.write("ERROR: %s is not a directory" % cwd)
sys.exit(lib.USER_ERROR)
return cwd or os.getcwd().replace("\\", "/") | [
"def",
"cwd",
"(",
")",
":",
"cwd",
"=",
"os",
".",
"environ",
".",
"get",
"(",
"\"BE_CWD\"",
")",
"if",
"cwd",
"and",
"not",
"os",
".",
"path",
".",
"isdir",
"(",
"cwd",
")",
":",
"sys",
".",
"stderr",
".",
"write",
"(",
"\"ERROR: %s is not a dire... | Return the be current working directory | [
"Return",
"the",
"be",
"current",
"working",
"directory"
] | train | https://github.com/mottosso/be/blob/0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71/be/_extern.py#L52-L58 |
mottosso/be | be/_extern.py | write_script | def write_script(script, tempdir):
"""Write script to a temporary directory
Arguments:
script (list): Commands which to put into a file
Returns:
Absolute path to script
"""
name = "script" + self.suffix
path = os.path.join(tempdir, name)
with open(path, "w") as f:
... | python | def write_script(script, tempdir):
"""Write script to a temporary directory
Arguments:
script (list): Commands which to put into a file
Returns:
Absolute path to script
"""
name = "script" + self.suffix
path = os.path.join(tempdir, name)
with open(path, "w") as f:
... | [
"def",
"write_script",
"(",
"script",
",",
"tempdir",
")",
":",
"name",
"=",
"\"script\"",
"+",
"self",
".",
"suffix",
"path",
"=",
"os",
".",
"path",
".",
"join",
"(",
"tempdir",
",",
"name",
")",
"with",
"open",
"(",
"path",
",",
"\"w\"",
")",
"a... | Write script to a temporary directory
Arguments:
script (list): Commands which to put into a file
Returns:
Absolute path to script | [
"Write",
"script",
"to",
"a",
"temporary",
"directory"
] | train | https://github.com/mottosso/be/blob/0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71/be/_extern.py#L105-L122 |
mottosso/be | be/_extern.py | write_aliases | def write_aliases(aliases, tempdir):
"""Write aliases to temporary directory
Arguments:
aliases (dict): {name: value} dict of aliases
tempdir (str): Absolute path to where aliases will be stored
"""
platform = lib.platform()
if platform == "unix":
home_alias = "cd $BE_DEVE... | python | def write_aliases(aliases, tempdir):
"""Write aliases to temporary directory
Arguments:
aliases (dict): {name: value} dict of aliases
tempdir (str): Absolute path to where aliases will be stored
"""
platform = lib.platform()
if platform == "unix":
home_alias = "cd $BE_DEVE... | [
"def",
"write_aliases",
"(",
"aliases",
",",
"tempdir",
")",
":",
"platform",
"=",
"lib",
".",
"platform",
"(",
")",
"if",
"platform",
"==",
"\"unix\"",
":",
"home_alias",
"=",
"\"cd $BE_DEVELOPMENTDIR\"",
"else",
":",
"home_alias",
"=",
"\"cd %BE_DEVELOPMENTDIR... | Write aliases to temporary directory
Arguments:
aliases (dict): {name: value} dict of aliases
tempdir (str): Absolute path to where aliases will be stored | [
"Write",
"aliases",
"to",
"temporary",
"directory"
] | train | https://github.com/mottosso/be/blob/0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71/be/_extern.py#L125-L160 |
mottosso/be | be/_extern.py | presets_dir | def presets_dir():
"""Return presets directory"""
default_presets_dir = os.path.join(
os.path.expanduser("~"), ".be", "presets")
presets_dir = os.environ.get(BE_PRESETSDIR) or default_presets_dir
if not os.path.exists(presets_dir):
os.makedirs(presets_dir)
return presets_dir | python | def presets_dir():
"""Return presets directory"""
default_presets_dir = os.path.join(
os.path.expanduser("~"), ".be", "presets")
presets_dir = os.environ.get(BE_PRESETSDIR) or default_presets_dir
if not os.path.exists(presets_dir):
os.makedirs(presets_dir)
return presets_dir | [
"def",
"presets_dir",
"(",
")",
":",
"default_presets_dir",
"=",
"os",
".",
"path",
".",
"join",
"(",
"os",
".",
"path",
".",
"expanduser",
"(",
"\"~\"",
")",
",",
"\".be\"",
",",
"\"presets\"",
")",
"presets_dir",
"=",
"os",
".",
"environ",
".",
"get"... | Return presets directory | [
"Return",
"presets",
"directory"
] | train | https://github.com/mottosso/be/blob/0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71/be/_extern.py#L168-L175 |
mottosso/be | be/_extern.py | remove_preset | def remove_preset(preset):
"""Physically delete local preset
Arguments:
preset (str): Name of preset
"""
preset_dir = os.path.join(presets_dir(), preset)
try:
shutil.rmtree(preset_dir)
except IOError:
lib.echo("\"%s\" did not exist" % preset) | python | def remove_preset(preset):
"""Physically delete local preset
Arguments:
preset (str): Name of preset
"""
preset_dir = os.path.join(presets_dir(), preset)
try:
shutil.rmtree(preset_dir)
except IOError:
lib.echo("\"%s\" did not exist" % preset) | [
"def",
"remove_preset",
"(",
"preset",
")",
":",
"preset_dir",
"=",
"os",
".",
"path",
".",
"join",
"(",
"presets_dir",
"(",
")",
",",
"preset",
")",
"try",
":",
"shutil",
".",
"rmtree",
"(",
"preset_dir",
")",
"except",
"IOError",
":",
"lib",
".",
"... | Physically delete local preset
Arguments:
preset (str): Name of preset | [
"Physically",
"delete",
"local",
"preset"
] | train | https://github.com/mottosso/be/blob/0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71/be/_extern.py#L178-L191 |
mottosso/be | be/_extern.py | get | def get(path, **kwargs):
"""requests.get wrapper"""
token = os.environ.get(BE_GITHUB_API_TOKEN)
if token:
kwargs["headers"] = {
"Authorization": "token %s" % token
}
try:
response = requests.get(path, verify=False, **kwargs)
if response.status_code == 403:
... | python | def get(path, **kwargs):
"""requests.get wrapper"""
token = os.environ.get(BE_GITHUB_API_TOKEN)
if token:
kwargs["headers"] = {
"Authorization": "token %s" % token
}
try:
response = requests.get(path, verify=False, **kwargs)
if response.status_code == 403:
... | [
"def",
"get",
"(",
"path",
",",
"*",
"*",
"kwargs",
")",
":",
"token",
"=",
"os",
".",
"environ",
".",
"get",
"(",
"BE_GITHUB_API_TOKEN",
")",
"if",
"token",
":",
"kwargs",
"[",
"\"headers\"",
"]",
"=",
"{",
"\"Authorization\"",
":",
"\"token %s\"",
"%... | requests.get wrapper | [
"requests",
".",
"get",
"wrapper"
] | train | https://github.com/mottosso/be/blob/0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71/be/_extern.py#L194-L216 |
mottosso/be | be/_extern.py | _gist_is_preset | def _gist_is_preset(repo):
"""Evaluate whether gist is a be package
Arguments:
gist (str): username/id pair e.g. mottosso/2bb4651a05af85711cde
"""
_, gistid = repo.split("/")
gist_template = "https://api.github.com/gists/{}"
gist_path = gist_template.format(gistid)
response = ge... | python | def _gist_is_preset(repo):
"""Evaluate whether gist is a be package
Arguments:
gist (str): username/id pair e.g. mottosso/2bb4651a05af85711cde
"""
_, gistid = repo.split("/")
gist_template = "https://api.github.com/gists/{}"
gist_path = gist_template.format(gistid)
response = ge... | [
"def",
"_gist_is_preset",
"(",
"repo",
")",
":",
"_",
",",
"gistid",
"=",
"repo",
".",
"split",
"(",
"\"/\"",
")",
"gist_template",
"=",
"\"https://api.github.com/gists/{}\"",
"gist_path",
"=",
"gist_template",
".",
"format",
"(",
"gistid",
")",
"response",
"=... | Evaluate whether gist is a be package
Arguments:
gist (str): username/id pair e.g. mottosso/2bb4651a05af85711cde | [
"Evaluate",
"whether",
"gist",
"is",
"a",
"be",
"package"
] | train | https://github.com/mottosso/be/blob/0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71/be/_extern.py#L239-L272 |
mottosso/be | be/_extern.py | _repo_is_preset | def _repo_is_preset(repo):
"""Evaluate whether GitHub repository is a be package
Arguments:
gist (str): username/id pair e.g. mottosso/be-ad
"""
package_template = "https://raw.githubusercontent.com"
package_template += "/{repo}/master/package.json"
package_path = package_template.for... | python | def _repo_is_preset(repo):
"""Evaluate whether GitHub repository is a be package
Arguments:
gist (str): username/id pair e.g. mottosso/be-ad
"""
package_template = "https://raw.githubusercontent.com"
package_template += "/{repo}/master/package.json"
package_path = package_template.for... | [
"def",
"_repo_is_preset",
"(",
"repo",
")",
":",
"package_template",
"=",
"\"https://raw.githubusercontent.com\"",
"package_template",
"+=",
"\"/{repo}/master/package.json\"",
"package_path",
"=",
"package_template",
".",
"format",
"(",
"repo",
"=",
"repo",
")",
"response... | Evaluate whether GitHub repository is a be package
Arguments:
gist (str): username/id pair e.g. mottosso/be-ad | [
"Evaluate",
"whether",
"GitHub",
"repository",
"is",
"a",
"be",
"package"
] | train | https://github.com/mottosso/be/blob/0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71/be/_extern.py#L275-L299 |
mottosso/be | be/_extern.py | github_presets | def github_presets():
"""Return remote presets hosted on GitHub"""
addr = ("https://raw.githubusercontent.com"
"/mottosso/be-presets/master/presets.json")
response = get(addr)
if response.status_code == 404:
lib.echo("Could not connect with preset database")
sys.exit(lib.PRO... | python | def github_presets():
"""Return remote presets hosted on GitHub"""
addr = ("https://raw.githubusercontent.com"
"/mottosso/be-presets/master/presets.json")
response = get(addr)
if response.status_code == 404:
lib.echo("Could not connect with preset database")
sys.exit(lib.PRO... | [
"def",
"github_presets",
"(",
")",
":",
"addr",
"=",
"(",
"\"https://raw.githubusercontent.com\"",
"\"/mottosso/be-presets/master/presets.json\"",
")",
"response",
"=",
"get",
"(",
"addr",
")",
"if",
"response",
".",
"status_code",
"==",
"404",
":",
"lib",
".",
"e... | Return remote presets hosted on GitHub | [
"Return",
"remote",
"presets",
"hosted",
"on",
"GitHub"
] | train | https://github.com/mottosso/be/blob/0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71/be/_extern.py#L383-L394 |
mottosso/be | be/_extern.py | copy_preset | def copy_preset(preset_dir, project_dir):
"""Copy contents of preset into new project
If package.json contains the key "contents", limit
the files copied to those present in this list.
Arguments:
preset_dir (str): Absolute path to preset
project_dir (str): Absolute path to new project
... | python | def copy_preset(preset_dir, project_dir):
"""Copy contents of preset into new project
If package.json contains the key "contents", limit
the files copied to those present in this list.
Arguments:
preset_dir (str): Absolute path to preset
project_dir (str): Absolute path to new project
... | [
"def",
"copy_preset",
"(",
"preset_dir",
",",
"project_dir",
")",
":",
"os",
".",
"makedirs",
"(",
"project_dir",
")",
"package_file",
"=",
"os",
".",
"path",
".",
"join",
"(",
"preset_dir",
",",
"\"package.json\"",
")",
"with",
"open",
"(",
"package_file",
... | Copy contents of preset into new project
If package.json contains the key "contents", limit
the files copied to those present in this list.
Arguments:
preset_dir (str): Absolute path to preset
project_dir (str): Absolute path to new project | [
"Copy",
"contents",
"of",
"preset",
"into",
"new",
"project"
] | train | https://github.com/mottosso/be/blob/0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71/be/_extern.py#L397-L427 |
mottosso/be | be/_extern.py | _resolve_references | def _resolve_references(templates):
"""Resolve {@} occurences by expansion
Given a dictionary {"a": "{@b}/x", "b": "{key}/y"}
Return {"a", "{key}/y/x", "b": "{key}/y"}
{
key: {@reference}/{variable} # pattern
}
In plain english, it looks within `pattern` for
references and replace... | python | def _resolve_references(templates):
"""Resolve {@} occurences by expansion
Given a dictionary {"a": "{@b}/x", "b": "{key}/y"}
Return {"a", "{key}/y/x", "b": "{key}/y"}
{
key: {@reference}/{variable} # pattern
}
In plain english, it looks within `pattern` for
references and replace... | [
"def",
"_resolve_references",
"(",
"templates",
")",
":",
"def",
"repl",
"(",
"match",
")",
":",
"lib",
".",
"echo",
"(",
"\"Deprecation warning: The {@ref} syntax is being removed\"",
")",
"key",
"=",
"pattern",
"[",
"match",
".",
"start",
"(",
")",
":",
"mat... | Resolve {@} occurences by expansion
Given a dictionary {"a": "{@b}/x", "b": "{key}/y"}
Return {"a", "{key}/y/x", "b": "{key}/y"}
{
key: {@reference}/{variable} # pattern
}
In plain english, it looks within `pattern` for
references and replaces them with the value of the
matching k... | [
"Resolve",
"{",
"@",
"}",
"occurences",
"by",
"expansion"
] | train | https://github.com/mottosso/be/blob/0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71/be/_extern.py#L430-L474 |
mottosso/be | be/vendor/requests/packages/urllib3/_collections.py | HTTPHeaderDict.add | def add(self, key, val):
"""Adds a (name, value) pair, doesn't overwrite the value if it already
exists.
>>> headers = HTTPHeaderDict(foo='bar')
>>> headers.add('Foo', 'baz')
>>> headers['foo']
'bar, baz'
"""
key_lower = key.lower()
new_vals = key... | python | def add(self, key, val):
"""Adds a (name, value) pair, doesn't overwrite the value if it already
exists.
>>> headers = HTTPHeaderDict(foo='bar')
>>> headers.add('Foo', 'baz')
>>> headers['foo']
'bar, baz'
"""
key_lower = key.lower()
new_vals = key... | [
"def",
"add",
"(",
"self",
",",
"key",
",",
"val",
")",
":",
"key_lower",
"=",
"key",
".",
"lower",
"(",
")",
"new_vals",
"=",
"key",
",",
"val",
"# Keep the common case aka no item present as fast as possible",
"vals",
"=",
"_dict_setdefault",
"(",
"self",
",... | Adds a (name, value) pair, doesn't overwrite the value if it already
exists.
>>> headers = HTTPHeaderDict(foo='bar')
>>> headers.add('Foo', 'baz')
>>> headers['foo']
'bar, baz' | [
"Adds",
"a",
"(",
"name",
"value",
")",
"pair",
"doesn",
"t",
"overwrite",
"the",
"value",
"if",
"it",
"already",
"exists",
"."
] | train | https://github.com/mottosso/be/blob/0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71/be/vendor/requests/packages/urllib3/_collections.py#L207-L228 |
mottosso/be | be/vendor/requests/packages/urllib3/_collections.py | HTTPHeaderDict.getlist | def getlist(self, key):
"""Returns a list of all the values for the named field. Returns an
empty list if the key doesn't exist."""
try:
vals = _dict_getitem(self, key.lower())
except KeyError:
return []
else:
if isinstance(vals, tuple):
... | python | def getlist(self, key):
"""Returns a list of all the values for the named field. Returns an
empty list if the key doesn't exist."""
try:
vals = _dict_getitem(self, key.lower())
except KeyError:
return []
else:
if isinstance(vals, tuple):
... | [
"def",
"getlist",
"(",
"self",
",",
"key",
")",
":",
"try",
":",
"vals",
"=",
"_dict_getitem",
"(",
"self",
",",
"key",
".",
"lower",
"(",
")",
")",
"except",
"KeyError",
":",
"return",
"[",
"]",
"else",
":",
"if",
"isinstance",
"(",
"vals",
",",
... | Returns a list of all the values for the named field. Returns an
empty list if the key doesn't exist. | [
"Returns",
"a",
"list",
"of",
"all",
"the",
"values",
"for",
"the",
"named",
"field",
".",
"Returns",
"an",
"empty",
"list",
"if",
"the",
"key",
"doesn",
"t",
"exist",
"."
] | train | https://github.com/mottosso/be/blob/0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71/be/vendor/requests/packages/urllib3/_collections.py#L256-L267 |
mottosso/be | be/vendor/requests/packages/urllib3/_collections.py | HTTPHeaderDict.iteritems | def iteritems(self):
"""Iterate over all header lines, including duplicate ones."""
for key in self:
vals = _dict_getitem(self, key)
for val in vals[1:]:
yield vals[0], val | python | def iteritems(self):
"""Iterate over all header lines, including duplicate ones."""
for key in self:
vals = _dict_getitem(self, key)
for val in vals[1:]:
yield vals[0], val | [
"def",
"iteritems",
"(",
"self",
")",
":",
"for",
"key",
"in",
"self",
":",
"vals",
"=",
"_dict_getitem",
"(",
"self",
",",
"key",
")",
"for",
"val",
"in",
"vals",
"[",
"1",
":",
"]",
":",
"yield",
"vals",
"[",
"0",
"]",
",",
"val"
] | Iterate over all header lines, including duplicate ones. | [
"Iterate",
"over",
"all",
"header",
"lines",
"including",
"duplicate",
"ones",
"."
] | train | https://github.com/mottosso/be/blob/0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71/be/vendor/requests/packages/urllib3/_collections.py#L290-L295 |
mottosso/be | be/vendor/requests/packages/urllib3/_collections.py | HTTPHeaderDict.itermerged | def itermerged(self):
"""Iterate over all headers, merging duplicate ones together."""
for key in self:
val = _dict_getitem(self, key)
yield val[0], ', '.join(val[1:]) | python | def itermerged(self):
"""Iterate over all headers, merging duplicate ones together."""
for key in self:
val = _dict_getitem(self, key)
yield val[0], ', '.join(val[1:]) | [
"def",
"itermerged",
"(",
"self",
")",
":",
"for",
"key",
"in",
"self",
":",
"val",
"=",
"_dict_getitem",
"(",
"self",
",",
"key",
")",
"yield",
"val",
"[",
"0",
"]",
",",
"', '",
".",
"join",
"(",
"val",
"[",
"1",
":",
"]",
")"
] | Iterate over all headers, merging duplicate ones together. | [
"Iterate",
"over",
"all",
"headers",
"merging",
"duplicate",
"ones",
"together",
"."
] | train | https://github.com/mottosso/be/blob/0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71/be/vendor/requests/packages/urllib3/_collections.py#L297-L301 |
mottosso/be | be/vendor/requests/packages/urllib3/_collections.py | HTTPHeaderDict.from_httplib | def from_httplib(cls, message, duplicates=('set-cookie',)): # Python 2
"""Read headers from a Python 2 httplib message object."""
ret = cls(message.items())
# ret now contains only the last header line for each duplicate.
# Importing with all duplicates would be nice, but this would
... | python | def from_httplib(cls, message, duplicates=('set-cookie',)): # Python 2
"""Read headers from a Python 2 httplib message object."""
ret = cls(message.items())
# ret now contains only the last header line for each duplicate.
# Importing with all duplicates would be nice, but this would
... | [
"def",
"from_httplib",
"(",
"cls",
",",
"message",
",",
"duplicates",
"=",
"(",
"'set-cookie'",
",",
")",
")",
":",
"# Python 2",
"ret",
"=",
"cls",
"(",
"message",
".",
"items",
"(",
")",
")",
"# ret now contains only the last header line for each duplicate.",
... | Read headers from a Python 2 httplib message object. | [
"Read",
"headers",
"from",
"a",
"Python",
"2",
"httplib",
"message",
"object",
"."
] | train | https://github.com/mottosso/be/blob/0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71/be/vendor/requests/packages/urllib3/_collections.py#L307-L320 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.