partition stringclasses 3
values | func_name stringlengths 1 134 | docstring stringlengths 1 46.9k | path stringlengths 4 223 | original_string stringlengths 75 104k | code stringlengths 75 104k | docstring_tokens listlengths 1 1.97k | repo stringlengths 7 55 | language stringclasses 1
value | url stringlengths 87 315 | code_tokens listlengths 19 28.4k | sha stringlengths 40 40 |
|---|---|---|---|---|---|---|---|---|---|---|---|
train | Rook.moves_in_direction | Finds moves in a given direction
:type: direction: lambda
:type: position: Board
:rtype: list | chess_py/pieces/rook.py | def moves_in_direction(self, direction, position):
"""
Finds moves in a given direction
:type: direction: lambda
:type: position: Board
:rtype: list
"""
current_square = self.location
while True:
try:
current_square = directio... | def moves_in_direction(self, direction, position):
"""
Finds moves in a given direction
:type: direction: lambda
:type: position: Board
:rtype: list
"""
current_square = self.location
while True:
try:
current_square = directio... | [
"Finds",
"moves",
"in",
"a",
"given",
"direction"
] | LordDarkula/chess_py | python | https://github.com/LordDarkula/chess_py/blob/14bebc2f8c49ae25c59375cc83d0b38d8ff7281d/chess_py/pieces/rook.py#L48-L70 | [
"def",
"moves_in_direction",
"(",
"self",
",",
"direction",
",",
"position",
")",
":",
"current_square",
"=",
"self",
".",
"location",
"while",
"True",
":",
"try",
":",
"current_square",
"=",
"direction",
"(",
"current_square",
")",
"except",
"IndexError",
":"... | 14bebc2f8c49ae25c59375cc83d0b38d8ff7281d |
train | Rook.possible_moves | Returns all possible rook moves.
:type: position: Board
:rtype: list | chess_py/pieces/rook.py | def possible_moves(self, position):
"""
Returns all possible rook moves.
:type: position: Board
:rtype: list
"""
for move in itertools.chain(*[self.moves_in_direction(fn, position) for fn in self.cross_fn]):
yield move | def possible_moves(self, position):
"""
Returns all possible rook moves.
:type: position: Board
:rtype: list
"""
for move in itertools.chain(*[self.moves_in_direction(fn, position) for fn in self.cross_fn]):
yield move | [
"Returns",
"all",
"possible",
"rook",
"moves",
"."
] | LordDarkula/chess_py | python | https://github.com/LordDarkula/chess_py/blob/14bebc2f8c49ae25c59375cc83d0b38d8ff7281d/chess_py/pieces/rook.py#L72-L80 | [
"def",
"possible_moves",
"(",
"self",
",",
"position",
")",
":",
"for",
"move",
"in",
"itertools",
".",
"chain",
"(",
"*",
"[",
"self",
".",
"moves_in_direction",
"(",
"fn",
",",
"position",
")",
"for",
"fn",
"in",
"self",
".",
"cross_fn",
"]",
")",
... | 14bebc2f8c49ae25c59375cc83d0b38d8ff7281d |
train | overlap_status | Check overlap between two arrays.
Parameters
----------
a, b : array-like
Arrays to check. Assumed to be in the same unit.
Returns
-------
result : {'full', 'partial', 'none'}
* 'full' - ``a`` is within or same as ``b``
* 'partial' - ``a`` partially overlaps with ``b``
... | synphot/utils.py | def overlap_status(a, b):
"""Check overlap between two arrays.
Parameters
----------
a, b : array-like
Arrays to check. Assumed to be in the same unit.
Returns
-------
result : {'full', 'partial', 'none'}
* 'full' - ``a`` is within or same as ``b``
* 'partial' - ``a... | def overlap_status(a, b):
"""Check overlap between two arrays.
Parameters
----------
a, b : array-like
Arrays to check. Assumed to be in the same unit.
Returns
-------
result : {'full', 'partial', 'none'}
* 'full' - ``a`` is within or same as ``b``
* 'partial' - ``a... | [
"Check",
"overlap",
"between",
"two",
"arrays",
"."
] | spacetelescope/synphot_refactor | python | https://github.com/spacetelescope/synphot_refactor/blob/9c064f3cff0c41dd8acadc0f67c6350931275b9f/synphot/utils.py#L23-L51 | [
"def",
"overlap_status",
"(",
"a",
",",
"b",
")",
":",
"# Get the endpoints",
"a1",
",",
"a2",
"=",
"a",
".",
"min",
"(",
")",
",",
"a",
".",
"max",
"(",
")",
"b1",
",",
"b2",
"=",
"b",
".",
"min",
"(",
")",
",",
"b",
".",
"max",
"(",
")",
... | 9c064f3cff0c41dd8acadc0f67c6350931275b9f |
train | validate_totalflux | Check integrated flux for invalid values.
Parameters
----------
totalflux : float
Integrated flux.
Raises
------
synphot.exceptions.SynphotError
Input is zero, negative, or not a number. | synphot/utils.py | def validate_totalflux(totalflux):
"""Check integrated flux for invalid values.
Parameters
----------
totalflux : float
Integrated flux.
Raises
------
synphot.exceptions.SynphotError
Input is zero, negative, or not a number.
"""
if totalflux <= 0.0:
raise e... | def validate_totalflux(totalflux):
"""Check integrated flux for invalid values.
Parameters
----------
totalflux : float
Integrated flux.
Raises
------
synphot.exceptions.SynphotError
Input is zero, negative, or not a number.
"""
if totalflux <= 0.0:
raise e... | [
"Check",
"integrated",
"flux",
"for",
"invalid",
"values",
"."
] | spacetelescope/synphot_refactor | python | https://github.com/spacetelescope/synphot_refactor/blob/9c064f3cff0c41dd8acadc0f67c6350931275b9f/synphot/utils.py#L54-L73 | [
"def",
"validate_totalflux",
"(",
"totalflux",
")",
":",
"if",
"totalflux",
"<=",
"0.0",
":",
"raise",
"exceptions",
".",
"SynphotError",
"(",
"'Integrated flux is <= 0'",
")",
"elif",
"np",
".",
"isnan",
"(",
"totalflux",
")",
":",
"raise",
"exceptions",
".",... | 9c064f3cff0c41dd8acadc0f67c6350931275b9f |
train | validate_wavelengths | Check wavelengths for ``synphot`` compatibility.
Wavelengths must satisfy these conditions:
* valid unit type, if given
* no zeroes
* monotonic ascending or descending
* no duplicate values
Parameters
----------
wavelengths : array-like or `~astropy.units.quantity.Quan... | synphot/utils.py | def validate_wavelengths(wavelengths):
"""Check wavelengths for ``synphot`` compatibility.
Wavelengths must satisfy these conditions:
* valid unit type, if given
* no zeroes
* monotonic ascending or descending
* no duplicate values
Parameters
----------
wavelengths... | def validate_wavelengths(wavelengths):
"""Check wavelengths for ``synphot`` compatibility.
Wavelengths must satisfy these conditions:
* valid unit type, if given
* no zeroes
* monotonic ascending or descending
* no duplicate values
Parameters
----------
wavelengths... | [
"Check",
"wavelengths",
"for",
"synphot",
"compatibility",
"."
] | spacetelescope/synphot_refactor | python | https://github.com/spacetelescope/synphot_refactor/blob/9c064f3cff0c41dd8acadc0f67c6350931275b9f/synphot/utils.py#L76-L139 | [
"def",
"validate_wavelengths",
"(",
"wavelengths",
")",
":",
"if",
"isinstance",
"(",
"wavelengths",
",",
"u",
".",
"Quantity",
")",
":",
"units",
".",
"validate_wave_unit",
"(",
"wavelengths",
".",
"unit",
")",
"wave",
"=",
"wavelengths",
".",
"value",
"els... | 9c064f3cff0c41dd8acadc0f67c6350931275b9f |
train | generate_wavelengths | Generate wavelength array to be used for spectrum sampling.
.. math::
minwave \\le \\lambda < maxwave
Parameters
----------
minwave, maxwave : float
Lower and upper limits of the wavelengths.
These must be values in linear space regardless of ``log``.
num : int
Th... | synphot/utils.py | def generate_wavelengths(minwave=500, maxwave=26000, num=10000, delta=None,
log=True, wave_unit=u.AA):
"""Generate wavelength array to be used for spectrum sampling.
.. math::
minwave \\le \\lambda < maxwave
Parameters
----------
minwave, maxwave : float
L... | def generate_wavelengths(minwave=500, maxwave=26000, num=10000, delta=None,
log=True, wave_unit=u.AA):
"""Generate wavelength array to be used for spectrum sampling.
.. math::
minwave \\le \\lambda < maxwave
Parameters
----------
minwave, maxwave : float
L... | [
"Generate",
"wavelength",
"array",
"to",
"be",
"used",
"for",
"spectrum",
"sampling",
"."
] | spacetelescope/synphot_refactor | python | https://github.com/spacetelescope/synphot_refactor/blob/9c064f3cff0c41dd8acadc0f67c6350931275b9f/synphot/utils.py#L142-L205 | [
"def",
"generate_wavelengths",
"(",
"minwave",
"=",
"500",
",",
"maxwave",
"=",
"26000",
",",
"num",
"=",
"10000",
",",
"delta",
"=",
"None",
",",
"log",
"=",
"True",
",",
"wave_unit",
"=",
"u",
".",
"AA",
")",
":",
"wave_unit",
"=",
"units",
".",
... | 9c064f3cff0c41dd8acadc0f67c6350931275b9f |
train | merge_wavelengths | Return the union of the two sets of wavelengths using
:func:`numpy.union1d`.
The merged wavelengths may sometimes contain numbers which are nearly
equal but differ at levels as small as 1e-14. Having values this
close together can cause problems down the line. So, here we test
whether any such smal... | synphot/utils.py | def merge_wavelengths(waveset1, waveset2, threshold=1e-12):
"""Return the union of the two sets of wavelengths using
:func:`numpy.union1d`.
The merged wavelengths may sometimes contain numbers which are nearly
equal but differ at levels as small as 1e-14. Having values this
close together can cause... | def merge_wavelengths(waveset1, waveset2, threshold=1e-12):
"""Return the union of the two sets of wavelengths using
:func:`numpy.union1d`.
The merged wavelengths may sometimes contain numbers which are nearly
equal but differ at levels as small as 1e-14. Having values this
close together can cause... | [
"Return",
"the",
"union",
"of",
"the",
"two",
"sets",
"of",
"wavelengths",
"using",
":",
"func",
":",
"numpy",
".",
"union1d",
"."
] | spacetelescope/synphot_refactor | python | https://github.com/spacetelescope/synphot_refactor/blob/9c064f3cff0c41dd8acadc0f67c6350931275b9f/synphot/utils.py#L208-L252 | [
"def",
"merge_wavelengths",
"(",
"waveset1",
",",
"waveset2",
",",
"threshold",
"=",
"1e-12",
")",
":",
"if",
"waveset1",
"is",
"None",
"and",
"waveset2",
"is",
"None",
":",
"out_wavelengths",
"=",
"None",
"elif",
"waveset1",
"is",
"not",
"None",
"and",
"w... | 9c064f3cff0c41dd8acadc0f67c6350931275b9f |
train | download_data | Download CDBS data files to given root directory.
Download is skipped if a data file already exists.
Parameters
----------
cdbs_root : str
Root directory for CDBS data files.
verbose : bool
Print extra information to screen.
dry_run : bool
Go through the logic but skip... | synphot/utils.py | def download_data(cdbs_root, verbose=True, dry_run=False):
"""Download CDBS data files to given root directory.
Download is skipped if a data file already exists.
Parameters
----------
cdbs_root : str
Root directory for CDBS data files.
verbose : bool
Print extra information to... | def download_data(cdbs_root, verbose=True, dry_run=False):
"""Download CDBS data files to given root directory.
Download is skipped if a data file already exists.
Parameters
----------
cdbs_root : str
Root directory for CDBS data files.
verbose : bool
Print extra information to... | [
"Download",
"CDBS",
"data",
"files",
"to",
"given",
"root",
"directory",
".",
"Download",
"is",
"skipped",
"if",
"a",
"data",
"file",
"already",
"exists",
"."
] | spacetelescope/synphot_refactor | python | https://github.com/spacetelescope/synphot_refactor/blob/9c064f3cff0c41dd8acadc0f67c6350931275b9f/synphot/utils.py#L255-L336 | [
"def",
"download_data",
"(",
"cdbs_root",
",",
"verbose",
"=",
"True",
",",
"dry_run",
"=",
"False",
")",
":",
"from",
".",
"config",
"import",
"conf",
"# Avoid potential circular import",
"if",
"not",
"os",
".",
"path",
".",
"exists",
"(",
"cdbs_root",
")",... | 9c064f3cff0c41dd8acadc0f67c6350931275b9f |
train | main | Demonstrate functionality of PyVLX. | examples/demo.py | async def main(loop):
"""Demonstrate functionality of PyVLX."""
pyvlx = PyVLX('pyvlx.yaml', loop=loop)
# Alternative:
# pyvlx = PyVLX(host="192.168.2.127", password="velux123", loop=loop)
# Runing scenes:
await pyvlx.load_scenes()
await pyvlx.scenes["All Windows Closed"].run()
# Changi... | async def main(loop):
"""Demonstrate functionality of PyVLX."""
pyvlx = PyVLX('pyvlx.yaml', loop=loop)
# Alternative:
# pyvlx = PyVLX(host="192.168.2.127", password="velux123", loop=loop)
# Runing scenes:
await pyvlx.load_scenes()
await pyvlx.scenes["All Windows Closed"].run()
# Changi... | [
"Demonstrate",
"functionality",
"of",
"PyVLX",
"."
] | Julius2342/pyvlx | python | https://github.com/Julius2342/pyvlx/blob/ee78e1324bcb1be5b8d1a9d05ab5496b72eae848/examples/demo.py#L7-L30 | [
"async",
"def",
"main",
"(",
"loop",
")",
":",
"pyvlx",
"=",
"PyVLX",
"(",
"'pyvlx.yaml'",
",",
"loop",
"=",
"loop",
")",
"# Alternative:",
"# pyvlx = PyVLX(host=\"192.168.2.127\", password=\"velux123\", loop=loop)",
"# Runing scenes:",
"await",
"pyvlx",
".",
"load_scen... | ee78e1324bcb1be5b8d1a9d05ab5496b72eae848 |
train | FramePasswordEnterRequest.get_payload | Return Payload. | pyvlx/frames/frame_password_enter.py | def get_payload(self):
"""Return Payload."""
if self.password is None:
raise PyVLXException("password is none")
if len(self.password) > self.MAX_SIZE:
raise PyVLXException("password is too long")
return string_to_bytes(self.password, self.MAX_SIZE) | def get_payload(self):
"""Return Payload."""
if self.password is None:
raise PyVLXException("password is none")
if len(self.password) > self.MAX_SIZE:
raise PyVLXException("password is too long")
return string_to_bytes(self.password, self.MAX_SIZE) | [
"Return",
"Payload",
"."
] | Julius2342/pyvlx | python | https://github.com/Julius2342/pyvlx/blob/ee78e1324bcb1be5b8d1a9d05ab5496b72eae848/pyvlx/frames/frame_password_enter.py#L22-L28 | [
"def",
"get_payload",
"(",
"self",
")",
":",
"if",
"self",
".",
"password",
"is",
"None",
":",
"raise",
"PyVLXException",
"(",
"\"password is none\"",
")",
"if",
"len",
"(",
"self",
".",
"password",
")",
">",
"self",
".",
"MAX_SIZE",
":",
"raise",
"PyVLX... | ee78e1324bcb1be5b8d1a9d05ab5496b72eae848 |
train | Nodes.add | Add Node, replace existing node if node with node_id is present. | pyvlx/nodes.py | def add(self, node):
"""Add Node, replace existing node if node with node_id is present."""
if not isinstance(node, Node):
raise TypeError()
for i, j in enumerate(self.__nodes):
if j.node_id == node.node_id:
self.__nodes[i] = node
return
... | def add(self, node):
"""Add Node, replace existing node if node with node_id is present."""
if not isinstance(node, Node):
raise TypeError()
for i, j in enumerate(self.__nodes):
if j.node_id == node.node_id:
self.__nodes[i] = node
return
... | [
"Add",
"Node",
"replace",
"existing",
"node",
"if",
"node",
"with",
"node_id",
"is",
"present",
"."
] | Julius2342/pyvlx | python | https://github.com/Julius2342/pyvlx/blob/ee78e1324bcb1be5b8d1a9d05ab5496b72eae848/pyvlx/nodes.py#L51-L59 | [
"def",
"add",
"(",
"self",
",",
"node",
")",
":",
"if",
"not",
"isinstance",
"(",
"node",
",",
"Node",
")",
":",
"raise",
"TypeError",
"(",
")",
"for",
"i",
",",
"j",
"in",
"enumerate",
"(",
"self",
".",
"__nodes",
")",
":",
"if",
"j",
".",
"no... | ee78e1324bcb1be5b8d1a9d05ab5496b72eae848 |
train | Nodes.load | Load nodes from KLF 200, if no node_id is specified all nodes are loaded. | pyvlx/nodes.py | async def load(self, node_id=None):
"""Load nodes from KLF 200, if no node_id is specified all nodes are loaded."""
if node_id is not None:
await self._load_node(node_id=node_id)
else:
await self._load_all_nodes() | async def load(self, node_id=None):
"""Load nodes from KLF 200, if no node_id is specified all nodes are loaded."""
if node_id is not None:
await self._load_node(node_id=node_id)
else:
await self._load_all_nodes() | [
"Load",
"nodes",
"from",
"KLF",
"200",
"if",
"no",
"node_id",
"is",
"specified",
"all",
"nodes",
"are",
"loaded",
"."
] | Julius2342/pyvlx | python | https://github.com/Julius2342/pyvlx/blob/ee78e1324bcb1be5b8d1a9d05ab5496b72eae848/pyvlx/nodes.py#L65-L70 | [
"async",
"def",
"load",
"(",
"self",
",",
"node_id",
"=",
"None",
")",
":",
"if",
"node_id",
"is",
"not",
"None",
":",
"await",
"self",
".",
"_load_node",
"(",
"node_id",
"=",
"node_id",
")",
"else",
":",
"await",
"self",
".",
"_load_all_nodes",
"(",
... | ee78e1324bcb1be5b8d1a9d05ab5496b72eae848 |
train | Nodes._load_node | Load single node via API. | pyvlx/nodes.py | async def _load_node(self, node_id):
"""Load single node via API."""
get_node_information = GetNodeInformation(pyvlx=self.pyvlx, node_id=node_id)
await get_node_information.do_api_call()
if not get_node_information.success:
raise PyVLXException("Unable to retrieve node inform... | async def _load_node(self, node_id):
"""Load single node via API."""
get_node_information = GetNodeInformation(pyvlx=self.pyvlx, node_id=node_id)
await get_node_information.do_api_call()
if not get_node_information.success:
raise PyVLXException("Unable to retrieve node inform... | [
"Load",
"single",
"node",
"via",
"API",
"."
] | Julius2342/pyvlx | python | https://github.com/Julius2342/pyvlx/blob/ee78e1324bcb1be5b8d1a9d05ab5496b72eae848/pyvlx/nodes.py#L72-L81 | [
"async",
"def",
"_load_node",
"(",
"self",
",",
"node_id",
")",
":",
"get_node_information",
"=",
"GetNodeInformation",
"(",
"pyvlx",
"=",
"self",
".",
"pyvlx",
",",
"node_id",
"=",
"node_id",
")",
"await",
"get_node_information",
".",
"do_api_call",
"(",
")",... | ee78e1324bcb1be5b8d1a9d05ab5496b72eae848 |
train | Nodes._load_all_nodes | Load all nodes via API. | pyvlx/nodes.py | async def _load_all_nodes(self):
"""Load all nodes via API."""
get_all_nodes_information = GetAllNodesInformation(pyvlx=self.pyvlx)
await get_all_nodes_information.do_api_call()
if not get_all_nodes_information.success:
raise PyVLXException("Unable to retrieve node informatio... | async def _load_all_nodes(self):
"""Load all nodes via API."""
get_all_nodes_information = GetAllNodesInformation(pyvlx=self.pyvlx)
await get_all_nodes_information.do_api_call()
if not get_all_nodes_information.success:
raise PyVLXException("Unable to retrieve node informatio... | [
"Load",
"all",
"nodes",
"via",
"API",
"."
] | Julius2342/pyvlx | python | https://github.com/Julius2342/pyvlx/blob/ee78e1324bcb1be5b8d1a9d05ab5496b72eae848/pyvlx/nodes.py#L83-L93 | [
"async",
"def",
"_load_all_nodes",
"(",
"self",
")",
":",
"get_all_nodes_information",
"=",
"GetAllNodesInformation",
"(",
"pyvlx",
"=",
"self",
".",
"pyvlx",
")",
"await",
"get_all_nodes_information",
".",
"do_api_call",
"(",
")",
"if",
"not",
"get_all_nodes_inform... | ee78e1324bcb1be5b8d1a9d05ab5496b72eae848 |
train | GetAllNodesInformation.handle_frame | Handle incoming API frame, return True if this was the expected frame. | pyvlx/get_all_nodes_information.py | async def handle_frame(self, frame):
"""Handle incoming API frame, return True if this was the expected frame."""
if isinstance(frame, FrameGetAllNodesInformationConfirmation):
self.number_of_nodes = frame.number_of_nodes
# We are still waiting for FrameGetAllNodesInformationNoti... | async def handle_frame(self, frame):
"""Handle incoming API frame, return True if this was the expected frame."""
if isinstance(frame, FrameGetAllNodesInformationConfirmation):
self.number_of_nodes = frame.number_of_nodes
# We are still waiting for FrameGetAllNodesInformationNoti... | [
"Handle",
"incoming",
"API",
"frame",
"return",
"True",
"if",
"this",
"was",
"the",
"expected",
"frame",
"."
] | Julius2342/pyvlx | python | https://github.com/Julius2342/pyvlx/blob/ee78e1324bcb1be5b8d1a9d05ab5496b72eae848/pyvlx/get_all_nodes_information.py#L21-L34 | [
"async",
"def",
"handle_frame",
"(",
"self",
",",
"frame",
")",
":",
"if",
"isinstance",
"(",
"frame",
",",
"FrameGetAllNodesInformationConfirmation",
")",
":",
"self",
".",
"number_of_nodes",
"=",
"frame",
".",
"number_of_nodes",
"# We are still waiting for FrameGetA... | ee78e1324bcb1be5b8d1a9d05ab5496b72eae848 |
train | GetNodeInformation.handle_frame | Handle incoming API frame, return True if this was the expected frame. | pyvlx/get_node_information.py | async def handle_frame(self, frame):
"""Handle incoming API frame, return True if this was the expected frame."""
if isinstance(frame, FrameGetNodeInformationConfirmation) and frame.node_id == self.node_id:
# We are still waiting for GetNodeInformationNotification
return False
... | async def handle_frame(self, frame):
"""Handle incoming API frame, return True if this was the expected frame."""
if isinstance(frame, FrameGetNodeInformationConfirmation) and frame.node_id == self.node_id:
# We are still waiting for GetNodeInformationNotification
return False
... | [
"Handle",
"incoming",
"API",
"frame",
"return",
"True",
"if",
"this",
"was",
"the",
"expected",
"frame",
"."
] | Julius2342/pyvlx | python | https://github.com/Julius2342/pyvlx/blob/ee78e1324bcb1be5b8d1a9d05ab5496b72eae848/pyvlx/get_node_information.py#L18-L27 | [
"async",
"def",
"handle_frame",
"(",
"self",
",",
"frame",
")",
":",
"if",
"isinstance",
"(",
"frame",
",",
"FrameGetNodeInformationConfirmation",
")",
"and",
"frame",
".",
"node_id",
"==",
"self",
".",
"node_id",
":",
"# We are still waiting for GetNodeInformationN... | ee78e1324bcb1be5b8d1a9d05ab5496b72eae848 |
train | Heartbeat.start | Create loop task. | pyvlx/heartbeat.py | def start(self):
"""Create loop task."""
self.run_task = self.pyvlx.loop.create_task(
self.loop()) | def start(self):
"""Create loop task."""
self.run_task = self.pyvlx.loop.create_task(
self.loop()) | [
"Create",
"loop",
"task",
"."
] | Julius2342/pyvlx | python | https://github.com/Julius2342/pyvlx/blob/ee78e1324bcb1be5b8d1a9d05ab5496b72eae848/pyvlx/heartbeat.py#L25-L28 | [
"def",
"start",
"(",
"self",
")",
":",
"self",
".",
"run_task",
"=",
"self",
".",
"pyvlx",
".",
"loop",
".",
"create_task",
"(",
"self",
".",
"loop",
"(",
")",
")"
] | ee78e1324bcb1be5b8d1a9d05ab5496b72eae848 |
train | Heartbeat.stop | Stop heartbeat. | pyvlx/heartbeat.py | async def stop(self):
"""Stop heartbeat."""
self.stopped = True
self.loop_event.set()
# Waiting for shutdown of loop()
await self.stopped_event.wait() | async def stop(self):
"""Stop heartbeat."""
self.stopped = True
self.loop_event.set()
# Waiting for shutdown of loop()
await self.stopped_event.wait() | [
"Stop",
"heartbeat",
"."
] | Julius2342/pyvlx | python | https://github.com/Julius2342/pyvlx/blob/ee78e1324bcb1be5b8d1a9d05ab5496b72eae848/pyvlx/heartbeat.py#L30-L35 | [
"async",
"def",
"stop",
"(",
"self",
")",
":",
"self",
".",
"stopped",
"=",
"True",
"self",
".",
"loop_event",
".",
"set",
"(",
")",
"# Waiting for shutdown of loop()",
"await",
"self",
".",
"stopped_event",
".",
"wait",
"(",
")"
] | ee78e1324bcb1be5b8d1a9d05ab5496b72eae848 |
train | Heartbeat.loop | Pulse every timeout seconds until stopped. | pyvlx/heartbeat.py | async def loop(self):
"""Pulse every timeout seconds until stopped."""
while not self.stopped:
self.timeout_handle = self.pyvlx.connection.loop.call_later(
self.timeout_in_seconds, self.loop_timeout)
await self.loop_event.wait()
if not self.stopped:
... | async def loop(self):
"""Pulse every timeout seconds until stopped."""
while not self.stopped:
self.timeout_handle = self.pyvlx.connection.loop.call_later(
self.timeout_in_seconds, self.loop_timeout)
await self.loop_event.wait()
if not self.stopped:
... | [
"Pulse",
"every",
"timeout",
"seconds",
"until",
"stopped",
"."
] | Julius2342/pyvlx | python | https://github.com/Julius2342/pyvlx/blob/ee78e1324bcb1be5b8d1a9d05ab5496b72eae848/pyvlx/heartbeat.py#L37-L47 | [
"async",
"def",
"loop",
"(",
"self",
")",
":",
"while",
"not",
"self",
".",
"stopped",
":",
"self",
".",
"timeout_handle",
"=",
"self",
".",
"pyvlx",
".",
"connection",
".",
"loop",
".",
"call_later",
"(",
"self",
".",
"timeout_in_seconds",
",",
"self",
... | ee78e1324bcb1be5b8d1a9d05ab5496b72eae848 |
train | Heartbeat.pulse | Send get state request to API to keep the connection alive. | pyvlx/heartbeat.py | async def pulse(self):
"""Send get state request to API to keep the connection alive."""
get_state = GetState(pyvlx=self.pyvlx)
await get_state.do_api_call()
if not get_state.success:
raise PyVLXException("Unable to send get state.") | async def pulse(self):
"""Send get state request to API to keep the connection alive."""
get_state = GetState(pyvlx=self.pyvlx)
await get_state.do_api_call()
if not get_state.success:
raise PyVLXException("Unable to send get state.") | [
"Send",
"get",
"state",
"request",
"to",
"API",
"to",
"keep",
"the",
"connection",
"alive",
"."
] | Julius2342/pyvlx | python | https://github.com/Julius2342/pyvlx/blob/ee78e1324bcb1be5b8d1a9d05ab5496b72eae848/pyvlx/heartbeat.py#L59-L64 | [
"async",
"def",
"pulse",
"(",
"self",
")",
":",
"get_state",
"=",
"GetState",
"(",
"pyvlx",
"=",
"self",
".",
"pyvlx",
")",
"await",
"get_state",
".",
"do_api_call",
"(",
")",
"if",
"not",
"get_state",
".",
"success",
":",
"raise",
"PyVLXException",
"(",... | ee78e1324bcb1be5b8d1a9d05ab5496b72eae848 |
train | FrameGetStateConfirmation.get_payload | Return Payload. | pyvlx/frames/frame_get_state.py | def get_payload(self):
"""Return Payload."""
payload = bytes([self.gateway_state.value, self.gateway_sub_state.value])
payload += bytes(4) # State date, reserved for future use
return payload | def get_payload(self):
"""Return Payload."""
payload = bytes([self.gateway_state.value, self.gateway_sub_state.value])
payload += bytes(4) # State date, reserved for future use
return payload | [
"Return",
"Payload",
"."
] | Julius2342/pyvlx | python | https://github.com/Julius2342/pyvlx/blob/ee78e1324bcb1be5b8d1a9d05ab5496b72eae848/pyvlx/frames/frame_get_state.py#L53-L57 | [
"def",
"get_payload",
"(",
"self",
")",
":",
"payload",
"=",
"bytes",
"(",
"[",
"self",
".",
"gateway_state",
".",
"value",
",",
"self",
".",
"gateway_sub_state",
".",
"value",
"]",
")",
"payload",
"+=",
"bytes",
"(",
"4",
")",
"# State date, reserved for ... | ee78e1324bcb1be5b8d1a9d05ab5496b72eae848 |
train | FrameGetStateConfirmation.from_payload | Init frame from binary data. | pyvlx/frames/frame_get_state.py | def from_payload(self, payload):
"""Init frame from binary data."""
self.gateway_state = GatewayState(payload[0])
self.gateway_sub_state = GatewaySubState(payload[1]) | def from_payload(self, payload):
"""Init frame from binary data."""
self.gateway_state = GatewayState(payload[0])
self.gateway_sub_state = GatewaySubState(payload[1]) | [
"Init",
"frame",
"from",
"binary",
"data",
"."
] | Julius2342/pyvlx | python | https://github.com/Julius2342/pyvlx/blob/ee78e1324bcb1be5b8d1a9d05ab5496b72eae848/pyvlx/frames/frame_get_state.py#L59-L62 | [
"def",
"from_payload",
"(",
"self",
",",
"payload",
")",
":",
"self",
".",
"gateway_state",
"=",
"GatewayState",
"(",
"payload",
"[",
"0",
"]",
")",
"self",
".",
"gateway_sub_state",
"=",
"GatewaySubState",
"(",
"payload",
"[",
"1",
"]",
")"
] | ee78e1324bcb1be5b8d1a9d05ab5496b72eae848 |
train | string_to_bytes | Convert string to bytes add padding. | pyvlx/string_helper.py | def string_to_bytes(string, size):
"""Convert string to bytes add padding."""
if len(string) > size:
raise PyVLXException("string_to_bytes::string_to_large")
encoded = bytes(string, encoding='utf-8')
return encoded + bytes(size-len(encoded)) | def string_to_bytes(string, size):
"""Convert string to bytes add padding."""
if len(string) > size:
raise PyVLXException("string_to_bytes::string_to_large")
encoded = bytes(string, encoding='utf-8')
return encoded + bytes(size-len(encoded)) | [
"Convert",
"string",
"to",
"bytes",
"add",
"padding",
"."
] | Julius2342/pyvlx | python | https://github.com/Julius2342/pyvlx/blob/ee78e1324bcb1be5b8d1a9d05ab5496b72eae848/pyvlx/string_helper.py#L5-L10 | [
"def",
"string_to_bytes",
"(",
"string",
",",
"size",
")",
":",
"if",
"len",
"(",
"string",
")",
">",
"size",
":",
"raise",
"PyVLXException",
"(",
"\"string_to_bytes::string_to_large\"",
")",
"encoded",
"=",
"bytes",
"(",
"string",
",",
"encoding",
"=",
"'ut... | ee78e1324bcb1be5b8d1a9d05ab5496b72eae848 |
train | bytes_to_string | Convert bytes to string. | pyvlx/string_helper.py | def bytes_to_string(raw):
"""Convert bytes to string."""
ret = bytes()
for byte in raw:
if byte == 0x00:
return ret.decode("utf-8")
ret += bytes([byte])
return ret.decode("utf-8") | def bytes_to_string(raw):
"""Convert bytes to string."""
ret = bytes()
for byte in raw:
if byte == 0x00:
return ret.decode("utf-8")
ret += bytes([byte])
return ret.decode("utf-8") | [
"Convert",
"bytes",
"to",
"string",
"."
] | Julius2342/pyvlx | python | https://github.com/Julius2342/pyvlx/blob/ee78e1324bcb1be5b8d1a9d05ab5496b72eae848/pyvlx/string_helper.py#L13-L20 | [
"def",
"bytes_to_string",
"(",
"raw",
")",
":",
"ret",
"=",
"bytes",
"(",
")",
"for",
"byte",
"in",
"raw",
":",
"if",
"byte",
"==",
"0x00",
":",
"return",
"ret",
".",
"decode",
"(",
"\"utf-8\"",
")",
"ret",
"+=",
"bytes",
"(",
"[",
"byte",
"]",
"... | ee78e1324bcb1be5b8d1a9d05ab5496b72eae848 |
train | FrameNodeStatePositionChangedNotification.get_payload | Return Payload. | pyvlx/frames/frame_node_state_position_changed_notification.py | def get_payload(self):
"""Return Payload."""
payload = bytes([self.node_id])
payload += bytes([self.state])
payload += bytes(self.current_position.raw)
payload += bytes(self.target.raw)
payload += bytes(self.current_position_fp1.raw)
payload += bytes(self.current_... | def get_payload(self):
"""Return Payload."""
payload = bytes([self.node_id])
payload += bytes([self.state])
payload += bytes(self.current_position.raw)
payload += bytes(self.target.raw)
payload += bytes(self.current_position_fp1.raw)
payload += bytes(self.current_... | [
"Return",
"Payload",
"."
] | Julius2342/pyvlx | python | https://github.com/Julius2342/pyvlx/blob/ee78e1324bcb1be5b8d1a9d05ab5496b72eae848/pyvlx/frames/frame_node_state_position_changed_notification.py#L30-L42 | [
"def",
"get_payload",
"(",
"self",
")",
":",
"payload",
"=",
"bytes",
"(",
"[",
"self",
".",
"node_id",
"]",
")",
"payload",
"+=",
"bytes",
"(",
"[",
"self",
".",
"state",
"]",
")",
"payload",
"+=",
"bytes",
"(",
"self",
".",
"current_position",
".",... | ee78e1324bcb1be5b8d1a9d05ab5496b72eae848 |
train | FrameNodeStatePositionChangedNotification.from_payload | Init frame from binary data. | pyvlx/frames/frame_node_state_position_changed_notification.py | def from_payload(self, payload):
"""Init frame from binary data."""
self.node_id = payload[0]
self.state = payload[1]
self.current_position = Parameter(payload[2:4])
self.target = Parameter(payload[4:6])
self.current_position_fp1 = Parameter(payload[6:8])
self.cur... | def from_payload(self, payload):
"""Init frame from binary data."""
self.node_id = payload[0]
self.state = payload[1]
self.current_position = Parameter(payload[2:4])
self.target = Parameter(payload[4:6])
self.current_position_fp1 = Parameter(payload[6:8])
self.cur... | [
"Init",
"frame",
"from",
"binary",
"data",
"."
] | Julius2342/pyvlx | python | https://github.com/Julius2342/pyvlx/blob/ee78e1324bcb1be5b8d1a9d05ab5496b72eae848/pyvlx/frames/frame_node_state_position_changed_notification.py#L44-L57 | [
"def",
"from_payload",
"(",
"self",
",",
"payload",
")",
":",
"self",
".",
"node_id",
"=",
"payload",
"[",
"0",
"]",
"self",
".",
"state",
"=",
"payload",
"[",
"1",
"]",
"self",
".",
"current_position",
"=",
"Parameter",
"(",
"payload",
"[",
"2",
":"... | ee78e1324bcb1be5b8d1a9d05ab5496b72eae848 |
train | house_status_monitor_enable | Enable house status monitor. | pyvlx/house_status_monitor.py | async def house_status_monitor_enable(pyvlx):
"""Enable house status monitor."""
status_monitor_enable = HouseStatusMonitorEnable(pyvlx=pyvlx)
await status_monitor_enable.do_api_call()
if not status_monitor_enable.success:
raise PyVLXException("Unable enable house status monitor.") | async def house_status_monitor_enable(pyvlx):
"""Enable house status monitor."""
status_monitor_enable = HouseStatusMonitorEnable(pyvlx=pyvlx)
await status_monitor_enable.do_api_call()
if not status_monitor_enable.success:
raise PyVLXException("Unable enable house status monitor.") | [
"Enable",
"house",
"status",
"monitor",
"."
] | Julius2342/pyvlx | python | https://github.com/Julius2342/pyvlx/blob/ee78e1324bcb1be5b8d1a9d05ab5496b72eae848/pyvlx/house_status_monitor.py#L51-L56 | [
"async",
"def",
"house_status_monitor_enable",
"(",
"pyvlx",
")",
":",
"status_monitor_enable",
"=",
"HouseStatusMonitorEnable",
"(",
"pyvlx",
"=",
"pyvlx",
")",
"await",
"status_monitor_enable",
".",
"do_api_call",
"(",
")",
"if",
"not",
"status_monitor_enable",
".",... | ee78e1324bcb1be5b8d1a9d05ab5496b72eae848 |
train | house_status_monitor_disable | Disable house status monitor. | pyvlx/house_status_monitor.py | async def house_status_monitor_disable(pyvlx):
"""Disable house status monitor."""
status_monitor_disable = HouseStatusMonitorDisable(pyvlx=pyvlx)
await status_monitor_disable.do_api_call()
if not status_monitor_disable.success:
raise PyVLXException("Unable disable house status monitor.") | async def house_status_monitor_disable(pyvlx):
"""Disable house status monitor."""
status_monitor_disable = HouseStatusMonitorDisable(pyvlx=pyvlx)
await status_monitor_disable.do_api_call()
if not status_monitor_disable.success:
raise PyVLXException("Unable disable house status monitor.") | [
"Disable",
"house",
"status",
"monitor",
"."
] | Julius2342/pyvlx | python | https://github.com/Julius2342/pyvlx/blob/ee78e1324bcb1be5b8d1a9d05ab5496b72eae848/pyvlx/house_status_monitor.py#L59-L64 | [
"async",
"def",
"house_status_monitor_disable",
"(",
"pyvlx",
")",
":",
"status_monitor_disable",
"=",
"HouseStatusMonitorDisable",
"(",
"pyvlx",
"=",
"pyvlx",
")",
"await",
"status_monitor_disable",
".",
"do_api_call",
"(",
")",
"if",
"not",
"status_monitor_disable",
... | ee78e1324bcb1be5b8d1a9d05ab5496b72eae848 |
train | HouseStatusMonitorEnable.handle_frame | Handle incoming API frame, return True if this was the expected frame. | pyvlx/house_status_monitor.py | async def handle_frame(self, frame):
"""Handle incoming API frame, return True if this was the expected frame."""
if not isinstance(frame, FrameHouseStatusMonitorEnableConfirmation):
return False
self.success = True
return True | async def handle_frame(self, frame):
"""Handle incoming API frame, return True if this was the expected frame."""
if not isinstance(frame, FrameHouseStatusMonitorEnableConfirmation):
return False
self.success = True
return True | [
"Handle",
"incoming",
"API",
"frame",
"return",
"True",
"if",
"this",
"was",
"the",
"expected",
"frame",
"."
] | Julius2342/pyvlx | python | https://github.com/Julius2342/pyvlx/blob/ee78e1324bcb1be5b8d1a9d05ab5496b72eae848/pyvlx/house_status_monitor.py#L19-L24 | [
"async",
"def",
"handle_frame",
"(",
"self",
",",
"frame",
")",
":",
"if",
"not",
"isinstance",
"(",
"frame",
",",
"FrameHouseStatusMonitorEnableConfirmation",
")",
":",
"return",
"False",
"self",
".",
"success",
"=",
"True",
"return",
"True"
] | ee78e1324bcb1be5b8d1a9d05ab5496b72eae848 |
train | HouseStatusMonitorDisable.handle_frame | Handle incoming API frame, return True if this was the expected frame. | pyvlx/house_status_monitor.py | async def handle_frame(self, frame):
"""Handle incoming API frame, return True if this was the expected frame."""
if not isinstance(frame, FrameHouseStatusMonitorDisableConfirmation):
return False
self.success = True
return True | async def handle_frame(self, frame):
"""Handle incoming API frame, return True if this was the expected frame."""
if not isinstance(frame, FrameHouseStatusMonitorDisableConfirmation):
return False
self.success = True
return True | [
"Handle",
"incoming",
"API",
"frame",
"return",
"True",
"if",
"this",
"was",
"the",
"expected",
"frame",
"."
] | Julius2342/pyvlx | python | https://github.com/Julius2342/pyvlx/blob/ee78e1324bcb1be5b8d1a9d05ab5496b72eae848/pyvlx/house_status_monitor.py#L39-L44 | [
"async",
"def",
"handle_frame",
"(",
"self",
",",
"frame",
")",
":",
"if",
"not",
"isinstance",
"(",
"frame",
",",
"FrameHouseStatusMonitorDisableConfirmation",
")",
":",
"return",
"False",
"self",
".",
"success",
"=",
"True",
"return",
"True"
] | ee78e1324bcb1be5b8d1a9d05ab5496b72eae848 |
train | BitmathType | An 'argument type' for integrations with the argparse module.
For more information, see
https://docs.python.org/2/library/argparse.html#type Of particular
interest to us is this bit:
``type=`` can take any callable that takes a single string
argument and returns the converted value
I.e., ``type`` can be a func... | bitmath/integrations.py | def BitmathType(bmstring):
"""An 'argument type' for integrations with the argparse module.
For more information, see
https://docs.python.org/2/library/argparse.html#type Of particular
interest to us is this bit:
``type=`` can take any callable that takes a single string
argument and returns the converted v... | def BitmathType(bmstring):
"""An 'argument type' for integrations with the argparse module.
For more information, see
https://docs.python.org/2/library/argparse.html#type Of particular
interest to us is this bit:
``type=`` can take any callable that takes a single string
argument and returns the converted v... | [
"An",
"argument",
"type",
"for",
"integrations",
"with",
"the",
"argparse",
"module",
"."
] | tbielawa/bitmath | python | https://github.com/tbielawa/bitmath/blob/58ad3ac5f076cc6e53f36a91af055c6028c850a5/bitmath/integrations.py#L33-L80 | [
"def",
"BitmathType",
"(",
"bmstring",
")",
":",
"try",
":",
"argvalue",
"=",
"bitmath",
".",
"parse_string",
"(",
"bmstring",
")",
"except",
"ValueError",
":",
"raise",
"argparse",
".",
"ArgumentTypeError",
"(",
"\"'%s' can not be parsed into a valid bitmath object\"... | 58ad3ac5f076cc6e53f36a91af055c6028c850a5 |
train | BitmathFileTransferSpeed.update | Updates the widget with the current NIST/SI speed.
Basically, this calculates the average rate of update and figures out
how to make a "pretty" prefix unit | bitmath/integrations.py | def update(self, pbar):
"""Updates the widget with the current NIST/SI speed.
Basically, this calculates the average rate of update and figures out
how to make a "pretty" prefix unit"""
if pbar.seconds_elapsed < 2e-6 or pbar.currval < 2e-6:
scaled = bitmath.Byte()
else:
... | def update(self, pbar):
"""Updates the widget with the current NIST/SI speed.
Basically, this calculates the average rate of update and figures out
how to make a "pretty" prefix unit"""
if pbar.seconds_elapsed < 2e-6 or pbar.currval < 2e-6:
scaled = bitmath.Byte()
else:
... | [
"Updates",
"the",
"widget",
"with",
"the",
"current",
"NIST",
"/",
"SI",
"speed",
"."
] | tbielawa/bitmath | python | https://github.com/tbielawa/bitmath/blob/58ad3ac5f076cc6e53f36a91af055c6028c850a5/bitmath/integrations.py#L92-L104 | [
"def",
"update",
"(",
"self",
",",
"pbar",
")",
":",
"if",
"pbar",
".",
"seconds_elapsed",
"<",
"2e-6",
"or",
"pbar",
".",
"currval",
"<",
"2e-6",
":",
"scaled",
"=",
"bitmath",
".",
"Byte",
"(",
")",
"else",
":",
"speed",
"=",
"pbar",
".",
"currva... | 58ad3ac5f076cc6e53f36a91af055c6028c850a5 |
train | CommandSend.handle_frame | Handle incoming API frame, return True if this was the expected frame. | pyvlx/command_send.py | async def handle_frame(self, frame):
"""Handle incoming API frame, return True if this was the expected frame."""
if isinstance(frame, FrameCommandSendConfirmation) and frame.session_id == self.session_id:
if frame.status == CommandSendConfirmationStatus.ACCEPTED:
self.succes... | async def handle_frame(self, frame):
"""Handle incoming API frame, return True if this was the expected frame."""
if isinstance(frame, FrameCommandSendConfirmation) and frame.session_id == self.session_id:
if frame.status == CommandSendConfirmationStatus.ACCEPTED:
self.succes... | [
"Handle",
"incoming",
"API",
"frame",
"return",
"True",
"if",
"this",
"was",
"the",
"expected",
"frame",
"."
] | Julius2342/pyvlx | python | https://github.com/Julius2342/pyvlx/blob/ee78e1324bcb1be5b8d1a9d05ab5496b72eae848/pyvlx/command_send.py#L22-L37 | [
"async",
"def",
"handle_frame",
"(",
"self",
",",
"frame",
")",
":",
"if",
"isinstance",
"(",
"frame",
",",
"FrameCommandSendConfirmation",
")",
"and",
"frame",
".",
"session_id",
"==",
"self",
".",
"session_id",
":",
"if",
"frame",
".",
"status",
"==",
"C... | ee78e1324bcb1be5b8d1a9d05ab5496b72eae848 |
train | CommandSend.request_frame | Construct initiating frame. | pyvlx/command_send.py | def request_frame(self):
"""Construct initiating frame."""
self.session_id = get_new_session_id()
return FrameCommandSendRequest(node_ids=[self.node_id], parameter=self.parameter, session_id=self.session_id) | def request_frame(self):
"""Construct initiating frame."""
self.session_id = get_new_session_id()
return FrameCommandSendRequest(node_ids=[self.node_id], parameter=self.parameter, session_id=self.session_id) | [
"Construct",
"initiating",
"frame",
"."
] | Julius2342/pyvlx | python | https://github.com/Julius2342/pyvlx/blob/ee78e1324bcb1be5b8d1a9d05ab5496b72eae848/pyvlx/command_send.py#L39-L42 | [
"def",
"request_frame",
"(",
"self",
")",
":",
"self",
".",
"session_id",
"=",
"get_new_session_id",
"(",
")",
"return",
"FrameCommandSendRequest",
"(",
"node_ids",
"=",
"[",
"self",
".",
"node_id",
"]",
",",
"parameter",
"=",
"self",
".",
"parameter",
",",
... | ee78e1324bcb1be5b8d1a9d05ab5496b72eae848 |
train | Config.read_config | Read configuration file. | pyvlx/config.py | def read_config(self, path):
"""Read configuration file."""
PYVLXLOG.info('Reading config file: %s', path)
try:
with open(path, 'r') as filehandle:
doc = yaml.safe_load(filehandle)
self.test_configuration(doc, path)
self.host = doc['con... | def read_config(self, path):
"""Read configuration file."""
PYVLXLOG.info('Reading config file: %s', path)
try:
with open(path, 'r') as filehandle:
doc = yaml.safe_load(filehandle)
self.test_configuration(doc, path)
self.host = doc['con... | [
"Read",
"configuration",
"file",
"."
] | Julius2342/pyvlx | python | https://github.com/Julius2342/pyvlx/blob/ee78e1324bcb1be5b8d1a9d05ab5496b72eae848/pyvlx/config.py#L22-L34 | [
"def",
"read_config",
"(",
"self",
",",
"path",
")",
":",
"PYVLXLOG",
".",
"info",
"(",
"'Reading config file: %s'",
",",
"path",
")",
"try",
":",
"with",
"open",
"(",
"path",
",",
"'r'",
")",
"as",
"filehandle",
":",
"doc",
"=",
"yaml",
".",
"safe_loa... | ee78e1324bcb1be5b8d1a9d05ab5496b72eae848 |
train | setup_apiv2 | Setup apiv2 when using PyQt4 and Python2. | pyqode/qt/__init__.py | def setup_apiv2():
"""
Setup apiv2 when using PyQt4 and Python2.
"""
# setup PyQt api to version 2
if sys.version_info[0] == 2:
logging.getLogger(__name__).debug(
'setting up SIP API to version 2')
import sip
try:
sip.setapi("QString", 2)
s... | def setup_apiv2():
"""
Setup apiv2 when using PyQt4 and Python2.
"""
# setup PyQt api to version 2
if sys.version_info[0] == 2:
logging.getLogger(__name__).debug(
'setting up SIP API to version 2')
import sip
try:
sip.setapi("QString", 2)
s... | [
"Setup",
"apiv2",
"when",
"using",
"PyQt4",
"and",
"Python2",
"."
] | pyQode/pyqode.qt | python | https://github.com/pyQode/pyqode.qt/blob/56ee08fdcd4d9c4441dcf85f89b51d4ae3a727bd/pyqode/qt/__init__.py#L79-L94 | [
"def",
"setup_apiv2",
"(",
")",
":",
"# setup PyQt api to version 2",
"if",
"sys",
".",
"version_info",
"[",
"0",
"]",
"==",
"2",
":",
"logging",
".",
"getLogger",
"(",
"__name__",
")",
".",
"debug",
"(",
"'setting up SIP API to version 2'",
")",
"import",
"si... | 56ee08fdcd4d9c4441dcf85f89b51d4ae3a727bd |
train | autodetect | Auto-detects and use the first available QT_API by importing them in the
following order:
1) PyQt5
2) PyQt4
3) PySide | pyqode/qt/__init__.py | def autodetect():
"""
Auto-detects and use the first available QT_API by importing them in the
following order:
1) PyQt5
2) PyQt4
3) PySide
"""
logging.getLogger(__name__).debug('auto-detecting QT_API')
try:
logging.getLogger(__name__).debug('trying PyQt5')
import Py... | def autodetect():
"""
Auto-detects and use the first available QT_API by importing them in the
following order:
1) PyQt5
2) PyQt4
3) PySide
"""
logging.getLogger(__name__).debug('auto-detecting QT_API')
try:
logging.getLogger(__name__).debug('trying PyQt5')
import Py... | [
"Auto",
"-",
"detects",
"and",
"use",
"the",
"first",
"available",
"QT_API",
"by",
"importing",
"them",
"in",
"the",
"following",
"order",
":"
] | pyQode/pyqode.qt | python | https://github.com/pyQode/pyqode.qt/blob/56ee08fdcd4d9c4441dcf85f89b51d4ae3a727bd/pyqode/qt/__init__.py#L97-L126 | [
"def",
"autodetect",
"(",
")",
":",
"logging",
".",
"getLogger",
"(",
"__name__",
")",
".",
"debug",
"(",
"'auto-detecting QT_API'",
")",
"try",
":",
"logging",
".",
"getLogger",
"(",
"__name__",
")",
".",
"debug",
"(",
"'trying PyQt5'",
")",
"import",
"Py... | 56ee08fdcd4d9c4441dcf85f89b51d4ae3a727bd |
train | RollerShutter.from_config | Read roller shutter from config. | old_api/pyvlx/rollershutter.py | def from_config(cls, pyvlx, item):
"""Read roller shutter from config."""
name = item['name']
ident = item['id']
subtype = item['subtype']
typeid = item['typeId']
return cls(pyvlx, ident, name, subtype, typeid) | def from_config(cls, pyvlx, item):
"""Read roller shutter from config."""
name = item['name']
ident = item['id']
subtype = item['subtype']
typeid = item['typeId']
return cls(pyvlx, ident, name, subtype, typeid) | [
"Read",
"roller",
"shutter",
"from",
"config",
"."
] | Julius2342/pyvlx | python | https://github.com/Julius2342/pyvlx/blob/ee78e1324bcb1be5b8d1a9d05ab5496b72eae848/old_api/pyvlx/rollershutter.py#L19-L25 | [
"def",
"from_config",
"(",
"cls",
",",
"pyvlx",
",",
"item",
")",
":",
"name",
"=",
"item",
"[",
"'name'",
"]",
"ident",
"=",
"item",
"[",
"'id'",
"]",
"subtype",
"=",
"item",
"[",
"'subtype'",
"]",
"typeid",
"=",
"item",
"[",
"'typeId'",
"]",
"ret... | ee78e1324bcb1be5b8d1a9d05ab5496b72eae848 |
train | GetSceneList.handle_frame | Handle incoming API frame, return True if this was the expected frame. | pyvlx/get_scene_list.py | async def handle_frame(self, frame):
"""Handle incoming API frame, return True if this was the expected frame."""
if isinstance(frame, FrameGetSceneListConfirmation):
self.count_scenes = frame.count_scenes
if self.count_scenes == 0:
self.success = True
... | async def handle_frame(self, frame):
"""Handle incoming API frame, return True if this was the expected frame."""
if isinstance(frame, FrameGetSceneListConfirmation):
self.count_scenes = frame.count_scenes
if self.count_scenes == 0:
self.success = True
... | [
"Handle",
"incoming",
"API",
"frame",
"return",
"True",
"if",
"this",
"was",
"the",
"expected",
"frame",
"."
] | Julius2342/pyvlx | python | https://github.com/Julius2342/pyvlx/blob/ee78e1324bcb1be5b8d1a9d05ab5496b72eae848/pyvlx/get_scene_list.py#L19-L37 | [
"async",
"def",
"handle_frame",
"(",
"self",
",",
"frame",
")",
":",
"if",
"isinstance",
"(",
"frame",
",",
"FrameGetSceneListConfirmation",
")",
":",
"self",
".",
"count_scenes",
"=",
"frame",
".",
"count_scenes",
"if",
"self",
".",
"count_scenes",
"==",
"0... | ee78e1324bcb1be5b8d1a9d05ab5496b72eae848 |
train | FrameGetSceneListNotification.get_payload | Return Payload. | pyvlx/frames/frame_get_scene_list.py | def get_payload(self):
"""Return Payload."""
ret = bytes([len(self.scenes)])
for number, name in self.scenes:
ret += bytes([number])
ret += string_to_bytes(name, 64)
ret += bytes([self.remaining_scenes])
return ret | def get_payload(self):
"""Return Payload."""
ret = bytes([len(self.scenes)])
for number, name in self.scenes:
ret += bytes([number])
ret += string_to_bytes(name, 64)
ret += bytes([self.remaining_scenes])
return ret | [
"Return",
"Payload",
"."
] | Julius2342/pyvlx | python | https://github.com/Julius2342/pyvlx/blob/ee78e1324bcb1be5b8d1a9d05ab5496b72eae848/pyvlx/frames/frame_get_scene_list.py#L51-L58 | [
"def",
"get_payload",
"(",
"self",
")",
":",
"ret",
"=",
"bytes",
"(",
"[",
"len",
"(",
"self",
".",
"scenes",
")",
"]",
")",
"for",
"number",
",",
"name",
"in",
"self",
".",
"scenes",
":",
"ret",
"+=",
"bytes",
"(",
"[",
"number",
"]",
")",
"r... | ee78e1324bcb1be5b8d1a9d05ab5496b72eae848 |
train | FrameGetSceneListNotification.from_payload | Init frame from binary data. | pyvlx/frames/frame_get_scene_list.py | def from_payload(self, payload):
"""Init frame from binary data."""
number_of_objects = payload[0]
self.remaining_scenes = payload[-1]
predicted_len = number_of_objects * 65 + 2
if len(payload) != predicted_len:
raise PyVLXException('scene_list_notification_wrong_leng... | def from_payload(self, payload):
"""Init frame from binary data."""
number_of_objects = payload[0]
self.remaining_scenes = payload[-1]
predicted_len = number_of_objects * 65 + 2
if len(payload) != predicted_len:
raise PyVLXException('scene_list_notification_wrong_leng... | [
"Init",
"frame",
"from",
"binary",
"data",
"."
] | Julius2342/pyvlx | python | https://github.com/Julius2342/pyvlx/blob/ee78e1324bcb1be5b8d1a9d05ab5496b72eae848/pyvlx/frames/frame_get_scene_list.py#L60-L72 | [
"def",
"from_payload",
"(",
"self",
",",
"payload",
")",
":",
"number_of_objects",
"=",
"payload",
"[",
"0",
"]",
"self",
".",
"remaining_scenes",
"=",
"payload",
"[",
"-",
"1",
"]",
"predicted_len",
"=",
"number_of_objects",
"*",
"65",
"+",
"2",
"if",
"... | ee78e1324bcb1be5b8d1a9d05ab5496b72eae848 |
train | read_remote_spec | Read FITS or ASCII spectrum from a remote location.
Parameters
----------
filename : str
Spectrum filename.
encoding, cache, show_progress
See :func:`~astropy.utils.data.get_readable_fileobj`.
kwargs : dict
Keywords acceptable by :func:`read_fits_spec` (if FITS) or
... | synphot/specio.py | def read_remote_spec(filename, encoding='binary', cache=True,
show_progress=True, **kwargs):
"""Read FITS or ASCII spectrum from a remote location.
Parameters
----------
filename : str
Spectrum filename.
encoding, cache, show_progress
See :func:`~astropy.utils.... | def read_remote_spec(filename, encoding='binary', cache=True,
show_progress=True, **kwargs):
"""Read FITS or ASCII spectrum from a remote location.
Parameters
----------
filename : str
Spectrum filename.
encoding, cache, show_progress
See :func:`~astropy.utils.... | [
"Read",
"FITS",
"or",
"ASCII",
"spectrum",
"from",
"a",
"remote",
"location",
"."
] | spacetelescope/synphot_refactor | python | https://github.com/spacetelescope/synphot_refactor/blob/9c064f3cff0c41dd8acadc0f67c6350931275b9f/synphot/specio.py#L26-L55 | [
"def",
"read_remote_spec",
"(",
"filename",
",",
"encoding",
"=",
"'binary'",
",",
"cache",
"=",
"True",
",",
"show_progress",
"=",
"True",
",",
"*",
"*",
"kwargs",
")",
":",
"with",
"get_readable_fileobj",
"(",
"filename",
",",
"encoding",
"=",
"encoding",
... | 9c064f3cff0c41dd8acadc0f67c6350931275b9f |
train | read_spec | Read FITS or ASCII spectrum.
Parameters
----------
filename : str or file pointer
Spectrum file name or pointer.
fname : str
Filename. This is *only* used if ``filename`` is a pointer.
kwargs : dict
Keywords acceptable by :func:`read_fits_spec` (if FITS) or
:func:`... | synphot/specio.py | def read_spec(filename, fname='', **kwargs):
"""Read FITS or ASCII spectrum.
Parameters
----------
filename : str or file pointer
Spectrum file name or pointer.
fname : str
Filename. This is *only* used if ``filename`` is a pointer.
kwargs : dict
Keywords acceptable by... | def read_spec(filename, fname='', **kwargs):
"""Read FITS or ASCII spectrum.
Parameters
----------
filename : str or file pointer
Spectrum file name or pointer.
fname : str
Filename. This is *only* used if ``filename`` is a pointer.
kwargs : dict
Keywords acceptable by... | [
"Read",
"FITS",
"or",
"ASCII",
"spectrum",
"."
] | spacetelescope/synphot_refactor | python | https://github.com/spacetelescope/synphot_refactor/blob/9c064f3cff0c41dd8acadc0f67c6350931275b9f/synphot/specio.py#L58-L97 | [
"def",
"read_spec",
"(",
"filename",
",",
"fname",
"=",
"''",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"isinstance",
"(",
"filename",
",",
"str",
")",
":",
"fname",
"=",
"filename",
"elif",
"not",
"fname",
":",
"# pragma: no cover",
"raise",
"exceptions"... | 9c064f3cff0c41dd8acadc0f67c6350931275b9f |
train | read_ascii_spec | Read ASCII spectrum.
ASCII table must have following columns:
#. Wavelength data
#. Flux data
It can have more than 2 columns but the rest is ignored.
Comments are discarded.
Parameters
----------
filename : str or file pointer
Spectrum file name or pointer.
wave... | synphot/specio.py | def read_ascii_spec(filename, wave_unit=u.AA, flux_unit=units.FLAM, **kwargs):
"""Read ASCII spectrum.
ASCII table must have following columns:
#. Wavelength data
#. Flux data
It can have more than 2 columns but the rest is ignored.
Comments are discarded.
Parameters
--------... | def read_ascii_spec(filename, wave_unit=u.AA, flux_unit=units.FLAM, **kwargs):
"""Read ASCII spectrum.
ASCII table must have following columns:
#. Wavelength data
#. Flux data
It can have more than 2 columns but the rest is ignored.
Comments are discarded.
Parameters
--------... | [
"Read",
"ASCII",
"spectrum",
"."
] | spacetelescope/synphot_refactor | python | https://github.com/spacetelescope/synphot_refactor/blob/9c064f3cff0c41dd8acadc0f67c6350931275b9f/synphot/specio.py#L100-L144 | [
"def",
"read_ascii_spec",
"(",
"filename",
",",
"wave_unit",
"=",
"u",
".",
"AA",
",",
"flux_unit",
"=",
"units",
".",
"FLAM",
",",
"*",
"*",
"kwargs",
")",
":",
"header",
"=",
"{",
"}",
"dat",
"=",
"ascii",
".",
"read",
"(",
"filename",
",",
"*",
... | 9c064f3cff0c41dd8acadc0f67c6350931275b9f |
train | read_fits_spec | Read FITS spectrum.
Wavelength and flux units are extracted from ``TUNIT1`` and ``TUNIT2``
keywords, respectively, from data table (not primary) header.
If these keywords are not present, units are taken from
``wave_unit`` and ``flux_unit`` instead.
Parameters
----------
filename : str or ... | synphot/specio.py | def read_fits_spec(filename, ext=1, wave_col='WAVELENGTH', flux_col='FLUX',
wave_unit=u.AA, flux_unit=units.FLAM):
"""Read FITS spectrum.
Wavelength and flux units are extracted from ``TUNIT1`` and ``TUNIT2``
keywords, respectively, from data table (not primary) header.
If these keyw... | def read_fits_spec(filename, ext=1, wave_col='WAVELENGTH', flux_col='FLUX',
wave_unit=u.AA, flux_unit=units.FLAM):
"""Read FITS spectrum.
Wavelength and flux units are extracted from ``TUNIT1`` and ``TUNIT2``
keywords, respectively, from data table (not primary) header.
If these keyw... | [
"Read",
"FITS",
"spectrum",
"."
] | spacetelescope/synphot_refactor | python | https://github.com/spacetelescope/synphot_refactor/blob/9c064f3cff0c41dd8acadc0f67c6350931275b9f/synphot/specio.py#L147-L215 | [
"def",
"read_fits_spec",
"(",
"filename",
",",
"ext",
"=",
"1",
",",
"wave_col",
"=",
"'WAVELENGTH'",
",",
"flux_col",
"=",
"'FLUX'",
",",
"wave_unit",
"=",
"u",
".",
"AA",
",",
"flux_unit",
"=",
"units",
".",
"FLAM",
")",
":",
"fs",
"=",
"fits",
"."... | 9c064f3cff0c41dd8acadc0f67c6350931275b9f |
train | write_fits_spec | Write FITS spectrum.
.. warning::
If data is being written out as single-precision but wavelengths
are in double-precision, some rows may be omitted.
Parameters
----------
filename : str
Output spectrum filename.
wavelengths, fluxes : array-like or `~astropy.units.quantit... | synphot/specio.py | def write_fits_spec(filename, wavelengths, fluxes, pri_header={},
ext_header={}, overwrite=False, trim_zero=True,
pad_zero_ends=True, precision=None, epsilon=0.00032,
wave_col='WAVELENGTH', flux_col='FLUX',
wave_unit=u.AA, flux_unit=units.F... | def write_fits_spec(filename, wavelengths, fluxes, pri_header={},
ext_header={}, overwrite=False, trim_zero=True,
pad_zero_ends=True, precision=None, epsilon=0.00032,
wave_col='WAVELENGTH', flux_col='FLUX',
wave_unit=u.AA, flux_unit=units.F... | [
"Write",
"FITS",
"spectrum",
"."
] | spacetelescope/synphot_refactor | python | https://github.com/spacetelescope/synphot_refactor/blob/9c064f3cff0c41dd8acadc0f67c6350931275b9f/synphot/specio.py#L218-L384 | [
"def",
"write_fits_spec",
"(",
"filename",
",",
"wavelengths",
",",
"fluxes",
",",
"pri_header",
"=",
"{",
"}",
",",
"ext_header",
"=",
"{",
"}",
",",
"overwrite",
"=",
"False",
",",
"trim_zero",
"=",
"True",
",",
"pad_zero_ends",
"=",
"True",
",",
"prec... | 9c064f3cff0c41dd8acadc0f67c6350931275b9f |
train | spectral_density_vega | Flux equivalencies between PHOTLAM and VEGAMAG.
Parameters
----------
wav : `~astropy.units.quantity.Quantity`
Quantity associated with values being converted
(e.g., wavelength or frequency).
vegaflux : `~astropy.units.quantity.Quantity`
Flux of Vega at ``wav``.
Returns
... | synphot/units.py | def spectral_density_vega(wav, vegaflux):
"""Flux equivalencies between PHOTLAM and VEGAMAG.
Parameters
----------
wav : `~astropy.units.quantity.Quantity`
Quantity associated with values being converted
(e.g., wavelength or frequency).
vegaflux : `~astropy.units.quantity.Quantity`... | def spectral_density_vega(wav, vegaflux):
"""Flux equivalencies between PHOTLAM and VEGAMAG.
Parameters
----------
wav : `~astropy.units.quantity.Quantity`
Quantity associated with values being converted
(e.g., wavelength or frequency).
vegaflux : `~astropy.units.quantity.Quantity`... | [
"Flux",
"equivalencies",
"between",
"PHOTLAM",
"and",
"VEGAMAG",
"."
] | spacetelescope/synphot_refactor | python | https://github.com/spacetelescope/synphot_refactor/blob/9c064f3cff0c41dd8acadc0f67c6350931275b9f/synphot/units.py#L64-L99 | [
"def",
"spectral_density_vega",
"(",
"wav",
",",
"vegaflux",
")",
":",
"vega_photlam",
"=",
"vegaflux",
".",
"to",
"(",
"PHOTLAM",
",",
"equivalencies",
"=",
"u",
".",
"spectral_density",
"(",
"wav",
")",
")",
".",
"value",
"def",
"converter",
"(",
"x",
... | 9c064f3cff0c41dd8acadc0f67c6350931275b9f |
train | spectral_density_count | Flux equivalencies between PHOTLAM and count/OBMAG.
Parameters
----------
wav : `~astropy.units.quantity.Quantity`
Quantity associated with values being converted
(e.g., wavelength or frequency).
area : `~astropy.units.quantity.Quantity`
Telescope collecting area.
Returns
... | synphot/units.py | def spectral_density_count(wav, area):
"""Flux equivalencies between PHOTLAM and count/OBMAG.
Parameters
----------
wav : `~astropy.units.quantity.Quantity`
Quantity associated with values being converted
(e.g., wavelength or frequency).
area : `~astropy.units.quantity.Quantity`
... | def spectral_density_count(wav, area):
"""Flux equivalencies between PHOTLAM and count/OBMAG.
Parameters
----------
wav : `~astropy.units.quantity.Quantity`
Quantity associated with values being converted
(e.g., wavelength or frequency).
area : `~astropy.units.quantity.Quantity`
... | [
"Flux",
"equivalencies",
"between",
"PHOTLAM",
"and",
"count",
"/",
"OBMAG",
"."
] | spacetelescope/synphot_refactor | python | https://github.com/spacetelescope/synphot_refactor/blob/9c064f3cff0c41dd8acadc0f67c6350931275b9f/synphot/units.py#L102-L140 | [
"def",
"spectral_density_count",
"(",
"wav",
",",
"area",
")",
":",
"from",
".",
"binning",
"import",
"calculate_bin_widths",
",",
"calculate_bin_edges",
"wav",
"=",
"wav",
".",
"to",
"(",
"u",
".",
"AA",
",",
"equivalencies",
"=",
"u",
".",
"spectral",
"(... | 9c064f3cff0c41dd8acadc0f67c6350931275b9f |
train | convert_flux | Perform conversion for :ref:`supported flux units <synphot-flux-units>`.
Parameters
----------
wavelengths : array-like or `~astropy.units.quantity.Quantity`
Wavelength values. If not a Quantity, assumed to be in
Angstrom.
fluxes : array-like or `~astropy.units.quantity.Quantity`
... | synphot/units.py | def convert_flux(wavelengths, fluxes, out_flux_unit, **kwargs):
"""Perform conversion for :ref:`supported flux units <synphot-flux-units>`.
Parameters
----------
wavelengths : array-like or `~astropy.units.quantity.Quantity`
Wavelength values. If not a Quantity, assumed to be in
Angstro... | def convert_flux(wavelengths, fluxes, out_flux_unit, **kwargs):
"""Perform conversion for :ref:`supported flux units <synphot-flux-units>`.
Parameters
----------
wavelengths : array-like or `~astropy.units.quantity.Quantity`
Wavelength values. If not a Quantity, assumed to be in
Angstro... | [
"Perform",
"conversion",
"for",
":",
"ref",
":",
"supported",
"flux",
"units",
"<synphot",
"-",
"flux",
"-",
"units",
">",
"."
] | spacetelescope/synphot_refactor | python | https://github.com/spacetelescope/synphot_refactor/blob/9c064f3cff0c41dd8acadc0f67c6350931275b9f/synphot/units.py#L143-L225 | [
"def",
"convert_flux",
"(",
"wavelengths",
",",
"fluxes",
",",
"out_flux_unit",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"not",
"isinstance",
"(",
"fluxes",
",",
"u",
".",
"Quantity",
")",
":",
"fluxes",
"=",
"fluxes",
"*",
"PHOTLAM",
"out_flux_unit",
"=... | 9c064f3cff0c41dd8acadc0f67c6350931275b9f |
train | _convert_flux | Flux conversion for PHOTLAM <-> X. | synphot/units.py | def _convert_flux(wavelengths, fluxes, out_flux_unit, area=None,
vegaspec=None):
"""Flux conversion for PHOTLAM <-> X."""
flux_unit_names = (fluxes.unit.to_string(), out_flux_unit.to_string())
if PHOTLAM.to_string() not in flux_unit_names:
raise exceptions.SynphotError(
... | def _convert_flux(wavelengths, fluxes, out_flux_unit, area=None,
vegaspec=None):
"""Flux conversion for PHOTLAM <-> X."""
flux_unit_names = (fluxes.unit.to_string(), out_flux_unit.to_string())
if PHOTLAM.to_string() not in flux_unit_names:
raise exceptions.SynphotError(
... | [
"Flux",
"conversion",
"for",
"PHOTLAM",
"<",
"-",
">",
"X",
"."
] | spacetelescope/synphot_refactor | python | https://github.com/spacetelescope/synphot_refactor/blob/9c064f3cff0c41dd8acadc0f67c6350931275b9f/synphot/units.py#L228-L268 | [
"def",
"_convert_flux",
"(",
"wavelengths",
",",
"fluxes",
",",
"out_flux_unit",
",",
"area",
"=",
"None",
",",
"vegaspec",
"=",
"None",
")",
":",
"flux_unit_names",
"=",
"(",
"fluxes",
".",
"unit",
".",
"to_string",
"(",
")",
",",
"out_flux_unit",
".",
... | 9c064f3cff0c41dd8acadc0f67c6350931275b9f |
train | validate_unit | Validate unit.
To be compatible with existing SYNPHOT data files:
* 'angstroms' and 'inversemicrons' are accepted although
unrecognized by astropy units
* 'transmission', 'extinction', and 'emissivity' are
converted to astropy dimensionless unit
Parameters
----------
... | synphot/units.py | def validate_unit(input_unit):
"""Validate unit.
To be compatible with existing SYNPHOT data files:
* 'angstroms' and 'inversemicrons' are accepted although
unrecognized by astropy units
* 'transmission', 'extinction', and 'emissivity' are
converted to astropy dimensionless... | def validate_unit(input_unit):
"""Validate unit.
To be compatible with existing SYNPHOT data files:
* 'angstroms' and 'inversemicrons' are accepted although
unrecognized by astropy units
* 'transmission', 'extinction', and 'emissivity' are
converted to astropy dimensionless... | [
"Validate",
"unit",
"."
] | spacetelescope/synphot_refactor | python | https://github.com/spacetelescope/synphot_refactor/blob/9c064f3cff0c41dd8acadc0f67c6350931275b9f/synphot/units.py#L275-L335 | [
"def",
"validate_unit",
"(",
"input_unit",
")",
":",
"if",
"isinstance",
"(",
"input_unit",
",",
"str",
")",
":",
"input_unit_lowcase",
"=",
"input_unit",
".",
"lower",
"(",
")",
"# Backward-compatibility",
"if",
"input_unit_lowcase",
"==",
"'angstroms'",
":",
"... | 9c064f3cff0c41dd8acadc0f67c6350931275b9f |
train | validate_wave_unit | Like :func:`validate_unit` but specific to wavelength. | synphot/units.py | def validate_wave_unit(wave_unit):
"""Like :func:`validate_unit` but specific to wavelength."""
output_unit = validate_unit(wave_unit)
unit_type = output_unit.physical_type
if unit_type not in ('length', 'wavenumber', 'frequency'):
raise exceptions.SynphotError(
'wavelength physical... | def validate_wave_unit(wave_unit):
"""Like :func:`validate_unit` but specific to wavelength."""
output_unit = validate_unit(wave_unit)
unit_type = output_unit.physical_type
if unit_type not in ('length', 'wavenumber', 'frequency'):
raise exceptions.SynphotError(
'wavelength physical... | [
"Like",
":",
"func",
":",
"validate_unit",
"but",
"specific",
"to",
"wavelength",
"."
] | spacetelescope/synphot_refactor | python | https://github.com/spacetelescope/synphot_refactor/blob/9c064f3cff0c41dd8acadc0f67c6350931275b9f/synphot/units.py#L338-L348 | [
"def",
"validate_wave_unit",
"(",
"wave_unit",
")",
":",
"output_unit",
"=",
"validate_unit",
"(",
"wave_unit",
")",
"unit_type",
"=",
"output_unit",
".",
"physical_type",
"if",
"unit_type",
"not",
"in",
"(",
"'length'",
",",
"'wavenumber'",
",",
"'frequency'",
... | 9c064f3cff0c41dd8acadc0f67c6350931275b9f |
train | validate_quantity | Validate quantity (value and unit).
.. note::
For flux conversion, use :func:`convert_flux` instead.
Parameters
----------
input_value : number, array-like, or `~astropy.units.quantity.Quantity`
Quantity to validate. If not a Quantity, assumed to be
already in output unit.
... | synphot/units.py | def validate_quantity(input_value, output_unit, equivalencies=[]):
"""Validate quantity (value and unit).
.. note::
For flux conversion, use :func:`convert_flux` instead.
Parameters
----------
input_value : number, array-like, or `~astropy.units.quantity.Quantity`
Quantity to vali... | def validate_quantity(input_value, output_unit, equivalencies=[]):
"""Validate quantity (value and unit).
.. note::
For flux conversion, use :func:`convert_flux` instead.
Parameters
----------
input_value : number, array-like, or `~astropy.units.quantity.Quantity`
Quantity to vali... | [
"Validate",
"quantity",
"(",
"value",
"and",
"unit",
")",
"."
] | spacetelescope/synphot_refactor | python | https://github.com/spacetelescope/synphot_refactor/blob/9c064f3cff0c41dd8acadc0f67c6350931275b9f/synphot/units.py#L351-L383 | [
"def",
"validate_quantity",
"(",
"input_value",
",",
"output_unit",
",",
"equivalencies",
"=",
"[",
"]",
")",
":",
"output_unit",
"=",
"validate_unit",
"(",
"output_unit",
")",
"if",
"isinstance",
"(",
"input_value",
",",
"u",
".",
"Quantity",
")",
":",
"out... | 9c064f3cff0c41dd8acadc0f67c6350931275b9f |
train | Devices.add | Add device. | old_api/pyvlx/devices.py | def add(self, device):
"""Add device."""
if not isinstance(device, Device):
raise TypeError()
self.__devices.append(device) | def add(self, device):
"""Add device."""
if not isinstance(device, Device):
raise TypeError()
self.__devices.append(device) | [
"Add",
"device",
"."
] | Julius2342/pyvlx | python | https://github.com/Julius2342/pyvlx/blob/ee78e1324bcb1be5b8d1a9d05ab5496b72eae848/old_api/pyvlx/devices.py#L36-L40 | [
"def",
"add",
"(",
"self",
",",
"device",
")",
":",
"if",
"not",
"isinstance",
"(",
"device",
",",
"Device",
")",
":",
"raise",
"TypeError",
"(",
")",
"self",
".",
"__devices",
".",
"append",
"(",
"device",
")"
] | ee78e1324bcb1be5b8d1a9d05ab5496b72eae848 |
train | Devices.data_import | Import data from json response. | old_api/pyvlx/devices.py | def data_import(self, json_response):
"""Import data from json response."""
if 'data' not in json_response:
raise PyVLXException('no element data found: {0}'.format(
json.dumps(json_response)))
data = json_response['data']
for item in data:
if 'ca... | def data_import(self, json_response):
"""Import data from json response."""
if 'data' not in json_response:
raise PyVLXException('no element data found: {0}'.format(
json.dumps(json_response)))
data = json_response['data']
for item in data:
if 'ca... | [
"Import",
"data",
"from",
"json",
"response",
"."
] | Julius2342/pyvlx | python | https://github.com/Julius2342/pyvlx/blob/ee78e1324bcb1be5b8d1a9d05ab5496b72eae848/old_api/pyvlx/devices.py#L47-L67 | [
"def",
"data_import",
"(",
"self",
",",
"json_response",
")",
":",
"if",
"'data'",
"not",
"in",
"json_response",
":",
"raise",
"PyVLXException",
"(",
"'no element data found: {0}'",
".",
"format",
"(",
"json",
".",
"dumps",
"(",
"json_response",
")",
")",
")",... | ee78e1324bcb1be5b8d1a9d05ab5496b72eae848 |
train | Devices.load_window_opener | Load window opener from JSON. | old_api/pyvlx/devices.py | def load_window_opener(self, item):
"""Load window opener from JSON."""
window = Window.from_config(self.pyvlx, item)
self.add(window) | def load_window_opener(self, item):
"""Load window opener from JSON."""
window = Window.from_config(self.pyvlx, item)
self.add(window) | [
"Load",
"window",
"opener",
"from",
"JSON",
"."
] | Julius2342/pyvlx | python | https://github.com/Julius2342/pyvlx/blob/ee78e1324bcb1be5b8d1a9d05ab5496b72eae848/old_api/pyvlx/devices.py#L69-L72 | [
"def",
"load_window_opener",
"(",
"self",
",",
"item",
")",
":",
"window",
"=",
"Window",
".",
"from_config",
"(",
"self",
".",
"pyvlx",
",",
"item",
")",
"self",
".",
"add",
"(",
"window",
")"
] | ee78e1324bcb1be5b8d1a9d05ab5496b72eae848 |
train | Devices.load_roller_shutter | Load roller shutter from JSON. | old_api/pyvlx/devices.py | def load_roller_shutter(self, item):
"""Load roller shutter from JSON."""
rollershutter = RollerShutter.from_config(self.pyvlx, item)
self.add(rollershutter) | def load_roller_shutter(self, item):
"""Load roller shutter from JSON."""
rollershutter = RollerShutter.from_config(self.pyvlx, item)
self.add(rollershutter) | [
"Load",
"roller",
"shutter",
"from",
"JSON",
"."
] | Julius2342/pyvlx | python | https://github.com/Julius2342/pyvlx/blob/ee78e1324bcb1be5b8d1a9d05ab5496b72eae848/old_api/pyvlx/devices.py#L74-L77 | [
"def",
"load_roller_shutter",
"(",
"self",
",",
"item",
")",
":",
"rollershutter",
"=",
"RollerShutter",
".",
"from_config",
"(",
"self",
".",
"pyvlx",
",",
"item",
")",
"self",
".",
"add",
"(",
"rollershutter",
")"
] | ee78e1324bcb1be5b8d1a9d05ab5496b72eae848 |
train | Devices.load_blind | Load blind from JSON. | old_api/pyvlx/devices.py | def load_blind(self, item):
"""Load blind from JSON."""
blind = Blind.from_config(self.pyvlx, item)
self.add(blind) | def load_blind(self, item):
"""Load blind from JSON."""
blind = Blind.from_config(self.pyvlx, item)
self.add(blind) | [
"Load",
"blind",
"from",
"JSON",
"."
] | Julius2342/pyvlx | python | https://github.com/Julius2342/pyvlx/blob/ee78e1324bcb1be5b8d1a9d05ab5496b72eae848/old_api/pyvlx/devices.py#L79-L82 | [
"def",
"load_blind",
"(",
"self",
",",
"item",
")",
":",
"blind",
"=",
"Blind",
".",
"from_config",
"(",
"self",
".",
"pyvlx",
",",
"item",
")",
"self",
".",
"add",
"(",
"blind",
")"
] | ee78e1324bcb1be5b8d1a9d05ab5496b72eae848 |
train | get_terminal_size | Return tuple containing columns and rows of controlling terminal, trying harder
than shutil.get_terminal_size to find a tty before returning fallback.
Theoretically, stdout, stderr, and stdin could all be different ttys that could
cause us to get the wrong measurements (instead of using the fallback) but t... | style50/_api.py | def get_terminal_size(fallback=(80, 24)):
"""
Return tuple containing columns and rows of controlling terminal, trying harder
than shutil.get_terminal_size to find a tty before returning fallback.
Theoretically, stdout, stderr, and stdin could all be different ttys that could
cause us to get the wr... | def get_terminal_size(fallback=(80, 24)):
"""
Return tuple containing columns and rows of controlling terminal, trying harder
than shutil.get_terminal_size to find a tty before returning fallback.
Theoretically, stdout, stderr, and stdin could all be different ttys that could
cause us to get the wr... | [
"Return",
"tuple",
"containing",
"columns",
"and",
"rows",
"of",
"controlling",
"terminal",
"trying",
"harder",
"than",
"shutil",
".",
"get_terminal_size",
"to",
"find",
"a",
"tty",
"before",
"returning",
"fallback",
"."
] | cs50/style50 | python | https://github.com/cs50/style50/blob/2dfe5957f7b727ee5163499e7b8191275aee914c/style50/_api.py#L23-L45 | [
"def",
"get_terminal_size",
"(",
"fallback",
"=",
"(",
"80",
",",
"24",
")",
")",
":",
"for",
"stream",
"in",
"[",
"sys",
".",
"__stdout__",
",",
"sys",
".",
"__stderr__",
",",
"sys",
".",
"__stdin__",
"]",
":",
"try",
":",
"# Make WINSIZE call to termin... | 2dfe5957f7b727ee5163499e7b8191275aee914c |
train | Style50.run_diff | Run checks on self.files, printing diff of styled/unstyled output to stdout. | style50/_api.py | def run_diff(self):
"""
Run checks on self.files, printing diff of styled/unstyled output to stdout.
"""
files = tuple(self.files)
# Use same header as more.
header, footer = (termcolor.colored("{0}\n{{}}\n{0}\n".format(
":" * 14), "cyan"), "\n") if len(files)... | def run_diff(self):
"""
Run checks on self.files, printing diff of styled/unstyled output to stdout.
"""
files = tuple(self.files)
# Use same header as more.
header, footer = (termcolor.colored("{0}\n{{}}\n{0}\n".format(
":" * 14), "cyan"), "\n") if len(files)... | [
"Run",
"checks",
"on",
"self",
".",
"files",
"printing",
"diff",
"of",
"styled",
"/",
"unstyled",
"output",
"to",
"stdout",
"."
] | cs50/style50 | python | https://github.com/cs50/style50/blob/2dfe5957f7b727ee5163499e7b8191275aee914c/style50/_api.py#L96-L134 | [
"def",
"run_diff",
"(",
"self",
")",
":",
"files",
"=",
"tuple",
"(",
"self",
".",
"files",
")",
"# Use same header as more.",
"header",
",",
"footer",
"=",
"(",
"termcolor",
".",
"colored",
"(",
"\"{0}\\n{{}}\\n{0}\\n\"",
".",
"format",
"(",
"\":\"",
"*",
... | 2dfe5957f7b727ee5163499e7b8191275aee914c |
train | Style50.run_json | Run checks on self.files, printing json object
containing information relavent to the CS50 IDE plugin at the end. | style50/_api.py | def run_json(self):
"""
Run checks on self.files, printing json object
containing information relavent to the CS50 IDE plugin at the end.
"""
checks = {}
for file in self.files:
try:
results = self._check(file)
except Error as e:
... | def run_json(self):
"""
Run checks on self.files, printing json object
containing information relavent to the CS50 IDE plugin at the end.
"""
checks = {}
for file in self.files:
try:
results = self._check(file)
except Error as e:
... | [
"Run",
"checks",
"on",
"self",
".",
"files",
"printing",
"json",
"object",
"containing",
"information",
"relavent",
"to",
"the",
"CS50",
"IDE",
"plugin",
"at",
"the",
"end",
"."
] | cs50/style50 | python | https://github.com/cs50/style50/blob/2dfe5957f7b727ee5163499e7b8191275aee914c/style50/_api.py#L136-L157 | [
"def",
"run_json",
"(",
"self",
")",
":",
"checks",
"=",
"{",
"}",
"for",
"file",
"in",
"self",
".",
"files",
":",
"try",
":",
"results",
"=",
"self",
".",
"_check",
"(",
"file",
")",
"except",
"Error",
"as",
"e",
":",
"checks",
"[",
"file",
"]",... | 2dfe5957f7b727ee5163499e7b8191275aee914c |
train | Style50.run_score | Run checks on self.files, printing raw percentage to stdout. | style50/_api.py | def run_score(self):
"""
Run checks on self.files, printing raw percentage to stdout.
"""
diffs = 0
lines = 0
for file in self.files:
try:
results = self._check(file)
except Error as e:
termcolor.cprint(e.msg, "yell... | def run_score(self):
"""
Run checks on self.files, printing raw percentage to stdout.
"""
diffs = 0
lines = 0
for file in self.files:
try:
results = self._check(file)
except Error as e:
termcolor.cprint(e.msg, "yell... | [
"Run",
"checks",
"on",
"self",
".",
"files",
"printing",
"raw",
"percentage",
"to",
"stdout",
"."
] | cs50/style50 | python | https://github.com/cs50/style50/blob/2dfe5957f7b727ee5163499e7b8191275aee914c/style50/_api.py#L159-L179 | [
"def",
"run_score",
"(",
"self",
")",
":",
"diffs",
"=",
"0",
"lines",
"=",
"0",
"for",
"file",
"in",
"self",
".",
"files",
":",
"try",
":",
"results",
"=",
"self",
".",
"_check",
"(",
"file",
")",
"except",
"Error",
"as",
"e",
":",
"termcolor",
... | 2dfe5957f7b727ee5163499e7b8191275aee914c |
train | Style50._check | Run apropriate check based on `file`'s extension and return it,
otherwise raise an Error | style50/_api.py | def _check(self, file):
"""
Run apropriate check based on `file`'s extension and return it,
otherwise raise an Error
"""
if not os.path.exists(file):
raise Error("file \"{}\" not found".format(file))
_, extension = os.path.splitext(file)
try:
... | def _check(self, file):
"""
Run apropriate check based on `file`'s extension and return it,
otherwise raise an Error
"""
if not os.path.exists(file):
raise Error("file \"{}\" not found".format(file))
_, extension = os.path.splitext(file)
try:
... | [
"Run",
"apropriate",
"check",
"based",
"on",
"file",
"s",
"extension",
"and",
"return",
"it",
"otherwise",
"raise",
"an",
"Error"
] | cs50/style50 | python | https://github.com/cs50/style50/blob/2dfe5957f7b727ee5163499e7b8191275aee914c/style50/_api.py#L181-L215 | [
"def",
"_check",
"(",
"self",
",",
"file",
")",
":",
"if",
"not",
"os",
".",
"path",
".",
"exists",
"(",
"file",
")",
":",
"raise",
"Error",
"(",
"\"file \\\"{}\\\" not found\"",
".",
"format",
"(",
"file",
")",
")",
"_",
",",
"extension",
"=",
"os",... | 2dfe5957f7b727ee5163499e7b8191275aee914c |
train | Style50.split_diff | Returns a generator yielding the side-by-side diff of `old` and `new`). | style50/_api.py | def split_diff(old, new):
"""
Returns a generator yielding the side-by-side diff of `old` and `new`).
"""
return map(lambda l: l.rstrip(),
icdiff.ConsoleDiff(cols=COLUMNS).make_table(old.splitlines(), new.splitlines())) | def split_diff(old, new):
"""
Returns a generator yielding the side-by-side diff of `old` and `new`).
"""
return map(lambda l: l.rstrip(),
icdiff.ConsoleDiff(cols=COLUMNS).make_table(old.splitlines(), new.splitlines())) | [
"Returns",
"a",
"generator",
"yielding",
"the",
"side",
"-",
"by",
"-",
"side",
"diff",
"of",
"old",
"and",
"new",
")",
"."
] | cs50/style50 | python | https://github.com/cs50/style50/blob/2dfe5957f7b727ee5163499e7b8191275aee914c/style50/_api.py#L218-L223 | [
"def",
"split_diff",
"(",
"old",
",",
"new",
")",
":",
"return",
"map",
"(",
"lambda",
"l",
":",
"l",
".",
"rstrip",
"(",
")",
",",
"icdiff",
".",
"ConsoleDiff",
"(",
"cols",
"=",
"COLUMNS",
")",
".",
"make_table",
"(",
"old",
".",
"splitlines",
"(... | 2dfe5957f7b727ee5163499e7b8191275aee914c |
train | Style50.unified | Returns a generator yielding a unified diff between `old` and `new`. | style50/_api.py | def unified(old, new):
"""
Returns a generator yielding a unified diff between `old` and `new`.
"""
for diff in difflib.ndiff(old.splitlines(), new.splitlines()):
if diff[0] == " ":
yield diff
elif diff[0] == "?":
continue
... | def unified(old, new):
"""
Returns a generator yielding a unified diff between `old` and `new`.
"""
for diff in difflib.ndiff(old.splitlines(), new.splitlines()):
if diff[0] == " ":
yield diff
elif diff[0] == "?":
continue
... | [
"Returns",
"a",
"generator",
"yielding",
"a",
"unified",
"diff",
"between",
"old",
"and",
"new",
"."
] | cs50/style50 | python | https://github.com/cs50/style50/blob/2dfe5957f7b727ee5163499e7b8191275aee914c/style50/_api.py#L226-L236 | [
"def",
"unified",
"(",
"old",
",",
"new",
")",
":",
"for",
"diff",
"in",
"difflib",
".",
"ndiff",
"(",
"old",
".",
"splitlines",
"(",
")",
",",
"new",
".",
"splitlines",
"(",
")",
")",
":",
"if",
"diff",
"[",
"0",
"]",
"==",
"\" \"",
":",
"yiel... | 2dfe5957f7b727ee5163499e7b8191275aee914c |
train | Style50.html_diff | Return HTML formatted character-based diff between old and new (used for CS50 IDE). | style50/_api.py | def html_diff(self, old, new):
"""
Return HTML formatted character-based diff between old and new (used for CS50 IDE).
"""
def html_transition(old_type, new_type):
tags = []
for tag in [("/", old_type), ("", new_type)]:
if tag[1] not in ["+", "-"]:... | def html_diff(self, old, new):
"""
Return HTML formatted character-based diff between old and new (used for CS50 IDE).
"""
def html_transition(old_type, new_type):
tags = []
for tag in [("/", old_type), ("", new_type)]:
if tag[1] not in ["+", "-"]:... | [
"Return",
"HTML",
"formatted",
"character",
"-",
"based",
"diff",
"between",
"old",
"and",
"new",
"(",
"used",
"for",
"CS50",
"IDE",
")",
"."
] | cs50/style50 | python | https://github.com/cs50/style50/blob/2dfe5957f7b727ee5163499e7b8191275aee914c/style50/_api.py#L238-L250 | [
"def",
"html_diff",
"(",
"self",
",",
"old",
",",
"new",
")",
":",
"def",
"html_transition",
"(",
"old_type",
",",
"new_type",
")",
":",
"tags",
"=",
"[",
"]",
"for",
"tag",
"in",
"[",
"(",
"\"/\"",
",",
"old_type",
")",
",",
"(",
"\"\"",
",",
"n... | 2dfe5957f7b727ee5163499e7b8191275aee914c |
train | Style50.char_diff | Return color-coded character-based diff between `old` and `new`. | style50/_api.py | def char_diff(self, old, new):
"""
Return color-coded character-based diff between `old` and `new`.
"""
def color_transition(old_type, new_type):
new_color = termcolor.colored("", None, "on_red" if new_type ==
"-" else "on_green" if n... | def char_diff(self, old, new):
"""
Return color-coded character-based diff between `old` and `new`.
"""
def color_transition(old_type, new_type):
new_color = termcolor.colored("", None, "on_red" if new_type ==
"-" else "on_green" if n... | [
"Return",
"color",
"-",
"coded",
"character",
"-",
"based",
"diff",
"between",
"old",
"and",
"new",
"."
] | cs50/style50 | python | https://github.com/cs50/style50/blob/2dfe5957f7b727ee5163499e7b8191275aee914c/style50/_api.py#L252-L261 | [
"def",
"char_diff",
"(",
"self",
",",
"old",
",",
"new",
")",
":",
"def",
"color_transition",
"(",
"old_type",
",",
"new_type",
")",
":",
"new_color",
"=",
"termcolor",
".",
"colored",
"(",
"\"\"",
",",
"None",
",",
"\"on_red\"",
"if",
"new_type",
"==",
... | 2dfe5957f7b727ee5163499e7b8191275aee914c |
train | Style50._char_diff | Returns a char-based diff between `old` and `new` where each character
is formatted by `fmt` and transitions between blocks are determined by `transition`. | style50/_api.py | def _char_diff(self, old, new, transition, fmt=lambda c: c):
"""
Returns a char-based diff between `old` and `new` where each character
is formatted by `fmt` and transitions between blocks are determined by `transition`.
"""
differ = difflib.ndiff(old, new)
# Type of di... | def _char_diff(self, old, new, transition, fmt=lambda c: c):
"""
Returns a char-based diff between `old` and `new` where each character
is formatted by `fmt` and transitions between blocks are determined by `transition`.
"""
differ = difflib.ndiff(old, new)
# Type of di... | [
"Returns",
"a",
"char",
"-",
"based",
"diff",
"between",
"old",
"and",
"new",
"where",
"each",
"character",
"is",
"formatted",
"by",
"fmt",
"and",
"transitions",
"between",
"blocks",
"are",
"determined",
"by",
"transition",
"."
] | cs50/style50 | python | https://github.com/cs50/style50/blob/2dfe5957f7b727ee5163499e7b8191275aee914c/style50/_api.py#L263-L309 | [
"def",
"_char_diff",
"(",
"self",
",",
"old",
",",
"new",
",",
"transition",
",",
"fmt",
"=",
"lambda",
"c",
":",
"c",
")",
":",
"differ",
"=",
"difflib",
".",
"ndiff",
"(",
"old",
",",
"new",
")",
"# Type of difference.",
"dtype",
"=",
"None",
"# Bu... | 2dfe5957f7b727ee5163499e7b8191275aee914c |
train | StyleCheck.count_lines | Count lines of code (by default ignores empty lines, but child could override to do more). | style50/_api.py | def count_lines(self, code):
"""
Count lines of code (by default ignores empty lines, but child could override to do more).
"""
return sum(bool(line.strip()) for line in code.splitlines()) | def count_lines(self, code):
"""
Count lines of code (by default ignores empty lines, but child could override to do more).
"""
return sum(bool(line.strip()) for line in code.splitlines()) | [
"Count",
"lines",
"of",
"code",
"(",
"by",
"default",
"ignores",
"empty",
"lines",
"but",
"child",
"could",
"override",
"to",
"do",
"more",
")",
"."
] | cs50/style50 | python | https://github.com/cs50/style50/blob/2dfe5957f7b727ee5163499e7b8191275aee914c/style50/_api.py#L366-L370 | [
"def",
"count_lines",
"(",
"self",
",",
"code",
")",
":",
"return",
"sum",
"(",
"bool",
"(",
"line",
".",
"strip",
"(",
")",
")",
"for",
"line",
"in",
"code",
".",
"splitlines",
"(",
")",
")"
] | 2dfe5957f7b727ee5163499e7b8191275aee914c |
train | StyleCheck.run | Run `command` passing it stdin from `input`, throwing a DependencyError if comand is not found.
Throws Error if exit code of command is not `exit` (unless `exit` is None). | style50/_api.py | def run(command, input=None, exit=0, shell=False):
"""
Run `command` passing it stdin from `input`, throwing a DependencyError if comand is not found.
Throws Error if exit code of command is not `exit` (unless `exit` is None).
"""
if isinstance(input, str):
input = in... | def run(command, input=None, exit=0, shell=False):
"""
Run `command` passing it stdin from `input`, throwing a DependencyError if comand is not found.
Throws Error if exit code of command is not `exit` (unless `exit` is None).
"""
if isinstance(input, str):
input = in... | [
"Run",
"command",
"passing",
"it",
"stdin",
"from",
"input",
"throwing",
"a",
"DependencyError",
"if",
"comand",
"is",
"not",
"found",
".",
"Throws",
"Error",
"if",
"exit",
"code",
"of",
"command",
"is",
"not",
"exit",
"(",
"unless",
"exit",
"is",
"None",
... | cs50/style50 | python | https://github.com/cs50/style50/blob/2dfe5957f7b727ee5163499e7b8191275aee914c/style50/_api.py#L373-L394 | [
"def",
"run",
"(",
"command",
",",
"input",
"=",
"None",
",",
"exit",
"=",
"0",
",",
"shell",
"=",
"False",
")",
":",
"if",
"isinstance",
"(",
"input",
",",
"str",
")",
":",
"input",
"=",
"input",
".",
"encode",
"(",
")",
"# Only pipe stdin if we hav... | 2dfe5957f7b727ee5163499e7b8191275aee914c |
train | frame_from_raw | Create and return frame from raw bytes. | pyvlx/frame_creation.py | def frame_from_raw(raw):
"""Create and return frame from raw bytes."""
command, payload = extract_from_frame(raw)
frame = create_frame(command)
if frame is None:
PYVLXLOG.warning("Command %s not implemented, raw: %s", command, ":".join("{:02x}".format(c) for c in raw))
return None
fr... | def frame_from_raw(raw):
"""Create and return frame from raw bytes."""
command, payload = extract_from_frame(raw)
frame = create_frame(command)
if frame is None:
PYVLXLOG.warning("Command %s not implemented, raw: %s", command, ":".join("{:02x}".format(c) for c in raw))
return None
fr... | [
"Create",
"and",
"return",
"frame",
"from",
"raw",
"bytes",
"."
] | Julius2342/pyvlx | python | https://github.com/Julius2342/pyvlx/blob/ee78e1324bcb1be5b8d1a9d05ab5496b72eae848/pyvlx/frame_creation.py#L32-L41 | [
"def",
"frame_from_raw",
"(",
"raw",
")",
":",
"command",
",",
"payload",
"=",
"extract_from_frame",
"(",
"raw",
")",
"frame",
"=",
"create_frame",
"(",
"command",
")",
"if",
"frame",
"is",
"None",
":",
"PYVLXLOG",
".",
"warning",
"(",
"\"Command %s not impl... | ee78e1324bcb1be5b8d1a9d05ab5496b72eae848 |
train | create_frame | Create and return empty Frame from Command. | pyvlx/frame_creation.py | def create_frame(command):
"""Create and return empty Frame from Command."""
# pylint: disable=too-many-branches,too-many-return-statements
if command == Command.GW_ERROR_NTF:
return FrameErrorNotification()
if command == Command.GW_COMMAND_SEND_REQ:
return FrameCommandSendRequest()
... | def create_frame(command):
"""Create and return empty Frame from Command."""
# pylint: disable=too-many-branches,too-many-return-statements
if command == Command.GW_ERROR_NTF:
return FrameErrorNotification()
if command == Command.GW_COMMAND_SEND_REQ:
return FrameCommandSendRequest()
... | [
"Create",
"and",
"return",
"empty",
"Frame",
"from",
"Command",
"."
] | Julius2342/pyvlx | python | https://github.com/Julius2342/pyvlx/blob/ee78e1324bcb1be5b8d1a9d05ab5496b72eae848/pyvlx/frame_creation.py#L44-L142 | [
"def",
"create_frame",
"(",
"command",
")",
":",
"# pylint: disable=too-many-branches,too-many-return-statements",
"if",
"command",
"==",
"Command",
".",
"GW_ERROR_NTF",
":",
"return",
"FrameErrorNotification",
"(",
")",
"if",
"command",
"==",
"Command",
".",
"GW_COMMAN... | ee78e1324bcb1be5b8d1a9d05ab5496b72eae848 |
train | Login.handle_frame | Handle incoming API frame, return True if this was the expected frame. | pyvlx/login.py | async def handle_frame(self, frame):
"""Handle incoming API frame, return True if this was the expected frame."""
if not isinstance(frame, FramePasswordEnterConfirmation):
return False
if frame.status == PasswordEnterConfirmationStatus.FAILED:
PYVLXLOG.warning('Failed to ... | async def handle_frame(self, frame):
"""Handle incoming API frame, return True if this was the expected frame."""
if not isinstance(frame, FramePasswordEnterConfirmation):
return False
if frame.status == PasswordEnterConfirmationStatus.FAILED:
PYVLXLOG.warning('Failed to ... | [
"Handle",
"incoming",
"API",
"frame",
"return",
"True",
"if",
"this",
"was",
"the",
"expected",
"frame",
"."
] | Julius2342/pyvlx | python | https://github.com/Julius2342/pyvlx/blob/ee78e1324bcb1be5b8d1a9d05ab5496b72eae848/pyvlx/login.py#L18-L27 | [
"async",
"def",
"handle_frame",
"(",
"self",
",",
"frame",
")",
":",
"if",
"not",
"isinstance",
"(",
"frame",
",",
"FramePasswordEnterConfirmation",
")",
":",
"return",
"False",
"if",
"frame",
".",
"status",
"==",
"PasswordEnterConfirmationStatus",
".",
"FAILED"... | ee78e1324bcb1be5b8d1a9d05ab5496b72eae848 |
train | FrameGetProtocolVersionConfirmation.get_payload | Return Payload. | pyvlx/frames/frame_get_protocol_version.py | def get_payload(self):
"""Return Payload."""
return bytes(
[self.major_version >> 8 & 255, self.major_version & 255,
self.minor_version >> 8 & 255, self.minor_version & 255]) | def get_payload(self):
"""Return Payload."""
return bytes(
[self.major_version >> 8 & 255, self.major_version & 255,
self.minor_version >> 8 & 255, self.minor_version & 255]) | [
"Return",
"Payload",
"."
] | Julius2342/pyvlx | python | https://github.com/Julius2342/pyvlx/blob/ee78e1324bcb1be5b8d1a9d05ab5496b72eae848/pyvlx/frames/frame_get_protocol_version.py#L33-L37 | [
"def",
"get_payload",
"(",
"self",
")",
":",
"return",
"bytes",
"(",
"[",
"self",
".",
"major_version",
">>",
"8",
"&",
"255",
",",
"self",
".",
"major_version",
"&",
"255",
",",
"self",
".",
"minor_version",
">>",
"8",
"&",
"255",
",",
"self",
".",
... | ee78e1324bcb1be5b8d1a9d05ab5496b72eae848 |
train | FrameGetProtocolVersionConfirmation.from_payload | Init frame from binary data. | pyvlx/frames/frame_get_protocol_version.py | def from_payload(self, payload):
"""Init frame from binary data."""
self.major_version = payload[0] * 256 + payload[1]
self.minor_version = payload[2] * 256 + payload[3] | def from_payload(self, payload):
"""Init frame from binary data."""
self.major_version = payload[0] * 256 + payload[1]
self.minor_version = payload[2] * 256 + payload[3] | [
"Init",
"frame",
"from",
"binary",
"data",
"."
] | Julius2342/pyvlx | python | https://github.com/Julius2342/pyvlx/blob/ee78e1324bcb1be5b8d1a9d05ab5496b72eae848/pyvlx/frames/frame_get_protocol_version.py#L39-L42 | [
"def",
"from_payload",
"(",
"self",
",",
"payload",
")",
":",
"self",
".",
"major_version",
"=",
"payload",
"[",
"0",
"]",
"*",
"256",
"+",
"payload",
"[",
"1",
"]",
"self",
".",
"minor_version",
"=",
"payload",
"[",
"2",
"]",
"*",
"256",
"+",
"pay... | ee78e1324bcb1be5b8d1a9d05ab5496b72eae848 |
train | TCPTransport.data_received | Handle data received. | pyvlx/connection.py | def data_received(self, data):
"""Handle data received."""
self.tokenizer.feed(data)
while self.tokenizer.has_tokens():
raw = self.tokenizer.get_next_token()
frame = frame_from_raw(raw)
if frame is not None:
self.frame_received_cb(frame) | def data_received(self, data):
"""Handle data received."""
self.tokenizer.feed(data)
while self.tokenizer.has_tokens():
raw = self.tokenizer.get_next_token()
frame = frame_from_raw(raw)
if frame is not None:
self.frame_received_cb(frame) | [
"Handle",
"data",
"received",
"."
] | Julius2342/pyvlx | python | https://github.com/Julius2342/pyvlx/blob/ee78e1324bcb1be5b8d1a9d05ab5496b72eae848/pyvlx/connection.py#L47-L54 | [
"def",
"data_received",
"(",
"self",
",",
"data",
")",
":",
"self",
".",
"tokenizer",
".",
"feed",
"(",
"data",
")",
"while",
"self",
".",
"tokenizer",
".",
"has_tokens",
"(",
")",
":",
"raw",
"=",
"self",
".",
"tokenizer",
".",
"get_next_token",
"(",
... | ee78e1324bcb1be5b8d1a9d05ab5496b72eae848 |
train | Connection.connect | Connect to gateway via SSL. | pyvlx/connection.py | async def connect(self):
"""Connect to gateway via SSL."""
tcp_client = TCPTransport(self.frame_received_cb, self.connection_closed_cb)
self.transport, _ = await self.loop.create_connection(
lambda: tcp_client,
host=self.config.host,
port=self.config.port,
... | async def connect(self):
"""Connect to gateway via SSL."""
tcp_client = TCPTransport(self.frame_received_cb, self.connection_closed_cb)
self.transport, _ = await self.loop.create_connection(
lambda: tcp_client,
host=self.config.host,
port=self.config.port,
... | [
"Connect",
"to",
"gateway",
"via",
"SSL",
"."
] | Julius2342/pyvlx | python | https://github.com/Julius2342/pyvlx/blob/ee78e1324bcb1be5b8d1a9d05ab5496b72eae848/pyvlx/connection.py#L82-L90 | [
"async",
"def",
"connect",
"(",
"self",
")",
":",
"tcp_client",
"=",
"TCPTransport",
"(",
"self",
".",
"frame_received_cb",
",",
"self",
".",
"connection_closed_cb",
")",
"self",
".",
"transport",
",",
"_",
"=",
"await",
"self",
".",
"loop",
".",
"create_c... | ee78e1324bcb1be5b8d1a9d05ab5496b72eae848 |
train | Connection.write | Write frame to Bus. | pyvlx/connection.py | def write(self, frame):
"""Write frame to Bus."""
if not isinstance(frame, FrameBase):
raise PyVLXException("Frame not of type FrameBase", frame_type=type(frame))
PYVLXLOG.debug("SEND: %s", frame)
self.transport.write(slip_pack(bytes(frame))) | def write(self, frame):
"""Write frame to Bus."""
if not isinstance(frame, FrameBase):
raise PyVLXException("Frame not of type FrameBase", frame_type=type(frame))
PYVLXLOG.debug("SEND: %s", frame)
self.transport.write(slip_pack(bytes(frame))) | [
"Write",
"frame",
"to",
"Bus",
"."
] | Julius2342/pyvlx | python | https://github.com/Julius2342/pyvlx/blob/ee78e1324bcb1be5b8d1a9d05ab5496b72eae848/pyvlx/connection.py#L100-L105 | [
"def",
"write",
"(",
"self",
",",
"frame",
")",
":",
"if",
"not",
"isinstance",
"(",
"frame",
",",
"FrameBase",
")",
":",
"raise",
"PyVLXException",
"(",
"\"Frame not of type FrameBase\"",
",",
"frame_type",
"=",
"type",
"(",
"frame",
")",
")",
"PYVLXLOG",
... | ee78e1324bcb1be5b8d1a9d05ab5496b72eae848 |
train | Connection.create_ssl_context | Create and return SSL Context. | pyvlx/connection.py | def create_ssl_context():
"""Create and return SSL Context."""
ssl_context = ssl.create_default_context(ssl.Purpose.SERVER_AUTH)
ssl_context.check_hostname = False
ssl_context.verify_mode = ssl.CERT_NONE
return ssl_context | def create_ssl_context():
"""Create and return SSL Context."""
ssl_context = ssl.create_default_context(ssl.Purpose.SERVER_AUTH)
ssl_context.check_hostname = False
ssl_context.verify_mode = ssl.CERT_NONE
return ssl_context | [
"Create",
"and",
"return",
"SSL",
"Context",
"."
] | Julius2342/pyvlx | python | https://github.com/Julius2342/pyvlx/blob/ee78e1324bcb1be5b8d1a9d05ab5496b72eae848/pyvlx/connection.py#L108-L113 | [
"def",
"create_ssl_context",
"(",
")",
":",
"ssl_context",
"=",
"ssl",
".",
"create_default_context",
"(",
"ssl",
".",
"Purpose",
".",
"SERVER_AUTH",
")",
"ssl_context",
".",
"check_hostname",
"=",
"False",
"ssl_context",
".",
"verify_mode",
"=",
"ssl",
".",
"... | ee78e1324bcb1be5b8d1a9d05ab5496b72eae848 |
train | Connection.frame_received_cb | Received message. | pyvlx/connection.py | def frame_received_cb(self, frame):
"""Received message."""
PYVLXLOG.debug("REC: %s", frame)
for frame_received_cb in self.frame_received_cbs:
# pylint: disable=not-callable
self.loop.create_task(frame_received_cb(frame)) | def frame_received_cb(self, frame):
"""Received message."""
PYVLXLOG.debug("REC: %s", frame)
for frame_received_cb in self.frame_received_cbs:
# pylint: disable=not-callable
self.loop.create_task(frame_received_cb(frame)) | [
"Received",
"message",
"."
] | Julius2342/pyvlx | python | https://github.com/Julius2342/pyvlx/blob/ee78e1324bcb1be5b8d1a9d05ab5496b72eae848/pyvlx/connection.py#L115-L120 | [
"def",
"frame_received_cb",
"(",
"self",
",",
"frame",
")",
":",
"PYVLXLOG",
".",
"debug",
"(",
"\"REC: %s\"",
",",
"frame",
")",
"for",
"frame_received_cb",
"in",
"self",
".",
"frame_received_cbs",
":",
"# pylint: disable=not-callable",
"self",
".",
"loop",
"."... | ee78e1324bcb1be5b8d1a9d05ab5496b72eae848 |
train | Config.read_config | Read configuration file. | old_api/pyvlx/config.py | def read_config(self, path):
"""Read configuration file."""
self.pyvlx.logger.info('Reading config file: ', path)
try:
with open(path, 'r') as filehandle:
doc = yaml.load(filehandle)
if 'config' not in doc:
raise PyVLXException('no ... | def read_config(self, path):
"""Read configuration file."""
self.pyvlx.logger.info('Reading config file: ', path)
try:
with open(path, 'r') as filehandle:
doc = yaml.load(filehandle)
if 'config' not in doc:
raise PyVLXException('no ... | [
"Read",
"configuration",
"file",
"."
] | Julius2342/pyvlx | python | https://github.com/Julius2342/pyvlx/blob/ee78e1324bcb1be5b8d1a9d05ab5496b72eae848/old_api/pyvlx/config.py#L19-L34 | [
"def",
"read_config",
"(",
"self",
",",
"path",
")",
":",
"self",
".",
"pyvlx",
".",
"logger",
".",
"info",
"(",
"'Reading config file: '",
",",
"path",
")",
"try",
":",
"with",
"open",
"(",
"path",
",",
"'r'",
")",
"as",
"filehandle",
":",
"doc",
"=... | ee78e1324bcb1be5b8d1a9d05ab5496b72eae848 |
train | NodeUpdater.process_frame | Update nodes via frame, usually received by house monitor. | pyvlx/node_updater.py | async def process_frame(self, frame):
"""Update nodes via frame, usually received by house monitor."""
if isinstance(frame, FrameNodeStatePositionChangedNotification):
if frame.node_id not in self.pyvlx.nodes:
return
node = self.pyvlx.nodes[frame.node_id]
... | async def process_frame(self, frame):
"""Update nodes via frame, usually received by house monitor."""
if isinstance(frame, FrameNodeStatePositionChangedNotification):
if frame.node_id not in self.pyvlx.nodes:
return
node = self.pyvlx.nodes[frame.node_id]
... | [
"Update",
"nodes",
"via",
"frame",
"usually",
"received",
"by",
"house",
"monitor",
"."
] | Julius2342/pyvlx | python | https://github.com/Julius2342/pyvlx/blob/ee78e1324bcb1be5b8d1a9d05ab5496b72eae848/pyvlx/node_updater.py#L14-L29 | [
"async",
"def",
"process_frame",
"(",
"self",
",",
"frame",
")",
":",
"if",
"isinstance",
"(",
"frame",
",",
"FrameNodeStatePositionChangedNotification",
")",
":",
"if",
"frame",
".",
"node_id",
"not",
"in",
"self",
".",
"pyvlx",
".",
"nodes",
":",
"return",... | ee78e1324bcb1be5b8d1a9d05ab5496b72eae848 |
train | Scenes.add | Add scene, replace existing scene if scene with scene_id is present. | pyvlx/scenes.py | def add(self, scene):
"""Add scene, replace existing scene if scene with scene_id is present."""
if not isinstance(scene, Scene):
raise TypeError()
for i, j in enumerate(self.__scenes):
if j.scene_id == scene.scene_id:
self.__scenes[i] = scene
... | def add(self, scene):
"""Add scene, replace existing scene if scene with scene_id is present."""
if not isinstance(scene, Scene):
raise TypeError()
for i, j in enumerate(self.__scenes):
if j.scene_id == scene.scene_id:
self.__scenes[i] = scene
... | [
"Add",
"scene",
"replace",
"existing",
"scene",
"if",
"scene",
"with",
"scene_id",
"is",
"present",
"."
] | Julius2342/pyvlx | python | https://github.com/Julius2342/pyvlx/blob/ee78e1324bcb1be5b8d1a9d05ab5496b72eae848/pyvlx/scenes.py#L34-L42 | [
"def",
"add",
"(",
"self",
",",
"scene",
")",
":",
"if",
"not",
"isinstance",
"(",
"scene",
",",
"Scene",
")",
":",
"raise",
"TypeError",
"(",
")",
"for",
"i",
",",
"j",
"in",
"enumerate",
"(",
"self",
".",
"__scenes",
")",
":",
"if",
"j",
".",
... | ee78e1324bcb1be5b8d1a9d05ab5496b72eae848 |
train | Scenes.load | Load scenes from KLF 200. | pyvlx/scenes.py | async def load(self):
"""Load scenes from KLF 200."""
get_scene_list = GetSceneList(pyvlx=self.pyvlx)
await get_scene_list.do_api_call()
if not get_scene_list.success:
raise PyVLXException("Unable to retrieve scene information")
for scene in get_scene_list.scenes:
... | async def load(self):
"""Load scenes from KLF 200."""
get_scene_list = GetSceneList(pyvlx=self.pyvlx)
await get_scene_list.do_api_call()
if not get_scene_list.success:
raise PyVLXException("Unable to retrieve scene information")
for scene in get_scene_list.scenes:
... | [
"Load",
"scenes",
"from",
"KLF",
"200",
"."
] | Julius2342/pyvlx | python | https://github.com/Julius2342/pyvlx/blob/ee78e1324bcb1be5b8d1a9d05ab5496b72eae848/pyvlx/scenes.py#L48-L55 | [
"async",
"def",
"load",
"(",
"self",
")",
":",
"get_scene_list",
"=",
"GetSceneList",
"(",
"pyvlx",
"=",
"self",
".",
"pyvlx",
")",
"await",
"get_scene_list",
".",
"do_api_call",
"(",
")",
"if",
"not",
"get_scene_list",
".",
"success",
":",
"raise",
"PyVLX... | ee78e1324bcb1be5b8d1a9d05ab5496b72eae848 |
train | best_prefix | Return a bitmath instance representing the best human-readable
representation of the number of bytes given by ``bytes``. In addition
to a numeric type, the ``bytes`` parameter may also be a bitmath type.
Optionally select a preferred unit system by specifying the ``system``
keyword. Choices for ``system`` are ``bitmat... | bitmath/__init__.py | def best_prefix(bytes, system=NIST):
"""Return a bitmath instance representing the best human-readable
representation of the number of bytes given by ``bytes``. In addition
to a numeric type, the ``bytes`` parameter may also be a bitmath type.
Optionally select a preferred unit system by specifying the ``system``
... | def best_prefix(bytes, system=NIST):
"""Return a bitmath instance representing the best human-readable
representation of the number of bytes given by ``bytes``. In addition
to a numeric type, the ``bytes`` parameter may also be a bitmath type.
Optionally select a preferred unit system by specifying the ``system``
... | [
"Return",
"a",
"bitmath",
"instance",
"representing",
"the",
"best",
"human",
"-",
"readable",
"representation",
"of",
"the",
"number",
"of",
"bytes",
"given",
"by",
"bytes",
".",
"In",
"addition",
"to",
"a",
"numeric",
"type",
"the",
"bytes",
"parameter",
"... | tbielawa/bitmath | python | https://github.com/tbielawa/bitmath/blob/58ad3ac5f076cc6e53f36a91af055c6028c850a5/bitmath/__init__.py#L1174-L1198 | [
"def",
"best_prefix",
"(",
"bytes",
",",
"system",
"=",
"NIST",
")",
":",
"if",
"isinstance",
"(",
"bytes",
",",
"Bitmath",
")",
":",
"value",
"=",
"bytes",
".",
"bytes",
"else",
":",
"value",
"=",
"bytes",
"return",
"Byte",
"(",
"value",
")",
".",
... | 58ad3ac5f076cc6e53f36a91af055c6028c850a5 |
train | query_device_capacity | Create bitmath instances of the capacity of a system block device
Make one or more ioctl request to query the capacity of a block
device. Perform any processing required to compute the final capacity
value. Return the device capacity in bytes as a :class:`bitmath.Byte`
instance.
Thanks to the following resources for ... | bitmath/__init__.py | def query_device_capacity(device_fd):
"""Create bitmath instances of the capacity of a system block device
Make one or more ioctl request to query the capacity of a block
device. Perform any processing required to compute the final capacity
value. Return the device capacity in bytes as a :class:`bitmath.Byte`
inst... | def query_device_capacity(device_fd):
"""Create bitmath instances of the capacity of a system block device
Make one or more ioctl request to query the capacity of a block
device. Perform any processing required to compute the final capacity
value. Return the device capacity in bytes as a :class:`bitmath.Byte`
inst... | [
"Create",
"bitmath",
"instances",
"of",
"the",
"capacity",
"of",
"a",
"system",
"block",
"device"
] | tbielawa/bitmath | python | https://github.com/tbielawa/bitmath/blob/58ad3ac5f076cc6e53f36a91af055c6028c850a5/bitmath/__init__.py#L1201-L1331 | [
"def",
"query_device_capacity",
"(",
"device_fd",
")",
":",
"if",
"os_name",
"(",
")",
"!=",
"'posix'",
":",
"raise",
"NotImplementedError",
"(",
"\"'bitmath.query_device_capacity' is not supported on this platform: %s\"",
"%",
"os_name",
"(",
")",
")",
"s",
"=",
"os"... | 58ad3ac5f076cc6e53f36a91af055c6028c850a5 |
train | getsize | Return a bitmath instance in the best human-readable representation
of the file size at `path`. Optionally, provide a preferred unit
system by setting `system` to either `bitmath.NIST` (default) or
`bitmath.SI`.
Optionally, set ``bestprefix`` to ``False`` to get ``bitmath.Byte``
instances back. | bitmath/__init__.py | def getsize(path, bestprefix=True, system=NIST):
"""Return a bitmath instance in the best human-readable representation
of the file size at `path`. Optionally, provide a preferred unit
system by setting `system` to either `bitmath.NIST` (default) or
`bitmath.SI`.
Optionally, set ``bestprefix`` to ``False`` to get ... | def getsize(path, bestprefix=True, system=NIST):
"""Return a bitmath instance in the best human-readable representation
of the file size at `path`. Optionally, provide a preferred unit
system by setting `system` to either `bitmath.NIST` (default) or
`bitmath.SI`.
Optionally, set ``bestprefix`` to ``False`` to get ... | [
"Return",
"a",
"bitmath",
"instance",
"in",
"the",
"best",
"human",
"-",
"readable",
"representation",
"of",
"the",
"file",
"size",
"at",
"path",
".",
"Optionally",
"provide",
"a",
"preferred",
"unit",
"system",
"by",
"setting",
"system",
"to",
"either",
"bi... | tbielawa/bitmath | python | https://github.com/tbielawa/bitmath/blob/58ad3ac5f076cc6e53f36a91af055c6028c850a5/bitmath/__init__.py#L1334-L1348 | [
"def",
"getsize",
"(",
"path",
",",
"bestprefix",
"=",
"True",
",",
"system",
"=",
"NIST",
")",
":",
"_path",
"=",
"os",
".",
"path",
".",
"realpath",
"(",
"path",
")",
"size_bytes",
"=",
"os",
".",
"path",
".",
"getsize",
"(",
"_path",
")",
"if",
... | 58ad3ac5f076cc6e53f36a91af055c6028c850a5 |
train | listdir | This is a generator which recurses the directory tree
`search_base`, yielding 2-tuples of:
* The absolute/relative path to a discovered file
* A bitmath instance representing the "apparent size" of the file.
- `search_base` - The directory to begin walking down.
- `followlinks` - Whether or not to follow symb... | bitmath/__init__.py | def listdir(search_base, followlinks=False, filter='*',
relpath=False, bestprefix=False, system=NIST):
"""This is a generator which recurses the directory tree
`search_base`, yielding 2-tuples of:
* The absolute/relative path to a discovered file
* A bitmath instance representing the "apparent size" of... | def listdir(search_base, followlinks=False, filter='*',
relpath=False, bestprefix=False, system=NIST):
"""This is a generator which recurses the directory tree
`search_base`, yielding 2-tuples of:
* The absolute/relative path to a discovered file
* A bitmath instance representing the "apparent size" of... | [
"This",
"is",
"a",
"generator",
"which",
"recurses",
"the",
"directory",
"tree",
"search_base",
"yielding",
"2",
"-",
"tuples",
"of",
":"
] | tbielawa/bitmath | python | https://github.com/tbielawa/bitmath/blob/58ad3ac5f076cc6e53f36a91af055c6028c850a5/bitmath/__init__.py#L1351-L1391 | [
"def",
"listdir",
"(",
"search_base",
",",
"followlinks",
"=",
"False",
",",
"filter",
"=",
"'*'",
",",
"relpath",
"=",
"False",
",",
"bestprefix",
"=",
"False",
",",
"system",
"=",
"NIST",
")",
":",
"for",
"root",
",",
"dirs",
",",
"files",
"in",
"o... | 58ad3ac5f076cc6e53f36a91af055c6028c850a5 |
train | parse_string | Parse a string with units and try to make a bitmath object out of
it.
String inputs may include whitespace characters between the value and
the unit. | bitmath/__init__.py | def parse_string(s):
"""Parse a string with units and try to make a bitmath object out of
it.
String inputs may include whitespace characters between the value and
the unit.
"""
# Strings only please
if not isinstance(s, (str, unicode)):
raise ValueError("parse_string only accepts string inputs... | def parse_string(s):
"""Parse a string with units and try to make a bitmath object out of
it.
String inputs may include whitespace characters between the value and
the unit.
"""
# Strings only please
if not isinstance(s, (str, unicode)):
raise ValueError("parse_string only accepts string inputs... | [
"Parse",
"a",
"string",
"with",
"units",
"and",
"try",
"to",
"make",
"a",
"bitmath",
"object",
"out",
"of",
"it",
"."
] | tbielawa/bitmath | python | https://github.com/tbielawa/bitmath/blob/58ad3ac5f076cc6e53f36a91af055c6028c850a5/bitmath/__init__.py#L1394-L1434 | [
"def",
"parse_string",
"(",
"s",
")",
":",
"# Strings only please",
"if",
"not",
"isinstance",
"(",
"s",
",",
"(",
"str",
",",
"unicode",
")",
")",
":",
"raise",
"ValueError",
"(",
"\"parse_string only accepts string inputs but a %s was given\"",
"%",
"type",
"(",... | 58ad3ac5f076cc6e53f36a91af055c6028c850a5 |
train | parse_string_unsafe | Attempt to parse a string with ambiguous units and try to make a
bitmath object out of it.
This may produce inaccurate results if parsing shell output. For
example `ls` may say a 2730 Byte file is '2.7K'. 2730 Bytes == 2.73 kB
~= 2.666 KiB. See the documentation for all of the important details.
Note the following ca... | bitmath/__init__.py | def parse_string_unsafe(s, system=SI):
"""Attempt to parse a string with ambiguous units and try to make a
bitmath object out of it.
This may produce inaccurate results if parsing shell output. For
example `ls` may say a 2730 Byte file is '2.7K'. 2730 Bytes == 2.73 kB
~= 2.666 KiB. See the documentation for all of... | def parse_string_unsafe(s, system=SI):
"""Attempt to parse a string with ambiguous units and try to make a
bitmath object out of it.
This may produce inaccurate results if parsing shell output. For
example `ls` may say a 2730 Byte file is '2.7K'. 2730 Bytes == 2.73 kB
~= 2.666 KiB. See the documentation for all of... | [
"Attempt",
"to",
"parse",
"a",
"string",
"with",
"ambiguous",
"units",
"and",
"try",
"to",
"make",
"a",
"bitmath",
"object",
"out",
"of",
"it",
"."
] | tbielawa/bitmath | python | https://github.com/tbielawa/bitmath/blob/58ad3ac5f076cc6e53f36a91af055c6028c850a5/bitmath/__init__.py#L1437-L1559 | [
"def",
"parse_string_unsafe",
"(",
"s",
",",
"system",
"=",
"SI",
")",
":",
"if",
"not",
"isinstance",
"(",
"s",
",",
"(",
"str",
",",
"unicode",
")",
")",
"and",
"not",
"isinstance",
"(",
"s",
",",
"numbers",
".",
"Number",
")",
":",
"raise",
"Val... | 58ad3ac5f076cc6e53f36a91af055c6028c850a5 |
train | format | Context manager for printing bitmath instances.
``fmt_str`` - a formatting mini-language compat formatting string. See
the @properties (above) for a list of available items.
``plural`` - True enables printing instances with 's's if they're
plural. False (default) prints them as singular (no trailing 's').
``bestpref... | bitmath/__init__.py | def format(fmt_str=None, plural=False, bestprefix=False):
"""Context manager for printing bitmath instances.
``fmt_str`` - a formatting mini-language compat formatting string. See
the @properties (above) for a list of available items.
``plural`` - True enables printing instances with 's's if they're
plural. False... | def format(fmt_str=None, plural=False, bestprefix=False):
"""Context manager for printing bitmath instances.
``fmt_str`` - a formatting mini-language compat formatting string. See
the @properties (above) for a list of available items.
``plural`` - True enables printing instances with 's's if they're
plural. False... | [
"Context",
"manager",
"for",
"printing",
"bitmath",
"instances",
"."
] | tbielawa/bitmath | python | https://github.com/tbielawa/bitmath/blob/58ad3ac5f076cc6e53f36a91af055c6028c850a5/bitmath/__init__.py#L1565-L1595 | [
"def",
"format",
"(",
"fmt_str",
"=",
"None",
",",
"plural",
"=",
"False",
",",
"bestprefix",
"=",
"False",
")",
":",
"if",
"'bitmath'",
"not",
"in",
"globals",
"(",
")",
":",
"import",
"bitmath",
"if",
"plural",
":",
"orig_fmt_plural",
"=",
"bitmath",
... | 58ad3ac5f076cc6e53f36a91af055c6028c850a5 |
train | cli_script_main | A command line interface to basic bitmath operations. | bitmath/__init__.py | def cli_script_main(cli_args):
"""
A command line interface to basic bitmath operations.
"""
choices = ALL_UNIT_TYPES
parser = argparse.ArgumentParser(
description='Converts from one type of size to another.')
parser.add_argument('--from-stdin', default=False, action='store_true',
... | def cli_script_main(cli_args):
"""
A command line interface to basic bitmath operations.
"""
choices = ALL_UNIT_TYPES
parser = argparse.ArgumentParser(
description='Converts from one type of size to another.')
parser.add_argument('--from-stdin', default=False, action='store_true',
... | [
"A",
"command",
"line",
"interface",
"to",
"basic",
"bitmath",
"operations",
"."
] | tbielawa/bitmath | python | https://github.com/tbielawa/bitmath/blob/58ad3ac5f076cc6e53f36a91af055c6028c850a5/bitmath/__init__.py#L1598-L1643 | [
"def",
"cli_script_main",
"(",
"cli_args",
")",
":",
"choices",
"=",
"ALL_UNIT_TYPES",
"parser",
"=",
"argparse",
".",
"ArgumentParser",
"(",
"description",
"=",
"'Converts from one type of size to another.'",
")",
"parser",
".",
"add_argument",
"(",
"'--from-stdin'",
... | 58ad3ac5f076cc6e53f36a91af055c6028c850a5 |
train | Bitmath._do_setup | Setup basic parameters for this class.
`base` is the numeric base which when raised to `power` is equivalent
to 1 unit of the corresponding prefix. I.e., base=2, power=10
represents 2^10, which is the NIST Binary Prefix for 1 Kibibyte.
Likewise, for the SI prefix classes `base` will be 10, and the `power`
for the Kil... | bitmath/__init__.py | def _do_setup(self):
"""Setup basic parameters for this class.
`base` is the numeric base which when raised to `power` is equivalent
to 1 unit of the corresponding prefix. I.e., base=2, power=10
represents 2^10, which is the NIST Binary Prefix for 1 Kibibyte.
Likewise, for the SI prefix classes `base` will be... | def _do_setup(self):
"""Setup basic parameters for this class.
`base` is the numeric base which when raised to `power` is equivalent
to 1 unit of the corresponding prefix. I.e., base=2, power=10
represents 2^10, which is the NIST Binary Prefix for 1 Kibibyte.
Likewise, for the SI prefix classes `base` will be... | [
"Setup",
"basic",
"parameters",
"for",
"this",
"class",
"."
] | tbielawa/bitmath | python | https://github.com/tbielawa/bitmath/blob/58ad3ac5f076cc6e53f36a91af055c6028c850a5/bitmath/__init__.py#L239-L250 | [
"def",
"_do_setup",
"(",
"self",
")",
":",
"(",
"self",
".",
"_base",
",",
"self",
".",
"_power",
",",
"self",
".",
"_name_singular",
",",
"self",
".",
"_name_plural",
")",
"=",
"self",
".",
"_setup",
"(",
")",
"self",
".",
"_unit_value",
"=",
"self"... | 58ad3ac5f076cc6e53f36a91af055c6028c850a5 |
train | Bitmath._norm | Normalize the input value into the fundamental unit for this prefix
type.
:param number value: The input value to be normalized
:raises ValueError: if the input value is not a type of real number | bitmath/__init__.py | def _norm(self, value):
"""Normalize the input value into the fundamental unit for this prefix
type.
:param number value: The input value to be normalized
:raises ValueError: if the input value is not a type of real number
"""
if isinstance(value, self.valid_types):
self._byte_value =... | def _norm(self, value):
"""Normalize the input value into the fundamental unit for this prefix
type.
:param number value: The input value to be normalized
:raises ValueError: if the input value is not a type of real number
"""
if isinstance(value, self.valid_types):
self._byte_value =... | [
"Normalize",
"the",
"input",
"value",
"into",
"the",
"fundamental",
"unit",
"for",
"this",
"prefix",
"type",
"."
] | tbielawa/bitmath | python | https://github.com/tbielawa/bitmath/blob/58ad3ac5f076cc6e53f36a91af055c6028c850a5/bitmath/__init__.py#L252-L267 | [
"def",
"_norm",
"(",
"self",
",",
"value",
")",
":",
"if",
"isinstance",
"(",
"value",
",",
"self",
".",
"valid_types",
")",
":",
"self",
".",
"_byte_value",
"=",
"value",
"*",
"self",
".",
"_unit_value",
"self",
".",
"_bit_value",
"=",
"self",
".",
... | 58ad3ac5f076cc6e53f36a91af055c6028c850a5 |
train | Bitmath.system | The system of units used to measure an instance | bitmath/__init__.py | def system(self):
"""The system of units used to measure an instance"""
if self._base == 2:
return "NIST"
elif self._base == 10:
return "SI"
else:
# I don't expect to ever encounter this logic branch, but
# hey, it's better to have extra te... | def system(self):
"""The system of units used to measure an instance"""
if self._base == 2:
return "NIST"
elif self._base == 10:
return "SI"
else:
# I don't expect to ever encounter this logic branch, but
# hey, it's better to have extra te... | [
"The",
"system",
"of",
"units",
"used",
"to",
"measure",
"an",
"instance"
] | tbielawa/bitmath | python | https://github.com/tbielawa/bitmath/blob/58ad3ac5f076cc6e53f36a91af055c6028c850a5/bitmath/__init__.py#L299-L310 | [
"def",
"system",
"(",
"self",
")",
":",
"if",
"self",
".",
"_base",
"==",
"2",
":",
"return",
"\"NIST\"",
"elif",
"self",
".",
"_base",
"==",
"10",
":",
"return",
"\"SI\"",
"else",
":",
"# I don't expect to ever encounter this logic branch, but",
"# hey, it's be... | 58ad3ac5f076cc6e53f36a91af055c6028c850a5 |
train | Bitmath.unit | The string that is this instances prefix unit name in agreement
with this instance value (singular or plural). Following the
convention that only 1 is singular. This will always be the singular
form when :attr:`bitmath.format_plural` is ``False`` (default value).
For example:
>>> KiB(1).unit == 'KiB'
>>> Byte(0... | bitmath/__init__.py | def unit(self):
"""The string that is this instances prefix unit name in agreement
with this instance value (singular or plural). Following the
convention that only 1 is singular. This will always be the singular
form when :attr:`bitmath.format_plural` is ``False`` (default value).
For example:
>>> KiB(1).... | def unit(self):
"""The string that is this instances prefix unit name in agreement
with this instance value (singular or plural). Following the
convention that only 1 is singular. This will always be the singular
form when :attr:`bitmath.format_plural` is ``False`` (default value).
For example:
>>> KiB(1).... | [
"The",
"string",
"that",
"is",
"this",
"instances",
"prefix",
"unit",
"name",
"in",
"agreement",
"with",
"this",
"instance",
"value",
"(",
"singular",
"or",
"plural",
")",
".",
"Following",
"the",
"convention",
"that",
"only",
"1",
"is",
"singular",
".",
"... | tbielawa/bitmath | python | https://github.com/tbielawa/bitmath/blob/58ad3ac5f076cc6e53f36a91af055c6028c850a5/bitmath/__init__.py#L313-L338 | [
"def",
"unit",
"(",
"self",
")",
":",
"global",
"format_plural",
"if",
"self",
".",
"prefix_value",
"==",
"1",
":",
"# If it's a '1', return it singular, no matter what",
"return",
"self",
".",
"_name_singular",
"elif",
"format_plural",
":",
"# Pluralization requested",... | 58ad3ac5f076cc6e53f36a91af055c6028c850a5 |
train | Bitmath.from_other | Factory function to return instances of `item` converted into a new
instance of ``cls``. Because this is a class method, it may be called
from any bitmath class object without the need to explicitly
instantiate the class ahead of time.
*Implicit Parameter:*
* ``cls`` A bitmath class, implicitly set to the class of th... | bitmath/__init__.py | def from_other(cls, item):
"""Factory function to return instances of `item` converted into a new
instance of ``cls``. Because this is a class method, it may be called
from any bitmath class object without the need to explicitly
instantiate the class ahead of time.
*Implicit Parameter:*
* ``cls`` A bitmath cl... | def from_other(cls, item):
"""Factory function to return instances of `item` converted into a new
instance of ``cls``. Because this is a class method, it may be called
from any bitmath class object without the need to explicitly
instantiate the class ahead of time.
*Implicit Parameter:*
* ``cls`` A bitmath cl... | [
"Factory",
"function",
"to",
"return",
"instances",
"of",
"item",
"converted",
"into",
"a",
"new",
"instance",
"of",
"cls",
".",
"Because",
"this",
"is",
"a",
"class",
"method",
"it",
"may",
"be",
"called",
"from",
"any",
"bitmath",
"class",
"object",
"wit... | tbielawa/bitmath | python | https://github.com/tbielawa/bitmath/blob/58ad3ac5f076cc6e53f36a91af055c6028c850a5/bitmath/__init__.py#L371-L398 | [
"def",
"from_other",
"(",
"cls",
",",
"item",
")",
":",
"if",
"isinstance",
"(",
"item",
",",
"Bitmath",
")",
":",
"return",
"cls",
"(",
"bits",
"=",
"item",
".",
"bits",
")",
"else",
":",
"raise",
"ValueError",
"(",
"\"The provided items must be a valid b... | 58ad3ac5f076cc6e53f36a91af055c6028c850a5 |
train | Bitmath.format | Return a representation of this instance formatted with user
supplied syntax | bitmath/__init__.py | def format(self, fmt):
"""Return a representation of this instance formatted with user
supplied syntax"""
_fmt_params = {
'base': self.base,
'bin': self.bin,
'binary': self.binary,
'bits': self.bits,
'bytes': self.bytes,
'power': se... | def format(self, fmt):
"""Return a representation of this instance formatted with user
supplied syntax"""
_fmt_params = {
'base': self.base,
'bin': self.bin,
'binary': self.binary,
'bits': self.bits,
'bytes': self.bytes,
'power': se... | [
"Return",
"a",
"representation",
"of",
"this",
"instance",
"formatted",
"with",
"user",
"supplied",
"syntax"
] | tbielawa/bitmath | python | https://github.com/tbielawa/bitmath/blob/58ad3ac5f076cc6e53f36a91af055c6028c850a5/bitmath/__init__.py#L416-L433 | [
"def",
"format",
"(",
"self",
",",
"fmt",
")",
":",
"_fmt_params",
"=",
"{",
"'base'",
":",
"self",
".",
"base",
",",
"'bin'",
":",
"self",
".",
"bin",
",",
"'binary'",
":",
"self",
".",
"binary",
",",
"'bits'",
":",
"self",
".",
"bits",
",",
"'b... | 58ad3ac5f076cc6e53f36a91af055c6028c850a5 |
train | Bitmath.best_prefix | Optional parameter, `system`, allows you to prefer NIST or SI in
the results. By default, the current system is used (Bit/Byte default
to NIST).
Logic discussion/notes:
Base-case, does it need converting?
If the instance is less than one Byte, return the instance as a Bit
instance.
Else, begin by recording the unit... | bitmath/__init__.py | def best_prefix(self, system=None):
"""Optional parameter, `system`, allows you to prefer NIST or SI in
the results. By default, the current system is used (Bit/Byte default
to NIST).
Logic discussion/notes:
Base-case, does it need converting?
If the instance is less than one Byte, return the instance as a B... | def best_prefix(self, system=None):
"""Optional parameter, `system`, allows you to prefer NIST or SI in
the results. By default, the current system is used (Bit/Byte default
to NIST).
Logic discussion/notes:
Base-case, does it need converting?
If the instance is less than one Byte, return the instance as a B... | [
"Optional",
"parameter",
"system",
"allows",
"you",
"to",
"prefer",
"NIST",
"or",
"SI",
"in",
"the",
"results",
".",
"By",
"default",
"the",
"current",
"system",
"is",
"used",
"(",
"Bit",
"/",
"Byte",
"default",
"to",
"NIST",
")",
"."
] | tbielawa/bitmath | python | https://github.com/tbielawa/bitmath/blob/58ad3ac5f076cc6e53f36a91af055c6028c850a5/bitmath/__init__.py#L439-L528 | [
"def",
"best_prefix",
"(",
"self",
",",
"system",
"=",
"None",
")",
":",
"# Use absolute value so we don't return Bit's for *everything*",
"# less than Byte(1). From github issue #55",
"if",
"abs",
"(",
"self",
")",
"<",
"Byte",
"(",
"1",
")",
":",
"return",
"Bit",
... | 58ad3ac5f076cc6e53f36a91af055c6028c850a5 |
train | Bit._norm | Normalize the input value into the fundamental unit for this prefix
type | bitmath/__init__.py | def _norm(self, value):
"""Normalize the input value into the fundamental unit for this prefix
type"""
self._bit_value = value * self._unit_value
self._byte_value = self._bit_value / 8.0 | def _norm(self, value):
"""Normalize the input value into the fundamental unit for this prefix
type"""
self._bit_value = value * self._unit_value
self._byte_value = self._bit_value / 8.0 | [
"Normalize",
"the",
"input",
"value",
"into",
"the",
"fundamental",
"unit",
"for",
"this",
"prefix",
"type"
] | tbielawa/bitmath | python | https://github.com/tbielawa/bitmath/blob/58ad3ac5f076cc6e53f36a91af055c6028c850a5/bitmath/__init__.py#L1091-L1095 | [
"def",
"_norm",
"(",
"self",
",",
"value",
")",
":",
"self",
".",
"_bit_value",
"=",
"value",
"*",
"self",
".",
"_unit_value",
"self",
".",
"_byte_value",
"=",
"self",
".",
"_bit_value",
"/",
"8.0"
] | 58ad3ac5f076cc6e53f36a91af055c6028c850a5 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.