repo stringlengths 7 55 | path stringlengths 4 223 | func_name stringlengths 1 134 | original_string stringlengths 75 104k | language stringclasses 1
value | code stringlengths 75 104k | code_tokens listlengths 19 28.4k | docstring stringlengths 1 46.9k | docstring_tokens listlengths 1 1.97k | sha stringlengths 40 40 | url stringlengths 87 315 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
MarcMeszaros/envitro | envitro/decorators.py | write | def write(name, value):
"""Temporarily change or set the environment variable during the execution of a function.
Args:
name: The name of the environment variable
value: A value to set for the environment variable
Returns:
The function return value.
"""
def wrapped(func):
... | python | def write(name, value):
"""Temporarily change or set the environment variable during the execution of a function.
Args:
name: The name of the environment variable
value: A value to set for the environment variable
Returns:
The function return value.
"""
def wrapped(func):
... | [
"def",
"write",
"(",
"name",
",",
"value",
")",
":",
"def",
"wrapped",
"(",
"func",
")",
":",
"@",
"functools",
".",
"wraps",
"(",
"func",
")",
"def",
"_decorator",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"existing_env",
"=",
"core",
... | Temporarily change or set the environment variable during the execution of a function.
Args:
name: The name of the environment variable
value: A value to set for the environment variable
Returns:
The function return value. | [
"Temporarily",
"change",
"or",
"set",
"the",
"environment",
"variable",
"during",
"the",
"execution",
"of",
"a",
"function",
"."
] | 19e925cd152c08d4db8126542afed35188cafff4 | https://github.com/MarcMeszaros/envitro/blob/19e925cd152c08d4db8126542afed35188cafff4/envitro/decorators.py#L17-L36 | train |
MarcMeszaros/envitro | envitro/decorators.py | isset | def isset(name):
"""Only execute the function if the variable is set.
Args:
name: The name of the environment variable
Returns:
The function return value or `None` if the function was skipped.
"""
def wrapped(func):
@functools.wraps(func)
def _decorator(*args, **kwa... | python | def isset(name):
"""Only execute the function if the variable is set.
Args:
name: The name of the environment variable
Returns:
The function return value or `None` if the function was skipped.
"""
def wrapped(func):
@functools.wraps(func)
def _decorator(*args, **kwa... | [
"def",
"isset",
"(",
"name",
")",
":",
"def",
"wrapped",
"(",
"func",
")",
":",
"@",
"functools",
".",
"wraps",
"(",
"func",
")",
"def",
"_decorator",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"core",
".",
"isset",
"(",
"name",
... | Only execute the function if the variable is set.
Args:
name: The name of the environment variable
Returns:
The function return value or `None` if the function was skipped. | [
"Only",
"execute",
"the",
"function",
"if",
"the",
"variable",
"is",
"set",
"."
] | 19e925cd152c08d4db8126542afed35188cafff4 | https://github.com/MarcMeszaros/envitro/blob/19e925cd152c08d4db8126542afed35188cafff4/envitro/decorators.py#L44-L59 | train |
MarcMeszaros/envitro | envitro/decorators.py | bool | def bool(name, execute_bool=True, default=None):
"""Only execute the function if the boolean variable is set.
Args:
name: The name of the environment variable
execute_bool: The boolean value to execute the function on
default: The default value if the environment variable is not set (re... | python | def bool(name, execute_bool=True, default=None):
"""Only execute the function if the boolean variable is set.
Args:
name: The name of the environment variable
execute_bool: The boolean value to execute the function on
default: The default value if the environment variable is not set (re... | [
"def",
"bool",
"(",
"name",
",",
"execute_bool",
"=",
"True",
",",
"default",
"=",
"None",
")",
":",
"def",
"wrapped",
"(",
"func",
")",
":",
"@",
"functools",
".",
"wraps",
"(",
"func",
")",
"def",
"_decorator",
"(",
"*",
"args",
",",
"*",
"*",
... | Only execute the function if the boolean variable is set.
Args:
name: The name of the environment variable
execute_bool: The boolean value to execute the function on
default: The default value if the environment variable is not set (respects `execute_bool`)
Returns:
The functio... | [
"Only",
"execute",
"the",
"function",
"if",
"the",
"boolean",
"variable",
"is",
"set",
"."
] | 19e925cd152c08d4db8126542afed35188cafff4 | https://github.com/MarcMeszaros/envitro/blob/19e925cd152c08d4db8126542afed35188cafff4/envitro/decorators.py#L62-L81 | train |
kappius/pyheaderfile | pyheaderfile/drive.py | GSheet.read_cell | def read_cell(self, x, y):
"""
Reads the cell at position x+1 and y+1; return value
:param x: line index
:param y: coll index
:return: {header: value}
"""
if isinstance(self.header[y], tuple):
header = self.header[y][0]
else:
header... | python | def read_cell(self, x, y):
"""
Reads the cell at position x+1 and y+1; return value
:param x: line index
:param y: coll index
:return: {header: value}
"""
if isinstance(self.header[y], tuple):
header = self.header[y][0]
else:
header... | [
"def",
"read_cell",
"(",
"self",
",",
"x",
",",
"y",
")",
":",
"if",
"isinstance",
"(",
"self",
".",
"header",
"[",
"y",
"]",
",",
"tuple",
")",
":",
"header",
"=",
"self",
".",
"header",
"[",
"y",
"]",
"[",
"0",
"]",
"else",
":",
"header",
"... | Reads the cell at position x+1 and y+1; return value
:param x: line index
:param y: coll index
:return: {header: value} | [
"Reads",
"the",
"cell",
"at",
"position",
"x",
"+",
"1",
"and",
"y",
"+",
"1",
";",
"return",
"value",
":",
"param",
"x",
":",
"line",
"index",
":",
"param",
"y",
":",
"coll",
"index",
":",
"return",
":",
"{",
"header",
":",
"value",
"}"
] | 8d587dadae538adcec527fd8e74ad89ed5e2006a | https://github.com/kappius/pyheaderfile/blob/8d587dadae538adcec527fd8e74ad89ed5e2006a/pyheaderfile/drive.py#L33-L49 | train |
kappius/pyheaderfile | pyheaderfile/drive.py | GSheet.write_cell | def write_cell(self, x, y, value):
"""
Writing value in the cell of x+1 and y+1 position
:param x: line index
:param y: coll index
:param value: value to be written
:return:
"""
x += 1
y += 1
self._sheet.update_cell(x, y, value) | python | def write_cell(self, x, y, value):
"""
Writing value in the cell of x+1 and y+1 position
:param x: line index
:param y: coll index
:param value: value to be written
:return:
"""
x += 1
y += 1
self._sheet.update_cell(x, y, value) | [
"def",
"write_cell",
"(",
"self",
",",
"x",
",",
"y",
",",
"value",
")",
":",
"x",
"+=",
"1",
"y",
"+=",
"1",
"self",
".",
"_sheet",
".",
"update_cell",
"(",
"x",
",",
"y",
",",
"value",
")"
] | Writing value in the cell of x+1 and y+1 position
:param x: line index
:param y: coll index
:param value: value to be written
:return: | [
"Writing",
"value",
"in",
"the",
"cell",
"of",
"x",
"+",
"1",
"and",
"y",
"+",
"1",
"position",
":",
"param",
"x",
":",
"line",
"index",
":",
"param",
"y",
":",
"coll",
"index",
":",
"param",
"value",
":",
"value",
"to",
"be",
"written",
":",
"re... | 8d587dadae538adcec527fd8e74ad89ed5e2006a | https://github.com/kappius/pyheaderfile/blob/8d587dadae538adcec527fd8e74ad89ed5e2006a/pyheaderfile/drive.py#L51-L61 | train |
kappius/pyheaderfile | pyheaderfile/drive.py | GSheet._open | def _open(self):
"""
Open the file; get sheets
:return:
"""
if not hasattr(self, '_file'):
self._file = self.gc.open(self.name)
self.sheet_names = self._file.worksheets() | python | def _open(self):
"""
Open the file; get sheets
:return:
"""
if not hasattr(self, '_file'):
self._file = self.gc.open(self.name)
self.sheet_names = self._file.worksheets() | [
"def",
"_open",
"(",
"self",
")",
":",
"if",
"not",
"hasattr",
"(",
"self",
",",
"'_file'",
")",
":",
"self",
".",
"_file",
"=",
"self",
".",
"gc",
".",
"open",
"(",
"self",
".",
"name",
")",
"self",
".",
"sheet_names",
"=",
"self",
".",
"_file",... | Open the file; get sheets
:return: | [
"Open",
"the",
"file",
";",
"get",
"sheets",
":",
"return",
":"
] | 8d587dadae538adcec527fd8e74ad89ed5e2006a | https://github.com/kappius/pyheaderfile/blob/8d587dadae538adcec527fd8e74ad89ed5e2006a/pyheaderfile/drive.py#L73-L80 | train |
kappius/pyheaderfile | pyheaderfile/drive.py | GSheet._open_sheet | def _open_sheet(self):
"""
Read the sheet, get value the header, get number columns and rows
:return:
"""
if self.sheet_name and not self.header:
self._sheet = self._file.worksheet(self.sheet_name.title)
self.ncols = self._sheet.col_count
self.... | python | def _open_sheet(self):
"""
Read the sheet, get value the header, get number columns and rows
:return:
"""
if self.sheet_name and not self.header:
self._sheet = self._file.worksheet(self.sheet_name.title)
self.ncols = self._sheet.col_count
self.... | [
"def",
"_open_sheet",
"(",
"self",
")",
":",
"if",
"self",
".",
"sheet_name",
"and",
"not",
"self",
".",
"header",
":",
"self",
".",
"_sheet",
"=",
"self",
".",
"_file",
".",
"worksheet",
"(",
"self",
".",
"sheet_name",
".",
"title",
")",
"self",
"."... | Read the sheet, get value the header, get number columns and rows
:return: | [
"Read",
"the",
"sheet",
"get",
"value",
"the",
"header",
"get",
"number",
"columns",
"and",
"rows",
":",
"return",
":"
] | 8d587dadae538adcec527fd8e74ad89ed5e2006a | https://github.com/kappius/pyheaderfile/blob/8d587dadae538adcec527fd8e74ad89ed5e2006a/pyheaderfile/drive.py#L82-L92 | train |
kappius/pyheaderfile | pyheaderfile/drive.py | GSheet._import | def _import(self):
"""
Makes imports
:return:
"""
import os.path
import gspread
self.path = os.path
self.gspread = gspread
self._login() | python | def _import(self):
"""
Makes imports
:return:
"""
import os.path
import gspread
self.path = os.path
self.gspread = gspread
self._login() | [
"def",
"_import",
"(",
"self",
")",
":",
"import",
"os",
".",
"path",
"import",
"gspread",
"self",
".",
"path",
"=",
"os",
".",
"path",
"self",
".",
"gspread",
"=",
"gspread",
"self",
".",
"_login",
"(",
")"
] | Makes imports
:return: | [
"Makes",
"imports",
":",
"return",
":"
] | 8d587dadae538adcec527fd8e74ad89ed5e2006a | https://github.com/kappius/pyheaderfile/blob/8d587dadae538adcec527fd8e74ad89ed5e2006a/pyheaderfile/drive.py#L101-L110 | train |
kappius/pyheaderfile | pyheaderfile/drive.py | GSheet._login | def _login(self):
"""
Login with your Google account
:return:
"""
# TODO(dmvieira) login changed to oauth2
self.gc = self.gspread.login(self.email, self.password) | python | def _login(self):
"""
Login with your Google account
:return:
"""
# TODO(dmvieira) login changed to oauth2
self.gc = self.gspread.login(self.email, self.password) | [
"def",
"_login",
"(",
"self",
")",
":",
"# TODO(dmvieira) login changed to oauth2",
"self",
".",
"gc",
"=",
"self",
".",
"gspread",
".",
"login",
"(",
"self",
".",
"email",
",",
"self",
".",
"password",
")"
] | Login with your Google account
:return: | [
"Login",
"with",
"your",
"Google",
"account",
":",
"return",
":"
] | 8d587dadae538adcec527fd8e74ad89ed5e2006a | https://github.com/kappius/pyheaderfile/blob/8d587dadae538adcec527fd8e74ad89ed5e2006a/pyheaderfile/drive.py#L112-L118 | train |
benoitkugler/abstractDataLibrary | pyDLib/GUI/list_views.py | abstractModel.flags | def flags(self, index: QModelIndex):
"""All fields are selectable"""
if self.IS_EDITABLE and self.header[index.column()] in self.EDITABLE_FIELDS:
return Qt.ItemIsEnabled | Qt.ItemIsSelectable | Qt.ItemIsEditable
else:
return super().flags(index) | Qt.ItemIsSelectable | python | def flags(self, index: QModelIndex):
"""All fields are selectable"""
if self.IS_EDITABLE and self.header[index.column()] in self.EDITABLE_FIELDS:
return Qt.ItemIsEnabled | Qt.ItemIsSelectable | Qt.ItemIsEditable
else:
return super().flags(index) | Qt.ItemIsSelectable | [
"def",
"flags",
"(",
"self",
",",
"index",
":",
"QModelIndex",
")",
":",
"if",
"self",
".",
"IS_EDITABLE",
"and",
"self",
".",
"header",
"[",
"index",
".",
"column",
"(",
")",
"]",
"in",
"self",
".",
"EDITABLE_FIELDS",
":",
"return",
"Qt",
".",
"Item... | All fields are selectable | [
"All",
"fields",
"are",
"selectable"
] | 16be28e99837e40287a63803bbfdf67ac1806b7b | https://github.com/benoitkugler/abstractDataLibrary/blob/16be28e99837e40287a63803bbfdf67ac1806b7b/pyDLib/GUI/list_views.py#L118-L123 | train |
benoitkugler/abstractDataLibrary | pyDLib/GUI/list_views.py | abstractModel.sort | def sort(self, section: int, order=None):
"""Order is defined by the current state of sorting"""
attr = self.header[section]
old_i, old_sort = self.sort_state
self.beginResetModel()
if section == old_i:
self.collection.sort(attr, not old_sort)
self.sort_st... | python | def sort(self, section: int, order=None):
"""Order is defined by the current state of sorting"""
attr = self.header[section]
old_i, old_sort = self.sort_state
self.beginResetModel()
if section == old_i:
self.collection.sort(attr, not old_sort)
self.sort_st... | [
"def",
"sort",
"(",
"self",
",",
"section",
":",
"int",
",",
"order",
"=",
"None",
")",
":",
"attr",
"=",
"self",
".",
"header",
"[",
"section",
"]",
"old_i",
",",
"old_sort",
"=",
"self",
".",
"sort_state",
"self",
".",
"beginResetModel",
"(",
")",
... | Order is defined by the current state of sorting | [
"Order",
"is",
"defined",
"by",
"the",
"current",
"state",
"of",
"sorting"
] | 16be28e99837e40287a63803bbfdf67ac1806b7b | https://github.com/benoitkugler/abstractDataLibrary/blob/16be28e99837e40287a63803bbfdf67ac1806b7b/pyDLib/GUI/list_views.py#L125-L136 | train |
benoitkugler/abstractDataLibrary | pyDLib/GUI/list_views.py | abstractModel.remove_line | def remove_line(self, section):
"""Base implementation just pops the item from collection.
Re-implements to add global behaviour
"""
self.beginResetModel()
self.collection.pop(section)
self.endResetModel() | python | def remove_line(self, section):
"""Base implementation just pops the item from collection.
Re-implements to add global behaviour
"""
self.beginResetModel()
self.collection.pop(section)
self.endResetModel() | [
"def",
"remove_line",
"(",
"self",
",",
"section",
")",
":",
"self",
".",
"beginResetModel",
"(",
")",
"self",
".",
"collection",
".",
"pop",
"(",
"section",
")",
"self",
".",
"endResetModel",
"(",
")"
] | Base implementation just pops the item from collection.
Re-implements to add global behaviour | [
"Base",
"implementation",
"just",
"pops",
"the",
"item",
"from",
"collection",
".",
"Re",
"-",
"implements",
"to",
"add",
"global",
"behaviour"
] | 16be28e99837e40287a63803bbfdf67ac1806b7b | https://github.com/benoitkugler/abstractDataLibrary/blob/16be28e99837e40287a63803bbfdf67ac1806b7b/pyDLib/GUI/list_views.py#L139-L145 | train |
benoitkugler/abstractDataLibrary | pyDLib/GUI/list_views.py | abstractModel._update | def _update(self):
"""Emit dataChanged signal on all cells"""
self.dataChanged.emit(self.createIndex(0, 0), self.createIndex(
len(self.collection), len(self.header))) | python | def _update(self):
"""Emit dataChanged signal on all cells"""
self.dataChanged.emit(self.createIndex(0, 0), self.createIndex(
len(self.collection), len(self.header))) | [
"def",
"_update",
"(",
"self",
")",
":",
"self",
".",
"dataChanged",
".",
"emit",
"(",
"self",
".",
"createIndex",
"(",
"0",
",",
"0",
")",
",",
"self",
".",
"createIndex",
"(",
"len",
"(",
"self",
".",
"collection",
")",
",",
"len",
"(",
"self",
... | Emit dataChanged signal on all cells | [
"Emit",
"dataChanged",
"signal",
"on",
"all",
"cells"
] | 16be28e99837e40287a63803bbfdf67ac1806b7b | https://github.com/benoitkugler/abstractDataLibrary/blob/16be28e99837e40287a63803bbfdf67ac1806b7b/pyDLib/GUI/list_views.py#L147-L150 | train |
benoitkugler/abstractDataLibrary | pyDLib/GUI/list_views.py | abstractModel.get_item | def get_item(self, index):
""" Acces shortcut
:param index: Number of row or index of cell
:return: Dict-like item
"""
row = index.row() if hasattr(index, "row") else index
try:
return self.collection[row]
except IndexError: # invalid index for exemp... | python | def get_item(self, index):
""" Acces shortcut
:param index: Number of row or index of cell
:return: Dict-like item
"""
row = index.row() if hasattr(index, "row") else index
try:
return self.collection[row]
except IndexError: # invalid index for exemp... | [
"def",
"get_item",
"(",
"self",
",",
"index",
")",
":",
"row",
"=",
"index",
".",
"row",
"(",
")",
"if",
"hasattr",
"(",
"index",
",",
"\"row\"",
")",
"else",
"index",
"try",
":",
"return",
"self",
".",
"collection",
"[",
"row",
"]",
"except",
"Ind... | Acces shortcut
:param index: Number of row or index of cell
:return: Dict-like item | [
"Acces",
"shortcut"
] | 16be28e99837e40287a63803bbfdf67ac1806b7b | https://github.com/benoitkugler/abstractDataLibrary/blob/16be28e99837e40287a63803bbfdf67ac1806b7b/pyDLib/GUI/list_views.py#L157-L167 | train |
benoitkugler/abstractDataLibrary | pyDLib/GUI/list_views.py | abstractModel.set_collection | def set_collection(self, collection):
"""Reset sort state, set collection and emit resetModel signal"""
self.beginResetModel()
self.collection = collection
self.sort_state = (-1, False)
self.endResetModel() | python | def set_collection(self, collection):
"""Reset sort state, set collection and emit resetModel signal"""
self.beginResetModel()
self.collection = collection
self.sort_state = (-1, False)
self.endResetModel() | [
"def",
"set_collection",
"(",
"self",
",",
"collection",
")",
":",
"self",
".",
"beginResetModel",
"(",
")",
"self",
".",
"collection",
"=",
"collection",
"self",
".",
"sort_state",
"=",
"(",
"-",
"1",
",",
"False",
")",
"self",
".",
"endResetModel",
"("... | Reset sort state, set collection and emit resetModel signal | [
"Reset",
"sort",
"state",
"set",
"collection",
"and",
"emit",
"resetModel",
"signal"
] | 16be28e99837e40287a63803bbfdf67ac1806b7b | https://github.com/benoitkugler/abstractDataLibrary/blob/16be28e99837e40287a63803bbfdf67ac1806b7b/pyDLib/GUI/list_views.py#L169-L174 | train |
benoitkugler/abstractDataLibrary | pyDLib/GUI/list_views.py | InternalDataModel.set_item | def set_item(self, index, new_item):
""" Changes item at index in collection. Emit dataChanged signal.
:param index: Number of row or index of cell
:param new_item: Dict-like object
"""
row = index.row() if hasattr(index, "row") else index
self.collection[row] = new_item... | python | def set_item(self, index, new_item):
""" Changes item at index in collection. Emit dataChanged signal.
:param index: Number of row or index of cell
:param new_item: Dict-like object
"""
row = index.row() if hasattr(index, "row") else index
self.collection[row] = new_item... | [
"def",
"set_item",
"(",
"self",
",",
"index",
",",
"new_item",
")",
":",
"row",
"=",
"index",
".",
"row",
"(",
")",
"if",
"hasattr",
"(",
"index",
",",
"\"row\"",
")",
"else",
"index",
"self",
".",
"collection",
"[",
"row",
"]",
"=",
"new_item",
"s... | Changes item at index in collection. Emit dataChanged signal.
:param index: Number of row or index of cell
:param new_item: Dict-like object | [
"Changes",
"item",
"at",
"index",
"in",
"collection",
".",
"Emit",
"dataChanged",
"signal",
"."
] | 16be28e99837e40287a63803bbfdf67ac1806b7b | https://github.com/benoitkugler/abstractDataLibrary/blob/16be28e99837e40287a63803bbfdf67ac1806b7b/pyDLib/GUI/list_views.py#L191-L200 | train |
benoitkugler/abstractDataLibrary | pyDLib/GUI/list_views.py | ExternalDataModel.set_data | def set_data(self, index, value):
"""Uses given data setter, and emit modelReset signal"""
acces, field = self.get_item(index), self.header[index.column()]
self.beginResetModel()
self.set_data_hook(acces, field, value)
self.endResetModel() | python | def set_data(self, index, value):
"""Uses given data setter, and emit modelReset signal"""
acces, field = self.get_item(index), self.header[index.column()]
self.beginResetModel()
self.set_data_hook(acces, field, value)
self.endResetModel() | [
"def",
"set_data",
"(",
"self",
",",
"index",
",",
"value",
")",
":",
"acces",
",",
"field",
"=",
"self",
".",
"get_item",
"(",
"index",
")",
",",
"self",
".",
"header",
"[",
"index",
".",
"column",
"(",
")",
"]",
"self",
".",
"beginResetModel",
"(... | Uses given data setter, and emit modelReset signal | [
"Uses",
"given",
"data",
"setter",
"and",
"emit",
"modelReset",
"signal"
] | 16be28e99837e40287a63803bbfdf67ac1806b7b | https://github.com/benoitkugler/abstractDataLibrary/blob/16be28e99837e40287a63803bbfdf67ac1806b7b/pyDLib/GUI/list_views.py#L223-L228 | train |
benoitkugler/abstractDataLibrary | pyDLib/GUI/list_views.py | MultiSelectModel._set_id | def _set_id(self, Id, is_added, index):
"""Update selected_ids and emit dataChanged"""
if is_added:
self.selected_ids.add(Id)
else:
self.selected_ids.remove(Id)
self.dataChanged.emit(index, index) | python | def _set_id(self, Id, is_added, index):
"""Update selected_ids and emit dataChanged"""
if is_added:
self.selected_ids.add(Id)
else:
self.selected_ids.remove(Id)
self.dataChanged.emit(index, index) | [
"def",
"_set_id",
"(",
"self",
",",
"Id",
",",
"is_added",
",",
"index",
")",
":",
"if",
"is_added",
":",
"self",
".",
"selected_ids",
".",
"add",
"(",
"Id",
")",
"else",
":",
"self",
".",
"selected_ids",
".",
"remove",
"(",
"Id",
")",
"self",
".",... | Update selected_ids and emit dataChanged | [
"Update",
"selected_ids",
"and",
"emit",
"dataChanged"
] | 16be28e99837e40287a63803bbfdf67ac1806b7b | https://github.com/benoitkugler/abstractDataLibrary/blob/16be28e99837e40287a63803bbfdf67ac1806b7b/pyDLib/GUI/list_views.py#L259-L265 | train |
benoitkugler/abstractDataLibrary | pyDLib/GUI/list_views.py | MultiSelectModel.setData | def setData(self, index: QModelIndex, value, role=None):
"""Update selected_ids on click on index cell."""
if not (index.isValid() and role == Qt.CheckStateRole):
return False
c_id = self.get_item(index).Id
self._set_id(c_id, value == Qt.Checked, index)
return True | python | def setData(self, index: QModelIndex, value, role=None):
"""Update selected_ids on click on index cell."""
if not (index.isValid() and role == Qt.CheckStateRole):
return False
c_id = self.get_item(index).Id
self._set_id(c_id, value == Qt.Checked, index)
return True | [
"def",
"setData",
"(",
"self",
",",
"index",
":",
"QModelIndex",
",",
"value",
",",
"role",
"=",
"None",
")",
":",
"if",
"not",
"(",
"index",
".",
"isValid",
"(",
")",
"and",
"role",
"==",
"Qt",
".",
"CheckStateRole",
")",
":",
"return",
"False",
"... | Update selected_ids on click on index cell. | [
"Update",
"selected_ids",
"on",
"click",
"on",
"index",
"cell",
"."
] | 16be28e99837e40287a63803bbfdf67ac1806b7b | https://github.com/benoitkugler/abstractDataLibrary/blob/16be28e99837e40287a63803bbfdf67ac1806b7b/pyDLib/GUI/list_views.py#L267-L273 | train |
benoitkugler/abstractDataLibrary | pyDLib/GUI/list_views.py | MultiSelectModel.set_by_Id | def set_by_Id(self, Id, is_added):
"""Update selected_ids with given Id"""
row = self.collection.index_from_id(Id)
if row is None:
return
self._set_id(Id, is_added, self.index(row, 0)) | python | def set_by_Id(self, Id, is_added):
"""Update selected_ids with given Id"""
row = self.collection.index_from_id(Id)
if row is None:
return
self._set_id(Id, is_added, self.index(row, 0)) | [
"def",
"set_by_Id",
"(",
"self",
",",
"Id",
",",
"is_added",
")",
":",
"row",
"=",
"self",
".",
"collection",
".",
"index_from_id",
"(",
"Id",
")",
"if",
"row",
"is",
"None",
":",
"return",
"self",
".",
"_set_id",
"(",
"Id",
",",
"is_added",
",",
"... | Update selected_ids with given Id | [
"Update",
"selected_ids",
"with",
"given",
"Id"
] | 16be28e99837e40287a63803bbfdf67ac1806b7b | https://github.com/benoitkugler/abstractDataLibrary/blob/16be28e99837e40287a63803bbfdf67ac1806b7b/pyDLib/GUI/list_views.py#L275-L280 | train |
benoitkugler/abstractDataLibrary | pyDLib/GUI/list_views.py | abstractList._setup_delegate | def _setup_delegate(self):
"""Add resize behavior on edit"""
delegate = self.DELEGATE_CLASS(self)
self.setItemDelegate(delegate)
delegate.sizeHintChanged.connect(
lambda index: self.resizeRowToContents(index.row()))
if self.RESIZE_COLUMN:
delegate.sizeHint... | python | def _setup_delegate(self):
"""Add resize behavior on edit"""
delegate = self.DELEGATE_CLASS(self)
self.setItemDelegate(delegate)
delegate.sizeHintChanged.connect(
lambda index: self.resizeRowToContents(index.row()))
if self.RESIZE_COLUMN:
delegate.sizeHint... | [
"def",
"_setup_delegate",
"(",
"self",
")",
":",
"delegate",
"=",
"self",
".",
"DELEGATE_CLASS",
"(",
"self",
")",
"self",
".",
"setItemDelegate",
"(",
"delegate",
")",
"delegate",
".",
"sizeHintChanged",
".",
"connect",
"(",
"lambda",
"index",
":",
"self",
... | Add resize behavior on edit | [
"Add",
"resize",
"behavior",
"on",
"edit"
] | 16be28e99837e40287a63803bbfdf67ac1806b7b | https://github.com/benoitkugler/abstractDataLibrary/blob/16be28e99837e40287a63803bbfdf67ac1806b7b/pyDLib/GUI/list_views.py#L346-L356 | train |
benoitkugler/abstractDataLibrary | pyDLib/GUI/list_views.py | abstractList._draw_placeholder | def _draw_placeholder(self):
"""To be used in QTreeView"""
if self.model().rowCount() == 0:
painter = QPainter(self.viewport())
painter.setFont(_custom_font(is_italic=True))
painter.drawText(self.rect().adjusted(0, 0, -5, -5), Qt.AlignCenter | Qt.TextWordWrap,
... | python | def _draw_placeholder(self):
"""To be used in QTreeView"""
if self.model().rowCount() == 0:
painter = QPainter(self.viewport())
painter.setFont(_custom_font(is_italic=True))
painter.drawText(self.rect().adjusted(0, 0, -5, -5), Qt.AlignCenter | Qt.TextWordWrap,
... | [
"def",
"_draw_placeholder",
"(",
"self",
")",
":",
"if",
"self",
".",
"model",
"(",
")",
".",
"rowCount",
"(",
")",
"==",
"0",
":",
"painter",
"=",
"QPainter",
"(",
"self",
".",
"viewport",
"(",
")",
")",
"painter",
".",
"setFont",
"(",
"_custom_font... | To be used in QTreeView | [
"To",
"be",
"used",
"in",
"QTreeView"
] | 16be28e99837e40287a63803bbfdf67ac1806b7b | https://github.com/benoitkugler/abstractDataLibrary/blob/16be28e99837e40287a63803bbfdf67ac1806b7b/pyDLib/GUI/list_views.py#L361-L367 | train |
benoitkugler/abstractDataLibrary | pyDLib/GUI/list_views.py | abstractList.get_current_item | def get_current_item(self):
"""Returns (first) selected item or None"""
l = self.selectedIndexes()
if len(l) > 0:
return self.model().get_item(l[0]) | python | def get_current_item(self):
"""Returns (first) selected item or None"""
l = self.selectedIndexes()
if len(l) > 0:
return self.model().get_item(l[0]) | [
"def",
"get_current_item",
"(",
"self",
")",
":",
"l",
"=",
"self",
".",
"selectedIndexes",
"(",
")",
"if",
"len",
"(",
"l",
")",
">",
"0",
":",
"return",
"self",
".",
"model",
"(",
")",
".",
"get_item",
"(",
"l",
"[",
"0",
"]",
")"
] | Returns (first) selected item or None | [
"Returns",
"(",
"first",
")",
"selected",
"item",
"or",
"None"
] | 16be28e99837e40287a63803bbfdf67ac1806b7b | https://github.com/benoitkugler/abstractDataLibrary/blob/16be28e99837e40287a63803bbfdf67ac1806b7b/pyDLib/GUI/list_views.py#L391-L395 | train |
benoitkugler/abstractDataLibrary | pyDLib/GUI/list_views.py | MultiSelectList.model_from_list | def model_from_list(l, header):
"""Return a model with a collection from a list of entry"""
col = groups.sortableListe(PseudoAccesCategorie(n) for n in l)
return MultiSelectModel(col, header) | python | def model_from_list(l, header):
"""Return a model with a collection from a list of entry"""
col = groups.sortableListe(PseudoAccesCategorie(n) for n in l)
return MultiSelectModel(col, header) | [
"def",
"model_from_list",
"(",
"l",
",",
"header",
")",
":",
"col",
"=",
"groups",
".",
"sortableListe",
"(",
"PseudoAccesCategorie",
"(",
"n",
")",
"for",
"n",
"in",
"l",
")",
"return",
"MultiSelectModel",
"(",
"col",
",",
"header",
")"
] | Return a model with a collection from a list of entry | [
"Return",
"a",
"model",
"with",
"a",
"collection",
"from",
"a",
"list",
"of",
"entry"
] | 16be28e99837e40287a63803bbfdf67ac1806b7b | https://github.com/benoitkugler/abstractDataLibrary/blob/16be28e99837e40287a63803bbfdf67ac1806b7b/pyDLib/GUI/list_views.py#L409-L412 | train |
runfalk/loopialib | loopialib/client.py | _parse_status_code | def _parse_status_code(response):
"""
Return error string code if the response is an error, otherwise ``"OK"``
"""
# This happens when a status response is expected
if isinstance(response, string_types):
return response
# This happens when a list of structs are expected
is_single_l... | python | def _parse_status_code(response):
"""
Return error string code if the response is an error, otherwise ``"OK"``
"""
# This happens when a status response is expected
if isinstance(response, string_types):
return response
# This happens when a list of structs are expected
is_single_l... | [
"def",
"_parse_status_code",
"(",
"response",
")",
":",
"# This happens when a status response is expected",
"if",
"isinstance",
"(",
"response",
",",
"string_types",
")",
":",
"return",
"response",
"# This happens when a list of structs are expected",
"is_single_list",
"=",
... | Return error string code if the response is an error, otherwise ``"OK"`` | [
"Return",
"error",
"string",
"code",
"if",
"the",
"response",
"is",
"an",
"error",
"otherwise",
"OK"
] | 58d99c56b0e9eb62f40d76b7b4ad5fdd4b079155 | https://github.com/runfalk/loopialib/blob/58d99c56b0e9eb62f40d76b7b4ad5fdd4b079155/loopialib/client.py#L6-L21 | train |
runfalk/loopialib | loopialib/client.py | Loopia.remove_zone_record | def remove_zone_record(self, id, domain, subdomain=None):
"""
Remove the zone record with the given ID that belongs to the given
domain and sub domain. If no sub domain is given the wildcard sub-domain
is assumed.
"""
if subdomain is None:
subdomain = "@"
... | python | def remove_zone_record(self, id, domain, subdomain=None):
"""
Remove the zone record with the given ID that belongs to the given
domain and sub domain. If no sub domain is given the wildcard sub-domain
is assumed.
"""
if subdomain is None:
subdomain = "@"
... | [
"def",
"remove_zone_record",
"(",
"self",
",",
"id",
",",
"domain",
",",
"subdomain",
"=",
"None",
")",
":",
"if",
"subdomain",
"is",
"None",
":",
"subdomain",
"=",
"\"@\"",
"_validate_int",
"(",
"\"id\"",
",",
"id",
")",
"self",
".",
"_call",
"(",
"\"... | Remove the zone record with the given ID that belongs to the given
domain and sub domain. If no sub domain is given the wildcard sub-domain
is assumed. | [
"Remove",
"the",
"zone",
"record",
"with",
"the",
"given",
"ID",
"that",
"belongs",
"to",
"the",
"given",
"domain",
"and",
"sub",
"domain",
".",
"If",
"no",
"sub",
"domain",
"is",
"given",
"the",
"wildcard",
"sub",
"-",
"domain",
"is",
"assumed",
"."
] | 58d99c56b0e9eb62f40d76b7b4ad5fdd4b079155 | https://github.com/runfalk/loopialib/blob/58d99c56b0e9eb62f40d76b7b4ad5fdd4b079155/loopialib/client.py#L100-L112 | train |
plandes/actioncli | src/python/zensols/actioncli/factory.py | ClassImporter.parse_module_class | def parse_module_class(self):
"""Parse the module and class name part of the fully qualifed class name.
"""
cname = self.class_name
match = re.match(self.CLASS_REGEX, cname)
if not match:
raise ValueError(f'not a fully qualified class name: {cname}')
return m... | python | def parse_module_class(self):
"""Parse the module and class name part of the fully qualifed class name.
"""
cname = self.class_name
match = re.match(self.CLASS_REGEX, cname)
if not match:
raise ValueError(f'not a fully qualified class name: {cname}')
return m... | [
"def",
"parse_module_class",
"(",
"self",
")",
":",
"cname",
"=",
"self",
".",
"class_name",
"match",
"=",
"re",
".",
"match",
"(",
"self",
".",
"CLASS_REGEX",
",",
"cname",
")",
"if",
"not",
"match",
":",
"raise",
"ValueError",
"(",
"f'not a fully qualifi... | Parse the module and class name part of the fully qualifed class name. | [
"Parse",
"the",
"module",
"and",
"class",
"name",
"part",
"of",
"the",
"fully",
"qualifed",
"class",
"name",
"."
] | d1c4ea27e6f3394b30a1652ddd4b916160662773 | https://github.com/plandes/actioncli/blob/d1c4ea27e6f3394b30a1652ddd4b916160662773/src/python/zensols/actioncli/factory.py#L33-L41 | train |
plandes/actioncli | src/python/zensols/actioncli/factory.py | ClassImporter.get_module_class | def get_module_class(self):
"""Return the module and class as a tuple of the given class in the
initializer.
:param reload: if ``True`` then reload the module before returning the
class
"""
pkg, cname = self.parse_module_class()
logger.debug(f'pkg: {pkg}, class:... | python | def get_module_class(self):
"""Return the module and class as a tuple of the given class in the
initializer.
:param reload: if ``True`` then reload the module before returning the
class
"""
pkg, cname = self.parse_module_class()
logger.debug(f'pkg: {pkg}, class:... | [
"def",
"get_module_class",
"(",
"self",
")",
":",
"pkg",
",",
"cname",
"=",
"self",
".",
"parse_module_class",
"(",
")",
"logger",
".",
"debug",
"(",
"f'pkg: {pkg}, class: {cname}'",
")",
"pkg",
"=",
"pkg",
".",
"split",
"(",
"'.'",
")",
"mod",
"=",
"red... | Return the module and class as a tuple of the given class in the
initializer.
:param reload: if ``True`` then reload the module before returning the
class | [
"Return",
"the",
"module",
"and",
"class",
"as",
"a",
"tuple",
"of",
"the",
"given",
"class",
"in",
"the",
"initializer",
"."
] | d1c4ea27e6f3394b30a1652ddd4b916160662773 | https://github.com/plandes/actioncli/blob/d1c4ea27e6f3394b30a1652ddd4b916160662773/src/python/zensols/actioncli/factory.py#L43-L60 | train |
plandes/actioncli | src/python/zensols/actioncli/factory.py | ClassImporter.instance | def instance(self, *args, **kwargs):
"""Create an instance of the specified class in the initializer.
:param args: the arguments given to the initializer of the new class
:param kwargs: the keyword arguments given to the initializer of the
new class
"""
mod... | python | def instance(self, *args, **kwargs):
"""Create an instance of the specified class in the initializer.
:param args: the arguments given to the initializer of the new class
:param kwargs: the keyword arguments given to the initializer of the
new class
"""
mod... | [
"def",
"instance",
"(",
"self",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"mod",
",",
"cls",
"=",
"self",
".",
"get_module_class",
"(",
")",
"inst",
"=",
"cls",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
"logger",
".",
"debug",
... | Create an instance of the specified class in the initializer.
:param args: the arguments given to the initializer of the new class
:param kwargs: the keyword arguments given to the initializer of the
new class | [
"Create",
"an",
"instance",
"of",
"the",
"specified",
"class",
"in",
"the",
"initializer",
"."
] | d1c4ea27e6f3394b30a1652ddd4b916160662773 | https://github.com/plandes/actioncli/blob/d1c4ea27e6f3394b30a1652ddd4b916160662773/src/python/zensols/actioncli/factory.py#L62-L73 | train |
plandes/actioncli | src/python/zensols/actioncli/factory.py | ClassImporter.set_log_level | def set_log_level(self, level=logging.INFO):
"""Convenciene method to set the log level of the module given in the
initializer of this class.
:param level: and instance of ``logging.<level>``
"""
mod, cls = self.parse_module_class()
logging.getLogger(mod).setLevel(level) | python | def set_log_level(self, level=logging.INFO):
"""Convenciene method to set the log level of the module given in the
initializer of this class.
:param level: and instance of ``logging.<level>``
"""
mod, cls = self.parse_module_class()
logging.getLogger(mod).setLevel(level) | [
"def",
"set_log_level",
"(",
"self",
",",
"level",
"=",
"logging",
".",
"INFO",
")",
":",
"mod",
",",
"cls",
"=",
"self",
".",
"parse_module_class",
"(",
")",
"logging",
".",
"getLogger",
"(",
"mod",
")",
".",
"setLevel",
"(",
"level",
")"
] | Convenciene method to set the log level of the module given in the
initializer of this class.
:param level: and instance of ``logging.<level>`` | [
"Convenciene",
"method",
"to",
"set",
"the",
"log",
"level",
"of",
"the",
"module",
"given",
"in",
"the",
"initializer",
"of",
"this",
"class",
"."
] | d1c4ea27e6f3394b30a1652ddd4b916160662773 | https://github.com/plandes/actioncli/blob/d1c4ea27e6f3394b30a1652ddd4b916160662773/src/python/zensols/actioncli/factory.py#L75-L82 | train |
plandes/actioncli | src/python/zensols/actioncli/factory.py | ConfigFactory.register | def register(cls, instance_class, name=None):
"""Register a class with the factory.
:param instance_class: the class to register with the factory (not a
string)
:param name: the name to use as the key for instance class lookups;
defaults to the name of the class
... | python | def register(cls, instance_class, name=None):
"""Register a class with the factory.
:param instance_class: the class to register with the factory (not a
string)
:param name: the name to use as the key for instance class lookups;
defaults to the name of the class
... | [
"def",
"register",
"(",
"cls",
",",
"instance_class",
",",
"name",
"=",
"None",
")",
":",
"if",
"name",
"is",
"None",
":",
"name",
"=",
"instance_class",
".",
"__name__",
"cls",
".",
"INSTANCE_CLASSES",
"[",
"name",
"]",
"=",
"instance_class"
] | Register a class with the factory.
:param instance_class: the class to register with the factory (not a
string)
:param name: the name to use as the key for instance class lookups;
defaults to the name of the class | [
"Register",
"a",
"class",
"with",
"the",
"factory",
"."
] | d1c4ea27e6f3394b30a1652ddd4b916160662773 | https://github.com/plandes/actioncli/blob/d1c4ea27e6f3394b30a1652ddd4b916160662773/src/python/zensols/actioncli/factory.py#L120-L131 | train |
plandes/actioncli | src/python/zensols/actioncli/factory.py | ConfigFactory._find_class | def _find_class(self, class_name):
"Resolve the class from the name."
classes = {}
classes.update(globals())
classes.update(self.INSTANCE_CLASSES)
logger.debug(f'looking up class: {class_name}')
cls = classes[class_name]
logger.debug(f'found class: {cls}')
... | python | def _find_class(self, class_name):
"Resolve the class from the name."
classes = {}
classes.update(globals())
classes.update(self.INSTANCE_CLASSES)
logger.debug(f'looking up class: {class_name}')
cls = classes[class_name]
logger.debug(f'found class: {cls}')
... | [
"def",
"_find_class",
"(",
"self",
",",
"class_name",
")",
":",
"classes",
"=",
"{",
"}",
"classes",
".",
"update",
"(",
"globals",
"(",
")",
")",
"classes",
".",
"update",
"(",
"self",
".",
"INSTANCE_CLASSES",
")",
"logger",
".",
"debug",
"(",
"f'look... | Resolve the class from the name. | [
"Resolve",
"the",
"class",
"from",
"the",
"name",
"."
] | d1c4ea27e6f3394b30a1652ddd4b916160662773 | https://github.com/plandes/actioncli/blob/d1c4ea27e6f3394b30a1652ddd4b916160662773/src/python/zensols/actioncli/factory.py#L133-L141 | train |
plandes/actioncli | src/python/zensols/actioncli/factory.py | ConfigFactory._class_name_params | def _class_name_params(self, name):
"Get the class name and parameters to use for ``__init__``."
sec = self.pattern.format(**{'name': name})
logger.debug(f'section: {sec}')
params = {}
params.update(self.config.populate({}, section=sec))
class_name = params['class_name']
... | python | def _class_name_params(self, name):
"Get the class name and parameters to use for ``__init__``."
sec = self.pattern.format(**{'name': name})
logger.debug(f'section: {sec}')
params = {}
params.update(self.config.populate({}, section=sec))
class_name = params['class_name']
... | [
"def",
"_class_name_params",
"(",
"self",
",",
"name",
")",
":",
"sec",
"=",
"self",
".",
"pattern",
".",
"format",
"(",
"*",
"*",
"{",
"'name'",
":",
"name",
"}",
")",
"logger",
".",
"debug",
"(",
"f'section: {sec}'",
")",
"params",
"=",
"{",
"}",
... | Get the class name and parameters to use for ``__init__``. | [
"Get",
"the",
"class",
"name",
"and",
"parameters",
"to",
"use",
"for",
"__init__",
"."
] | d1c4ea27e6f3394b30a1652ddd4b916160662773 | https://github.com/plandes/actioncli/blob/d1c4ea27e6f3394b30a1652ddd4b916160662773/src/python/zensols/actioncli/factory.py#L143-L151 | train |
plandes/actioncli | src/python/zensols/actioncli/factory.py | ConfigFactory._has_init_config | def _has_init_config(self, cls):
"""Return whether the class has a ``config`` parameter in the ``__init__``
method.
"""
args = inspect.signature(cls.__init__)
return self.config_param_name in args.parameters | python | def _has_init_config(self, cls):
"""Return whether the class has a ``config`` parameter in the ``__init__``
method.
"""
args = inspect.signature(cls.__init__)
return self.config_param_name in args.parameters | [
"def",
"_has_init_config",
"(",
"self",
",",
"cls",
")",
":",
"args",
"=",
"inspect",
".",
"signature",
"(",
"cls",
".",
"__init__",
")",
"return",
"self",
".",
"config_param_name",
"in",
"args",
".",
"parameters"
] | Return whether the class has a ``config`` parameter in the ``__init__``
method. | [
"Return",
"whether",
"the",
"class",
"has",
"a",
"config",
"parameter",
"in",
"the",
"__init__",
"method",
"."
] | d1c4ea27e6f3394b30a1652ddd4b916160662773 | https://github.com/plandes/actioncli/blob/d1c4ea27e6f3394b30a1652ddd4b916160662773/src/python/zensols/actioncli/factory.py#L153-L159 | train |
plandes/actioncli | src/python/zensols/actioncli/factory.py | ConfigFactory._has_init_name | def _has_init_name(self, cls):
"""Return whether the class has a ``name`` parameter in the ``__init__``
method.
"""
args = inspect.signature(cls.__init__)
return self.name_param_name in args.parameters | python | def _has_init_name(self, cls):
"""Return whether the class has a ``name`` parameter in the ``__init__``
method.
"""
args = inspect.signature(cls.__init__)
return self.name_param_name in args.parameters | [
"def",
"_has_init_name",
"(",
"self",
",",
"cls",
")",
":",
"args",
"=",
"inspect",
".",
"signature",
"(",
"cls",
".",
"__init__",
")",
"return",
"self",
".",
"name_param_name",
"in",
"args",
".",
"parameters"
] | Return whether the class has a ``name`` parameter in the ``__init__``
method. | [
"Return",
"whether",
"the",
"class",
"has",
"a",
"name",
"parameter",
"in",
"the",
"__init__",
"method",
"."
] | d1c4ea27e6f3394b30a1652ddd4b916160662773 | https://github.com/plandes/actioncli/blob/d1c4ea27e6f3394b30a1652ddd4b916160662773/src/python/zensols/actioncli/factory.py#L161-L167 | train |
plandes/actioncli | src/python/zensols/actioncli/factory.py | ConfigFactory._instance | def _instance(self, cls, *args, **kwargs):
"""Return the instance.
:param cls: the class to create the instance from
:param args: given to the ``__init__`` method
:param kwargs: given to the ``__init__`` method
"""
logger.debug(f'args: {args}, kwargs: {kwargs}')
... | python | def _instance(self, cls, *args, **kwargs):
"""Return the instance.
:param cls: the class to create the instance from
:param args: given to the ``__init__`` method
:param kwargs: given to the ``__init__`` method
"""
logger.debug(f'args: {args}, kwargs: {kwargs}')
... | [
"def",
"_instance",
"(",
"self",
",",
"cls",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"logger",
".",
"debug",
"(",
"f'args: {args}, kwargs: {kwargs}'",
")",
"return",
"cls",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")"
] | Return the instance.
:param cls: the class to create the instance from
:param args: given to the ``__init__`` method
:param kwargs: given to the ``__init__`` method | [
"Return",
"the",
"instance",
"."
] | d1c4ea27e6f3394b30a1652ddd4b916160662773 | https://github.com/plandes/actioncli/blob/d1c4ea27e6f3394b30a1652ddd4b916160662773/src/python/zensols/actioncli/factory.py#L169-L177 | train |
plandes/actioncli | src/python/zensols/actioncli/factory.py | ConfigFactory.instance | def instance(self, name=None, *args, **kwargs):
"""Create a new instance using key ``name``.
:param name: the name of the class (by default) or the key name of the
class used to find the class
:param args: given to the ``__init__`` method
:param kwargs: given to the ``__init... | python | def instance(self, name=None, *args, **kwargs):
"""Create a new instance using key ``name``.
:param name: the name of the class (by default) or the key name of the
class used to find the class
:param args: given to the ``__init__`` method
:param kwargs: given to the ``__init... | [
"def",
"instance",
"(",
"self",
",",
"name",
"=",
"None",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"logger",
".",
"info",
"(",
"f'new instance of {name}'",
")",
"t0",
"=",
"time",
"(",
")",
"name",
"=",
"self",
".",
"default_name",
"if",
... | Create a new instance using key ``name``.
:param name: the name of the class (by default) or the key name of the
class used to find the class
:param args: given to the ``__init__`` method
:param kwargs: given to the ``__init__`` method | [
"Create",
"a",
"new",
"instance",
"using",
"key",
"name",
"."
] | d1c4ea27e6f3394b30a1652ddd4b916160662773 | https://github.com/plandes/actioncli/blob/d1c4ea27e6f3394b30a1652ddd4b916160662773/src/python/zensols/actioncli/factory.py#L179-L207 | train |
plandes/actioncli | src/python/zensols/actioncli/factory.py | ConfigManager.load | def load(self, name=None, *args, **kwargs):
"Load the instance of the object from the stash."
inst = self.stash.load(name)
if inst is None:
inst = self.instance(name, *args, **kwargs)
logger.debug(f'loaded (conf mng) instance: {inst}')
return inst | python | def load(self, name=None, *args, **kwargs):
"Load the instance of the object from the stash."
inst = self.stash.load(name)
if inst is None:
inst = self.instance(name, *args, **kwargs)
logger.debug(f'loaded (conf mng) instance: {inst}')
return inst | [
"def",
"load",
"(",
"self",
",",
"name",
"=",
"None",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"inst",
"=",
"self",
".",
"stash",
".",
"load",
"(",
"name",
")",
"if",
"inst",
"is",
"None",
":",
"inst",
"=",
"self",
".",
"instance",
... | Load the instance of the object from the stash. | [
"Load",
"the",
"instance",
"of",
"the",
"object",
"from",
"the",
"stash",
"."
] | d1c4ea27e6f3394b30a1652ddd4b916160662773 | https://github.com/plandes/actioncli/blob/d1c4ea27e6f3394b30a1652ddd4b916160662773/src/python/zensols/actioncli/factory.py#L225-L231 | train |
plandes/actioncli | src/python/zensols/actioncli/factory.py | ConfigManager.dump | def dump(self, name: str, inst):
"Save the object instance to the stash."
self.stash.dump(name, inst) | python | def dump(self, name: str, inst):
"Save the object instance to the stash."
self.stash.dump(name, inst) | [
"def",
"dump",
"(",
"self",
",",
"name",
":",
"str",
",",
"inst",
")",
":",
"self",
".",
"stash",
".",
"dump",
"(",
"name",
",",
"inst",
")"
] | Save the object instance to the stash. | [
"Save",
"the",
"object",
"instance",
"to",
"the",
"stash",
"."
] | d1c4ea27e6f3394b30a1652ddd4b916160662773 | https://github.com/plandes/actioncli/blob/d1c4ea27e6f3394b30a1652ddd4b916160662773/src/python/zensols/actioncli/factory.py#L241-L243 | train |
saltant-org/saltant-py | saltant/client.py | Client.from_env | def from_env(cls, default_timeout=DEFAULT_TIMEOUT_SECONDS):
"""Return a client configured from environment variables.
Essentially copying this:
https://github.com/docker/docker-py/blob/master/docker/client.py#L43.
The environment variables looked for are the following:
.. envv... | python | def from_env(cls, default_timeout=DEFAULT_TIMEOUT_SECONDS):
"""Return a client configured from environment variables.
Essentially copying this:
https://github.com/docker/docker-py/blob/master/docker/client.py#L43.
The environment variables looked for are the following:
.. envv... | [
"def",
"from_env",
"(",
"cls",
",",
"default_timeout",
"=",
"DEFAULT_TIMEOUT_SECONDS",
")",
":",
"# Get variables from environment",
"try",
":",
"base_api_url",
"=",
"os",
".",
"environ",
"[",
"\"SALTANT_API_URL\"",
"]",
"except",
"KeyError",
":",
"raise",
"BadEnvir... | Return a client configured from environment variables.
Essentially copying this:
https://github.com/docker/docker-py/blob/master/docker/client.py#L43.
The environment variables looked for are the following:
.. envvar:: SALTANT_API_URL
The URL of the saltant API. For examp... | [
"Return",
"a",
"client",
"configured",
"from",
"environment",
"variables",
"."
] | bf3bdbc4ec9c772c7f621f8bd6a76c5932af68be | https://github.com/saltant-org/saltant-py/blob/bf3bdbc4ec9c772c7f621f8bd6a76c5932af68be/saltant/client.py#L127-L178 | train |
plandes/actioncli | src/python/zensols/actioncli/persist.py | PersistedWork.clear_global | def clear_global(self):
"""Clear only any cached global data.
"""
vname = self.varname
logger.debug(f'global clearning {vname}')
if vname in globals():
logger.debug('removing global instance var: {}'.format(vname))
del globals()[vname] | python | def clear_global(self):
"""Clear only any cached global data.
"""
vname = self.varname
logger.debug(f'global clearning {vname}')
if vname in globals():
logger.debug('removing global instance var: {}'.format(vname))
del globals()[vname] | [
"def",
"clear_global",
"(",
"self",
")",
":",
"vname",
"=",
"self",
".",
"varname",
"logger",
".",
"debug",
"(",
"f'global clearning {vname}'",
")",
"if",
"vname",
"in",
"globals",
"(",
")",
":",
"logger",
".",
"debug",
"(",
"'removing global instance var: {}'... | Clear only any cached global data. | [
"Clear",
"only",
"any",
"cached",
"global",
"data",
"."
] | d1c4ea27e6f3394b30a1652ddd4b916160662773 | https://github.com/plandes/actioncli/blob/d1c4ea27e6f3394b30a1652ddd4b916160662773/src/python/zensols/actioncli/persist.py#L64-L72 | train |
plandes/actioncli | src/python/zensols/actioncli/persist.py | PersistedWork.clear | def clear(self):
"""Clear the data, and thus, force it to be created on the next fetch. This is
done by removing the attribute from ``owner``, deleting it from globals
and removing the file from the disk.
"""
vname = self.varname
if self.path.exists():
logge... | python | def clear(self):
"""Clear the data, and thus, force it to be created on the next fetch. This is
done by removing the attribute from ``owner``, deleting it from globals
and removing the file from the disk.
"""
vname = self.varname
if self.path.exists():
logge... | [
"def",
"clear",
"(",
"self",
")",
":",
"vname",
"=",
"self",
".",
"varname",
"if",
"self",
".",
"path",
".",
"exists",
"(",
")",
":",
"logger",
".",
"debug",
"(",
"'deleting cached work: {}'",
".",
"format",
"(",
"self",
".",
"path",
")",
")",
"self"... | Clear the data, and thus, force it to be created on the next fetch. This is
done by removing the attribute from ``owner``, deleting it from globals
and removing the file from the disk. | [
"Clear",
"the",
"data",
"and",
"thus",
"force",
"it",
"to",
"be",
"created",
"on",
"the",
"next",
"fetch",
".",
"This",
"is",
"done",
"by",
"removing",
"the",
"attribute",
"from",
"owner",
"deleting",
"it",
"from",
"globals",
"and",
"removing",
"the",
"f... | d1c4ea27e6f3394b30a1652ddd4b916160662773 | https://github.com/plandes/actioncli/blob/d1c4ea27e6f3394b30a1652ddd4b916160662773/src/python/zensols/actioncli/persist.py#L74-L87 | train |
plandes/actioncli | src/python/zensols/actioncli/persist.py | PersistedWork._load_or_create | def _load_or_create(self, *argv, **kwargs):
"""Invoke the file system operations to get the data, or create work.
If the file does not exist, calling ``__do_work__`` and save it.
"""
if self.path.exists():
self._info('loading work from {}'.format(self.path))
with... | python | def _load_or_create(self, *argv, **kwargs):
"""Invoke the file system operations to get the data, or create work.
If the file does not exist, calling ``__do_work__`` and save it.
"""
if self.path.exists():
self._info('loading work from {}'.format(self.path))
with... | [
"def",
"_load_or_create",
"(",
"self",
",",
"*",
"argv",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"self",
".",
"path",
".",
"exists",
"(",
")",
":",
"self",
".",
"_info",
"(",
"'loading work from {}'",
".",
"format",
"(",
"self",
".",
"path",
")",
... | Invoke the file system operations to get the data, or create work.
If the file does not exist, calling ``__do_work__`` and save it. | [
"Invoke",
"the",
"file",
"system",
"operations",
"to",
"get",
"the",
"data",
"or",
"create",
"work",
"."
] | d1c4ea27e6f3394b30a1652ddd4b916160662773 | https://github.com/plandes/actioncli/blob/d1c4ea27e6f3394b30a1652ddd4b916160662773/src/python/zensols/actioncli/persist.py#L96-L110 | train |
plandes/actioncli | src/python/zensols/actioncli/persist.py | PreemptiveStash.has_data | def has_data(self):
"""Return whether or not the stash has any data available or not."""
if not hasattr(self, '_has_data'):
try:
next(iter(self.delegate.keys()))
self._has_data = True
except StopIteration:
self._has_data = False
... | python | def has_data(self):
"""Return whether or not the stash has any data available or not."""
if not hasattr(self, '_has_data'):
try:
next(iter(self.delegate.keys()))
self._has_data = True
except StopIteration:
self._has_data = False
... | [
"def",
"has_data",
"(",
"self",
")",
":",
"if",
"not",
"hasattr",
"(",
"self",
",",
"'_has_data'",
")",
":",
"try",
":",
"next",
"(",
"iter",
"(",
"self",
".",
"delegate",
".",
"keys",
"(",
")",
")",
")",
"self",
".",
"_has_data",
"=",
"True",
"e... | Return whether or not the stash has any data available or not. | [
"Return",
"whether",
"or",
"not",
"the",
"stash",
"has",
"any",
"data",
"available",
"or",
"not",
"."
] | d1c4ea27e6f3394b30a1652ddd4b916160662773 | https://github.com/plandes/actioncli/blob/d1c4ea27e6f3394b30a1652ddd4b916160662773/src/python/zensols/actioncli/persist.py#L393-L401 | train |
plandes/actioncli | src/python/zensols/actioncli/persist.py | DirectoryStash._get_instance_path | def _get_instance_path(self, name):
"Return a path to the pickled data with key ``name``."
fname = self.pattern.format(**{'name': name})
logger.debug(f'path {self.create_path}: {self.create_path.exists()}')
self._create_path_dir()
return Path(self.create_path, fname) | python | def _get_instance_path(self, name):
"Return a path to the pickled data with key ``name``."
fname = self.pattern.format(**{'name': name})
logger.debug(f'path {self.create_path}: {self.create_path.exists()}')
self._create_path_dir()
return Path(self.create_path, fname) | [
"def",
"_get_instance_path",
"(",
"self",
",",
"name",
")",
":",
"fname",
"=",
"self",
".",
"pattern",
".",
"format",
"(",
"*",
"*",
"{",
"'name'",
":",
"name",
"}",
")",
"logger",
".",
"debug",
"(",
"f'path {self.create_path}: {self.create_path.exists()}'",
... | Return a path to the pickled data with key ``name``. | [
"Return",
"a",
"path",
"to",
"the",
"pickled",
"data",
"with",
"key",
"name",
"."
] | d1c4ea27e6f3394b30a1652ddd4b916160662773 | https://github.com/plandes/actioncli/blob/d1c4ea27e6f3394b30a1652ddd4b916160662773/src/python/zensols/actioncli/persist.py#L533-L538 | train |
plandes/actioncli | src/python/zensols/actioncli/persist.py | ShelveStash.shelve | def shelve(self):
"""Return an opened shelve object.
"""
logger.info('creating shelve data')
fname = str(self.create_path.absolute())
inst = sh.open(fname, writeback=self.writeback)
self.is_open = True
return inst | python | def shelve(self):
"""Return an opened shelve object.
"""
logger.info('creating shelve data')
fname = str(self.create_path.absolute())
inst = sh.open(fname, writeback=self.writeback)
self.is_open = True
return inst | [
"def",
"shelve",
"(",
"self",
")",
":",
"logger",
".",
"info",
"(",
"'creating shelve data'",
")",
"fname",
"=",
"str",
"(",
"self",
".",
"create_path",
".",
"absolute",
"(",
")",
")",
"inst",
"=",
"sh",
".",
"open",
"(",
"fname",
",",
"writeback",
"... | Return an opened shelve object. | [
"Return",
"an",
"opened",
"shelve",
"object",
"."
] | d1c4ea27e6f3394b30a1652ddd4b916160662773 | https://github.com/plandes/actioncli/blob/d1c4ea27e6f3394b30a1652ddd4b916160662773/src/python/zensols/actioncli/persist.py#L602-L610 | train |
plandes/actioncli | src/python/zensols/actioncli/persist.py | ShelveStash.delete | def delete(self, name=None):
"Delete the shelve data file."
logger.info('clearing shelve data')
self.close()
for path in Path(self.create_path.parent, self.create_path.name), \
Path(self.create_path.parent, self.create_path.name + '.db'):
logger.debug(f'clearing {... | python | def delete(self, name=None):
"Delete the shelve data file."
logger.info('clearing shelve data')
self.close()
for path in Path(self.create_path.parent, self.create_path.name), \
Path(self.create_path.parent, self.create_path.name + '.db'):
logger.debug(f'clearing {... | [
"def",
"delete",
"(",
"self",
",",
"name",
"=",
"None",
")",
":",
"logger",
".",
"info",
"(",
"'clearing shelve data'",
")",
"self",
".",
"close",
"(",
")",
"for",
"path",
"in",
"Path",
"(",
"self",
".",
"create_path",
".",
"parent",
",",
"self",
"."... | Delete the shelve data file. | [
"Delete",
"the",
"shelve",
"data",
"file",
"."
] | d1c4ea27e6f3394b30a1652ddd4b916160662773 | https://github.com/plandes/actioncli/blob/d1c4ea27e6f3394b30a1652ddd4b916160662773/src/python/zensols/actioncli/persist.py#L625-L634 | train |
plandes/actioncli | src/python/zensols/actioncli/persist.py | ShelveStash.close | def close(self):
"Close the shelve object, which is needed for data consistency."
if self.is_open:
logger.info('closing shelve data')
try:
self.shelve.close()
self._shelve.clear()
except Exception:
self.is_open = False | python | def close(self):
"Close the shelve object, which is needed for data consistency."
if self.is_open:
logger.info('closing shelve data')
try:
self.shelve.close()
self._shelve.clear()
except Exception:
self.is_open = False | [
"def",
"close",
"(",
"self",
")",
":",
"if",
"self",
".",
"is_open",
":",
"logger",
".",
"info",
"(",
"'closing shelve data'",
")",
"try",
":",
"self",
".",
"shelve",
".",
"close",
"(",
")",
"self",
".",
"_shelve",
".",
"clear",
"(",
")",
"except",
... | Close the shelve object, which is needed for data consistency. | [
"Close",
"the",
"shelve",
"object",
"which",
"is",
"needed",
"for",
"data",
"consistency",
"."
] | d1c4ea27e6f3394b30a1652ddd4b916160662773 | https://github.com/plandes/actioncli/blob/d1c4ea27e6f3394b30a1652ddd4b916160662773/src/python/zensols/actioncli/persist.py#L636-L644 | train |
plandes/actioncli | src/python/zensols/actioncli/persist.py | MultiThreadedPoolStash._map | def _map(self, data_item):
"Map ``data_item`` separately in each thread."
delegate = self.delegate
logger.debug(f'mapping: {data_item}')
if self.clobber or not self.exists(data_item.id):
logger.debug(f'exist: {data_item.id}: {self.exists(data_item.id)}')
delegate.... | python | def _map(self, data_item):
"Map ``data_item`` separately in each thread."
delegate = self.delegate
logger.debug(f'mapping: {data_item}')
if self.clobber or not self.exists(data_item.id):
logger.debug(f'exist: {data_item.id}: {self.exists(data_item.id)}')
delegate.... | [
"def",
"_map",
"(",
"self",
",",
"data_item",
")",
":",
"delegate",
"=",
"self",
".",
"delegate",
"logger",
".",
"debug",
"(",
"f'mapping: {data_item}'",
")",
"if",
"self",
".",
"clobber",
"or",
"not",
"self",
".",
"exists",
"(",
"data_item",
".",
"id",
... | Map ``data_item`` separately in each thread. | [
"Map",
"data_item",
"separately",
"in",
"each",
"thread",
"."
] | d1c4ea27e6f3394b30a1652ddd4b916160662773 | https://github.com/plandes/actioncli/blob/d1c4ea27e6f3394b30a1652ddd4b916160662773/src/python/zensols/actioncli/persist.py#L685-L691 | train |
plandes/actioncli | src/python/zensols/actioncli/persist.py | MultiThreadedPoolStash.load_all | def load_all(self, workers=None, limit=None, n_expected=None):
"""Load all instances witih multiple threads.
:param workers: number of workers to use to load instances, which
defaults to what was given in the class initializer
:param limit: return a maximum, which defaul... | python | def load_all(self, workers=None, limit=None, n_expected=None):
"""Load all instances witih multiple threads.
:param workers: number of workers to use to load instances, which
defaults to what was given in the class initializer
:param limit: return a maximum, which defaul... | [
"def",
"load_all",
"(",
"self",
",",
"workers",
"=",
"None",
",",
"limit",
"=",
"None",
",",
"n_expected",
"=",
"None",
")",
":",
"if",
"not",
"self",
".",
"has_data",
":",
"self",
".",
"_preempt",
"(",
"True",
")",
"# we did the best we could (avoid repea... | Load all instances witih multiple threads.
:param workers: number of workers to use to load instances, which
defaults to what was given in the class initializer
:param limit: return a maximum, which defaults to no limit
:param n_expected: rerun the iteration on the data... | [
"Load",
"all",
"instances",
"witih",
"multiple",
"threads",
"."
] | d1c4ea27e6f3394b30a1652ddd4b916160662773 | https://github.com/plandes/actioncli/blob/d1c4ea27e6f3394b30a1652ddd4b916160662773/src/python/zensols/actioncli/persist.py#L714-L741 | train |
pymacaron/pymacaron-core | pymacaron_core/swagger/api.py | API._make_persistent | def _make_persistent(self, model_name, pkg_name):
"""Monkey-patch object persistence (ex: to/from database) into a
bravado-core model class"""
#
# WARNING: ugly piece of monkey-patching below. Hopefully will replace
# with native bravado-core code in the future...
#
... | python | def _make_persistent(self, model_name, pkg_name):
"""Monkey-patch object persistence (ex: to/from database) into a
bravado-core model class"""
#
# WARNING: ugly piece of monkey-patching below. Hopefully will replace
# with native bravado-core code in the future...
#
... | [
"def",
"_make_persistent",
"(",
"self",
",",
"model_name",
",",
"pkg_name",
")",
":",
"#",
"# WARNING: ugly piece of monkey-patching below. Hopefully will replace",
"# with native bravado-core code in the future...",
"#",
"# Load class at path pkg_name",
"c",
"=",
"get_function",
... | Monkey-patch object persistence (ex: to/from database) into a
bravado-core model class | [
"Monkey",
"-",
"patch",
"object",
"persistence",
"(",
"ex",
":",
"to",
"/",
"from",
"database",
")",
"into",
"a",
"bravado",
"-",
"core",
"model",
"class"
] | 95070a39ed7065a84244ff5601fea4d54cc72b66 | https://github.com/pymacaron/pymacaron-core/blob/95070a39ed7065a84244ff5601fea4d54cc72b66/pymacaron_core/swagger/api.py#L121-L145 | train |
pymacaron/pymacaron-core | pymacaron_core/swagger/api.py | API.spawn_api | def spawn_api(self, app, decorator=None):
"""Auto-generate server endpoints implementing the API into this Flask app"""
if decorator:
assert type(decorator).__name__ == 'function'
self.is_server = True
self.app = app
if self.local:
# Re-generate client ca... | python | def spawn_api(self, app, decorator=None):
"""Auto-generate server endpoints implementing the API into this Flask app"""
if decorator:
assert type(decorator).__name__ == 'function'
self.is_server = True
self.app = app
if self.local:
# Re-generate client ca... | [
"def",
"spawn_api",
"(",
"self",
",",
"app",
",",
"decorator",
"=",
"None",
")",
":",
"if",
"decorator",
":",
"assert",
"type",
"(",
"decorator",
")",
".",
"__name__",
"==",
"'function'",
"self",
".",
"is_server",
"=",
"True",
"self",
".",
"app",
"=",
... | Auto-generate server endpoints implementing the API into this Flask app | [
"Auto",
"-",
"generate",
"server",
"endpoints",
"implementing",
"the",
"API",
"into",
"this",
"Flask",
"app"
] | 95070a39ed7065a84244ff5601fea4d54cc72b66 | https://github.com/pymacaron/pymacaron-core/blob/95070a39ed7065a84244ff5601fea4d54cc72b66/pymacaron_core/swagger/api.py#L161-L172 | train |
pymacaron/pymacaron-core | pymacaron_core/swagger/api.py | API.json_to_model | def json_to_model(self, model_name, j, validate=False):
"""Take a json strust and a model name, and return a model instance"""
if validate:
self.api_spec.validate(model_name, j)
return self.api_spec.json_to_model(model_name, j) | python | def json_to_model(self, model_name, j, validate=False):
"""Take a json strust and a model name, and return a model instance"""
if validate:
self.api_spec.validate(model_name, j)
return self.api_spec.json_to_model(model_name, j) | [
"def",
"json_to_model",
"(",
"self",
",",
"model_name",
",",
"j",
",",
"validate",
"=",
"False",
")",
":",
"if",
"validate",
":",
"self",
".",
"api_spec",
".",
"validate",
"(",
"model_name",
",",
"j",
")",
"return",
"self",
".",
"api_spec",
".",
"json_... | Take a json strust and a model name, and return a model instance | [
"Take",
"a",
"json",
"strust",
"and",
"a",
"model",
"name",
"and",
"return",
"a",
"model",
"instance"
] | 95070a39ed7065a84244ff5601fea4d54cc72b66 | https://github.com/pymacaron/pymacaron-core/blob/95070a39ed7065a84244ff5601fea4d54cc72b66/pymacaron_core/swagger/api.py#L185-L189 | train |
4degrees/clique | source/clique/__init__.py | assemble | def assemble(
iterable, patterns=None, minimum_items=2, case_sensitive=True,
assume_padded_when_ambiguous=False
):
'''Assemble items in *iterable* into discreet collections.
*patterns* may be specified as a list of regular expressions to limit
the returned collection possibilities. Use this when in... | python | def assemble(
iterable, patterns=None, minimum_items=2, case_sensitive=True,
assume_padded_when_ambiguous=False
):
'''Assemble items in *iterable* into discreet collections.
*patterns* may be specified as a list of regular expressions to limit
the returned collection possibilities. Use this when in... | [
"def",
"assemble",
"(",
"iterable",
",",
"patterns",
"=",
"None",
",",
"minimum_items",
"=",
"2",
",",
"case_sensitive",
"=",
"True",
",",
"assume_padded_when_ambiguous",
"=",
"False",
")",
":",
"collection_map",
"=",
"defaultdict",
"(",
"set",
")",
"collectio... | Assemble items in *iterable* into discreet collections.
*patterns* may be specified as a list of regular expressions to limit
the returned collection possibilities. Use this when interested in
collections that only match specific patterns. Each pattern must contain
the expression from :py:data:`DIGITS_... | [
"Assemble",
"items",
"in",
"*",
"iterable",
"*",
"into",
"discreet",
"collections",
"."
] | af1d4fef1d60c30a870257199a4d98597d15417d | https://github.com/4degrees/clique/blob/af1d4fef1d60c30a870257199a4d98597d15417d/source/clique/__init__.py#L23-L206 | train |
4degrees/clique | source/clique/__init__.py | parse | def parse(value, pattern='{head}{padding}{tail} [{ranges}]'):
'''Parse *value* into a :py:class:`~clique.collection.Collection`.
Use *pattern* to extract information from *value*. It may make use of the
following keys:
* *head* - Common leading part of the collection.
* *tail* - Common tra... | python | def parse(value, pattern='{head}{padding}{tail} [{ranges}]'):
'''Parse *value* into a :py:class:`~clique.collection.Collection`.
Use *pattern* to extract information from *value*. It may make use of the
following keys:
* *head* - Common leading part of the collection.
* *tail* - Common tra... | [
"def",
"parse",
"(",
"value",
",",
"pattern",
"=",
"'{head}{padding}{tail} [{ranges}]'",
")",
":",
"# Construct regular expression for given pattern.",
"expressions",
"=",
"{",
"'head'",
":",
"'(?P<head>.*)'",
",",
"'tail'",
":",
"'(?P<tail>.*)'",
",",
"'padding'",
":",... | Parse *value* into a :py:class:`~clique.collection.Collection`.
Use *pattern* to extract information from *value*. It may make use of the
following keys:
* *head* - Common leading part of the collection.
* *tail* - Common trailing part of the collection.
* *padding* - Padding value in ... | [
"Parse",
"*",
"value",
"*",
"into",
"a",
":",
"py",
":",
"class",
":",
"~clique",
".",
"collection",
".",
"Collection",
"."
] | af1d4fef1d60c30a870257199a4d98597d15417d | https://github.com/4degrees/clique/blob/af1d4fef1d60c30a870257199a4d98597d15417d/source/clique/__init__.py#L209-L293 | train |
4degrees/clique | source/clique/sorted_set.py | SortedSet.add | def add(self, item):
'''Add *item*.'''
if not item in self:
index = bisect.bisect_right(self._members, item)
self._members.insert(index, item) | python | def add(self, item):
'''Add *item*.'''
if not item in self:
index = bisect.bisect_right(self._members, item)
self._members.insert(index, item) | [
"def",
"add",
"(",
"self",
",",
"item",
")",
":",
"if",
"not",
"item",
"in",
"self",
":",
"index",
"=",
"bisect",
".",
"bisect_right",
"(",
"self",
".",
"_members",
",",
"item",
")",
"self",
".",
"_members",
".",
"insert",
"(",
"index",
",",
"item"... | Add *item*. | [
"Add",
"*",
"item",
"*",
"."
] | af1d4fef1d60c30a870257199a4d98597d15417d | https://github.com/4degrees/clique/blob/af1d4fef1d60c30a870257199a4d98597d15417d/source/clique/sorted_set.py#L39-L43 | train |
4degrees/clique | source/clique/sorted_set.py | SortedSet.discard | def discard(self, item):
'''Remove *item*.'''
index = self._index(item)
if index >= 0:
del self._members[index] | python | def discard(self, item):
'''Remove *item*.'''
index = self._index(item)
if index >= 0:
del self._members[index] | [
"def",
"discard",
"(",
"self",
",",
"item",
")",
":",
"index",
"=",
"self",
".",
"_index",
"(",
"item",
")",
"if",
"index",
">=",
"0",
":",
"del",
"self",
".",
"_members",
"[",
"index",
"]"
] | Remove *item*. | [
"Remove",
"*",
"item",
"*",
"."
] | af1d4fef1d60c30a870257199a4d98597d15417d | https://github.com/4degrees/clique/blob/af1d4fef1d60c30a870257199a4d98597d15417d/source/clique/sorted_set.py#L45-L49 | train |
4degrees/clique | source/clique/sorted_set.py | SortedSet._index | def _index(self, item):
'''Return index of *item* in member list or -1 if not present.'''
index = bisect.bisect_left(self._members, item)
if index != len(self) and self._members[index] == item:
return index
return -1 | python | def _index(self, item):
'''Return index of *item* in member list or -1 if not present.'''
index = bisect.bisect_left(self._members, item)
if index != len(self) and self._members[index] == item:
return index
return -1 | [
"def",
"_index",
"(",
"self",
",",
"item",
")",
":",
"index",
"=",
"bisect",
".",
"bisect_left",
"(",
"self",
".",
"_members",
",",
"item",
")",
"if",
"index",
"!=",
"len",
"(",
"self",
")",
"and",
"self",
".",
"_members",
"[",
"index",
"]",
"==",
... | Return index of *item* in member list or -1 if not present. | [
"Return",
"index",
"of",
"*",
"item",
"*",
"in",
"member",
"list",
"or",
"-",
"1",
"if",
"not",
"present",
"."
] | af1d4fef1d60c30a870257199a4d98597d15417d | https://github.com/4degrees/clique/blob/af1d4fef1d60c30a870257199a4d98597d15417d/source/clique/sorted_set.py#L56-L62 | train |
4degrees/clique | source/clique/collection.py | Collection._update_expression | def _update_expression(self):
'''Update internal expression.'''
self._expression = re.compile(
'^{0}(?P<index>(?P<padding>0*)\d+?){1}$'
.format(re.escape(self.head), re.escape(self.tail))
) | python | def _update_expression(self):
'''Update internal expression.'''
self._expression = re.compile(
'^{0}(?P<index>(?P<padding>0*)\d+?){1}$'
.format(re.escape(self.head), re.escape(self.tail))
) | [
"def",
"_update_expression",
"(",
"self",
")",
":",
"self",
".",
"_expression",
"=",
"re",
".",
"compile",
"(",
"'^{0}(?P<index>(?P<padding>0*)\\d+?){1}$'",
".",
"format",
"(",
"re",
".",
"escape",
"(",
"self",
".",
"head",
")",
",",
"re",
".",
"escape",
"... | Update internal expression. | [
"Update",
"internal",
"expression",
"."
] | af1d4fef1d60c30a870257199a4d98597d15417d | https://github.com/4degrees/clique/blob/af1d4fef1d60c30a870257199a4d98597d15417d/source/clique/collection.py#L77-L82 | train |
4degrees/clique | source/clique/collection.py | Collection.match | def match(self, item):
'''Return whether *item* matches this collection expression.
If a match is successful return data about the match otherwise return
None.
'''
match = self._expression.match(item)
if not match:
return None
index = match.group('i... | python | def match(self, item):
'''Return whether *item* matches this collection expression.
If a match is successful return data about the match otherwise return
None.
'''
match = self._expression.match(item)
if not match:
return None
index = match.group('i... | [
"def",
"match",
"(",
"self",
",",
"item",
")",
":",
"match",
"=",
"self",
".",
"_expression",
".",
"match",
"(",
"item",
")",
"if",
"not",
"match",
":",
"return",
"None",
"index",
"=",
"match",
".",
"group",
"(",
"'index'",
")",
"padded",
"=",
"Fal... | Return whether *item* matches this collection expression.
If a match is successful return data about the match otherwise return
None. | [
"Return",
"whether",
"*",
"item",
"*",
"matches",
"this",
"collection",
"expression",
"."
] | af1d4fef1d60c30a870257199a4d98597d15417d | https://github.com/4degrees/clique/blob/af1d4fef1d60c30a870257199a4d98597d15417d/source/clique/collection.py#L170-L193 | train |
4degrees/clique | source/clique/collection.py | Collection.add | def add(self, item):
'''Add *item* to collection.
raise :py:class:`~clique.error.CollectionError` if *item* cannot be
added to the collection.
'''
match = self.match(item)
if match is None:
raise clique.error.CollectionError(
'Item does not m... | python | def add(self, item):
'''Add *item* to collection.
raise :py:class:`~clique.error.CollectionError` if *item* cannot be
added to the collection.
'''
match = self.match(item)
if match is None:
raise clique.error.CollectionError(
'Item does not m... | [
"def",
"add",
"(",
"self",
",",
"item",
")",
":",
"match",
"=",
"self",
".",
"match",
"(",
"item",
")",
"if",
"match",
"is",
"None",
":",
"raise",
"clique",
".",
"error",
".",
"CollectionError",
"(",
"'Item does not match collection expression.'",
")",
"se... | Add *item* to collection.
raise :py:class:`~clique.error.CollectionError` if *item* cannot be
added to the collection. | [
"Add",
"*",
"item",
"*",
"to",
"collection",
"."
] | af1d4fef1d60c30a870257199a4d98597d15417d | https://github.com/4degrees/clique/blob/af1d4fef1d60c30a870257199a4d98597d15417d/source/clique/collection.py#L195-L208 | train |
4degrees/clique | source/clique/collection.py | Collection.remove | def remove(self, item):
'''Remove *item* from collection.
raise :py:class:`~clique.error.CollectionError` if *item* cannot be
removed from the collection.
'''
match = self.match(item)
if match is None:
raise clique.error.CollectionError(
'Ite... | python | def remove(self, item):
'''Remove *item* from collection.
raise :py:class:`~clique.error.CollectionError` if *item* cannot be
removed from the collection.
'''
match = self.match(item)
if match is None:
raise clique.error.CollectionError(
'Ite... | [
"def",
"remove",
"(",
"self",
",",
"item",
")",
":",
"match",
"=",
"self",
".",
"match",
"(",
"item",
")",
"if",
"match",
"is",
"None",
":",
"raise",
"clique",
".",
"error",
".",
"CollectionError",
"(",
"'Item not present in collection.'",
")",
"index",
... | Remove *item* from collection.
raise :py:class:`~clique.error.CollectionError` if *item* cannot be
removed from the collection. | [
"Remove",
"*",
"item",
"*",
"from",
"collection",
"."
] | af1d4fef1d60c30a870257199a4d98597d15417d | https://github.com/4degrees/clique/blob/af1d4fef1d60c30a870257199a4d98597d15417d/source/clique/collection.py#L210-L229 | train |
4degrees/clique | source/clique/collection.py | Collection.format | def format(self, pattern='{head}{padding}{tail} [{ranges}]'):
'''Return string representation as specified by *pattern*.
Pattern can be any format accepted by Python's standard format function
and will receive the following keyword arguments as context:
* *head* - Common leading pa... | python | def format(self, pattern='{head}{padding}{tail} [{ranges}]'):
'''Return string representation as specified by *pattern*.
Pattern can be any format accepted by Python's standard format function
and will receive the following keyword arguments as context:
* *head* - Common leading pa... | [
"def",
"format",
"(",
"self",
",",
"pattern",
"=",
"'{head}{padding}{tail} [{ranges}]'",
")",
":",
"data",
"=",
"{",
"}",
"data",
"[",
"'head'",
"]",
"=",
"self",
".",
"head",
"data",
"[",
"'tail'",
"]",
"=",
"self",
".",
"tail",
"if",
"self",
".",
"... | Return string representation as specified by *pattern*.
Pattern can be any format accepted by Python's standard format function
and will receive the following keyword arguments as context:
* *head* - Common leading part of the collection.
* *tail* - Common trailing part of the ... | [
"Return",
"string",
"representation",
"as",
"specified",
"by",
"*",
"pattern",
"*",
"."
] | af1d4fef1d60c30a870257199a4d98597d15417d | https://github.com/4degrees/clique/blob/af1d4fef1d60c30a870257199a4d98597d15417d/source/clique/collection.py#L231-L283 | train |
4degrees/clique | source/clique/collection.py | Collection.is_contiguous | def is_contiguous(self):
'''Return whether entire collection is contiguous.'''
previous = None
for index in self.indexes:
if previous is None:
previous = index
continue
if index != (previous + 1):
return False
... | python | def is_contiguous(self):
'''Return whether entire collection is contiguous.'''
previous = None
for index in self.indexes:
if previous is None:
previous = index
continue
if index != (previous + 1):
return False
... | [
"def",
"is_contiguous",
"(",
"self",
")",
":",
"previous",
"=",
"None",
"for",
"index",
"in",
"self",
".",
"indexes",
":",
"if",
"previous",
"is",
"None",
":",
"previous",
"=",
"index",
"continue",
"if",
"index",
"!=",
"(",
"previous",
"+",
"1",
")",
... | Return whether entire collection is contiguous. | [
"Return",
"whether",
"entire",
"collection",
"is",
"contiguous",
"."
] | af1d4fef1d60c30a870257199a4d98597d15417d | https://github.com/4degrees/clique/blob/af1d4fef1d60c30a870257199a4d98597d15417d/source/clique/collection.py#L285-L298 | train |
4degrees/clique | source/clique/collection.py | Collection.holes | def holes(self):
'''Return holes in collection.
Return :py:class:`~clique.collection.Collection` of missing indexes.
'''
missing = set([])
previous = None
for index in self.indexes:
if previous is None:
previous = index
contin... | python | def holes(self):
'''Return holes in collection.
Return :py:class:`~clique.collection.Collection` of missing indexes.
'''
missing = set([])
previous = None
for index in self.indexes:
if previous is None:
previous = index
contin... | [
"def",
"holes",
"(",
"self",
")",
":",
"missing",
"=",
"set",
"(",
"[",
"]",
")",
"previous",
"=",
"None",
"for",
"index",
"in",
"self",
".",
"indexes",
":",
"if",
"previous",
"is",
"None",
":",
"previous",
"=",
"index",
"continue",
"if",
"index",
... | Return holes in collection.
Return :py:class:`~clique.collection.Collection` of missing indexes. | [
"Return",
"holes",
"in",
"collection",
"."
] | af1d4fef1d60c30a870257199a4d98597d15417d | https://github.com/4degrees/clique/blob/af1d4fef1d60c30a870257199a4d98597d15417d/source/clique/collection.py#L300-L318 | train |
4degrees/clique | source/clique/collection.py | Collection.is_compatible | def is_compatible(self, collection):
'''Return whether *collection* is compatible with this collection.
To be compatible *collection* must have the same head, tail and padding
properties as this collection.
'''
return all([
isinstance(collection, Collection),
... | python | def is_compatible(self, collection):
'''Return whether *collection* is compatible with this collection.
To be compatible *collection* must have the same head, tail and padding
properties as this collection.
'''
return all([
isinstance(collection, Collection),
... | [
"def",
"is_compatible",
"(",
"self",
",",
"collection",
")",
":",
"return",
"all",
"(",
"[",
"isinstance",
"(",
"collection",
",",
"Collection",
")",
",",
"collection",
".",
"head",
"==",
"self",
".",
"head",
",",
"collection",
".",
"tail",
"==",
"self",... | Return whether *collection* is compatible with this collection.
To be compatible *collection* must have the same head, tail and padding
properties as this collection. | [
"Return",
"whether",
"*",
"collection",
"*",
"is",
"compatible",
"with",
"this",
"collection",
"."
] | af1d4fef1d60c30a870257199a4d98597d15417d | https://github.com/4degrees/clique/blob/af1d4fef1d60c30a870257199a4d98597d15417d/source/clique/collection.py#L320-L332 | train |
4degrees/clique | source/clique/collection.py | Collection.merge | def merge(self, collection):
'''Merge *collection* into this collection.
If the *collection* is compatible with this collection then update
indexes with all indexes in *collection*.
raise :py:class:`~clique.error.CollectionError` if *collection* is not
compatible with this coll... | python | def merge(self, collection):
'''Merge *collection* into this collection.
If the *collection* is compatible with this collection then update
indexes with all indexes in *collection*.
raise :py:class:`~clique.error.CollectionError` if *collection* is not
compatible with this coll... | [
"def",
"merge",
"(",
"self",
",",
"collection",
")",
":",
"if",
"not",
"self",
".",
"is_compatible",
"(",
"collection",
")",
":",
"raise",
"clique",
".",
"error",
".",
"CollectionError",
"(",
"'Collection is not compatible '",
"'with this collection.'",
")",
"se... | Merge *collection* into this collection.
If the *collection* is compatible with this collection then update
indexes with all indexes in *collection*.
raise :py:class:`~clique.error.CollectionError` if *collection* is not
compatible with this collection. | [
"Merge",
"*",
"collection",
"*",
"into",
"this",
"collection",
"."
] | af1d4fef1d60c30a870257199a4d98597d15417d | https://github.com/4degrees/clique/blob/af1d4fef1d60c30a870257199a4d98597d15417d/source/clique/collection.py#L334-L348 | train |
4degrees/clique | source/clique/collection.py | Collection.separate | def separate(self):
'''Return contiguous parts of collection as separate collections.
Return as list of :py:class:`~clique.collection.Collection` instances.
'''
collections = []
start = None
end = None
for index in self.indexes:
if start is None:
... | python | def separate(self):
'''Return contiguous parts of collection as separate collections.
Return as list of :py:class:`~clique.collection.Collection` instances.
'''
collections = []
start = None
end = None
for index in self.indexes:
if start is None:
... | [
"def",
"separate",
"(",
"self",
")",
":",
"collections",
"=",
"[",
"]",
"start",
"=",
"None",
"end",
"=",
"None",
"for",
"index",
"in",
"self",
".",
"indexes",
":",
"if",
"start",
"is",
"None",
":",
"start",
"=",
"index",
"end",
"=",
"start",
"cont... | Return contiguous parts of collection as separate collections.
Return as list of :py:class:`~clique.collection.Collection` instances. | [
"Return",
"contiguous",
"parts",
"of",
"collection",
"as",
"separate",
"collections",
"."
] | af1d4fef1d60c30a870257199a4d98597d15417d | https://github.com/4degrees/clique/blob/af1d4fef1d60c30a870257199a4d98597d15417d/source/clique/collection.py#L350-L385 | train |
UDST/osmnet | osmnet/config.py | format_check | def format_check(settings):
"""
Check the format of a osmnet_config object.
Parameters
----------
settings : dict
osmnet_config as a dictionary
Returns
-------
Nothing
"""
valid_keys = ['logs_folder', 'log_file', 'log_console', 'log_name',
'log_filenam... | python | def format_check(settings):
"""
Check the format of a osmnet_config object.
Parameters
----------
settings : dict
osmnet_config as a dictionary
Returns
-------
Nothing
"""
valid_keys = ['logs_folder', 'log_file', 'log_console', 'log_name',
'log_filenam... | [
"def",
"format_check",
"(",
"settings",
")",
":",
"valid_keys",
"=",
"[",
"'logs_folder'",
",",
"'log_file'",
",",
"'log_console'",
",",
"'log_name'",
",",
"'log_filename'",
",",
"'keep_osm_tags'",
"]",
"for",
"key",
"in",
"list",
"(",
"settings",
".",
"keys",... | Check the format of a osmnet_config object.
Parameters
----------
settings : dict
osmnet_config as a dictionary
Returns
-------
Nothing | [
"Check",
"the",
"format",
"of",
"a",
"osmnet_config",
"object",
"."
] | 155110a8e38d3646b9dbc3ec729063930cab3d5f | https://github.com/UDST/osmnet/blob/155110a8e38d3646b9dbc3ec729063930cab3d5f/osmnet/config.py#L2-L30 | train |
UDST/osmnet | osmnet/config.py | osmnet_config.to_dict | def to_dict(self):
"""
Return a dict representation of an osmnet osmnet_config instance.
"""
return {'logs_folder': self.logs_folder,
'log_file': self.log_file,
'log_console': self.log_console,
'log_name': self.log_name,
'lo... | python | def to_dict(self):
"""
Return a dict representation of an osmnet osmnet_config instance.
"""
return {'logs_folder': self.logs_folder,
'log_file': self.log_file,
'log_console': self.log_console,
'log_name': self.log_name,
'lo... | [
"def",
"to_dict",
"(",
"self",
")",
":",
"return",
"{",
"'logs_folder'",
":",
"self",
".",
"logs_folder",
",",
"'log_file'",
":",
"self",
".",
"log_file",
",",
"'log_console'",
":",
"self",
".",
"log_console",
",",
"'log_name'",
":",
"self",
".",
"log_name... | Return a dict representation of an osmnet osmnet_config instance. | [
"Return",
"a",
"dict",
"representation",
"of",
"an",
"osmnet",
"osmnet_config",
"instance",
"."
] | 155110a8e38d3646b9dbc3ec729063930cab3d5f | https://github.com/UDST/osmnet/blob/155110a8e38d3646b9dbc3ec729063930cab3d5f/osmnet/config.py#L73-L83 | train |
UDST/osmnet | osmnet/utils.py | great_circle_dist | def great_circle_dist(lat1, lon1, lat2, lon2):
"""
Get the distance (in meters) between two lat/lon points
via the Haversine formula.
Parameters
----------
lat1, lon1, lat2, lon2 : float
Latitude and longitude in degrees.
Returns
-------
dist : float
Distance in met... | python | def great_circle_dist(lat1, lon1, lat2, lon2):
"""
Get the distance (in meters) between two lat/lon points
via the Haversine formula.
Parameters
----------
lat1, lon1, lat2, lon2 : float
Latitude and longitude in degrees.
Returns
-------
dist : float
Distance in met... | [
"def",
"great_circle_dist",
"(",
"lat1",
",",
"lon1",
",",
"lat2",
",",
"lon2",
")",
":",
"radius",
"=",
"6372795",
"# meters",
"lat1",
"=",
"math",
".",
"radians",
"(",
"lat1",
")",
"lon1",
"=",
"math",
".",
"radians",
"(",
"lon1",
")",
"lat2",
"=",... | Get the distance (in meters) between two lat/lon points
via the Haversine formula.
Parameters
----------
lat1, lon1, lat2, lon2 : float
Latitude and longitude in degrees.
Returns
-------
dist : float
Distance in meters. | [
"Get",
"the",
"distance",
"(",
"in",
"meters",
")",
"between",
"two",
"lat",
"/",
"lon",
"points",
"via",
"the",
"Haversine",
"formula",
"."
] | 155110a8e38d3646b9dbc3ec729063930cab3d5f | https://github.com/UDST/osmnet/blob/155110a8e38d3646b9dbc3ec729063930cab3d5f/osmnet/utils.py#L17-L49 | train |
UDST/osmnet | osmnet/load.py | osm_filter | def osm_filter(network_type):
"""
Create a filter to query Overpass API for the specified OSM network type.
Parameters
----------
network_type : string, {'walk', 'drive'} denoting the type of street
network to extract
Returns
-------
osm_filter : string
"""
filters = {}
... | python | def osm_filter(network_type):
"""
Create a filter to query Overpass API for the specified OSM network type.
Parameters
----------
network_type : string, {'walk', 'drive'} denoting the type of street
network to extract
Returns
-------
osm_filter : string
"""
filters = {}
... | [
"def",
"osm_filter",
"(",
"network_type",
")",
":",
"filters",
"=",
"{",
"}",
"# drive: select only roads that are drivable by normal 2 wheel drive",
"# passenger vehicles both private and public",
"# roads. Filter out un-drivable roads and service roads tagged as parking,",
"# driveway, o... | Create a filter to query Overpass API for the specified OSM network type.
Parameters
----------
network_type : string, {'walk', 'drive'} denoting the type of street
network to extract
Returns
-------
osm_filter : string | [
"Create",
"a",
"filter",
"to",
"query",
"Overpass",
"API",
"for",
"the",
"specified",
"OSM",
"network",
"type",
"."
] | 155110a8e38d3646b9dbc3ec729063930cab3d5f | https://github.com/UDST/osmnet/blob/155110a8e38d3646b9dbc3ec729063930cab3d5f/osmnet/load.py#L29-L67 | train |
UDST/osmnet | osmnet/load.py | osm_net_download | def osm_net_download(lat_min=None, lng_min=None, lat_max=None, lng_max=None,
network_type='walk', timeout=180, memory=None,
max_query_area_size=50*1000*50*1000,
custom_osm_filter=None):
"""
Download OSM ways and nodes within a bounding box from the ... | python | def osm_net_download(lat_min=None, lng_min=None, lat_max=None, lng_max=None,
network_type='walk', timeout=180, memory=None,
max_query_area_size=50*1000*50*1000,
custom_osm_filter=None):
"""
Download OSM ways and nodes within a bounding box from the ... | [
"def",
"osm_net_download",
"(",
"lat_min",
"=",
"None",
",",
"lng_min",
"=",
"None",
",",
"lat_max",
"=",
"None",
",",
"lng_max",
"=",
"None",
",",
"network_type",
"=",
"'walk'",
",",
"timeout",
"=",
"180",
",",
"memory",
"=",
"None",
",",
"max_query_are... | Download OSM ways and nodes within a bounding box from the Overpass API.
Parameters
----------
lat_min : float
southern latitude of bounding box
lng_min : float
eastern longitude of bounding box
lat_max : float
northern latitude of bounding box
lng_max : float
we... | [
"Download",
"OSM",
"ways",
"and",
"nodes",
"within",
"a",
"bounding",
"box",
"from",
"the",
"Overpass",
"API",
"."
] | 155110a8e38d3646b9dbc3ec729063930cab3d5f | https://github.com/UDST/osmnet/blob/155110a8e38d3646b9dbc3ec729063930cab3d5f/osmnet/load.py#L70-L200 | train |
UDST/osmnet | osmnet/load.py | overpass_request | def overpass_request(data, pause_duration=None, timeout=180,
error_pause_duration=None):
"""
Send a request to the Overpass API via HTTP POST and return the
JSON response
Parameters
----------
data : dict or OrderedDict
key-value pairs of parameters to post to Overp... | python | def overpass_request(data, pause_duration=None, timeout=180,
error_pause_duration=None):
"""
Send a request to the Overpass API via HTTP POST and return the
JSON response
Parameters
----------
data : dict or OrderedDict
key-value pairs of parameters to post to Overp... | [
"def",
"overpass_request",
"(",
"data",
",",
"pause_duration",
"=",
"None",
",",
"timeout",
"=",
"180",
",",
"error_pause_duration",
"=",
"None",
")",
":",
"# define the Overpass API URL, then construct a GET-style URL",
"url",
"=",
"'http://www.overpass-api.de/api/interpre... | Send a request to the Overpass API via HTTP POST and return the
JSON response
Parameters
----------
data : dict or OrderedDict
key-value pairs of parameters to post to Overpass API
pause_duration : int
how long to pause in seconds before requests, if None, will query
Overpas... | [
"Send",
"a",
"request",
"to",
"the",
"Overpass",
"API",
"via",
"HTTP",
"POST",
"and",
"return",
"the",
"JSON",
"response"
] | 155110a8e38d3646b9dbc3ec729063930cab3d5f | https://github.com/UDST/osmnet/blob/155110a8e38d3646b9dbc3ec729063930cab3d5f/osmnet/load.py#L203-L270 | train |
UDST/osmnet | osmnet/load.py | get_pause_duration | def get_pause_duration(recursive_delay=5, default_duration=10):
"""
Check the Overpass API status endpoint to determine how long to wait until
next slot is available.
Parameters
----------
recursive_delay : int
how long to wait between recursive calls if server is currently
runn... | python | def get_pause_duration(recursive_delay=5, default_duration=10):
"""
Check the Overpass API status endpoint to determine how long to wait until
next slot is available.
Parameters
----------
recursive_delay : int
how long to wait between recursive calls if server is currently
runn... | [
"def",
"get_pause_duration",
"(",
"recursive_delay",
"=",
"5",
",",
"default_duration",
"=",
"10",
")",
":",
"try",
":",
"response",
"=",
"requests",
".",
"get",
"(",
"'http://overpass-api.de/api/status'",
")",
"status",
"=",
"response",
".",
"text",
".",
"spl... | Check the Overpass API status endpoint to determine how long to wait until
next slot is available.
Parameters
----------
recursive_delay : int
how long to wait between recursive calls if server is currently
running a query
default_duration : int
if fatal error, function fall... | [
"Check",
"the",
"Overpass",
"API",
"status",
"endpoint",
"to",
"determine",
"how",
"long",
"to",
"wait",
"until",
"next",
"slot",
"is",
"available",
"."
] | 155110a8e38d3646b9dbc3ec729063930cab3d5f | https://github.com/UDST/osmnet/blob/155110a8e38d3646b9dbc3ec729063930cab3d5f/osmnet/load.py#L273-L328 | train |
UDST/osmnet | osmnet/load.py | consolidate_subdivide_geometry | def consolidate_subdivide_geometry(geometry, max_query_area_size):
"""
Consolidate a geometry into a convex hull, then subdivide it into
smaller sub-polygons if its area exceeds max size (in geometry's units).
Parameters
----------
geometry : shapely Polygon or MultiPolygon
the geometry... | python | def consolidate_subdivide_geometry(geometry, max_query_area_size):
"""
Consolidate a geometry into a convex hull, then subdivide it into
smaller sub-polygons if its area exceeds max size (in geometry's units).
Parameters
----------
geometry : shapely Polygon or MultiPolygon
the geometry... | [
"def",
"consolidate_subdivide_geometry",
"(",
"geometry",
",",
"max_query_area_size",
")",
":",
"# let the linear length of the quadrats (with which to subdivide the",
"# geometry) be the square root of max area size",
"quadrat_width",
"=",
"math",
".",
"sqrt",
"(",
"max_query_area_s... | Consolidate a geometry into a convex hull, then subdivide it into
smaller sub-polygons if its area exceeds max size (in geometry's units).
Parameters
----------
geometry : shapely Polygon or MultiPolygon
the geometry to consolidate and subdivide
max_query_area_size : float
max area ... | [
"Consolidate",
"a",
"geometry",
"into",
"a",
"convex",
"hull",
"then",
"subdivide",
"it",
"into",
"smaller",
"sub",
"-",
"polygons",
"if",
"its",
"area",
"exceeds",
"max",
"size",
"(",
"in",
"geometry",
"s",
"units",
")",
"."
] | 155110a8e38d3646b9dbc3ec729063930cab3d5f | https://github.com/UDST/osmnet/blob/155110a8e38d3646b9dbc3ec729063930cab3d5f/osmnet/load.py#L331-L373 | train |
UDST/osmnet | osmnet/load.py | quadrat_cut_geometry | def quadrat_cut_geometry(geometry, quadrat_width, min_num=3,
buffer_amount=1e-9):
"""
Split a Polygon or MultiPolygon up into sub-polygons of a specified size,
using quadrats.
Parameters
----------
geometry : shapely Polygon or MultiPolygon
the geometry to split... | python | def quadrat_cut_geometry(geometry, quadrat_width, min_num=3,
buffer_amount=1e-9):
"""
Split a Polygon or MultiPolygon up into sub-polygons of a specified size,
using quadrats.
Parameters
----------
geometry : shapely Polygon or MultiPolygon
the geometry to split... | [
"def",
"quadrat_cut_geometry",
"(",
"geometry",
",",
"quadrat_width",
",",
"min_num",
"=",
"3",
",",
"buffer_amount",
"=",
"1e-9",
")",
":",
"# create n evenly spaced points between the min and max x and y bounds",
"lng_max",
",",
"lat_min",
",",
"lng_min",
",",
"lat_ma... | Split a Polygon or MultiPolygon up into sub-polygons of a specified size,
using quadrats.
Parameters
----------
geometry : shapely Polygon or MultiPolygon
the geometry to split up into smaller sub-polygons
quadrat_width : float
the linear width of the quadrats with which to cut up t... | [
"Split",
"a",
"Polygon",
"or",
"MultiPolygon",
"up",
"into",
"sub",
"-",
"polygons",
"of",
"a",
"specified",
"size",
"using",
"quadrats",
"."
] | 155110a8e38d3646b9dbc3ec729063930cab3d5f | https://github.com/UDST/osmnet/blob/155110a8e38d3646b9dbc3ec729063930cab3d5f/osmnet/load.py#L376-L421 | train |
UDST/osmnet | osmnet/load.py | project_geometry | def project_geometry(geometry, crs, to_latlong=False):
"""
Project a shapely Polygon or MultiPolygon from WGS84 to UTM, or vice-versa
Parameters
----------
geometry : shapely Polygon or MultiPolygon
the geometry to project
crs : int
the starting coordinate reference system of th... | python | def project_geometry(geometry, crs, to_latlong=False):
"""
Project a shapely Polygon or MultiPolygon from WGS84 to UTM, or vice-versa
Parameters
----------
geometry : shapely Polygon or MultiPolygon
the geometry to project
crs : int
the starting coordinate reference system of th... | [
"def",
"project_geometry",
"(",
"geometry",
",",
"crs",
",",
"to_latlong",
"=",
"False",
")",
":",
"gdf",
"=",
"gpd",
".",
"GeoDataFrame",
"(",
")",
"gdf",
".",
"crs",
"=",
"crs",
"gdf",
".",
"name",
"=",
"'geometry to project'",
"gdf",
"[",
"'geometry'"... | Project a shapely Polygon or MultiPolygon from WGS84 to UTM, or vice-versa
Parameters
----------
geometry : shapely Polygon or MultiPolygon
the geometry to project
crs : int
the starting coordinate reference system of the passed-in geometry
to_latlong : bool
if True, project... | [
"Project",
"a",
"shapely",
"Polygon",
"or",
"MultiPolygon",
"from",
"WGS84",
"to",
"UTM",
"or",
"vice",
"-",
"versa"
] | 155110a8e38d3646b9dbc3ec729063930cab3d5f | https://github.com/UDST/osmnet/blob/155110a8e38d3646b9dbc3ec729063930cab3d5f/osmnet/load.py#L424-L450 | train |
UDST/osmnet | osmnet/load.py | process_node | def process_node(e):
"""
Process a node element entry into a dict suitable for going into a
Pandas DataFrame.
Parameters
----------
e : dict
individual node element in downloaded OSM json
Returns
-------
node : dict
"""
node = {'id': e['id'],
'lat': e['... | python | def process_node(e):
"""
Process a node element entry into a dict suitable for going into a
Pandas DataFrame.
Parameters
----------
e : dict
individual node element in downloaded OSM json
Returns
-------
node : dict
"""
node = {'id': e['id'],
'lat': e['... | [
"def",
"process_node",
"(",
"e",
")",
":",
"node",
"=",
"{",
"'id'",
":",
"e",
"[",
"'id'",
"]",
",",
"'lat'",
":",
"e",
"[",
"'lat'",
"]",
",",
"'lon'",
":",
"e",
"[",
"'lon'",
"]",
"}",
"if",
"'tags'",
"in",
"e",
":",
"if",
"e",
"[",
"'ta... | Process a node element entry into a dict suitable for going into a
Pandas DataFrame.
Parameters
----------
e : dict
individual node element in downloaded OSM json
Returns
-------
node : dict | [
"Process",
"a",
"node",
"element",
"entry",
"into",
"a",
"dict",
"suitable",
"for",
"going",
"into",
"a",
"Pandas",
"DataFrame",
"."
] | 155110a8e38d3646b9dbc3ec729063930cab3d5f | https://github.com/UDST/osmnet/blob/155110a8e38d3646b9dbc3ec729063930cab3d5f/osmnet/load.py#L514-L539 | train |
UDST/osmnet | osmnet/load.py | process_way | def process_way(e):
"""
Process a way element entry into a list of dicts suitable for going into
a Pandas DataFrame.
Parameters
----------
e : dict
individual way element in downloaded OSM json
Returns
-------
way : dict
waynodes : list of dict
"""
way = {'id':... | python | def process_way(e):
"""
Process a way element entry into a list of dicts suitable for going into
a Pandas DataFrame.
Parameters
----------
e : dict
individual way element in downloaded OSM json
Returns
-------
way : dict
waynodes : list of dict
"""
way = {'id':... | [
"def",
"process_way",
"(",
"e",
")",
":",
"way",
"=",
"{",
"'id'",
":",
"e",
"[",
"'id'",
"]",
"}",
"if",
"'tags'",
"in",
"e",
":",
"if",
"e",
"[",
"'tags'",
"]",
"is",
"not",
"np",
".",
"nan",
":",
"for",
"t",
",",
"v",
"in",
"list",
"(",
... | Process a way element entry into a list of dicts suitable for going into
a Pandas DataFrame.
Parameters
----------
e : dict
individual way element in downloaded OSM json
Returns
-------
way : dict
waynodes : list of dict | [
"Process",
"a",
"way",
"element",
"entry",
"into",
"a",
"list",
"of",
"dicts",
"suitable",
"for",
"going",
"into",
"a",
"Pandas",
"DataFrame",
"."
] | 155110a8e38d3646b9dbc3ec729063930cab3d5f | https://github.com/UDST/osmnet/blob/155110a8e38d3646b9dbc3ec729063930cab3d5f/osmnet/load.py#L542-L572 | train |
UDST/osmnet | osmnet/load.py | parse_network_osm_query | def parse_network_osm_query(data):
"""
Convert OSM query data to DataFrames of ways and way-nodes.
Parameters
----------
data : dict
Result of an OSM query.
Returns
-------
nodes, ways, waynodes : pandas.DataFrame
"""
if len(data['elements']) == 0:
raise Runtim... | python | def parse_network_osm_query(data):
"""
Convert OSM query data to DataFrames of ways and way-nodes.
Parameters
----------
data : dict
Result of an OSM query.
Returns
-------
nodes, ways, waynodes : pandas.DataFrame
"""
if len(data['elements']) == 0:
raise Runtim... | [
"def",
"parse_network_osm_query",
"(",
"data",
")",
":",
"if",
"len",
"(",
"data",
"[",
"'elements'",
"]",
")",
"==",
"0",
":",
"raise",
"RuntimeError",
"(",
"'OSM query results contain no data.'",
")",
"nodes",
"=",
"[",
"]",
"ways",
"=",
"[",
"]",
"wayno... | Convert OSM query data to DataFrames of ways and way-nodes.
Parameters
----------
data : dict
Result of an OSM query.
Returns
-------
nodes, ways, waynodes : pandas.DataFrame | [
"Convert",
"OSM",
"query",
"data",
"to",
"DataFrames",
"of",
"ways",
"and",
"way",
"-",
"nodes",
"."
] | 155110a8e38d3646b9dbc3ec729063930cab3d5f | https://github.com/UDST/osmnet/blob/155110a8e38d3646b9dbc3ec729063930cab3d5f/osmnet/load.py#L575-L608 | train |
UDST/osmnet | osmnet/load.py | ways_in_bbox | def ways_in_bbox(lat_min, lng_min, lat_max, lng_max, network_type,
timeout=180, memory=None,
max_query_area_size=50*1000*50*1000,
custom_osm_filter=None):
"""
Get DataFrames of OSM data in a bounding box.
Parameters
----------
lat_min : float
... | python | def ways_in_bbox(lat_min, lng_min, lat_max, lng_max, network_type,
timeout=180, memory=None,
max_query_area_size=50*1000*50*1000,
custom_osm_filter=None):
"""
Get DataFrames of OSM data in a bounding box.
Parameters
----------
lat_min : float
... | [
"def",
"ways_in_bbox",
"(",
"lat_min",
",",
"lng_min",
",",
"lat_max",
",",
"lng_max",
",",
"network_type",
",",
"timeout",
"=",
"180",
",",
"memory",
"=",
"None",
",",
"max_query_area_size",
"=",
"50",
"*",
"1000",
"*",
"50",
"*",
"1000",
",",
"custom_o... | Get DataFrames of OSM data in a bounding box.
Parameters
----------
lat_min : float
southern latitude of bounding box
lng_min : float
eastern longitude of bounding box
lat_max : float
northern latitude of bounding box
lng_max : float
western longitude of bounding... | [
"Get",
"DataFrames",
"of",
"OSM",
"data",
"in",
"a",
"bounding",
"box",
"."
] | 155110a8e38d3646b9dbc3ec729063930cab3d5f | https://github.com/UDST/osmnet/blob/155110a8e38d3646b9dbc3ec729063930cab3d5f/osmnet/load.py#L611-L658 | train |
UDST/osmnet | osmnet/load.py | intersection_nodes | def intersection_nodes(waynodes):
"""
Returns a set of all the nodes that appear in 2 or more ways.
Parameters
----------
waynodes : pandas.DataFrame
Mapping of way IDs to node IDs as returned by `ways_in_bbox`.
Returns
-------
intersections : set
Node IDs that appear i... | python | def intersection_nodes(waynodes):
"""
Returns a set of all the nodes that appear in 2 or more ways.
Parameters
----------
waynodes : pandas.DataFrame
Mapping of way IDs to node IDs as returned by `ways_in_bbox`.
Returns
-------
intersections : set
Node IDs that appear i... | [
"def",
"intersection_nodes",
"(",
"waynodes",
")",
":",
"counts",
"=",
"waynodes",
".",
"node_id",
".",
"value_counts",
"(",
")",
"return",
"set",
"(",
"counts",
"[",
"counts",
">",
"1",
"]",
".",
"index",
".",
"values",
")"
] | Returns a set of all the nodes that appear in 2 or more ways.
Parameters
----------
waynodes : pandas.DataFrame
Mapping of way IDs to node IDs as returned by `ways_in_bbox`.
Returns
-------
intersections : set
Node IDs that appear in 2 or more ways. | [
"Returns",
"a",
"set",
"of",
"all",
"the",
"nodes",
"that",
"appear",
"in",
"2",
"or",
"more",
"ways",
"."
] | 155110a8e38d3646b9dbc3ec729063930cab3d5f | https://github.com/UDST/osmnet/blob/155110a8e38d3646b9dbc3ec729063930cab3d5f/osmnet/load.py#L661-L677 | train |
UDST/osmnet | osmnet/load.py | node_pairs | def node_pairs(nodes, ways, waynodes, two_way=True):
"""
Create a table of node pairs with the distances between them.
Parameters
----------
nodes : pandas.DataFrame
Must have 'lat' and 'lon' columns.
ways : pandas.DataFrame
Table of way metadata.
waynodes : pandas.DataFrame... | python | def node_pairs(nodes, ways, waynodes, two_way=True):
"""
Create a table of node pairs with the distances between them.
Parameters
----------
nodes : pandas.DataFrame
Must have 'lat' and 'lon' columns.
ways : pandas.DataFrame
Table of way metadata.
waynodes : pandas.DataFrame... | [
"def",
"node_pairs",
"(",
"nodes",
",",
"ways",
",",
"waynodes",
",",
"two_way",
"=",
"True",
")",
":",
"start_time",
"=",
"time",
".",
"time",
"(",
")",
"def",
"pairwise",
"(",
"l",
")",
":",
"return",
"zip",
"(",
"islice",
"(",
"l",
",",
"0",
"... | Create a table of node pairs with the distances between them.
Parameters
----------
nodes : pandas.DataFrame
Must have 'lat' and 'lon' columns.
ways : pandas.DataFrame
Table of way metadata.
waynodes : pandas.DataFrame
Table linking way IDs to node IDs. Way IDs should be in ... | [
"Create",
"a",
"table",
"of",
"node",
"pairs",
"with",
"the",
"distances",
"between",
"them",
"."
] | 155110a8e38d3646b9dbc3ec729063930cab3d5f | https://github.com/UDST/osmnet/blob/155110a8e38d3646b9dbc3ec729063930cab3d5f/osmnet/load.py#L680-L764 | train |
UDST/osmnet | osmnet/load.py | network_from_bbox | def network_from_bbox(lat_min=None, lng_min=None, lat_max=None, lng_max=None,
bbox=None, network_type='walk', two_way=True,
timeout=180, memory=None,
max_query_area_size=50*1000*50*1000,
custom_osm_filter=None):
"""
Make a g... | python | def network_from_bbox(lat_min=None, lng_min=None, lat_max=None, lng_max=None,
bbox=None, network_type='walk', two_way=True,
timeout=180, memory=None,
max_query_area_size=50*1000*50*1000,
custom_osm_filter=None):
"""
Make a g... | [
"def",
"network_from_bbox",
"(",
"lat_min",
"=",
"None",
",",
"lng_min",
"=",
"None",
",",
"lat_max",
"=",
"None",
",",
"lng_max",
"=",
"None",
",",
"bbox",
"=",
"None",
",",
"network_type",
"=",
"'walk'",
",",
"two_way",
"=",
"True",
",",
"timeout",
"... | Make a graph network from a bounding lat/lon box composed of nodes and
edges for use in Pandana street network accessibility calculations.
You may either enter a lat/long box via the four lat_min,
lng_min, lat_max, lng_max parameters or the bbox parameter as a tuple.
Parameters
----------
lat_m... | [
"Make",
"a",
"graph",
"network",
"from",
"a",
"bounding",
"lat",
"/",
"lon",
"box",
"composed",
"of",
"nodes",
"and",
"edges",
"for",
"use",
"in",
"Pandana",
"street",
"network",
"accessibility",
"calculations",
".",
"You",
"may",
"either",
"enter",
"a",
"... | 155110a8e38d3646b9dbc3ec729063930cab3d5f | https://github.com/UDST/osmnet/blob/155110a8e38d3646b9dbc3ec729063930cab3d5f/osmnet/load.py#L767-L873 | train |
rasbt/markdown-toclify | markdown_toclify/markdown_toclify.py | read_lines | def read_lines(in_file):
"""Returns a list of lines from a input markdown file."""
with open(in_file, 'r') as inf:
in_contents = inf.read().split('\n')
return in_contents | python | def read_lines(in_file):
"""Returns a list of lines from a input markdown file."""
with open(in_file, 'r') as inf:
in_contents = inf.read().split('\n')
return in_contents | [
"def",
"read_lines",
"(",
"in_file",
")",
":",
"with",
"open",
"(",
"in_file",
",",
"'r'",
")",
"as",
"inf",
":",
"in_contents",
"=",
"inf",
".",
"read",
"(",
")",
".",
"split",
"(",
"'\\n'",
")",
"return",
"in_contents"
] | Returns a list of lines from a input markdown file. | [
"Returns",
"a",
"list",
"of",
"lines",
"from",
"a",
"input",
"markdown",
"file",
"."
] | 517cde672bebda5371130b87c1fcb7184d141a02 | https://github.com/rasbt/markdown-toclify/blob/517cde672bebda5371130b87c1fcb7184d141a02/markdown_toclify/markdown_toclify.py#L33-L38 | train |
rasbt/markdown-toclify | markdown_toclify/markdown_toclify.py | remove_lines | def remove_lines(lines, remove=('[[back to top]', '<a class="mk-toclify"')):
"""Removes existing [back to top] links and <a id> tags."""
if not remove:
return lines[:]
out = []
for l in lines:
if l.startswith(remove):
continue
out.append(l)
return out | python | def remove_lines(lines, remove=('[[back to top]', '<a class="mk-toclify"')):
"""Removes existing [back to top] links and <a id> tags."""
if not remove:
return lines[:]
out = []
for l in lines:
if l.startswith(remove):
continue
out.append(l)
return out | [
"def",
"remove_lines",
"(",
"lines",
",",
"remove",
"=",
"(",
"'[[back to top]'",
",",
"'<a class=\"mk-toclify\"'",
")",
")",
":",
"if",
"not",
"remove",
":",
"return",
"lines",
"[",
":",
"]",
"out",
"=",
"[",
"]",
"for",
"l",
"in",
"lines",
":",
"if",... | Removes existing [back to top] links and <a id> tags. | [
"Removes",
"existing",
"[",
"back",
"to",
"top",
"]",
"links",
"and",
"<a",
"id",
">",
"tags",
"."
] | 517cde672bebda5371130b87c1fcb7184d141a02 | https://github.com/rasbt/markdown-toclify/blob/517cde672bebda5371130b87c1fcb7184d141a02/markdown_toclify/markdown_toclify.py#L41-L52 | train |
rasbt/markdown-toclify | markdown_toclify/markdown_toclify.py | slugify_headline | def slugify_headline(line, remove_dashes=False):
"""
Takes a header line from a Markdown document and
returns a tuple of the
'#'-stripped version of the head line,
a string version for <a id=''></a> anchor tags,
and the level of the headline as integer.
E.g.,
>>> dashify_head... | python | def slugify_headline(line, remove_dashes=False):
"""
Takes a header line from a Markdown document and
returns a tuple of the
'#'-stripped version of the head line,
a string version for <a id=''></a> anchor tags,
and the level of the headline as integer.
E.g.,
>>> dashify_head... | [
"def",
"slugify_headline",
"(",
"line",
",",
"remove_dashes",
"=",
"False",
")",
":",
"stripped_right",
"=",
"line",
".",
"rstrip",
"(",
"'#'",
")",
"stripped_both",
"=",
"stripped_right",
".",
"lstrip",
"(",
"'#'",
")",
"level",
"=",
"len",
"(",
"stripped... | Takes a header line from a Markdown document and
returns a tuple of the
'#'-stripped version of the head line,
a string version for <a id=''></a> anchor tags,
and the level of the headline as integer.
E.g.,
>>> dashify_headline('### some header lvl3')
('Some header lvl3', 'some-h... | [
"Takes",
"a",
"header",
"line",
"from",
"a",
"Markdown",
"document",
"and",
"returns",
"a",
"tuple",
"of",
"the",
"#",
"-",
"stripped",
"version",
"of",
"the",
"head",
"line",
"a",
"string",
"version",
"for",
"<a",
"id",
"=",
">",
"<",
"/",
"a",
">",... | 517cde672bebda5371130b87c1fcb7184d141a02 | https://github.com/rasbt/markdown-toclify/blob/517cde672bebda5371130b87c1fcb7184d141a02/markdown_toclify/markdown_toclify.py#L55-L88 | train |
rasbt/markdown-toclify | markdown_toclify/markdown_toclify.py | tag_and_collect | def tag_and_collect(lines, id_tag=True, back_links=False, exclude_h=None, remove_dashes=False):
"""
Gets headlines from the markdown document and creates anchor tags.
Keyword arguments:
lines: a list of sublists where every sublist
represents a line from a Markdown document.
id_... | python | def tag_and_collect(lines, id_tag=True, back_links=False, exclude_h=None, remove_dashes=False):
"""
Gets headlines from the markdown document and creates anchor tags.
Keyword arguments:
lines: a list of sublists where every sublist
represents a line from a Markdown document.
id_... | [
"def",
"tag_and_collect",
"(",
"lines",
",",
"id_tag",
"=",
"True",
",",
"back_links",
"=",
"False",
",",
"exclude_h",
"=",
"None",
",",
"remove_dashes",
"=",
"False",
")",
":",
"out_contents",
"=",
"[",
"]",
"headlines",
"=",
"[",
"]",
"for",
"l",
"in... | Gets headlines from the markdown document and creates anchor tags.
Keyword arguments:
lines: a list of sublists where every sublist
represents a line from a Markdown document.
id_tag: if true, creates inserts a the <a id> tags (not req. by GitHub)
back_links: if true, adds "back... | [
"Gets",
"headlines",
"from",
"the",
"markdown",
"document",
"and",
"creates",
"anchor",
"tags",
"."
] | 517cde672bebda5371130b87c1fcb7184d141a02 | https://github.com/rasbt/markdown-toclify/blob/517cde672bebda5371130b87c1fcb7184d141a02/markdown_toclify/markdown_toclify.py#L91-L157 | train |
rasbt/markdown-toclify | markdown_toclify/markdown_toclify.py | positioning_headlines | def positioning_headlines(headlines):
"""
Strips unnecessary whitespaces/tabs if first header is not left-aligned
"""
left_just = False
for row in headlines:
if row[-1] == 1:
left_just = True
break
if not left_just:
for row in headlines:
row[-1... | python | def positioning_headlines(headlines):
"""
Strips unnecessary whitespaces/tabs if first header is not left-aligned
"""
left_just = False
for row in headlines:
if row[-1] == 1:
left_just = True
break
if not left_just:
for row in headlines:
row[-1... | [
"def",
"positioning_headlines",
"(",
"headlines",
")",
":",
"left_just",
"=",
"False",
"for",
"row",
"in",
"headlines",
":",
"if",
"row",
"[",
"-",
"1",
"]",
"==",
"1",
":",
"left_just",
"=",
"True",
"break",
"if",
"not",
"left_just",
":",
"for",
"row"... | Strips unnecessary whitespaces/tabs if first header is not left-aligned | [
"Strips",
"unnecessary",
"whitespaces",
"/",
"tabs",
"if",
"first",
"header",
"is",
"not",
"left",
"-",
"aligned"
] | 517cde672bebda5371130b87c1fcb7184d141a02 | https://github.com/rasbt/markdown-toclify/blob/517cde672bebda5371130b87c1fcb7184d141a02/markdown_toclify/markdown_toclify.py#L160-L172 | train |
rasbt/markdown-toclify | markdown_toclify/markdown_toclify.py | create_toc | def create_toc(headlines, hyperlink=True, top_link=False, no_toc_header=False):
"""
Creates the table of contents from the headline list
that was returned by the tag_and_collect function.
Keyword Arguments:
headlines: list of lists
e.g., ['Some header lvl3', 'some-header-lvl3', 3]
... | python | def create_toc(headlines, hyperlink=True, top_link=False, no_toc_header=False):
"""
Creates the table of contents from the headline list
that was returned by the tag_and_collect function.
Keyword Arguments:
headlines: list of lists
e.g., ['Some header lvl3', 'some-header-lvl3', 3]
... | [
"def",
"create_toc",
"(",
"headlines",
",",
"hyperlink",
"=",
"True",
",",
"top_link",
"=",
"False",
",",
"no_toc_header",
"=",
"False",
")",
":",
"processed",
"=",
"[",
"]",
"if",
"not",
"no_toc_header",
":",
"if",
"top_link",
":",
"processed",
".",
"ap... | Creates the table of contents from the headline list
that was returned by the tag_and_collect function.
Keyword Arguments:
headlines: list of lists
e.g., ['Some header lvl3', 'some-header-lvl3', 3]
hyperlink: Creates hyperlinks in Markdown format if True,
e.g., '- [Some ... | [
"Creates",
"the",
"table",
"of",
"contents",
"from",
"the",
"headline",
"list",
"that",
"was",
"returned",
"by",
"the",
"tag_and_collect",
"function",
"."
] | 517cde672bebda5371130b87c1fcb7184d141a02 | https://github.com/rasbt/markdown-toclify/blob/517cde672bebda5371130b87c1fcb7184d141a02/markdown_toclify/markdown_toclify.py#L175-L207 | train |
rasbt/markdown-toclify | markdown_toclify/markdown_toclify.py | build_markdown | def build_markdown(toc_headlines, body, spacer=0, placeholder=None):
"""
Returns a string with the Markdown output contents incl.
the table of contents.
Keyword arguments:
toc_headlines: lines for the table of contents
as created by the create_toc function.
body: contents of... | python | def build_markdown(toc_headlines, body, spacer=0, placeholder=None):
"""
Returns a string with the Markdown output contents incl.
the table of contents.
Keyword arguments:
toc_headlines: lines for the table of contents
as created by the create_toc function.
body: contents of... | [
"def",
"build_markdown",
"(",
"toc_headlines",
",",
"body",
",",
"spacer",
"=",
"0",
",",
"placeholder",
"=",
"None",
")",
":",
"if",
"spacer",
":",
"spacer_line",
"=",
"[",
"'\\n<div style=\"height:%spx;\"></div>\\n'",
"%",
"(",
"spacer",
")",
"]",
"toc_markd... | Returns a string with the Markdown output contents incl.
the table of contents.
Keyword arguments:
toc_headlines: lines for the table of contents
as created by the create_toc function.
body: contents of the Markdown file including
ID-anchor tags as returned by the
... | [
"Returns",
"a",
"string",
"with",
"the",
"Markdown",
"output",
"contents",
"incl",
".",
"the",
"table",
"of",
"contents",
"."
] | 517cde672bebda5371130b87c1fcb7184d141a02 | https://github.com/rasbt/markdown-toclify/blob/517cde672bebda5371130b87c1fcb7184d141a02/markdown_toclify/markdown_toclify.py#L210-L241 | train |
rasbt/markdown-toclify | markdown_toclify/markdown_toclify.py | output_markdown | def output_markdown(markdown_cont, output_file):
"""
Writes to an output file if `outfile` is a valid path.
"""
if output_file:
with open(output_file, 'w') as out:
out.write(markdown_cont) | python | def output_markdown(markdown_cont, output_file):
"""
Writes to an output file if `outfile` is a valid path.
"""
if output_file:
with open(output_file, 'w') as out:
out.write(markdown_cont) | [
"def",
"output_markdown",
"(",
"markdown_cont",
",",
"output_file",
")",
":",
"if",
"output_file",
":",
"with",
"open",
"(",
"output_file",
",",
"'w'",
")",
"as",
"out",
":",
"out",
".",
"write",
"(",
"markdown_cont",
")"
] | Writes to an output file if `outfile` is a valid path. | [
"Writes",
"to",
"an",
"output",
"file",
"if",
"outfile",
"is",
"a",
"valid",
"path",
"."
] | 517cde672bebda5371130b87c1fcb7184d141a02 | https://github.com/rasbt/markdown-toclify/blob/517cde672bebda5371130b87c1fcb7184d141a02/markdown_toclify/markdown_toclify.py#L244-L251 | train |
rasbt/markdown-toclify | markdown_toclify/markdown_toclify.py | markdown_toclify | def markdown_toclify(input_file, output_file=None, github=False,
back_to_top=False, nolink=False,
no_toc_header=False, spacer=0, placeholder=None,
exclude_h=None, remove_dashes=False):
""" Function to add table of contents to markdown files.
Parame... | python | def markdown_toclify(input_file, output_file=None, github=False,
back_to_top=False, nolink=False,
no_toc_header=False, spacer=0, placeholder=None,
exclude_h=None, remove_dashes=False):
""" Function to add table of contents to markdown files.
Parame... | [
"def",
"markdown_toclify",
"(",
"input_file",
",",
"output_file",
"=",
"None",
",",
"github",
"=",
"False",
",",
"back_to_top",
"=",
"False",
",",
"nolink",
"=",
"False",
",",
"no_toc_header",
"=",
"False",
",",
"spacer",
"=",
"0",
",",
"placeholder",
"=",... | Function to add table of contents to markdown files.
Parameters
-----------
input_file: str
Path to the markdown input file.
output_file: str (defaul: None)
Path to the markdown output file.
github: bool (default: False)
Uses GitHub TOC syntax if True.
back_to... | [
"Function",
"to",
"add",
"table",
"of",
"contents",
"to",
"markdown",
"files",
"."
] | 517cde672bebda5371130b87c1fcb7184d141a02 | https://github.com/rasbt/markdown-toclify/blob/517cde672bebda5371130b87c1fcb7184d141a02/markdown_toclify/markdown_toclify.py#L254-L326 | train |
harshasrinivas/cli-github | cli_github/utils.py | url_parse | def url_parse(name):
"""parse urls with different prefixes"""
position = name.find("github.com")
if position >= 0:
if position != 0:
position_1 = name.find("www.github.com")
position_2 = name.find("http://github.com")
position_3 = name.find("https://github.com")
... | python | def url_parse(name):
"""parse urls with different prefixes"""
position = name.find("github.com")
if position >= 0:
if position != 0:
position_1 = name.find("www.github.com")
position_2 = name.find("http://github.com")
position_3 = name.find("https://github.com")
... | [
"def",
"url_parse",
"(",
"name",
")",
":",
"position",
"=",
"name",
".",
"find",
"(",
"\"github.com\"",
")",
"if",
"position",
">=",
"0",
":",
"if",
"position",
"!=",
"0",
":",
"position_1",
"=",
"name",
".",
"find",
"(",
"\"www.github.com\"",
")",
"po... | parse urls with different prefixes | [
"parse",
"urls",
"with",
"different",
"prefixes"
] | 33e08d0325b48f908506ca76e501cfb890a9a2cd | https://github.com/harshasrinivas/cli-github/blob/33e08d0325b48f908506ca76e501cfb890a9a2cd/cli_github/utils.py#L30-L48 | train |
harshasrinivas/cli-github | cli_github/utils.py | get_req | def get_req(url):
"""simple get request"""
request = urllib.request.Request(url)
request.add_header('Authorization', 'token %s' % API_TOKEN)
try:
response = urllib.request.urlopen(request).read().decode('utf-8')
return response
except urllib.error.HTTPError:
exception()
... | python | def get_req(url):
"""simple get request"""
request = urllib.request.Request(url)
request.add_header('Authorization', 'token %s' % API_TOKEN)
try:
response = urllib.request.urlopen(request).read().decode('utf-8')
return response
except urllib.error.HTTPError:
exception()
... | [
"def",
"get_req",
"(",
"url",
")",
":",
"request",
"=",
"urllib",
".",
"request",
".",
"Request",
"(",
"url",
")",
"request",
".",
"add_header",
"(",
"'Authorization'",
",",
"'token %s'",
"%",
"API_TOKEN",
")",
"try",
":",
"response",
"=",
"urllib",
".",... | simple get request | [
"simple",
"get",
"request"
] | 33e08d0325b48f908506ca76e501cfb890a9a2cd | https://github.com/harshasrinivas/cli-github/blob/33e08d0325b48f908506ca76e501cfb890a9a2cd/cli_github/utils.py#L53-L62 | train |
harshasrinivas/cli-github | cli_github/utils.py | geturl_req | def geturl_req(url):
"""get request that returns 302"""
request = urllib.request.Request(url)
request.add_header('Authorization', 'token %s' % API_TOKEN)
try:
response_url = urllib.request.urlopen(request).geturl()
return response_url
except urllib.error.HTTPError:
exception(... | python | def geturl_req(url):
"""get request that returns 302"""
request = urllib.request.Request(url)
request.add_header('Authorization', 'token %s' % API_TOKEN)
try:
response_url = urllib.request.urlopen(request).geturl()
return response_url
except urllib.error.HTTPError:
exception(... | [
"def",
"geturl_req",
"(",
"url",
")",
":",
"request",
"=",
"urllib",
".",
"request",
".",
"Request",
"(",
"url",
")",
"request",
".",
"add_header",
"(",
"'Authorization'",
",",
"'token %s'",
"%",
"API_TOKEN",
")",
"try",
":",
"response_url",
"=",
"urllib",... | get request that returns 302 | [
"get",
"request",
"that",
"returns",
"302"
] | 33e08d0325b48f908506ca76e501cfb890a9a2cd | https://github.com/harshasrinivas/cli-github/blob/33e08d0325b48f908506ca76e501cfb890a9a2cd/cli_github/utils.py#L67-L76 | train |
harshasrinivas/cli-github | cli_github/mains.py | main | def main():
"""main function"""
parser = argparse.ArgumentParser(
description='Github within the Command Line')
group = parser.add_mutually_exclusive_group()
group.add_argument('-n', '--url', type=str,
help="Get repos from the user profile's URL")
group.add_argument('-... | python | def main():
"""main function"""
parser = argparse.ArgumentParser(
description='Github within the Command Line')
group = parser.add_mutually_exclusive_group()
group.add_argument('-n', '--url', type=str,
help="Get repos from the user profile's URL")
group.add_argument('-... | [
"def",
"main",
"(",
")",
":",
"parser",
"=",
"argparse",
".",
"ArgumentParser",
"(",
"description",
"=",
"'Github within the Command Line'",
")",
"group",
"=",
"parser",
".",
"add_mutually_exclusive_group",
"(",
")",
"group",
".",
"add_argument",
"(",
"'-n'",
",... | main function | [
"main",
"function"
] | 33e08d0325b48f908506ca76e501cfb890a9a2cd | https://github.com/harshasrinivas/cli-github/blob/33e08d0325b48f908506ca76e501cfb890a9a2cd/cli_github/mains.py#L25-L223 | train |
edoburu/django-capture-tag | capture_tag/templatetags/capture_tags.py | do_capture | def do_capture(parser, token):
"""
Capture the contents of a tag output.
Usage:
.. code-block:: html+django
{% capture %}..{% endcapture %} # output in {{ capture }}
{% capture silent %}..{% endcapture %} # output in {{ capture }} only
{% capture ... | python | def do_capture(parser, token):
"""
Capture the contents of a tag output.
Usage:
.. code-block:: html+django
{% capture %}..{% endcapture %} # output in {{ capture }}
{% capture silent %}..{% endcapture %} # output in {{ capture }} only
{% capture ... | [
"def",
"do_capture",
"(",
"parser",
",",
"token",
")",
":",
"bits",
"=",
"token",
".",
"split_contents",
"(",
")",
"# tokens",
"t_as",
"=",
"'as'",
"t_silent",
"=",
"'silent'",
"var",
"=",
"'capture'",
"silent",
"=",
"False",
"num_bits",
"=",
"len",
"(",... | Capture the contents of a tag output.
Usage:
.. code-block:: html+django
{% capture %}..{% endcapture %} # output in {{ capture }}
{% capture silent %}..{% endcapture %} # output in {{ capture }} only
{% capture as varname %}..{% endcapture %} # o... | [
"Capture",
"the",
"contents",
"of",
"a",
"tag",
"output",
".",
"Usage",
":"
] | 68b2c635f14dca0d90857d09bde9c4c68e249476 | https://github.com/edoburu/django-capture-tag/blob/68b2c635f14dca0d90857d09bde9c4c68e249476/capture_tag/templatetags/capture_tags.py#L7-L59 | train |
pawelad/pymonzo | src/pymonzo/api_objects.py | MonzoTransaction._parse_special_fields | def _parse_special_fields(self, data):
"""
Helper method that parses special fields to Python objects
:param data: response from Monzo API request
:type data: dict
"""
self.created = parse_date(data.pop('created'))
if data.get('settled'): # Not always returned
... | python | def _parse_special_fields(self, data):
"""
Helper method that parses special fields to Python objects
:param data: response from Monzo API request
:type data: dict
"""
self.created = parse_date(data.pop('created'))
if data.get('settled'): # Not always returned
... | [
"def",
"_parse_special_fields",
"(",
"self",
",",
"data",
")",
":",
"self",
".",
"created",
"=",
"parse_date",
"(",
"data",
".",
"pop",
"(",
"'created'",
")",
")",
"if",
"data",
".",
"get",
"(",
"'settled'",
")",
":",
"# Not always returned",
"self",
"."... | Helper method that parses special fields to Python objects
:param data: response from Monzo API request
:type data: dict | [
"Helper",
"method",
"that",
"parses",
"special",
"fields",
"to",
"Python",
"objects"
] | b5c8d4f46dcb3a2f475797a8b8ef1c15f6493fb9 | https://github.com/pawelad/pymonzo/blob/b5c8d4f46dcb3a2f475797a8b8ef1c15f6493fb9/src/pymonzo/api_objects.py#L102-L117 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.