repository_name stringlengths 5 67 | func_path_in_repository stringlengths 4 234 | func_name stringlengths 0 314 | whole_func_string stringlengths 52 3.87M | language stringclasses 6
values | func_code_string stringlengths 52 3.87M | func_code_tokens listlengths 15 672k | func_documentation_string stringlengths 1 47.2k | func_documentation_tokens listlengths 1 3.92k | split_name stringclasses 1
value | func_code_url stringlengths 85 339 |
|---|---|---|---|---|---|---|---|---|---|---|
cqparts/cqparts | src/cqparts_fasteners/solidtypes/threads/base.py | Thread.make_pilothole_cutter | def make_pilothole_cutter(self):
"""
Make a solid to subtract from an interfacing solid to bore a pilot-hole.
"""
# get pilothole ratio
# note: not done in .initialize_parameters() because this would cause
# the thread's profile to be created at initialisation (by def... | python | def make_pilothole_cutter(self):
"""
Make a solid to subtract from an interfacing solid to bore a pilot-hole.
"""
# get pilothole ratio
# note: not done in .initialize_parameters() because this would cause
# the thread's profile to be created at initialisation (by def... | [
"def",
"make_pilothole_cutter",
"(",
"self",
")",
":",
"# get pilothole ratio",
"# note: not done in .initialize_parameters() because this would cause",
"# the thread's profile to be created at initialisation (by default).",
"pilothole_radius",
"=",
"self",
".",
"pilothole_radius",
"... | Make a solid to subtract from an interfacing solid to bore a pilot-hole. | [
"Make",
"a",
"solid",
"to",
"subtract",
"from",
"an",
"interfacing",
"solid",
"to",
"bore",
"a",
"pilot",
"-",
"hole",
"."
] | train | https://github.com/cqparts/cqparts/blob/018e87e14c2c4d1d40b4bfe6a7e22bcf9baf0a53/src/cqparts_fasteners/solidtypes/threads/base.py#L373-L387 |
cqparts/cqparts | src/cqparts/assembly.py | Assembly.components | def components(self):
"""
Returns full :class:`dict` of :class:`Component` instances, after
a successful :meth:`build`
:return: dict of named :class:`Component` instances
:rtype: :class:`dict`
For more information read about the :ref:`parts_assembly-build-cycle` .
... | python | def components(self):
"""
Returns full :class:`dict` of :class:`Component` instances, after
a successful :meth:`build`
:return: dict of named :class:`Component` instances
:rtype: :class:`dict`
For more information read about the :ref:`parts_assembly-build-cycle` .
... | [
"def",
"components",
"(",
"self",
")",
":",
"if",
"self",
".",
"_components",
"is",
"None",
":",
"self",
".",
"build",
"(",
"recursive",
"=",
"False",
")",
"return",
"self",
".",
"_components"
] | Returns full :class:`dict` of :class:`Component` instances, after
a successful :meth:`build`
:return: dict of named :class:`Component` instances
:rtype: :class:`dict`
For more information read about the :ref:`parts_assembly-build-cycle` . | [
"Returns",
"full",
":",
"class",
":",
"dict",
"of",
":",
"class",
":",
"Component",
"instances",
"after",
"a",
"successful",
":",
"meth",
":",
"build"
] | train | https://github.com/cqparts/cqparts/blob/018e87e14c2c4d1d40b4bfe6a7e22bcf9baf0a53/src/cqparts/assembly.py#L94-L106 |
cqparts/cqparts | src/cqparts/assembly.py | Assembly.constraints | def constraints(self):
"""
Returns full :class:`list` of :class:`Constraint <cqparts.constraint.Constraint>` instances, after
a successful :meth:`build`
:return: list of named :class:`Constraint <cqparts.constraint.Constraint>` instances
:rtype: :class:`list`
For more i... | python | def constraints(self):
"""
Returns full :class:`list` of :class:`Constraint <cqparts.constraint.Constraint>` instances, after
a successful :meth:`build`
:return: list of named :class:`Constraint <cqparts.constraint.Constraint>` instances
:rtype: :class:`list`
For more i... | [
"def",
"constraints",
"(",
"self",
")",
":",
"if",
"self",
".",
"_constraints",
"is",
"None",
":",
"self",
".",
"build",
"(",
"recursive",
"=",
"False",
")",
"return",
"self",
".",
"_constraints"
] | Returns full :class:`list` of :class:`Constraint <cqparts.constraint.Constraint>` instances, after
a successful :meth:`build`
:return: list of named :class:`Constraint <cqparts.constraint.Constraint>` instances
:rtype: :class:`list`
For more information read about the :ref:`parts_assem... | [
"Returns",
"full",
":",
"class",
":",
"list",
"of",
":",
"class",
":",
"Constraint",
"<cqparts",
".",
"constraint",
".",
"Constraint",
">",
"instances",
"after",
"a",
"successful",
":",
"meth",
":",
"build"
] | train | https://github.com/cqparts/cqparts/blob/018e87e14c2c4d1d40b4bfe6a7e22bcf9baf0a53/src/cqparts/assembly.py#L109-L121 |
cqparts/cqparts | src/cqparts/assembly.py | Assembly.solve | def solve(self):
"""
Run the solver and assign the solution's :class:`CoordSystem` instances
as the corresponding part's world coordinates.
"""
if self.world_coords is None:
log.warning("solving for Assembly without world coordinates set: %r", self)
for (comp... | python | def solve(self):
"""
Run the solver and assign the solution's :class:`CoordSystem` instances
as the corresponding part's world coordinates.
"""
if self.world_coords is None:
log.warning("solving for Assembly without world coordinates set: %r", self)
for (comp... | [
"def",
"solve",
"(",
"self",
")",
":",
"if",
"self",
".",
"world_coords",
"is",
"None",
":",
"log",
".",
"warning",
"(",
"\"solving for Assembly without world coordinates set: %r\"",
",",
"self",
")",
"for",
"(",
"component",
",",
"world_coords",
")",
"in",
"s... | Run the solver and assign the solution's :class:`CoordSystem` instances
as the corresponding part's world coordinates. | [
"Run",
"the",
"solver",
"and",
"assign",
"the",
"solution",
"s",
":",
"class",
":",
"CoordSystem",
"instances",
"as",
"the",
"corresponding",
"part",
"s",
"world",
"coordinates",
"."
] | train | https://github.com/cqparts/cqparts/blob/018e87e14c2c4d1d40b4bfe6a7e22bcf9baf0a53/src/cqparts/assembly.py#L132-L141 |
cqparts/cqparts | src/cqparts/assembly.py | Assembly.verify_components | def verify_components(components):
"""
Verify values returned from :meth:`make_components`.
Used internally during the :meth:`build` process.
:param components: value returned from :meth:`make_components`
:type components: :class:`dict`
:raises ValueError: if verificati... | python | def verify_components(components):
"""
Verify values returned from :meth:`make_components`.
Used internally during the :meth:`build` process.
:param components: value returned from :meth:`make_components`
:type components: :class:`dict`
:raises ValueError: if verificati... | [
"def",
"verify_components",
"(",
"components",
")",
":",
"# verify returned type from user-defined function",
"if",
"not",
"isinstance",
"(",
"components",
",",
"dict",
")",
":",
"raise",
"ValueError",
"(",
"\"invalid type returned by make_components(): %r (must be a dict)\"",
... | Verify values returned from :meth:`make_components`.
Used internally during the :meth:`build` process.
:param components: value returned from :meth:`make_components`
:type components: :class:`dict`
:raises ValueError: if verification fails | [
"Verify",
"values",
"returned",
"from",
":",
"meth",
":",
"make_components",
"."
] | train | https://github.com/cqparts/cqparts/blob/018e87e14c2c4d1d40b4bfe6a7e22bcf9baf0a53/src/cqparts/assembly.py#L144-L183 |
cqparts/cqparts | src/cqparts/assembly.py | Assembly.verify_constraints | def verify_constraints(constraints):
"""
Verify values returned from :meth:`make_constraints`.
Used internally during the :meth:`build` process.
:param constraints: value returned from :meth:`make_constraints`
:type constraints: :class:`list`
:raises ValueError: if veri... | python | def verify_constraints(constraints):
"""
Verify values returned from :meth:`make_constraints`.
Used internally during the :meth:`build` process.
:param constraints: value returned from :meth:`make_constraints`
:type constraints: :class:`list`
:raises ValueError: if veri... | [
"def",
"verify_constraints",
"(",
"constraints",
")",
":",
"# verify return is a list",
"if",
"not",
"isinstance",
"(",
"constraints",
",",
"list",
")",
":",
"raise",
"ValueError",
"(",
"\"invalid type returned by make_constraints: %r (must be a list)\"",
"%",
"constraints"... | Verify values returned from :meth:`make_constraints`.
Used internally during the :meth:`build` process.
:param constraints: value returned from :meth:`make_constraints`
:type constraints: :class:`list`
:raises ValueError: if verification fails | [
"Verify",
"values",
"returned",
"from",
":",
"meth",
":",
"make_constraints",
"."
] | train | https://github.com/cqparts/cqparts/blob/018e87e14c2c4d1d40b4bfe6a7e22bcf9baf0a53/src/cqparts/assembly.py#L186-L207 |
cqparts/cqparts | src/cqparts/assembly.py | Assembly.build | def build(self, recursive=True):
"""
Building an assembly buffers the :meth:`components` and :meth:`constraints`.
Running ``build()`` is optional, it's automatically run when requesting
:meth:`components` or :meth:`constraints`.
Mostly it's used to test that there aren't any c... | python | def build(self, recursive=True):
"""
Building an assembly buffers the :meth:`components` and :meth:`constraints`.
Running ``build()`` is optional, it's automatically run when requesting
:meth:`components` or :meth:`constraints`.
Mostly it's used to test that there aren't any c... | [
"def",
"build",
"(",
"self",
",",
"recursive",
"=",
"True",
")",
":",
"# initialize values",
"self",
".",
"_components",
"=",
"{",
"}",
"self",
".",
"_constraints",
"=",
"[",
"]",
"def",
"genwrap",
"(",
"obj",
",",
"name",
",",
"iter_type",
"=",
"None"... | Building an assembly buffers the :meth:`components` and :meth:`constraints`.
Running ``build()`` is optional, it's automatically run when requesting
:meth:`components` or :meth:`constraints`.
Mostly it's used to test that there aren't any critical runtime
issues with its construction,... | [
"Building",
"an",
"assembly",
"buffers",
"the",
":",
"meth",
":",
"components",
"and",
":",
"meth",
":",
"constraints",
"."
] | train | https://github.com/cqparts/cqparts/blob/018e87e14c2c4d1d40b4bfe6a7e22bcf9baf0a53/src/cqparts/assembly.py#L209-L298 |
cqparts/cqparts | src/cqparts/assembly.py | Assembly.find | def find(self, keys, _index=0):
"""
:param keys: key path. ``'a.b'`` is equivalent to ``['a', 'b']``
:type keys: :class:`str` or :class:`list`
Find a nested :class:`Component` by a "`.`" separated list of names.
for example::
>>> motor.find('bearing.outer_ring')
... | python | def find(self, keys, _index=0):
"""
:param keys: key path. ``'a.b'`` is equivalent to ``['a', 'b']``
:type keys: :class:`str` or :class:`list`
Find a nested :class:`Component` by a "`.`" separated list of names.
for example::
>>> motor.find('bearing.outer_ring')
... | [
"def",
"find",
"(",
"self",
",",
"keys",
",",
"_index",
"=",
"0",
")",
":",
"if",
"isinstance",
"(",
"keys",
",",
"six",
".",
"string_types",
")",
":",
"keys",
"=",
"re",
".",
"split",
"(",
"r'[\\.-]+'",
",",
"keys",
")",
"if",
"_index",
">=",
"l... | :param keys: key path. ``'a.b'`` is equivalent to ``['a', 'b']``
:type keys: :class:`str` or :class:`list`
Find a nested :class:`Component` by a "`.`" separated list of names.
for example::
>>> motor.find('bearing.outer_ring')
would return the Part instance of the motor be... | [
":",
"param",
"keys",
":",
"key",
"path",
".",
"a",
".",
"b",
"is",
"equivalent",
"to",
"[",
"a",
"b",
"]",
":",
"type",
"keys",
":",
":",
"class",
":",
"str",
"or",
":",
"class",
":",
"list"
] | train | https://github.com/cqparts/cqparts/blob/018e87e14c2c4d1d40b4bfe6a7e22bcf9baf0a53/src/cqparts/assembly.py#L309-L362 |
cqparts/cqparts | src/cqparts/assembly.py | Assembly.tree_str | def tree_str(self, name=None, prefix='', add_repr=False, _depth=0):
u"""
Return string listing recursively the assembly hierarchy
:param name: if set, names the tree's trunk, otherwise the object's :meth:`repr` names the tree
:type name: :class:`str`
:param prefix: string prefix... | python | def tree_str(self, name=None, prefix='', add_repr=False, _depth=0):
u"""
Return string listing recursively the assembly hierarchy
:param name: if set, names the tree's trunk, otherwise the object's :meth:`repr` names the tree
:type name: :class:`str`
:param prefix: string prefix... | [
"def",
"tree_str",
"(",
"self",
",",
"name",
"=",
"None",
",",
"prefix",
"=",
"''",
",",
"add_repr",
"=",
"False",
",",
"_depth",
"=",
"0",
")",
":",
"# unicode characters",
"c_t",
"=",
"u'\\u251c'",
"c_l",
"=",
"u'\\u2514'",
"c_dash",
"=",
"u'\\u2500'",... | u"""
Return string listing recursively the assembly hierarchy
:param name: if set, names the tree's trunk, otherwise the object's :meth:`repr` names the tree
:type name: :class:`str`
:param prefix: string prefixed to each line, can be used to indent
:type prefix: :class:`str`
... | [
"u",
"Return",
"string",
"listing",
"recursively",
"the",
"assembly",
"hierarchy"
] | train | https://github.com/cqparts/cqparts/blob/018e87e14c2c4d1d40b4bfe6a7e22bcf9baf0a53/src/cqparts/assembly.py#L365-L442 |
cqparts/cqparts | src/cqparts_template/catalogue/scripts/build.py | _relative_path_to | def _relative_path_to(path_list, filename):
"""Get a neat relative path to files relative to the CWD"""
return os.path.join(
os.path.relpath(os.path.join(*path_list), os.getcwd()),
filename
) | python | def _relative_path_to(path_list, filename):
"""Get a neat relative path to files relative to the CWD"""
return os.path.join(
os.path.relpath(os.path.join(*path_list), os.getcwd()),
filename
) | [
"def",
"_relative_path_to",
"(",
"path_list",
",",
"filename",
")",
":",
"return",
"os",
".",
"path",
".",
"join",
"(",
"os",
".",
"path",
".",
"relpath",
"(",
"os",
".",
"path",
".",
"join",
"(",
"*",
"path_list",
")",
",",
"os",
".",
"getcwd",
"(... | Get a neat relative path to files relative to the CWD | [
"Get",
"a",
"neat",
"relative",
"path",
"to",
"files",
"relative",
"to",
"the",
"CWD"
] | train | https://github.com/cqparts/cqparts/blob/018e87e14c2c4d1d40b4bfe6a7e22bcf9baf0a53/src/cqparts_template/catalogue/scripts/build.py#L21-L26 |
cqparts/cqparts | src/cqparts_gears/trapezoidal.py | TrapezoidalGear._make_tooth_template | def _make_tooth_template(self):
"""
Builds a single tooth including the cylinder with tooth faces
tangential to its circumference.
"""
# parameters
period_arc = (2 * pi) / self.tooth_count
tooth_arc = period_arc * self.spacing_ratio # the arc between faces at eff... | python | def _make_tooth_template(self):
"""
Builds a single tooth including the cylinder with tooth faces
tangential to its circumference.
"""
# parameters
period_arc = (2 * pi) / self.tooth_count
tooth_arc = period_arc * self.spacing_ratio # the arc between faces at eff... | [
"def",
"_make_tooth_template",
"(",
"self",
")",
":",
"# parameters",
"period_arc",
"=",
"(",
"2",
"*",
"pi",
")",
"/",
"self",
".",
"tooth_count",
"tooth_arc",
"=",
"period_arc",
"*",
"self",
".",
"spacing_ratio",
"# the arc between faces at effective_radius",
"o... | Builds a single tooth including the cylinder with tooth faces
tangential to its circumference. | [
"Builds",
"a",
"single",
"tooth",
"including",
"the",
"cylinder",
"with",
"tooth",
"faces",
"tangential",
"to",
"its",
"circumference",
"."
] | train | https://github.com/cqparts/cqparts/blob/018e87e14c2c4d1d40b4bfe6a7e22bcf9baf0a53/src/cqparts_gears/trapezoidal.py#L31-L76 |
cqparts/cqparts | src/cqparts_bearings/ball.py | _Ring.get_mate_center | def get_mate_center(self, angle=0):
"""
Mate at ring's center rotated ``angle`` degrees.
:param angle: rotation around z-axis (unit: deg)
:type angle: :class:`float`
:return: mate in ring's center rotated about z-axis
:rtype: :class:`Mate <cqparts.constraint.Mate>`
... | python | def get_mate_center(self, angle=0):
"""
Mate at ring's center rotated ``angle`` degrees.
:param angle: rotation around z-axis (unit: deg)
:type angle: :class:`float`
:return: mate in ring's center rotated about z-axis
:rtype: :class:`Mate <cqparts.constraint.Mate>`
... | [
"def",
"get_mate_center",
"(",
"self",
",",
"angle",
"=",
"0",
")",
":",
"return",
"Mate",
"(",
"self",
",",
"CoordSystem",
".",
"from_plane",
"(",
"cadquery",
".",
"Plane",
"(",
"origin",
"=",
"(",
"0",
",",
"0",
",",
"self",
".",
"width",
"/",
"2... | Mate at ring's center rotated ``angle`` degrees.
:param angle: rotation around z-axis (unit: deg)
:type angle: :class:`float`
:return: mate in ring's center rotated about z-axis
:rtype: :class:`Mate <cqparts.constraint.Mate>` | [
"Mate",
"at",
"ring",
"s",
"center",
"rotated",
"angle",
"degrees",
"."
] | train | https://github.com/cqparts/cqparts/blob/018e87e14c2c4d1d40b4bfe6a7e22bcf9baf0a53/src/cqparts_bearings/ball.py#L50-L66 |
cqparts/cqparts | src/cqparts_bearings/ball.py | _BallRing.get_max_ballcount | def get_max_ballcount(cls, ball_diam, rolling_radius, min_gap=0.):
"""
The maximum number of balls given ``rolling_radius`` and ``ball_diam``
:param min_gap: minimum gap between balls (measured along vector between
spherical centers)
:type min_gap: :class:`float`... | python | def get_max_ballcount(cls, ball_diam, rolling_radius, min_gap=0.):
"""
The maximum number of balls given ``rolling_radius`` and ``ball_diam``
:param min_gap: minimum gap between balls (measured along vector between
spherical centers)
:type min_gap: :class:`float`... | [
"def",
"get_max_ballcount",
"(",
"cls",
",",
"ball_diam",
",",
"rolling_radius",
",",
"min_gap",
"=",
"0.",
")",
":",
"min_arc",
"=",
"asin",
"(",
"(",
"(",
"ball_diam",
"+",
"min_gap",
")",
"/",
"2",
")",
"/",
"rolling_radius",
")",
"*",
"2",
"return"... | The maximum number of balls given ``rolling_radius`` and ``ball_diam``
:param min_gap: minimum gap between balls (measured along vector between
spherical centers)
:type min_gap: :class:`float`
:return: maximum ball count
:rtype: :class:`int` | [
"The",
"maximum",
"number",
"of",
"balls",
"given",
"rolling_radius",
"and",
"ball_diam"
] | train | https://github.com/cqparts/cqparts/blob/018e87e14c2c4d1d40b4bfe6a7e22bcf9baf0a53/src/cqparts_bearings/ball.py#L87-L99 |
cqparts/cqparts | src/cqparts/display/environment.py | map_environment | def map_environment(**kwargs):
"""
Decorator to map a DisplayEnvironment for displaying components.
The decorated environment will be chosen if its condition is ``True``, and
its order is the smallest.
:param add_to: if set to ``globals()``, display environment's constructor
may ... | python | def map_environment(**kwargs):
"""
Decorator to map a DisplayEnvironment for displaying components.
The decorated environment will be chosen if its condition is ``True``, and
its order is the smallest.
:param add_to: if set to ``globals()``, display environment's constructor
may ... | [
"def",
"map_environment",
"(",
"*",
"*",
"kwargs",
")",
":",
"def",
"inner",
"(",
"cls",
")",
":",
"global",
"display_environments",
"assert",
"issubclass",
"(",
"cls",
",",
"DisplayEnvironment",
")",
",",
"\"can only map DisplayEnvironment classes\"",
"# Add class ... | Decorator to map a DisplayEnvironment for displaying components.
The decorated environment will be chosen if its condition is ``True``, and
its order is the smallest.
:param add_to: if set to ``globals()``, display environment's constructor
may reference its own type.
:type add_to: :... | [
"Decorator",
"to",
"map",
"a",
"DisplayEnvironment",
"for",
"displaying",
"components",
".",
"The",
"decorated",
"environment",
"will",
"be",
"chosen",
"if",
"its",
"condition",
"is",
"True",
"and",
"its",
"order",
"is",
"the",
"smallest",
"."
] | train | https://github.com/cqparts/cqparts/blob/018e87e14c2c4d1d40b4bfe6a7e22bcf9baf0a53/src/cqparts/display/environment.py#L14-L80 |
cqparts/cqparts | src/cqparts/display/environment.py | DisplayEnvironment.display_callback | def display_callback(self, component, **kwargs):
"""
Display given component in this environment.
.. note::
To be overridden by inheriting classes
An example of a introducing a custom display environment.
.. doctest::
import cqparts
from c... | python | def display_callback(self, component, **kwargs):
"""
Display given component in this environment.
.. note::
To be overridden by inheriting classes
An example of a introducing a custom display environment.
.. doctest::
import cqparts
from c... | [
"def",
"display_callback",
"(",
"self",
",",
"component",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"type",
"(",
"self",
")",
"is",
"DisplayEnvironment",
":",
"raise",
"RuntimeError",
"(",
"(",
"\"%r is not a functional display environment, \"",
"%",
"(",
"type",... | Display given component in this environment.
.. note::
To be overridden by inheriting classes
An example of a introducing a custom display environment.
.. doctest::
import cqparts
from cqparts.display.environment import DisplayEnvironment, map_environment... | [
"Display",
"given",
"component",
"in",
"this",
"environment",
"."
] | train | https://github.com/cqparts/cqparts/blob/018e87e14c2c4d1d40b4bfe6a7e22bcf9baf0a53/src/cqparts/display/environment.py#L105-L180 |
cqparts/cqparts | src/cqparts/codec/gltf.py | ShapeBuffer.add_vertex | def add_vertex(self, x, y, z):
"""
Add a ``VEC3`` of ``floats`` to the ``vert_data`` buffer
"""
self.vert_data.write(
struct.pack('<f', x) +
struct.pack('<f', y) +
struct.pack('<f', z)
)
# retain min/max values
self.vert_min = ... | python | def add_vertex(self, x, y, z):
"""
Add a ``VEC3`` of ``floats`` to the ``vert_data`` buffer
"""
self.vert_data.write(
struct.pack('<f', x) +
struct.pack('<f', y) +
struct.pack('<f', z)
)
# retain min/max values
self.vert_min = ... | [
"def",
"add_vertex",
"(",
"self",
",",
"x",
",",
"y",
",",
"z",
")",
":",
"self",
".",
"vert_data",
".",
"write",
"(",
"struct",
".",
"pack",
"(",
"'<f'",
",",
"x",
")",
"+",
"struct",
".",
"pack",
"(",
"'<f'",
",",
"y",
")",
"+",
"struct",
"... | Add a ``VEC3`` of ``floats`` to the ``vert_data`` buffer | [
"Add",
"a",
"VEC3",
"of",
"floats",
"to",
"the",
"vert_data",
"buffer"
] | train | https://github.com/cqparts/cqparts/blob/018e87e14c2c4d1d40b4bfe6a7e22bcf9baf0a53/src/cqparts/codec/gltf.py#L173-L185 |
cqparts/cqparts | src/cqparts/codec/gltf.py | ShapeBuffer.add_poly_index | def add_poly_index(self, i, j, k):
"""
Add 3 ``SCALAR`` of ``uint`` to the ``idx_data`` buffer.
"""
self.idx_data.write(
struct.pack(self.idx_fmt, i) +
struct.pack(self.idx_fmt, j) +
struct.pack(self.idx_fmt, k)
) | python | def add_poly_index(self, i, j, k):
"""
Add 3 ``SCALAR`` of ``uint`` to the ``idx_data`` buffer.
"""
self.idx_data.write(
struct.pack(self.idx_fmt, i) +
struct.pack(self.idx_fmt, j) +
struct.pack(self.idx_fmt, k)
) | [
"def",
"add_poly_index",
"(",
"self",
",",
"i",
",",
"j",
",",
"k",
")",
":",
"self",
".",
"idx_data",
".",
"write",
"(",
"struct",
".",
"pack",
"(",
"self",
".",
"idx_fmt",
",",
"i",
")",
"+",
"struct",
".",
"pack",
"(",
"self",
".",
"idx_fmt",
... | Add 3 ``SCALAR`` of ``uint`` to the ``idx_data`` buffer. | [
"Add",
"3",
"SCALAR",
"of",
"uint",
"to",
"the",
"idx_data",
"buffer",
"."
] | train | https://github.com/cqparts/cqparts/blob/018e87e14c2c4d1d40b4bfe6a7e22bcf9baf0a53/src/cqparts/codec/gltf.py#L187-L195 |
cqparts/cqparts | src/cqparts/codec/gltf.py | ShapeBuffer.buffer_iter | def buffer_iter(self, block_size=1024):
"""
Iterate through chunks of the vertices, and indices buffers seamlessly.
.. note::
To see a usage example, look at the :class:`ShapeBuffer` description.
"""
streams = (
self.vert_data,
self.idx_data,... | python | def buffer_iter(self, block_size=1024):
"""
Iterate through chunks of the vertices, and indices buffers seamlessly.
.. note::
To see a usage example, look at the :class:`ShapeBuffer` description.
"""
streams = (
self.vert_data,
self.idx_data,... | [
"def",
"buffer_iter",
"(",
"self",
",",
"block_size",
"=",
"1024",
")",
":",
"streams",
"=",
"(",
"self",
".",
"vert_data",
",",
"self",
".",
"idx_data",
",",
")",
"# Chain streams seamlessly",
"for",
"stream",
"in",
"streams",
":",
"stream",
".",
"seek",
... | Iterate through chunks of the vertices, and indices buffers seamlessly.
.. note::
To see a usage example, look at the :class:`ShapeBuffer` description. | [
"Iterate",
"through",
"chunks",
"of",
"the",
"vertices",
"and",
"indices",
"buffers",
"seamlessly",
"."
] | train | https://github.com/cqparts/cqparts/blob/018e87e14c2c4d1d40b4bfe6a7e22bcf9baf0a53/src/cqparts/codec/gltf.py#L197-L218 |
cqparts/cqparts | src/cqparts/codec/gltf.py | ShapeBuffer.read | def read(self):
"""
Read buffer out as a single stream.
.. warning::
Avoid using this function!
**Why?** This is a *convenience* function; it doesn't encourage good
memory management.
All memory required for a mesh is duplicated, and returned a... | python | def read(self):
"""
Read buffer out as a single stream.
.. warning::
Avoid using this function!
**Why?** This is a *convenience* function; it doesn't encourage good
memory management.
All memory required for a mesh is duplicated, and returned a... | [
"def",
"read",
"(",
"self",
")",
":",
"buffer",
"=",
"BytesIO",
"(",
")",
"for",
"chunk",
"in",
"self",
".",
"buffer_iter",
"(",
")",
":",
"log",
".",
"debug",
"(",
"'buffer.write(%r)'",
",",
"chunk",
")",
"buffer",
".",
"write",
"(",
"chunk",
")",
... | Read buffer out as a single stream.
.. warning::
Avoid using this function!
**Why?** This is a *convenience* function; it doesn't encourage good
memory management.
All memory required for a mesh is duplicated, and returned as a
single :class:`str`.... | [
"Read",
"buffer",
"out",
"as",
"a",
"single",
"stream",
"."
] | train | https://github.com/cqparts/cqparts/blob/018e87e14c2c4d1d40b4bfe6a7e22bcf9baf0a53/src/cqparts/codec/gltf.py#L223-L245 |
cqparts/cqparts | src/cqparts/constraint/mate.py | Mate.world_coords | def world_coords(self):
"""
:return: world coordinates of mate.
:rtype: :class:`CoordSystem <cqparts.utils.geometry.CoordSystem>`
:raises ValueError: if ``.component`` does not have valid world coordinates.
If ``.component`` is ``None``, then the ``.local_coords`` are returned.
... | python | def world_coords(self):
"""
:return: world coordinates of mate.
:rtype: :class:`CoordSystem <cqparts.utils.geometry.CoordSystem>`
:raises ValueError: if ``.component`` does not have valid world coordinates.
If ``.component`` is ``None``, then the ``.local_coords`` are returned.
... | [
"def",
"world_coords",
"(",
"self",
")",
":",
"if",
"self",
".",
"component",
"is",
"None",
":",
"# no component, world == local",
"return",
"copy",
"(",
"self",
".",
"local_coords",
")",
"else",
":",
"cmp_origin",
"=",
"self",
".",
"component",
".",
"world_... | :return: world coordinates of mate.
:rtype: :class:`CoordSystem <cqparts.utils.geometry.CoordSystem>`
:raises ValueError: if ``.component`` does not have valid world coordinates.
If ``.component`` is ``None``, then the ``.local_coords`` are returned. | [
":",
"return",
":",
"world",
"coordinates",
"of",
"mate",
".",
":",
"rtype",
":",
":",
"class",
":",
"CoordSystem",
"<cqparts",
".",
"utils",
".",
"geometry",
".",
"CoordSystem",
">",
":",
"raises",
"ValueError",
":",
"if",
".",
"component",
"does",
"not... | train | https://github.com/cqparts/cqparts/blob/018e87e14c2c4d1d40b4bfe6a7e22bcf9baf0a53/src/cqparts/constraint/mate.py#L43-L62 |
cqparts/cqparts | src/cqparts/part.py | Part.make_simple | def make_simple(self):
"""
Create and return *simplified* solid part.
The simplified representation of a ``Part`` is to lower the export
quality of an ``Assembly`` or ``Part`` for rendering.
Overriding this is optional, but highly recommended.
The default behaviour ret... | python | def make_simple(self):
"""
Create and return *simplified* solid part.
The simplified representation of a ``Part`` is to lower the export
quality of an ``Assembly`` or ``Part`` for rendering.
Overriding this is optional, but highly recommended.
The default behaviour ret... | [
"def",
"make_simple",
"(",
"self",
")",
":",
"complex_obj",
"=",
"self",
".",
"make",
"(",
")",
"bb",
"=",
"complex_obj",
".",
"findSolid",
"(",
")",
".",
"BoundingBox",
"(",
")",
"simple_obj",
"=",
"cadquery",
".",
"Workplane",
"(",
"'XY'",
",",
"orig... | Create and return *simplified* solid part.
The simplified representation of a ``Part`` is to lower the export
quality of an ``Assembly`` or ``Part`` for rendering.
Overriding this is optional, but highly recommended.
The default behaviour returns the full complexity object's bounding ... | [
"Create",
"and",
"return",
"*",
"simplified",
"*",
"solid",
"part",
"."
] | train | https://github.com/cqparts/cqparts/blob/018e87e14c2c4d1d40b4bfe6a7e22bcf9baf0a53/src/cqparts/part.py#L48-L80 |
cqparts/cqparts | src/cqparts/part.py | Part.local_obj | def local_obj(self):
"""
Buffered result of :meth:`make` which is (probably) a
:class:`cadquery.Workplane` instance. If ``_simple`` is ``True``, then
:meth:`make_simple` is returned instead.
.. note::
This is usually the correct way to get your part's object
... | python | def local_obj(self):
"""
Buffered result of :meth:`make` which is (probably) a
:class:`cadquery.Workplane` instance. If ``_simple`` is ``True``, then
:meth:`make_simple` is returned instead.
.. note::
This is usually the correct way to get your part's object
... | [
"def",
"local_obj",
"(",
"self",
")",
":",
"if",
"self",
".",
"_local_obj",
"is",
"None",
":",
"# Simplified or Complex",
"if",
"self",
".",
"_simple",
":",
"value",
"=",
"self",
".",
"make_simple",
"(",
")",
"else",
":",
"value",
"=",
"self",
".",
"ma... | Buffered result of :meth:`make` which is (probably) a
:class:`cadquery.Workplane` instance. If ``_simple`` is ``True``, then
:meth:`make_simple` is returned instead.
.. note::
This is usually the correct way to get your part's object
for rendering, exporting, or measurin... | [
"Buffered",
"result",
"of",
":",
"meth",
":",
"make",
"which",
"is",
"(",
"probably",
")",
"a",
":",
"class",
":",
"cadquery",
".",
"Workplane",
"instance",
".",
"If",
"_simple",
"is",
"True",
"then",
":",
"meth",
":",
"make_simple",
"is",
"returned",
... | train | https://github.com/cqparts/cqparts/blob/018e87e14c2c4d1d40b4bfe6a7e22bcf9baf0a53/src/cqparts/part.py#L95-L119 |
cqparts/cqparts | src/cqparts/part.py | Part.world_obj | def world_obj(self):
"""
The :meth:`local_obj <local_obj>` object in the
:meth:`world_coords <Component.world_coords>` coordinate system.
.. note::
This is automatically generated when called, and
:meth:`world_coords <Component.world_coords>` is not ``Null``.
... | python | def world_obj(self):
"""
The :meth:`local_obj <local_obj>` object in the
:meth:`world_coords <Component.world_coords>` coordinate system.
.. note::
This is automatically generated when called, and
:meth:`world_coords <Component.world_coords>` is not ``Null``.
... | [
"def",
"world_obj",
"(",
"self",
")",
":",
"if",
"self",
".",
"_world_obj",
"is",
"None",
":",
"local_obj",
"=",
"self",
".",
"local_obj",
"world_coords",
"=",
"self",
".",
"world_coords",
"if",
"(",
"local_obj",
"is",
"not",
"None",
")",
"and",
"(",
"... | The :meth:`local_obj <local_obj>` object in the
:meth:`world_coords <Component.world_coords>` coordinate system.
.. note::
This is automatically generated when called, and
:meth:`world_coords <Component.world_coords>` is not ``Null``. | [
"The",
":",
"meth",
":",
"local_obj",
"<local_obj",
">",
"object",
"in",
"the",
":",
"meth",
":",
"world_coords",
"<Component",
".",
"world_coords",
">",
"coordinate",
"system",
"."
] | train | https://github.com/cqparts/cqparts/blob/018e87e14c2c4d1d40b4bfe6a7e22bcf9baf0a53/src/cqparts/part.py#L128-L144 |
cqparts/cqparts | src/cqparts/part.py | Part.bounding_box | def bounding_box(self):
"""
Generate a bounding box based on the full complexity part.
:return: bounding box of part
:rtype: cadquery.BoundBox
"""
if self.world_coords:
return self.world_obj.findSolid().BoundingBox()
return self.local_obj.findSolid().... | python | def bounding_box(self):
"""
Generate a bounding box based on the full complexity part.
:return: bounding box of part
:rtype: cadquery.BoundBox
"""
if self.world_coords:
return self.world_obj.findSolid().BoundingBox()
return self.local_obj.findSolid().... | [
"def",
"bounding_box",
"(",
"self",
")",
":",
"if",
"self",
".",
"world_coords",
":",
"return",
"self",
".",
"world_obj",
".",
"findSolid",
"(",
")",
".",
"BoundingBox",
"(",
")",
"return",
"self",
".",
"local_obj",
".",
"findSolid",
"(",
")",
".",
"Bo... | Generate a bounding box based on the full complexity part.
:return: bounding box of part
:rtype: cadquery.BoundBox | [
"Generate",
"a",
"bounding",
"box",
"based",
"on",
"the",
"full",
"complexity",
"part",
"."
] | train | https://github.com/cqparts/cqparts/blob/018e87e14c2c4d1d40b4bfe6a7e22bcf9baf0a53/src/cqparts/part.py#L152-L161 |
cqparts/cqparts | src/cqparts_fasteners/male.py | MaleFastenerPart.make_cutter | def make_cutter(self):
"""
Makes a shape to be used as a negative; it can be cut away from other
shapes to make a perfectly shaped pocket for this part.
For example, for a countersunk screw with a neck, the following
cutter would be generated.
.. image:: /_static/img/fa... | python | def make_cutter(self):
"""
Makes a shape to be used as a negative; it can be cut away from other
shapes to make a perfectly shaped pocket for this part.
For example, for a countersunk screw with a neck, the following
cutter would be generated.
.. image:: /_static/img/fa... | [
"def",
"make_cutter",
"(",
"self",
")",
":",
"# head",
"obj",
"=",
"self",
".",
"head",
".",
"make_cutter",
"(",
")",
"# neck",
"if",
"self",
".",
"neck_length",
":",
"# neck cut diameter (if thread is larger than the neck, thread must fit through)",
"(",
"inner_radiu... | Makes a shape to be used as a negative; it can be cut away from other
shapes to make a perfectly shaped pocket for this part.
For example, for a countersunk screw with a neck, the following
cutter would be generated.
.. image:: /_static/img/fastenerpart/male.cutter.png
If the ... | [
"Makes",
"a",
"shape",
"to",
"be",
"used",
"as",
"a",
"negative",
";",
"it",
"can",
"be",
"cut",
"away",
"from",
"other",
"shapes",
"to",
"make",
"a",
"perfectly",
"shaped",
"pocket",
"for",
"this",
"part",
"."
] | train | https://github.com/cqparts/cqparts/blob/018e87e14c2c4d1d40b4bfe6a7e22bcf9baf0a53/src/cqparts_fasteners/male.py#L245-L277 |
cqparts/cqparts | src/cqparts_motors/dc.py | _Cup.get_cutout | def get_cutout(self, clearance=0):
" get the cutout for the shaft"
return cq.Workplane('XY', origin=(0, 0, 0)) \
.circle((self.diam / 2) + clearance) \
.extrude(10) | python | def get_cutout(self, clearance=0):
" get the cutout for the shaft"
return cq.Workplane('XY', origin=(0, 0, 0)) \
.circle((self.diam / 2) + clearance) \
.extrude(10) | [
"def",
"get_cutout",
"(",
"self",
",",
"clearance",
"=",
"0",
")",
":",
"return",
"cq",
".",
"Workplane",
"(",
"'XY'",
",",
"origin",
"=",
"(",
"0",
",",
"0",
",",
"0",
")",
")",
".",
"circle",
"(",
"(",
"self",
".",
"diam",
"/",
"2",
")",
"+... | get the cutout for the shaft | [
"get",
"the",
"cutout",
"for",
"the",
"shaft"
] | train | https://github.com/cqparts/cqparts/blob/018e87e14c2c4d1d40b4bfe6a7e22bcf9baf0a53/src/cqparts_motors/dc.py#L68-L72 |
cqparts/cqparts | src/cqparts_motors/dc.py | _Cup.mate_bottom | def mate_bottom(self):
" connect to the bottom of the cup"
return Mate(self, CoordSystem(\
origin=(0, 0, -self.height),\
xDir=(1, 0, 0),\
normal=(0, 0, 1))) | python | def mate_bottom(self):
" connect to the bottom of the cup"
return Mate(self, CoordSystem(\
origin=(0, 0, -self.height),\
xDir=(1, 0, 0),\
normal=(0, 0, 1))) | [
"def",
"mate_bottom",
"(",
"self",
")",
":",
"return",
"Mate",
"(",
"self",
",",
"CoordSystem",
"(",
"origin",
"=",
"(",
"0",
",",
"0",
",",
"-",
"self",
".",
"height",
")",
",",
"xDir",
"=",
"(",
"1",
",",
"0",
",",
"0",
")",
",",
"normal",
... | connect to the bottom of the cup | [
"connect",
"to",
"the",
"bottom",
"of",
"the",
"cup"
] | train | https://github.com/cqparts/cqparts/blob/018e87e14c2c4d1d40b4bfe6a7e22bcf9baf0a53/src/cqparts_motors/dc.py#L75-L80 |
cqparts/cqparts | src/cqparts/params/utils.py | as_parameter | def as_parameter(nullable=True, strict=True):
"""
Decorate a container class as a functional :class:`Parameter` class
for a :class:`ParametricObject`.
:param nullable: if set, parameter's value may be Null
:type nullable: :class:`bool`
.. doctest::
>>> from cqparts.params import as_pa... | python | def as_parameter(nullable=True, strict=True):
"""
Decorate a container class as a functional :class:`Parameter` class
for a :class:`ParametricObject`.
:param nullable: if set, parameter's value may be Null
:type nullable: :class:`bool`
.. doctest::
>>> from cqparts.params import as_pa... | [
"def",
"as_parameter",
"(",
"nullable",
"=",
"True",
",",
"strict",
"=",
"True",
")",
":",
"def",
"decorator",
"(",
"cls",
")",
":",
"base_class",
"=",
"Parameter",
"if",
"nullable",
"else",
"NonNullParameter",
"return",
"type",
"(",
"cls",
".",
"__name__"... | Decorate a container class as a functional :class:`Parameter` class
for a :class:`ParametricObject`.
:param nullable: if set, parameter's value may be Null
:type nullable: :class:`bool`
.. doctest::
>>> from cqparts.params import as_parameter, ParametricObject
>>> @as_parameter(nulla... | [
"Decorate",
"a",
"container",
"class",
"as",
"a",
"functional",
":",
"class",
":",
"Parameter",
"class",
"for",
"a",
":",
"class",
":",
"ParametricObject",
"."
] | train | https://github.com/cqparts/cqparts/blob/018e87e14c2c4d1d40b4bfe6a7e22bcf9baf0a53/src/cqparts/params/utils.py#L6-L54 |
calmh/unifi-api | unifi/controller.py | Controller._construct_api_path | def _construct_api_path(self, version):
"""Returns valid base API path based on version given
The base API path for the URL is different depending on UniFi server version.
Default returns correct path for latest known stable working versions.
"""
V2_PATH = 'api/'
... | python | def _construct_api_path(self, version):
"""Returns valid base API path based on version given
The base API path for the URL is different depending on UniFi server version.
Default returns correct path for latest known stable working versions.
"""
V2_PATH = 'api/'
... | [
"def",
"_construct_api_path",
"(",
"self",
",",
"version",
")",
":",
"V2_PATH",
"=",
"'api/'",
"V3_PATH",
"=",
"'api/s/'",
"+",
"self",
".",
"site_id",
"+",
"'/'",
"if",
"(",
"version",
"==",
"'v2'",
")",
":",
"return",
"V2_PATH",
"if",
"(",
"version",
... | Returns valid base API path based on version given
The base API path for the URL is different depending on UniFi server version.
Default returns correct path for latest known stable working versions. | [
"Returns",
"valid",
"base",
"API",
"path",
"based",
"on",
"version",
"given"
] | train | https://github.com/calmh/unifi-api/blob/5562d9c7689ef3d08c2d2390fb83d66f65d1086e/unifi/controller.py#L123-L143 |
calmh/unifi-api | unifi/controller.py | Controller.get_alerts_unarchived | def get_alerts_unarchived(self):
"""Return a list of Alerts unarchived."""
js = json.dumps({'_sort': '-time', 'archived': False})
params = urllib.urlencode({'json': js})
return self._read(self.api_url + 'list/alarm', params) | python | def get_alerts_unarchived(self):
"""Return a list of Alerts unarchived."""
js = json.dumps({'_sort': '-time', 'archived': False})
params = urllib.urlencode({'json': js})
return self._read(self.api_url + 'list/alarm', params) | [
"def",
"get_alerts_unarchived",
"(",
"self",
")",
":",
"js",
"=",
"json",
".",
"dumps",
"(",
"{",
"'_sort'",
":",
"'-time'",
",",
"'archived'",
":",
"False",
"}",
")",
"params",
"=",
"urllib",
".",
"urlencode",
"(",
"{",
"'json'",
":",
"js",
"}",
")"... | Return a list of Alerts unarchived. | [
"Return",
"a",
"list",
"of",
"Alerts",
"unarchived",
"."
] | train | https://github.com/calmh/unifi-api/blob/5562d9c7689ef3d08c2d2390fb83d66f65d1086e/unifi/controller.py#L177-L182 |
calmh/unifi-api | unifi/controller.py | Controller.get_statistics_24h | def get_statistics_24h(self, endtime):
"""Return statistical data last 24h from time"""
js = json.dumps(
{'attrs': ["bytes", "num_sta", "time"], 'start': int(endtime - 86400) * 1000, 'end': int(endtime - 3600) * 1000})
params = urllib.urlencode({'json': js})
return self._rea... | python | def get_statistics_24h(self, endtime):
"""Return statistical data last 24h from time"""
js = json.dumps(
{'attrs': ["bytes", "num_sta", "time"], 'start': int(endtime - 86400) * 1000, 'end': int(endtime - 3600) * 1000})
params = urllib.urlencode({'json': js})
return self._rea... | [
"def",
"get_statistics_24h",
"(",
"self",
",",
"endtime",
")",
":",
"js",
"=",
"json",
".",
"dumps",
"(",
"{",
"'attrs'",
":",
"[",
"\"bytes\"",
",",
"\"num_sta\"",
",",
"\"time\"",
"]",
",",
"'start'",
":",
"int",
"(",
"endtime",
"-",
"86400",
")",
... | Return statistical data last 24h from time | [
"Return",
"statistical",
"data",
"last",
"24h",
"from",
"time"
] | train | https://github.com/calmh/unifi-api/blob/5562d9c7689ef3d08c2d2390fb83d66f65d1086e/unifi/controller.py#L189-L195 |
calmh/unifi-api | unifi/controller.py | Controller.get_aps | def get_aps(self):
"""Return a list of all AP:s, with significant information about each."""
#Set test to 0 instead of NULL
params = json.dumps({'_depth': 2, 'test': 0})
return self._read(self.api_url + 'stat/device', params) | python | def get_aps(self):
"""Return a list of all AP:s, with significant information about each."""
#Set test to 0 instead of NULL
params = json.dumps({'_depth': 2, 'test': 0})
return self._read(self.api_url + 'stat/device', params) | [
"def",
"get_aps",
"(",
"self",
")",
":",
"#Set test to 0 instead of NULL",
"params",
"=",
"json",
".",
"dumps",
"(",
"{",
"'_depth'",
":",
"2",
",",
"'test'",
":",
"0",
"}",
")",
"return",
"self",
".",
"_read",
"(",
"self",
".",
"api_url",
"+",
"'stat/... | Return a list of all AP:s, with significant information about each. | [
"Return",
"a",
"list",
"of",
"all",
"AP",
":",
"s",
"with",
"significant",
"information",
"about",
"each",
"."
] | train | https://github.com/calmh/unifi-api/blob/5562d9c7689ef3d08c2d2390fb83d66f65d1086e/unifi/controller.py#L202-L207 |
calmh/unifi-api | unifi/controller.py | Controller.restart_ap_name | def restart_ap_name(self, name):
"""Restart an access point (by name).
Arguments:
name -- the name address of the AP to restart.
"""
if not name:
raise APIError('%s is not a valid name' % str(name))
for ap in self.get_aps():
if ap.get('state... | python | def restart_ap_name(self, name):
"""Restart an access point (by name).
Arguments:
name -- the name address of the AP to restart.
"""
if not name:
raise APIError('%s is not a valid name' % str(name))
for ap in self.get_aps():
if ap.get('state... | [
"def",
"restart_ap_name",
"(",
"self",
",",
"name",
")",
":",
"if",
"not",
"name",
":",
"raise",
"APIError",
"(",
"'%s is not a valid name'",
"%",
"str",
"(",
"name",
")",
")",
"for",
"ap",
"in",
"self",
".",
"get_aps",
"(",
")",
":",
"if",
"ap",
"."... | Restart an access point (by name).
Arguments:
name -- the name address of the AP to restart. | [
"Restart",
"an",
"access",
"point",
"(",
"by",
"name",
")",
"."
] | train | https://github.com/calmh/unifi-api/blob/5562d9c7689ef3d08c2d2390fb83d66f65d1086e/unifi/controller.py#L285-L297 |
calmh/unifi-api | unifi/controller.py | Controller.archive_all_alerts | def archive_all_alerts(self):
"""Archive all Alerts
"""
js = json.dumps({'cmd': 'archive-all-alarms'})
params = urllib.urlencode({'json': js})
answer = self._read(self.api_url + 'cmd/evtmgr', params) | python | def archive_all_alerts(self):
"""Archive all Alerts
"""
js = json.dumps({'cmd': 'archive-all-alarms'})
params = urllib.urlencode({'json': js})
answer = self._read(self.api_url + 'cmd/evtmgr', params) | [
"def",
"archive_all_alerts",
"(",
"self",
")",
":",
"js",
"=",
"json",
".",
"dumps",
"(",
"{",
"'cmd'",
":",
"'archive-all-alarms'",
"}",
")",
"params",
"=",
"urllib",
".",
"urlencode",
"(",
"{",
"'json'",
":",
"js",
"}",
")",
"answer",
"=",
"self",
... | Archive all Alerts | [
"Archive",
"all",
"Alerts"
] | train | https://github.com/calmh/unifi-api/blob/5562d9c7689ef3d08c2d2390fb83d66f65d1086e/unifi/controller.py#L299-L304 |
calmh/unifi-api | unifi/controller.py | Controller.create_backup | def create_backup(self):
"""Ask controller to create a backup archive file, response contains the path to the backup file.
Warning: This process puts significant load on the controller may
render it partially unresponsive for other requests.
"""
js = json.dumps({'cmd':... | python | def create_backup(self):
"""Ask controller to create a backup archive file, response contains the path to the backup file.
Warning: This process puts significant load on the controller may
render it partially unresponsive for other requests.
"""
js = json.dumps({'cmd':... | [
"def",
"create_backup",
"(",
"self",
")",
":",
"js",
"=",
"json",
".",
"dumps",
"(",
"{",
"'cmd'",
":",
"'backup'",
"}",
")",
"params",
"=",
"urllib",
".",
"urlencode",
"(",
"{",
"'json'",
":",
"js",
"}",
")",
"answer",
"=",
"self",
".",
"_read",
... | Ask controller to create a backup archive file, response contains the path to the backup file.
Warning: This process puts significant load on the controller may
render it partially unresponsive for other requests. | [
"Ask",
"controller",
"to",
"create",
"a",
"backup",
"archive",
"file",
"response",
"contains",
"the",
"path",
"to",
"the",
"backup",
"file",
"."
] | train | https://github.com/calmh/unifi-api/blob/5562d9c7689ef3d08c2d2390fb83d66f65d1086e/unifi/controller.py#L306-L317 |
calmh/unifi-api | unifi/controller.py | Controller.get_backup | def get_backup(self, target_file='unifi-backup.unf'):
"""Get a backup archive from a controller.
Arguments:
target_file -- Filename or full path to download the backup archive to, should have .unf extension for restore.
"""
download_path = self.create_backup()
open... | python | def get_backup(self, target_file='unifi-backup.unf'):
"""Get a backup archive from a controller.
Arguments:
target_file -- Filename or full path to download the backup archive to, should have .unf extension for restore.
"""
download_path = self.create_backup()
open... | [
"def",
"get_backup",
"(",
"self",
",",
"target_file",
"=",
"'unifi-backup.unf'",
")",
":",
"download_path",
"=",
"self",
".",
"create_backup",
"(",
")",
"opener",
"=",
"self",
".",
"opener",
".",
"open",
"(",
"self",
".",
"url",
"+",
"download_path",
")",
... | Get a backup archive from a controller.
Arguments:
target_file -- Filename or full path to download the backup archive to, should have .unf extension for restore. | [
"Get",
"a",
"backup",
"archive",
"from",
"a",
"controller",
"."
] | train | https://github.com/calmh/unifi-api/blob/5562d9c7689ef3d08c2d2390fb83d66f65d1086e/unifi/controller.py#L319-L333 |
calmh/unifi-api | unifi/controller.py | Controller.authorize_guest | def authorize_guest(self, guest_mac, minutes, up_bandwidth=None, down_bandwidth=None, byte_quota=None, ap_mac=None):
"""
Authorize a guest based on his MAC address.
Arguments:
guest_mac -- the guest MAC address : aa:bb:cc:dd:ee:ff
minutes -- duration of the aut... | python | def authorize_guest(self, guest_mac, minutes, up_bandwidth=None, down_bandwidth=None, byte_quota=None, ap_mac=None):
"""
Authorize a guest based on his MAC address.
Arguments:
guest_mac -- the guest MAC address : aa:bb:cc:dd:ee:ff
minutes -- duration of the aut... | [
"def",
"authorize_guest",
"(",
"self",
",",
"guest_mac",
",",
"minutes",
",",
"up_bandwidth",
"=",
"None",
",",
"down_bandwidth",
"=",
"None",
",",
"byte_quota",
"=",
"None",
",",
"ap_mac",
"=",
"None",
")",
":",
"cmd",
"=",
"'authorize-guest'",
"js",
"=",... | Authorize a guest based on his MAC address.
Arguments:
guest_mac -- the guest MAC address : aa:bb:cc:dd:ee:ff
minutes -- duration of the authorization in minutes
up_bandwith -- up speed allowed in kbps (optional)
down_bandwith -- down speed allowed in... | [
"Authorize",
"a",
"guest",
"based",
"on",
"his",
"MAC",
"address",
"."
] | train | https://github.com/calmh/unifi-api/blob/5562d9c7689ef3d08c2d2390fb83d66f65d1086e/unifi/controller.py#L335-L359 |
calmh/unifi-api | unifi/controller.py | Controller.unauthorize_guest | def unauthorize_guest(self, guest_mac):
"""
Unauthorize a guest based on his MAC address.
Arguments:
guest_mac -- the guest MAC address : aa:bb:cc:dd:ee:ff
"""
cmd = 'unauthorize-guest'
js = {'mac': guest_mac}
return self._run_command(cmd, params=js) | python | def unauthorize_guest(self, guest_mac):
"""
Unauthorize a guest based on his MAC address.
Arguments:
guest_mac -- the guest MAC address : aa:bb:cc:dd:ee:ff
"""
cmd = 'unauthorize-guest'
js = {'mac': guest_mac}
return self._run_command(cmd, params=js) | [
"def",
"unauthorize_guest",
"(",
"self",
",",
"guest_mac",
")",
":",
"cmd",
"=",
"'unauthorize-guest'",
"js",
"=",
"{",
"'mac'",
":",
"guest_mac",
"}",
"return",
"self",
".",
"_run_command",
"(",
"cmd",
",",
"params",
"=",
"js",
")"
] | Unauthorize a guest based on his MAC address.
Arguments:
guest_mac -- the guest MAC address : aa:bb:cc:dd:ee:ff | [
"Unauthorize",
"a",
"guest",
"based",
"on",
"his",
"MAC",
"address",
"."
] | train | https://github.com/calmh/unifi-api/blob/5562d9c7689ef3d08c2d2390fb83d66f65d1086e/unifi/controller.py#L361-L371 |
maybelinot/df2gspread | df2gspread/gspread2df.py | download | def download(gfile, wks_name=None, col_names=False, row_names=False,
credentials=None, start_cell = 'A1'):
"""
Download Google Spreadsheet and convert it to Pandas DataFrame
:param gfile: path to Google Spreadsheet or gspread ID
:param wks_name: worksheet name
:param col... | python | def download(gfile, wks_name=None, col_names=False, row_names=False,
credentials=None, start_cell = 'A1'):
"""
Download Google Spreadsheet and convert it to Pandas DataFrame
:param gfile: path to Google Spreadsheet or gspread ID
:param wks_name: worksheet name
:param col... | [
"def",
"download",
"(",
"gfile",
",",
"wks_name",
"=",
"None",
",",
"col_names",
"=",
"False",
",",
"row_names",
"=",
"False",
",",
"credentials",
"=",
"None",
",",
"start_cell",
"=",
"'A1'",
")",
":",
"# access credentials",
"credentials",
"=",
"get_credent... | Download Google Spreadsheet and convert it to Pandas DataFrame
:param gfile: path to Google Spreadsheet or gspread ID
:param wks_name: worksheet name
:param col_names: assing top row to column names for Pandas DataFrame
:param row_names: assing left column to row names for Pandas DataFr... | [
"Download",
"Google",
"Spreadsheet",
"and",
"convert",
"it",
"to",
"Pandas",
"DataFrame"
] | train | https://github.com/maybelinot/df2gspread/blob/f4cef3800704aceff2ed08a623a594b558d44898/df2gspread/gspread2df.py#L29-L123 |
maybelinot/df2gspread | df2gspread/utils.py | get_credentials | def get_credentials(credentials=None, client_secret_file=CLIENT_SECRET_FILE, refresh_token=None):
"""Consistently returns valid credentials object.
See Also:
https://developers.google.com/drive/web/quickstart/python
Args:
client_secret_file (str): path to client secrets file, defaults to .... | python | def get_credentials(credentials=None, client_secret_file=CLIENT_SECRET_FILE, refresh_token=None):
"""Consistently returns valid credentials object.
See Also:
https://developers.google.com/drive/web/quickstart/python
Args:
client_secret_file (str): path to client secrets file, defaults to .... | [
"def",
"get_credentials",
"(",
"credentials",
"=",
"None",
",",
"client_secret_file",
"=",
"CLIENT_SECRET_FILE",
",",
"refresh_token",
"=",
"None",
")",
":",
"# if the utility was provided credentials just return those",
"if",
"credentials",
":",
"if",
"_is_valid_credential... | Consistently returns valid credentials object.
See Also:
https://developers.google.com/drive/web/quickstart/python
Args:
client_secret_file (str): path to client secrets file, defaults to .gdrive_private
refresh_token (str): path to a user provided refresh token that is already
... | [
"Consistently",
"returns",
"valid",
"credentials",
"object",
"."
] | train | https://github.com/maybelinot/df2gspread/blob/f4cef3800704aceff2ed08a623a594b558d44898/df2gspread/utils.py#L33-L90 |
maybelinot/df2gspread | df2gspread/utils.py | create_service_credentials | def create_service_credentials(private_key_file=None, client_email=None,
client_secret_file=CLIENT_SECRET_FILE):
"""Create credentials from service account information.
See Also:
https://developers.google.com/api-client-library/python/auth/service-accounts
Args:
... | python | def create_service_credentials(private_key_file=None, client_email=None,
client_secret_file=CLIENT_SECRET_FILE):
"""Create credentials from service account information.
See Also:
https://developers.google.com/api-client-library/python/auth/service-accounts
Args:
... | [
"def",
"create_service_credentials",
"(",
"private_key_file",
"=",
"None",
",",
"client_email",
"=",
"None",
",",
"client_secret_file",
"=",
"CLIENT_SECRET_FILE",
")",
":",
"if",
"private_key_file",
"is",
"not",
"None",
":",
"with",
"open",
"(",
"os",
".",
"path... | Create credentials from service account information.
See Also:
https://developers.google.com/api-client-library/python/auth/service-accounts
Args:
client_secret_file (str): path to json file with just the client_email when
providing the `private_key_file` separately, or this file c... | [
"Create",
"credentials",
"from",
"service",
"account",
"information",
"."
] | train | https://github.com/maybelinot/df2gspread/blob/f4cef3800704aceff2ed08a623a594b558d44898/df2gspread/utils.py#L97-L146 |
maybelinot/df2gspread | df2gspread/gfiles.py | get_file_id | def get_file_id(credentials, gfile, write_access=False):
"""
Get file ID by provided path. If file does not exist and
`write_access` is true, it will create whole path for you.
:param credentials: provide own credentials
:param gfile: path to Google Spreadsheet
:param write_... | python | def get_file_id(credentials, gfile, write_access=False):
"""
Get file ID by provided path. If file does not exist and
`write_access` is true, it will create whole path for you.
:param credentials: provide own credentials
:param gfile: path to Google Spreadsheet
:param write_... | [
"def",
"get_file_id",
"(",
"credentials",
",",
"gfile",
",",
"write_access",
"=",
"False",
")",
":",
"# auth for apiclient",
"http",
"=",
"credentials",
".",
"authorize",
"(",
"Http",
"(",
")",
")",
"service",
"=",
"discovery",
".",
"build",
"(",
"'drive'",
... | Get file ID by provided path. If file does not exist and
`write_access` is true, it will create whole path for you.
:param credentials: provide own credentials
:param gfile: path to Google Spreadsheet
:param write_access: allows to create full path if file does not exist
:type c... | [
"Get",
"file",
"ID",
"by",
"provided",
"path",
".",
"If",
"file",
"does",
"not",
"exist",
"and",
"write_access",
"is",
"true",
"it",
"will",
"create",
"whole",
"path",
"for",
"you",
"."
] | train | https://github.com/maybelinot/df2gspread/blob/f4cef3800704aceff2ed08a623a594b558d44898/df2gspread/gfiles.py#L19-L66 |
maybelinot/df2gspread | df2gspread/gfiles.py | get_worksheet | def get_worksheet(gc, gfile_id, wks_name, write_access=False, new_sheet_dimensions=(1000, 100)):
"""DOCS..."""
spsh = gc.open_by_key(gfile_id)
# if worksheet name is not provided , take first worksheet
if wks_name is None:
wks = spsh.sheet1
# if worksheet name provided and exist in given s... | python | def get_worksheet(gc, gfile_id, wks_name, write_access=False, new_sheet_dimensions=(1000, 100)):
"""DOCS..."""
spsh = gc.open_by_key(gfile_id)
# if worksheet name is not provided , take first worksheet
if wks_name is None:
wks = spsh.sheet1
# if worksheet name provided and exist in given s... | [
"def",
"get_worksheet",
"(",
"gc",
",",
"gfile_id",
",",
"wks_name",
",",
"write_access",
"=",
"False",
",",
"new_sheet_dimensions",
"=",
"(",
"1000",
",",
"100",
")",
")",
":",
"spsh",
"=",
"gc",
".",
"open_by_key",
"(",
"gfile_id",
")",
"# if worksheet n... | DOCS... | [
"DOCS",
"..."
] | train | https://github.com/maybelinot/df2gspread/blob/f4cef3800704aceff2ed08a623a594b558d44898/df2gspread/gfiles.py#L69-L86 |
maybelinot/df2gspread | df2gspread/gfiles.py | delete_file | def delete_file(credentials, file_id):
"""DOCS..."""
try:
http = credentials.authorize(Http())
service = discovery.build(
'drive', 'v3', http=http, cache_discovery=False)
service.files().delete(fileId=file_id).execute()
except errors.HttpError as e:
logr.error(e)
... | python | def delete_file(credentials, file_id):
"""DOCS..."""
try:
http = credentials.authorize(Http())
service = discovery.build(
'drive', 'v3', http=http, cache_discovery=False)
service.files().delete(fileId=file_id).execute()
except errors.HttpError as e:
logr.error(e)
... | [
"def",
"delete_file",
"(",
"credentials",
",",
"file_id",
")",
":",
"try",
":",
"http",
"=",
"credentials",
".",
"authorize",
"(",
"Http",
"(",
")",
")",
"service",
"=",
"discovery",
".",
"build",
"(",
"'drive'",
",",
"'v3'",
",",
"http",
"=",
"http",
... | DOCS... | [
"DOCS",
"..."
] | train | https://github.com/maybelinot/df2gspread/blob/f4cef3800704aceff2ed08a623a594b558d44898/df2gspread/gfiles.py#L89-L98 |
maybelinot/df2gspread | df2gspread/df2gspread.py | upload | def upload(df, gfile="/New Spreadsheet", wks_name=None,
col_names=True, row_names=True, clean=True, credentials=None,
start_cell = 'A1', df_size = False, new_sheet_dimensions = (1000,100)):
'''
Upload given Pandas DataFrame to Google Drive and returns
gspread Worksheet object
... | python | def upload(df, gfile="/New Spreadsheet", wks_name=None,
col_names=True, row_names=True, clean=True, credentials=None,
start_cell = 'A1', df_size = False, new_sheet_dimensions = (1000,100)):
'''
Upload given Pandas DataFrame to Google Drive and returns
gspread Worksheet object
... | [
"def",
"upload",
"(",
"df",
",",
"gfile",
"=",
"\"/New Spreadsheet\"",
",",
"wks_name",
"=",
"None",
",",
"col_names",
"=",
"True",
",",
"row_names",
"=",
"True",
",",
"clean",
"=",
"True",
",",
"credentials",
"=",
"None",
",",
"start_cell",
"=",
"'A1'",... | Upload given Pandas DataFrame to Google Drive and returns
gspread Worksheet object
:param df: Pandas DataFrame
:param gfile: path to Google Spreadsheet or gspread ID
:param wks_name: worksheet name
:param col_names: passing top row to column names for Pandas DataFrame
:p... | [
"Upload",
"given",
"Pandas",
"DataFrame",
"to",
"Google",
"Drive",
"and",
"returns",
"gspread",
"Worksheet",
"object"
] | train | https://github.com/maybelinot/df2gspread/blob/f4cef3800704aceff2ed08a623a594b558d44898/df2gspread/df2gspread.py#L24-L148 |
maybelinot/df2gspread | df2gspread/df2gspread.py | clean_worksheet | def clean_worksheet(wks, gfile_id, wks_name, credentials):
"""DOCS..."""
values = wks.get_all_values()
if values:
df_ = pd.DataFrame(index=range(len(values)),
columns=range(len(values[0])))
df_ = df_.fillna('')
wks = upload(df_, gfile_id, wks_name=wks_name... | python | def clean_worksheet(wks, gfile_id, wks_name, credentials):
"""DOCS..."""
values = wks.get_all_values()
if values:
df_ = pd.DataFrame(index=range(len(values)),
columns=range(len(values[0])))
df_ = df_.fillna('')
wks = upload(df_, gfile_id, wks_name=wks_name... | [
"def",
"clean_worksheet",
"(",
"wks",
",",
"gfile_id",
",",
"wks_name",
",",
"credentials",
")",
":",
"values",
"=",
"wks",
".",
"get_all_values",
"(",
")",
"if",
"values",
":",
"df_",
"=",
"pd",
".",
"DataFrame",
"(",
"index",
"=",
"range",
"(",
"len"... | DOCS... | [
"DOCS",
"..."
] | train | https://github.com/maybelinot/df2gspread/blob/f4cef3800704aceff2ed08a623a594b558d44898/df2gspread/df2gspread.py#L150-L161 |
konstantinstadler/country_converter | country_converter/country_converter.py | agg_conc | def agg_conc(original_countries,
aggregates,
missing_countries='test',
merge_multiple_string='_&_',
log_missing_countries=None,
log_merge_multiple_strings=None,
coco=None,
as_dataframe='sparse',
original_countries_cl... | python | def agg_conc(original_countries,
aggregates,
missing_countries='test',
merge_multiple_string='_&_',
log_missing_countries=None,
log_merge_multiple_strings=None,
coco=None,
as_dataframe='sparse',
original_countries_cl... | [
"def",
"agg_conc",
"(",
"original_countries",
",",
"aggregates",
",",
"missing_countries",
"=",
"'test'",
",",
"merge_multiple_string",
"=",
"'_&_'",
",",
"log_missing_countries",
"=",
"None",
",",
"log_merge_multiple_strings",
"=",
"None",
",",
"coco",
"=",
"None",... | Builds an aggregation concordance dict, vec or matrix
Parameters
----------
original_countries: list or str
List of countries to aggregated, also accepts and valid column name of
CountryConverter.data
aggregates: list of dict or str
List of aggregation information. This can ei... | [
"Builds",
"an",
"aggregation",
"concordance",
"dict",
"vec",
"or",
"matrix"
] | train | https://github.com/konstantinstadler/country_converter/blob/b78622dfa6700480df632fe061d6837b96f31b71/country_converter/country_converter.py#L18-L153 |
konstantinstadler/country_converter | country_converter/country_converter.py | match | def match(list_a, list_b, not_found='not_found', enforce_sublist=False,
country_data=COUNTRY_DATA_FILE, additional_data=None):
""" Matches the country names given in two lists into a dictionary.
This function matches names given in list_a to the one provided in list_b
using regular expressions de... | python | def match(list_a, list_b, not_found='not_found', enforce_sublist=False,
country_data=COUNTRY_DATA_FILE, additional_data=None):
""" Matches the country names given in two lists into a dictionary.
This function matches names given in list_a to the one provided in list_b
using regular expressions de... | [
"def",
"match",
"(",
"list_a",
",",
"list_b",
",",
"not_found",
"=",
"'not_found'",
",",
"enforce_sublist",
"=",
"False",
",",
"country_data",
"=",
"COUNTRY_DATA_FILE",
",",
"additional_data",
"=",
"None",
")",
":",
"if",
"isinstance",
"(",
"list_a",
",",
"s... | Matches the country names given in two lists into a dictionary.
This function matches names given in list_a to the one provided in list_b
using regular expressions defined in country_data.
Parameters
----------
list_a : list
Names of countries to identify
list_b : list
Master l... | [
"Matches",
"the",
"country",
"names",
"given",
"in",
"two",
"lists",
"into",
"a",
"dictionary",
"."
] | train | https://github.com/konstantinstadler/country_converter/blob/b78622dfa6700480df632fe061d6837b96f31b71/country_converter/country_converter.py#L156-L253 |
konstantinstadler/country_converter | country_converter/country_converter.py | convert | def convert(*args, **kargs):
""" Wrapper around CountryConverter.convert()
Uses the same parameters. This function has the same performance as
CountryConverter.convert for one call; for multiple calls it is better to
instantiate a common CountryConverter (this avoid loading the source data
file mul... | python | def convert(*args, **kargs):
""" Wrapper around CountryConverter.convert()
Uses the same parameters. This function has the same performance as
CountryConverter.convert for one call; for multiple calls it is better to
instantiate a common CountryConverter (this avoid loading the source data
file mul... | [
"def",
"convert",
"(",
"*",
"args",
",",
"*",
"*",
"kargs",
")",
":",
"init",
"=",
"{",
"'country_data'",
":",
"COUNTRY_DATA_FILE",
",",
"'additional_data'",
":",
"None",
",",
"'only_UNmember'",
":",
"False",
",",
"'include_obsolete'",
":",
"False",
"}",
"... | Wrapper around CountryConverter.convert()
Uses the same parameters. This function has the same performance as
CountryConverter.convert for one call; for multiple calls it is better to
instantiate a common CountryConverter (this avoid loading the source data
file multiple times).
Note
----
... | [
"Wrapper",
"around",
"CountryConverter",
".",
"convert",
"()"
] | train | https://github.com/konstantinstadler/country_converter/blob/b78622dfa6700480df632fe061d6837b96f31b71/country_converter/country_converter.py#L256-L317 |
konstantinstadler/country_converter | country_converter/country_converter.py | _parse_arg | def _parse_arg(valid_classifications):
""" Command line parser for coco
Parameters
----------
valid_classifications: list
Available classifications, used for checking input parameters.
Returns
-------
args : ArgumentParser namespace
"""
parser = argparse.ArgumentParser(
... | python | def _parse_arg(valid_classifications):
""" Command line parser for coco
Parameters
----------
valid_classifications: list
Available classifications, used for checking input parameters.
Returns
-------
args : ArgumentParser namespace
"""
parser = argparse.ArgumentParser(
... | [
"def",
"_parse_arg",
"(",
"valid_classifications",
")",
":",
"parser",
"=",
"argparse",
".",
"ArgumentParser",
"(",
"description",
"=",
"(",
"'The country converter (coco): a Python package for '",
"'converting country names between '",
"'different classifications schemes. '",
"'... | Command line parser for coco
Parameters
----------
valid_classifications: list
Available classifications, used for checking input parameters.
Returns
-------
args : ArgumentParser namespace | [
"Command",
"line",
"parser",
"for",
"coco"
] | train | https://github.com/konstantinstadler/country_converter/blob/b78622dfa6700480df632fe061d6837b96f31b71/country_converter/country_converter.py#L805-L863 |
konstantinstadler/country_converter | country_converter/country_converter.py | main | def main():
""" Main entry point - used for command line call
"""
args = _parse_arg(CountryConverter().valid_class)
coco = CountryConverter(additional_data=args.additional_data)
converted_names = coco.convert(
names=args.names,
src=args.src,
to=args.to,
enforce_list=F... | python | def main():
""" Main entry point - used for command line call
"""
args = _parse_arg(CountryConverter().valid_class)
coco = CountryConverter(additional_data=args.additional_data)
converted_names = coco.convert(
names=args.names,
src=args.src,
to=args.to,
enforce_list=F... | [
"def",
"main",
"(",
")",
":",
"args",
"=",
"_parse_arg",
"(",
"CountryConverter",
"(",
")",
".",
"valid_class",
")",
"coco",
"=",
"CountryConverter",
"(",
"additional_data",
"=",
"args",
".",
"additional_data",
")",
"converted_names",
"=",
"coco",
".",
"conv... | Main entry point - used for command line call | [
"Main",
"entry",
"point",
"-",
"used",
"for",
"command",
"line",
"call"
] | train | https://github.com/konstantinstadler/country_converter/blob/b78622dfa6700480df632fe061d6837b96f31b71/country_converter/country_converter.py#L866-L880 |
konstantinstadler/country_converter | country_converter/country_converter.py | CountryConverter._separate_exclude_cases | def _separate_exclude_cases(name, exclude_prefix):
""" Splits the excluded
Parameters
----------
name : str
Name of the country/region to convert.
exclude_prefix : list of valid regex strings
List of indicators which negate the subsequent country/region.... | python | def _separate_exclude_cases(name, exclude_prefix):
""" Splits the excluded
Parameters
----------
name : str
Name of the country/region to convert.
exclude_prefix : list of valid regex strings
List of indicators which negate the subsequent country/region.... | [
"def",
"_separate_exclude_cases",
"(",
"name",
",",
"exclude_prefix",
")",
":",
"excluder",
"=",
"re",
".",
"compile",
"(",
"'|'",
".",
"join",
"(",
"exclude_prefix",
")",
")",
"split_entries",
"=",
"excluder",
".",
"split",
"(",
"name",
")",
"return",
"{"... | Splits the excluded
Parameters
----------
name : str
Name of the country/region to convert.
exclude_prefix : list of valid regex strings
List of indicators which negate the subsequent country/region.
These prefixes and everything following will not b... | [
"Splits",
"the",
"excluded"
] | train | https://github.com/konstantinstadler/country_converter/blob/b78622dfa6700480df632fe061d6837b96f31b71/country_converter/country_converter.py#L332-L361 |
konstantinstadler/country_converter | country_converter/country_converter.py | CountryConverter.convert | def convert(self, names, src=None, to='ISO3', enforce_list=False,
not_found='not found',
exclude_prefix=['excl\\w.*', 'without', 'w/o']):
""" Convert names from a list to another list.
Note
----
A lot of the functionality can also be done directly in Pand... | python | def convert(self, names, src=None, to='ISO3', enforce_list=False,
not_found='not found',
exclude_prefix=['excl\\w.*', 'without', 'w/o']):
""" Convert names from a list to another list.
Note
----
A lot of the functionality can also be done directly in Pand... | [
"def",
"convert",
"(",
"self",
",",
"names",
",",
"src",
"=",
"None",
",",
"to",
"=",
"'ISO3'",
",",
"enforce_list",
"=",
"False",
",",
"not_found",
"=",
"'not found'",
",",
"exclude_prefix",
"=",
"[",
"'excl\\\\w.*'",
",",
"'without'",
",",
"'w/o'",
"]"... | Convert names from a list to another list.
Note
----
A lot of the functionality can also be done directly in Pandas
DataFrames.
For example:
coco = CountryConverter()
names = ['USA', 'SWZ', 'PRI']
coco.data[coco.data['ISO3'].isin(names)][['ISO2', 'contine... | [
"Convert",
"names",
"from",
"a",
"list",
"to",
"another",
"list",
"."
] | train | https://github.com/konstantinstadler/country_converter/blob/b78622dfa6700480df632fe061d6837b96f31b71/country_converter/country_converter.py#L445-L561 |
konstantinstadler/country_converter | country_converter/country_converter.py | CountryConverter.EU28as | def EU28as(self, to='name_short'):
"""
Return EU28 countries in the specified classification
Parameters
----------
to : str, optional
Output classification (valid str for an index of
country_data file), default: name_short
Returns
-------... | python | def EU28as(self, to='name_short'):
"""
Return EU28 countries in the specified classification
Parameters
----------
to : str, optional
Output classification (valid str for an index of
country_data file), default: name_short
Returns
-------... | [
"def",
"EU28as",
"(",
"self",
",",
"to",
"=",
"'name_short'",
")",
":",
"if",
"type",
"(",
"to",
")",
"is",
"str",
":",
"to",
"=",
"[",
"to",
"]",
"return",
"self",
".",
"data",
"[",
"self",
".",
"data",
".",
"EU",
"<",
"2015",
"]",
"[",
"to"... | Return EU28 countries in the specified classification
Parameters
----------
to : str, optional
Output classification (valid str for an index of
country_data file), default: name_short
Returns
-------
Pandas DataFrame | [
"Return",
"EU28",
"countries",
"in",
"the",
"specified",
"classification"
] | train | https://github.com/konstantinstadler/country_converter/blob/b78622dfa6700480df632fe061d6837b96f31b71/country_converter/country_converter.py#L563-L580 |
konstantinstadler/country_converter | country_converter/country_converter.py | CountryConverter.EU27as | def EU27as(self, to='name_short'):
"""
Return EU27 countries in the specified classification
Parameters
----------
to : str, optional
Output classification (valid str for an index of
country_data file), default: name_short
Returns
-------... | python | def EU27as(self, to='name_short'):
"""
Return EU27 countries in the specified classification
Parameters
----------
to : str, optional
Output classification (valid str for an index of
country_data file), default: name_short
Returns
-------... | [
"def",
"EU27as",
"(",
"self",
",",
"to",
"=",
"'name_short'",
")",
":",
"if",
"isinstance",
"(",
"to",
",",
"str",
")",
":",
"to",
"=",
"[",
"to",
"]",
"return",
"self",
".",
"data",
"[",
"self",
".",
"data",
".",
"EU",
"<",
"2013",
"]",
"[",
... | Return EU27 countries in the specified classification
Parameters
----------
to : str, optional
Output classification (valid str for an index of
country_data file), default: name_short
Returns
-------
Pandas DataFrame | [
"Return",
"EU27",
"countries",
"in",
"the",
"specified",
"classification"
] | train | https://github.com/konstantinstadler/country_converter/blob/b78622dfa6700480df632fe061d6837b96f31b71/country_converter/country_converter.py#L582-L599 |
konstantinstadler/country_converter | country_converter/country_converter.py | CountryConverter.OECDas | def OECDas(self, to='name_short'):
"""
Return OECD member states in the specified classification
Parameters
----------
to : str, optional
Output classification (valid str for an index of
country_data file), default: name_short
Returns
---... | python | def OECDas(self, to='name_short'):
"""
Return OECD member states in the specified classification
Parameters
----------
to : str, optional
Output classification (valid str for an index of
country_data file), default: name_short
Returns
---... | [
"def",
"OECDas",
"(",
"self",
",",
"to",
"=",
"'name_short'",
")",
":",
"if",
"isinstance",
"(",
"to",
",",
"str",
")",
":",
"to",
"=",
"[",
"to",
"]",
"return",
"self",
".",
"data",
"[",
"self",
".",
"data",
".",
"OECD",
">",
"0",
"]",
"[",
... | Return OECD member states in the specified classification
Parameters
----------
to : str, optional
Output classification (valid str for an index of
country_data file), default: name_short
Returns
-------
Pandas DataFrame | [
"Return",
"OECD",
"member",
"states",
"in",
"the",
"specified",
"classification"
] | train | https://github.com/konstantinstadler/country_converter/blob/b78622dfa6700480df632fe061d6837b96f31b71/country_converter/country_converter.py#L601-L618 |
konstantinstadler/country_converter | country_converter/country_converter.py | CountryConverter.UNas | def UNas(self, to='name_short'):
"""
Return UN member states in the specified classification
Parameters
----------
to : str, optional
Output classification (valid str for an index of
country_data file), default: name_short
Returns
-------... | python | def UNas(self, to='name_short'):
"""
Return UN member states in the specified classification
Parameters
----------
to : str, optional
Output classification (valid str for an index of
country_data file), default: name_short
Returns
-------... | [
"def",
"UNas",
"(",
"self",
",",
"to",
"=",
"'name_short'",
")",
":",
"if",
"isinstance",
"(",
"to",
",",
"str",
")",
":",
"to",
"=",
"[",
"to",
"]",
"return",
"self",
".",
"data",
"[",
"self",
".",
"data",
".",
"UNmember",
">",
"0",
"]",
"[",
... | Return UN member states in the specified classification
Parameters
----------
to : str, optional
Output classification (valid str for an index of
country_data file), default: name_short
Returns
-------
Pandas DataFrame | [
"Return",
"UN",
"member",
"states",
"in",
"the",
"specified",
"classification"
] | train | https://github.com/konstantinstadler/country_converter/blob/b78622dfa6700480df632fe061d6837b96f31b71/country_converter/country_converter.py#L620-L637 |
konstantinstadler/country_converter | country_converter/country_converter.py | CountryConverter.obsoleteas | def obsoleteas(self, to='name_short'):
"""
Return obsolete countries in the specified classification
Parameters
----------
to : str, optional
Output classification (valid str for an index of
country_data file), default: name_short
Returns
... | python | def obsoleteas(self, to='name_short'):
"""
Return obsolete countries in the specified classification
Parameters
----------
to : str, optional
Output classification (valid str for an index of
country_data file), default: name_short
Returns
... | [
"def",
"obsoleteas",
"(",
"self",
",",
"to",
"=",
"'name_short'",
")",
":",
"if",
"isinstance",
"(",
"to",
",",
"str",
")",
":",
"to",
"=",
"[",
"to",
"]",
"return",
"self",
".",
"data",
"[",
"self",
".",
"data",
".",
"obsolete",
">",
"0",
"]",
... | Return obsolete countries in the specified classification
Parameters
----------
to : str, optional
Output classification (valid str for an index of
country_data file), default: name_short
Returns
-------
Pandas DataFrame | [
"Return",
"obsolete",
"countries",
"in",
"the",
"specified",
"classification"
] | train | https://github.com/konstantinstadler/country_converter/blob/b78622dfa6700480df632fe061d6837b96f31b71/country_converter/country_converter.py#L639-L656 |
konstantinstadler/country_converter | country_converter/country_converter.py | CountryConverter.get_correspondance_dict | def get_correspondance_dict(self, classA, classB,
restrict=None,
replace_numeric=True):
""" Returns a correspondance between classification A and B as dict
Parameters
----------
classA: str
Valid classification... | python | def get_correspondance_dict(self, classA, classB,
restrict=None,
replace_numeric=True):
""" Returns a correspondance between classification A and B as dict
Parameters
----------
classA: str
Valid classification... | [
"def",
"get_correspondance_dict",
"(",
"self",
",",
"classA",
",",
"classB",
",",
"restrict",
"=",
"None",
",",
"replace_numeric",
"=",
"True",
")",
":",
"result",
"=",
"{",
"nn",
":",
"None",
"for",
"nn",
"in",
"self",
".",
"data",
"[",
"classA",
"]",... | Returns a correspondance between classification A and B as dict
Parameters
----------
classA: str
Valid classification (column name of data)
classB: str
Valid classification (column name of data).
restrict: boolean vector of size cc.data, optional
... | [
"Returns",
"a",
"correspondance",
"between",
"classification",
"A",
"and",
"B",
"as",
"dict"
] | train | https://github.com/konstantinstadler/country_converter/blob/b78622dfa6700480df632fe061d6837b96f31b71/country_converter/country_converter.py#L691-L740 |
konstantinstadler/country_converter | country_converter/country_converter.py | CountryConverter._validate_input_para | def _validate_input_para(self, para, column_names):
""" Convert the input classificaton para to the correct df column name
Parameters
----------
para : string
column_names : list of strings
Returns
-------
validated_para : string
Converted ... | python | def _validate_input_para(self, para, column_names):
""" Convert the input classificaton para to the correct df column name
Parameters
----------
para : string
column_names : list of strings
Returns
-------
validated_para : string
Converted ... | [
"def",
"_validate_input_para",
"(",
"self",
",",
"para",
",",
"column_names",
")",
":",
"lower_case_valid_class",
"=",
"[",
"et",
".",
"lower",
"(",
")",
"for",
"et",
"in",
"self",
".",
"valid_class",
"]",
"alt_valid_names",
"=",
"{",
"'name_short'",
":",
... | Convert the input classificaton para to the correct df column name
Parameters
----------
para : string
column_names : list of strings
Returns
-------
validated_para : string
Converted to the case used in the country file | [
"Convert",
"the",
"input",
"classificaton",
"para",
"to",
"the",
"correct",
"df",
"column",
"name"
] | train | https://github.com/konstantinstadler/country_converter/blob/b78622dfa6700480df632fe061d6837b96f31b71/country_converter/country_converter.py#L742-L777 |
konstantinstadler/country_converter | country_converter/country_converter.py | CountryConverter._get_input_format_from_name | def _get_input_format_from_name(self, name):
""" Determines the input format based on the given country name
Parameters
----------
name : string
Returns
-------
string : valid input format
"""
try:
int(name)
src_format =... | python | def _get_input_format_from_name(self, name):
""" Determines the input format based on the given country name
Parameters
----------
name : string
Returns
-------
string : valid input format
"""
try:
int(name)
src_format =... | [
"def",
"_get_input_format_from_name",
"(",
"self",
",",
"name",
")",
":",
"try",
":",
"int",
"(",
"name",
")",
"src_format",
"=",
"'ISOnumeric'",
"except",
"ValueError",
":",
"if",
"len",
"(",
"name",
")",
"==",
"2",
":",
"src_format",
"=",
"'ISO2'",
"el... | Determines the input format based on the given country name
Parameters
----------
name : string
Returns
-------
string : valid input format | [
"Determines",
"the",
"input",
"format",
"based",
"on",
"the",
"given",
"country",
"name"
] | train | https://github.com/konstantinstadler/country_converter/blob/b78622dfa6700480df632fe061d6837b96f31b71/country_converter/country_converter.py#L779-L802 |
matplotlib/viscm | viscm/bezierbuilder.py | Bernstein | def Bernstein(n, k):
"""Bernstein polynomial.
"""
coeff = binom(n, k)
def _bpoly(x):
return coeff * x ** k * (1 - x) ** (n - k)
return _bpoly | python | def Bernstein(n, k):
"""Bernstein polynomial.
"""
coeff = binom(n, k)
def _bpoly(x):
return coeff * x ** k * (1 - x) ** (n - k)
return _bpoly | [
"def",
"Bernstein",
"(",
"n",
",",
"k",
")",
":",
"coeff",
"=",
"binom",
"(",
"n",
",",
"k",
")",
"def",
"_bpoly",
"(",
"x",
")",
":",
"return",
"coeff",
"*",
"x",
"**",
"k",
"*",
"(",
"1",
"-",
"x",
")",
"**",
"(",
"n",
"-",
"k",
")",
... | Bernstein polynomial. | [
"Bernstein",
"polynomial",
"."
] | train | https://github.com/matplotlib/viscm/blob/cb31d0a6b95bcb23fd8f48d23e28e415db5ddb7c/viscm/bezierbuilder.py#L299-L308 |
matplotlib/viscm | viscm/bezierbuilder.py | Bezier | def Bezier(points, at):
"""Build Bézier curve from points.
Deprecated. CatmulClark builds nicer splines
"""
at = np.asarray(at)
at_flat = at.ravel()
N = len(points)
curve = np.zeros((at_flat.shape[0], 2))
for ii in range(N):
curve += np.outer(Bernstein(N - 1, ii)(at_flat), points... | python | def Bezier(points, at):
"""Build Bézier curve from points.
Deprecated. CatmulClark builds nicer splines
"""
at = np.asarray(at)
at_flat = at.ravel()
N = len(points)
curve = np.zeros((at_flat.shape[0], 2))
for ii in range(N):
curve += np.outer(Bernstein(N - 1, ii)(at_flat), points... | [
"def",
"Bezier",
"(",
"points",
",",
"at",
")",
":",
"at",
"=",
"np",
".",
"asarray",
"(",
"at",
")",
"at_flat",
"=",
"at",
".",
"ravel",
"(",
")",
"N",
"=",
"len",
"(",
"points",
")",
"curve",
"=",
"np",
".",
"zeros",
"(",
"(",
"at_flat",
".... | Build Bézier curve from points.
Deprecated. CatmulClark builds nicer splines | [
"Build",
"Bézier",
"curve",
"from",
"points",
".",
"Deprecated",
".",
"CatmulClark",
"builds",
"nicer",
"splines"
] | train | https://github.com/matplotlib/viscm/blob/cb31d0a6b95bcb23fd8f48d23e28e415db5ddb7c/viscm/bezierbuilder.py#L311-L321 |
spyder-ide/pywinpty | winpty/ptyprocess.py | _read_in_thread | def _read_in_thread(address, pty, blocking):
"""Read data from the pty in a thread.
"""
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client.connect(address)
while 1:
data = pty.read(4096, blocking=blocking)
if not data and not pty.isalive():
while not data... | python | def _read_in_thread(address, pty, blocking):
"""Read data from the pty in a thread.
"""
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client.connect(address)
while 1:
data = pty.read(4096, blocking=blocking)
if not data and not pty.isalive():
while not data... | [
"def",
"_read_in_thread",
"(",
"address",
",",
"pty",
",",
"blocking",
")",
":",
"client",
"=",
"socket",
".",
"socket",
"(",
"socket",
".",
"AF_INET",
",",
"socket",
".",
"SOCK_STREAM",
")",
"client",
".",
"connect",
"(",
"address",
")",
"while",
"1",
... | Read data from the pty in a thread. | [
"Read",
"data",
"from",
"the",
"pty",
"in",
"a",
"thread",
"."
] | train | https://github.com/spyder-ide/pywinpty/blob/f4461cde9f0c53047e61e9eff7f7ec21ecbc4573/winpty/ptyprocess.py#L325-L349 |
spyder-ide/pywinpty | winpty/ptyprocess.py | PtyProcess.spawn | def spawn(cls, argv, cwd=None, env=None, dimensions=(24, 80)):
"""Start the given command in a child process in a pseudo terminal.
This does all the setting up the pty, and returns an instance of
PtyProcess.
Dimensions of the psuedoterminal used for the subprocess can be
specif... | python | def spawn(cls, argv, cwd=None, env=None, dimensions=(24, 80)):
"""Start the given command in a child process in a pseudo terminal.
This does all the setting up the pty, and returns an instance of
PtyProcess.
Dimensions of the psuedoterminal used for the subprocess can be
specif... | [
"def",
"spawn",
"(",
"cls",
",",
"argv",
",",
"cwd",
"=",
"None",
",",
"env",
"=",
"None",
",",
"dimensions",
"=",
"(",
"24",
",",
"80",
")",
")",
":",
"if",
"isinstance",
"(",
"argv",
",",
"str",
")",
":",
"argv",
"=",
"shlex",
".",
"split",
... | Start the given command in a child process in a pseudo terminal.
This does all the setting up the pty, and returns an instance of
PtyProcess.
Dimensions of the psuedoterminal used for the subprocess can be
specified as a tuple (rows, cols), or the default (24, 80) will be
used. | [
"Start",
"the",
"given",
"command",
"in",
"a",
"child",
"process",
"in",
"a",
"pseudo",
"terminal",
"."
] | train | https://github.com/spyder-ide/pywinpty/blob/f4461cde9f0c53047e61e9eff7f7ec21ecbc4573/winpty/ptyprocess.py#L63-L125 |
spyder-ide/pywinpty | winpty/ptyprocess.py | PtyProcess.close | def close(self, force=False):
"""This closes the connection with the child application. Note that
calling close() more than once is valid. This emulates standard Python
behavior with files. Set force to True if you want to make sure that
the child is terminated (SIGKILL is sent if the ch... | python | def close(self, force=False):
"""This closes the connection with the child application. Note that
calling close() more than once is valid. This emulates standard Python
behavior with files. Set force to True if you want to make sure that
the child is terminated (SIGKILL is sent if the ch... | [
"def",
"close",
"(",
"self",
",",
"force",
"=",
"False",
")",
":",
"if",
"not",
"self",
".",
"closed",
":",
"self",
".",
"pty",
".",
"close",
"(",
")",
"self",
".",
"fileobj",
".",
"close",
"(",
")",
"self",
".",
"_server",
".",
"close",
"(",
"... | This closes the connection with the child application. Note that
calling close() more than once is valid. This emulates standard Python
behavior with files. Set force to True if you want to make sure that
the child is terminated (SIGKILL is sent if the child ignores
SIGINT). | [
"This",
"closes",
"the",
"connection",
"with",
"the",
"child",
"application",
".",
"Note",
"that",
"calling",
"close",
"()",
"more",
"than",
"once",
"is",
"valid",
".",
"This",
"emulates",
"standard",
"Python",
"behavior",
"with",
"files",
".",
"Set",
"force... | train | https://github.com/spyder-ide/pywinpty/blob/f4461cde9f0c53047e61e9eff7f7ec21ecbc4573/winpty/ptyprocess.py#L138-L156 |
spyder-ide/pywinpty | winpty/ptyprocess.py | PtyProcess.read | def read(self, size=1024):
"""Read and return at most ``size`` characters from the pty.
Can block if there is nothing to read. Raises :exc:`EOFError` if the
terminal was closed.
"""
data = self.fileobj.recv(size)
if not data:
self.flag_eof = True
... | python | def read(self, size=1024):
"""Read and return at most ``size`` characters from the pty.
Can block if there is nothing to read. Raises :exc:`EOFError` if the
terminal was closed.
"""
data = self.fileobj.recv(size)
if not data:
self.flag_eof = True
... | [
"def",
"read",
"(",
"self",
",",
"size",
"=",
"1024",
")",
":",
"data",
"=",
"self",
".",
"fileobj",
".",
"recv",
"(",
"size",
")",
"if",
"not",
"data",
":",
"self",
".",
"flag_eof",
"=",
"True",
"raise",
"EOFError",
"(",
"'Pty is closed'",
")",
"r... | Read and return at most ``size`` characters from the pty.
Can block if there is nothing to read. Raises :exc:`EOFError` if the
terminal was closed. | [
"Read",
"and",
"return",
"at",
"most",
"size",
"characters",
"from",
"the",
"pty",
"."
] | train | https://github.com/spyder-ide/pywinpty/blob/f4461cde9f0c53047e61e9eff7f7ec21ecbc4573/winpty/ptyprocess.py#L183-L194 |
spyder-ide/pywinpty | winpty/ptyprocess.py | PtyProcess.readline | def readline(self):
"""Read one line from the pseudoterminal as bytes.
Can block if there is nothing to read. Raises :exc:`EOFError` if the
terminal was closed.
"""
buf = []
while 1:
try:
ch = self.read(1)
except EOFError:
... | python | def readline(self):
"""Read one line from the pseudoterminal as bytes.
Can block if there is nothing to read. Raises :exc:`EOFError` if the
terminal was closed.
"""
buf = []
while 1:
try:
ch = self.read(1)
except EOFError:
... | [
"def",
"readline",
"(",
"self",
")",
":",
"buf",
"=",
"[",
"]",
"while",
"1",
":",
"try",
":",
"ch",
"=",
"self",
".",
"read",
"(",
"1",
")",
"except",
"EOFError",
":",
"return",
"''",
".",
"join",
"(",
"buf",
")",
"buf",
".",
"append",
"(",
... | Read one line from the pseudoterminal as bytes.
Can block if there is nothing to read. Raises :exc:`EOFError` if the
terminal was closed. | [
"Read",
"one",
"line",
"from",
"the",
"pseudoterminal",
"as",
"bytes",
"."
] | train | https://github.com/spyder-ide/pywinpty/blob/f4461cde9f0c53047e61e9eff7f7ec21ecbc4573/winpty/ptyprocess.py#L196-L210 |
spyder-ide/pywinpty | winpty/ptyprocess.py | PtyProcess.write | def write(self, s):
"""Write the string ``s`` to the pseudoterminal.
Returns the number of bytes written.
"""
if not self.isalive():
raise EOFError('Pty is closed')
if PY2:
s = _unicode(s)
success, nbytes = self.pty.write(s)
if not succes... | python | def write(self, s):
"""Write the string ``s`` to the pseudoterminal.
Returns the number of bytes written.
"""
if not self.isalive():
raise EOFError('Pty is closed')
if PY2:
s = _unicode(s)
success, nbytes = self.pty.write(s)
if not succes... | [
"def",
"write",
"(",
"self",
",",
"s",
")",
":",
"if",
"not",
"self",
".",
"isalive",
"(",
")",
":",
"raise",
"EOFError",
"(",
"'Pty is closed'",
")",
"if",
"PY2",
":",
"s",
"=",
"_unicode",
"(",
"s",
")",
"success",
",",
"nbytes",
"=",
"self",
"... | Write the string ``s`` to the pseudoterminal.
Returns the number of bytes written. | [
"Write",
"the",
"string",
"s",
"to",
"the",
"pseudoterminal",
"."
] | train | https://github.com/spyder-ide/pywinpty/blob/f4461cde9f0c53047e61e9eff7f7ec21ecbc4573/winpty/ptyprocess.py#L212-L225 |
spyder-ide/pywinpty | winpty/ptyprocess.py | PtyProcess.terminate | def terminate(self, force=False):
"""This forces a child process to terminate."""
if not self.isalive():
return True
self.kill(signal.SIGINT)
time.sleep(self.delayafterterminate)
if not self.isalive():
return True
if force:
self.kill(si... | python | def terminate(self, force=False):
"""This forces a child process to terminate."""
if not self.isalive():
return True
self.kill(signal.SIGINT)
time.sleep(self.delayafterterminate)
if not self.isalive():
return True
if force:
self.kill(si... | [
"def",
"terminate",
"(",
"self",
",",
"force",
"=",
"False",
")",
":",
"if",
"not",
"self",
".",
"isalive",
"(",
")",
":",
"return",
"True",
"self",
".",
"kill",
"(",
"signal",
".",
"SIGINT",
")",
"time",
".",
"sleep",
"(",
"self",
".",
"delayafter... | This forces a child process to terminate. | [
"This",
"forces",
"a",
"child",
"process",
"to",
"terminate",
"."
] | train | https://github.com/spyder-ide/pywinpty/blob/f4461cde9f0c53047e61e9eff7f7ec21ecbc4573/winpty/ptyprocess.py#L227-L241 |
spyder-ide/pywinpty | winpty/ptyprocess.py | PtyProcess.sendcontrol | def sendcontrol(self, char):
'''Helper method that wraps send() with mnemonic access for sending control
character to the child (such as Ctrl-C or Ctrl-D). For example, to send
Ctrl-G (ASCII 7, bell, '\a')::
child.sendcontrol('g')
See also, sendintr() and sendeof().
... | python | def sendcontrol(self, char):
'''Helper method that wraps send() with mnemonic access for sending control
character to the child (such as Ctrl-C or Ctrl-D). For example, to send
Ctrl-G (ASCII 7, bell, '\a')::
child.sendcontrol('g')
See also, sendintr() and sendeof().
... | [
"def",
"sendcontrol",
"(",
"self",
",",
"char",
")",
":",
"char",
"=",
"char",
".",
"lower",
"(",
")",
"a",
"=",
"ord",
"(",
"char",
")",
"if",
"97",
"<=",
"a",
"<=",
"122",
":",
"a",
"=",
"a",
"-",
"ord",
"(",
"'a'",
")",
"+",
"1",
"byte",... | Helper method that wraps send() with mnemonic access for sending control
character to the child (such as Ctrl-C or Ctrl-D). For example, to send
Ctrl-G (ASCII 7, bell, '\a')::
child.sendcontrol('g')
See also, sendintr() and sendeof(). | [
"Helper",
"method",
"that",
"wraps",
"send",
"()",
"with",
"mnemonic",
"access",
"for",
"sending",
"control",
"character",
"to",
"the",
"child",
"(",
"such",
"as",
"Ctrl",
"-",
"C",
"or",
"Ctrl",
"-",
"D",
")",
".",
"For",
"example",
"to",
"send",
"Ctr... | train | https://github.com/spyder-ide/pywinpty/blob/f4461cde9f0c53047e61e9eff7f7ec21ecbc4573/winpty/ptyprocess.py#L264-L288 |
spyder-ide/pywinpty | winpty/ptyprocess.py | PtyProcess.setwinsize | def setwinsize(self, rows, cols):
"""Set the terminal window size of the child tty.
"""
self._winsize = (rows, cols)
self.pty.set_size(cols, rows) | python | def setwinsize(self, rows, cols):
"""Set the terminal window size of the child tty.
"""
self._winsize = (rows, cols)
self.pty.set_size(cols, rows) | [
"def",
"setwinsize",
"(",
"self",
",",
"rows",
",",
"cols",
")",
":",
"self",
".",
"_winsize",
"=",
"(",
"rows",
",",
"cols",
")",
"self",
".",
"pty",
".",
"set_size",
"(",
"cols",
",",
"rows",
")"
] | Set the terminal window size of the child tty. | [
"Set",
"the",
"terminal",
"window",
"size",
"of",
"the",
"child",
"tty",
"."
] | train | https://github.com/spyder-ide/pywinpty/blob/f4461cde9f0c53047e61e9eff7f7ec21ecbc4573/winpty/ptyprocess.py#L318-L322 |
spyder-ide/pywinpty | winpty/winpty_wrapper.py | PTY.read | def read(self, length=1000, blocking=False):
"""
Read ``length`` bytes from current process output stream.
Note: This method is not fully non-blocking, however it
behaves like one.
"""
size_p = PLARGE_INTEGER(LARGE_INTEGER(0))
if not blocking:
windll.... | python | def read(self, length=1000, blocking=False):
"""
Read ``length`` bytes from current process output stream.
Note: This method is not fully non-blocking, however it
behaves like one.
"""
size_p = PLARGE_INTEGER(LARGE_INTEGER(0))
if not blocking:
windll.... | [
"def",
"read",
"(",
"self",
",",
"length",
"=",
"1000",
",",
"blocking",
"=",
"False",
")",
":",
"size_p",
"=",
"PLARGE_INTEGER",
"(",
"LARGE_INTEGER",
"(",
"0",
")",
")",
"if",
"not",
"blocking",
":",
"windll",
".",
"kernel32",
".",
"GetFileSizeEx",
"... | Read ``length`` bytes from current process output stream.
Note: This method is not fully non-blocking, however it
behaves like one. | [
"Read",
"length",
"bytes",
"from",
"current",
"process",
"output",
"stream",
"."
] | train | https://github.com/spyder-ide/pywinpty/blob/f4461cde9f0c53047e61e9eff7f7ec21ecbc4573/winpty/winpty_wrapper.py#L60-L76 |
spyder-ide/pywinpty | winpty/winpty_wrapper.py | PTY.write | def write(self, data):
"""Write string data to current process input stream."""
data = data.encode('utf-8')
data_p = ctypes.create_string_buffer(data)
num_bytes = PLARGE_INTEGER(LARGE_INTEGER(0))
bytes_to_write = len(data)
success = WriteFile(self.conin_pipe, data_p,
... | python | def write(self, data):
"""Write string data to current process input stream."""
data = data.encode('utf-8')
data_p = ctypes.create_string_buffer(data)
num_bytes = PLARGE_INTEGER(LARGE_INTEGER(0))
bytes_to_write = len(data)
success = WriteFile(self.conin_pipe, data_p,
... | [
"def",
"write",
"(",
"self",
",",
"data",
")",
":",
"data",
"=",
"data",
".",
"encode",
"(",
"'utf-8'",
")",
"data_p",
"=",
"ctypes",
".",
"create_string_buffer",
"(",
"data",
")",
"num_bytes",
"=",
"PLARGE_INTEGER",
"(",
"LARGE_INTEGER",
"(",
"0",
")",
... | Write string data to current process input stream. | [
"Write",
"string",
"data",
"to",
"current",
"process",
"input",
"stream",
"."
] | train | https://github.com/spyder-ide/pywinpty/blob/f4461cde9f0c53047e61e9eff7f7ec21ecbc4573/winpty/winpty_wrapper.py#L78-L86 |
spyder-ide/pywinpty | winpty/winpty_wrapper.py | PTY.close | def close(self):
"""Close all communication process streams."""
windll.kernel32.CloseHandle(self.conout_pipe)
windll.kernel32.CloseHandle(self.conin_pipe) | python | def close(self):
"""Close all communication process streams."""
windll.kernel32.CloseHandle(self.conout_pipe)
windll.kernel32.CloseHandle(self.conin_pipe) | [
"def",
"close",
"(",
"self",
")",
":",
"windll",
".",
"kernel32",
".",
"CloseHandle",
"(",
"self",
".",
"conout_pipe",
")",
"windll",
".",
"kernel32",
".",
"CloseHandle",
"(",
"self",
".",
"conin_pipe",
")"
] | Close all communication process streams. | [
"Close",
"all",
"communication",
"process",
"streams",
"."
] | train | https://github.com/spyder-ide/pywinpty/blob/f4461cde9f0c53047e61e9eff7f7ec21ecbc4573/winpty/winpty_wrapper.py#L88-L91 |
spyder-ide/pywinpty | winpty/winpty_wrapper.py | PTY.iseof | def iseof(self):
"""Check if current process streams are still open."""
succ = windll.kernel32.PeekNamedPipe(
self.conout_pipe, None, None, None, None, None
)
return not bool(succ) | python | def iseof(self):
"""Check if current process streams are still open."""
succ = windll.kernel32.PeekNamedPipe(
self.conout_pipe, None, None, None, None, None
)
return not bool(succ) | [
"def",
"iseof",
"(",
"self",
")",
":",
"succ",
"=",
"windll",
".",
"kernel32",
".",
"PeekNamedPipe",
"(",
"self",
".",
"conout_pipe",
",",
"None",
",",
"None",
",",
"None",
",",
"None",
",",
"None",
")",
"return",
"not",
"bool",
"(",
"succ",
")"
] | Check if current process streams are still open. | [
"Check",
"if",
"current",
"process",
"streams",
"are",
"still",
"open",
"."
] | train | https://github.com/spyder-ide/pywinpty/blob/f4461cde9f0c53047e61e9eff7f7ec21ecbc4573/winpty/winpty_wrapper.py#L93-L98 |
marcopompili/django-instagram | django_instagram/scraper.py | instagram_scrap_profile | def instagram_scrap_profile(username):
"""
Scrap an instagram profile page
:param username:
:return:
"""
try:
url = "https://www.instagram.com/{}/".format(username)
page = requests.get(url)
# Raise error for 404 cause by a bad profile name
page.raise_for_status()
... | python | def instagram_scrap_profile(username):
"""
Scrap an instagram profile page
:param username:
:return:
"""
try:
url = "https://www.instagram.com/{}/".format(username)
page = requests.get(url)
# Raise error for 404 cause by a bad profile name
page.raise_for_status()
... | [
"def",
"instagram_scrap_profile",
"(",
"username",
")",
":",
"try",
":",
"url",
"=",
"\"https://www.instagram.com/{}/\"",
".",
"format",
"(",
"username",
")",
"page",
"=",
"requests",
".",
"get",
"(",
"url",
")",
"# Raise error for 404 cause by a bad profile name",
... | Scrap an instagram profile page
:param username:
:return: | [
"Scrap",
"an",
"instagram",
"profile",
"page",
":",
"param",
"username",
":",
":",
"return",
":"
] | train | https://github.com/marcopompili/django-instagram/blob/b237b52516b2408c862c791f37fa2bb950630a01/django_instagram/scraper.py#L18-L33 |
marcopompili/django-instagram | django_instagram/scraper.py | instagram_profile_js | def instagram_profile_js(username):
"""
Retrieve the script tags from the parsed page.
:param username:
:return:
"""
try:
tree = instagram_scrap_profile(username)
return tree.xpath('//script')
except AttributeError:
logging.exception("scripts not found")
retur... | python | def instagram_profile_js(username):
"""
Retrieve the script tags from the parsed page.
:param username:
:return:
"""
try:
tree = instagram_scrap_profile(username)
return tree.xpath('//script')
except AttributeError:
logging.exception("scripts not found")
retur... | [
"def",
"instagram_profile_js",
"(",
"username",
")",
":",
"try",
":",
"tree",
"=",
"instagram_scrap_profile",
"(",
"username",
")",
"return",
"tree",
".",
"xpath",
"(",
"'//script'",
")",
"except",
"AttributeError",
":",
"logging",
".",
"exception",
"(",
"\"sc... | Retrieve the script tags from the parsed page.
:param username:
:return: | [
"Retrieve",
"the",
"script",
"tags",
"from",
"the",
"parsed",
"page",
".",
":",
"param",
"username",
":",
":",
"return",
":"
] | train | https://github.com/marcopompili/django-instagram/blob/b237b52516b2408c862c791f37fa2bb950630a01/django_instagram/scraper.py#L36-L47 |
marcopompili/django-instagram | django_instagram/scraper.py | instagram_profile_json | def instagram_profile_json(username):
"""
Get the JSON data string from the scripts.
:param username:
:return:
"""
scripts = instagram_profile_js(username)
source = None
if scripts:
for script in scripts:
if script.text:
if script.text[0:SCRIPT_JSON_P... | python | def instagram_profile_json(username):
"""
Get the JSON data string from the scripts.
:param username:
:return:
"""
scripts = instagram_profile_js(username)
source = None
if scripts:
for script in scripts:
if script.text:
if script.text[0:SCRIPT_JSON_P... | [
"def",
"instagram_profile_json",
"(",
"username",
")",
":",
"scripts",
"=",
"instagram_profile_js",
"(",
"username",
")",
"source",
"=",
"None",
"if",
"scripts",
":",
"for",
"script",
"in",
"scripts",
":",
"if",
"script",
".",
"text",
":",
"if",
"script",
... | Get the JSON data string from the scripts.
:param username:
:return: | [
"Get",
"the",
"JSON",
"data",
"string",
"from",
"the",
"scripts",
".",
":",
"param",
"username",
":",
":",
"return",
":"
] | train | https://github.com/marcopompili/django-instagram/blob/b237b52516b2408c862c791f37fa2bb950630a01/django_instagram/scraper.py#L50-L65 |
marcopompili/django-instagram | django_instagram/templatetags/instagram_client.py | get_profile_media | def get_profile_media(profile, page = 0):
"""
Parse a generated media object
:param profile:
:param page:
:return:
"""
try:
edges = profile['entry_data']['ProfilePage'][page]['graphql']['user']['edge_owner_to_timeline_media']['edges']
return [edge['node'] for edge in edges]
... | python | def get_profile_media(profile, page = 0):
"""
Parse a generated media object
:param profile:
:param page:
:return:
"""
try:
edges = profile['entry_data']['ProfilePage'][page]['graphql']['user']['edge_owner_to_timeline_media']['edges']
return [edge['node'] for edge in edges]
... | [
"def",
"get_profile_media",
"(",
"profile",
",",
"page",
"=",
"0",
")",
":",
"try",
":",
"edges",
"=",
"profile",
"[",
"'entry_data'",
"]",
"[",
"'ProfilePage'",
"]",
"[",
"page",
"]",
"[",
"'graphql'",
"]",
"[",
"'user'",
"]",
"[",
"'edge_owner_to_timel... | Parse a generated media object
:param profile:
:param page:
:return: | [
"Parse",
"a",
"generated",
"media",
"object",
":",
"param",
"profile",
":",
":",
"param",
"page",
":",
":",
"return",
":"
] | train | https://github.com/marcopompili/django-instagram/blob/b237b52516b2408c862c791f37fa2bb950630a01/django_instagram/templatetags/instagram_client.py#L20-L31 |
marcopompili/django-instagram | django_instagram/templatetags/instagram_client.py | instagram_user_recent_media | def instagram_user_recent_media(parser, token):
"""
Tag for getting data about recent media of an user.
:param parser:
:param token:
:return:
"""
try:
tagname, username = token.split_contents()
return InstagramUserRecentMediaNode(username)
except ValueError:
rais... | python | def instagram_user_recent_media(parser, token):
"""
Tag for getting data about recent media of an user.
:param parser:
:param token:
:return:
"""
try:
tagname, username = token.split_contents()
return InstagramUserRecentMediaNode(username)
except ValueError:
rais... | [
"def",
"instagram_user_recent_media",
"(",
"parser",
",",
"token",
")",
":",
"try",
":",
"tagname",
",",
"username",
"=",
"token",
".",
"split_contents",
"(",
")",
"return",
"InstagramUserRecentMediaNode",
"(",
"username",
")",
"except",
"ValueError",
":",
"rais... | Tag for getting data about recent media of an user.
:param parser:
:param token:
:return: | [
"Tag",
"for",
"getting",
"data",
"about",
"recent",
"media",
"of",
"an",
"user",
".",
":",
"param",
"parser",
":",
":",
"param",
"token",
":",
":",
"return",
":"
] | train | https://github.com/marcopompili/django-instagram/blob/b237b52516b2408c862c791f37fa2bb950630a01/django_instagram/templatetags/instagram_client.py#L53-L67 |
tehmaze/ipcalc | ipcalc.py | IP.bin | def bin(self):
"""Full-length binary representation of the IP address.
>>> ip = IP("127.0.0.1")
>>> print(ip.bin())
01111111000000000000000000000001
"""
bits = self.v == 4 and 32 or 128
return bin(self.ip).split('b')[1].rjust(bits, '0') | python | def bin(self):
"""Full-length binary representation of the IP address.
>>> ip = IP("127.0.0.1")
>>> print(ip.bin())
01111111000000000000000000000001
"""
bits = self.v == 4 and 32 or 128
return bin(self.ip).split('b')[1].rjust(bits, '0') | [
"def",
"bin",
"(",
"self",
")",
":",
"bits",
"=",
"self",
".",
"v",
"==",
"4",
"and",
"32",
"or",
"128",
"return",
"bin",
"(",
"self",
".",
"ip",
")",
".",
"split",
"(",
"'b'",
")",
"[",
"1",
"]",
".",
"rjust",
"(",
"bits",
",",
"'0'",
")"
... | Full-length binary representation of the IP address.
>>> ip = IP("127.0.0.1")
>>> print(ip.bin())
01111111000000000000000000000001 | [
"Full",
"-",
"length",
"binary",
"representation",
"of",
"the",
"IP",
"address",
"."
] | train | https://github.com/tehmaze/ipcalc/blob/d436b95d2783347c3e0084d76ec3c52d1f5d2f0b/ipcalc.py#L175-L183 |
tehmaze/ipcalc | ipcalc.py | IP.info | def info(self):
"""Show IANA allocation information for the current IP address.
>>> ip = IP("127.0.0.1")
>>> print(ip.info())
LOOPBACK
"""
b = self.bin()
for i in range(len(b), 0, -1):
if b[:i] in self._range[self.v]:
return self._rang... | python | def info(self):
"""Show IANA allocation information for the current IP address.
>>> ip = IP("127.0.0.1")
>>> print(ip.info())
LOOPBACK
"""
b = self.bin()
for i in range(len(b), 0, -1):
if b[:i] in self._range[self.v]:
return self._rang... | [
"def",
"info",
"(",
"self",
")",
":",
"b",
"=",
"self",
".",
"bin",
"(",
")",
"for",
"i",
"in",
"range",
"(",
"len",
"(",
"b",
")",
",",
"0",
",",
"-",
"1",
")",
":",
"if",
"b",
"[",
":",
"i",
"]",
"in",
"self",
".",
"_range",
"[",
"sel... | Show IANA allocation information for the current IP address.
>>> ip = IP("127.0.0.1")
>>> print(ip.info())
LOOPBACK | [
"Show",
"IANA",
"allocation",
"information",
"for",
"the",
"current",
"IP",
"address",
"."
] | train | https://github.com/tehmaze/ipcalc/blob/d436b95d2783347c3e0084d76ec3c52d1f5d2f0b/ipcalc.py#L210-L221 |
tehmaze/ipcalc | ipcalc.py | IP._dqtoi | def _dqtoi(self, dq):
"""Convert dotquad or hextet to long."""
# hex notation
if dq.startswith('0x'):
return self._dqtoi_hex(dq)
# IPv6
if ':' in dq:
return self._dqtoi_ipv6(dq)
elif len(dq) == 32:
# Assume full heximal notation
... | python | def _dqtoi(self, dq):
"""Convert dotquad or hextet to long."""
# hex notation
if dq.startswith('0x'):
return self._dqtoi_hex(dq)
# IPv6
if ':' in dq:
return self._dqtoi_ipv6(dq)
elif len(dq) == 32:
# Assume full heximal notation
... | [
"def",
"_dqtoi",
"(",
"self",
",",
"dq",
")",
":",
"# hex notation",
"if",
"dq",
".",
"startswith",
"(",
"'0x'",
")",
":",
"return",
"self",
".",
"_dqtoi_hex",
"(",
"dq",
")",
"# IPv6",
"if",
"':'",
"in",
"dq",
":",
"return",
"self",
".",
"_dqtoi_ipv... | Convert dotquad or hextet to long. | [
"Convert",
"dotquad",
"or",
"hextet",
"to",
"long",
"."
] | train | https://github.com/tehmaze/ipcalc/blob/d436b95d2783347c3e0084d76ec3c52d1f5d2f0b/ipcalc.py#L223-L241 |
tehmaze/ipcalc | ipcalc.py | IP._itodq | def _itodq(self, n):
"""Convert long to dotquad or hextet."""
if self.v == 4:
return '.'.join(map(str, [
(n >> 24) & 0xff,
(n >> 16) & 0xff,
(n >> 8) & 0xff,
n & 0xff,
]))
else:
n = '%032x' % n
... | python | def _itodq(self, n):
"""Convert long to dotquad or hextet."""
if self.v == 4:
return '.'.join(map(str, [
(n >> 24) & 0xff,
(n >> 16) & 0xff,
(n >> 8) & 0xff,
n & 0xff,
]))
else:
n = '%032x' % n
... | [
"def",
"_itodq",
"(",
"self",
",",
"n",
")",
":",
"if",
"self",
".",
"v",
"==",
"4",
":",
"return",
"'.'",
".",
"join",
"(",
"map",
"(",
"str",
",",
"[",
"(",
"n",
">>",
"24",
")",
"&",
"0xff",
",",
"(",
"n",
">>",
"16",
")",
"&",
"0xff",... | Convert long to dotquad or hextet. | [
"Convert",
"long",
"to",
"dotquad",
"or",
"hextet",
"."
] | train | https://github.com/tehmaze/ipcalc/blob/d436b95d2783347c3e0084d76ec3c52d1f5d2f0b/ipcalc.py#L309-L320 |
tehmaze/ipcalc | ipcalc.py | IP.to_compressed | def to_compressed(self):
"""
Compress an IP address to its shortest possible compressed form.
>>> print(IP('127.0.0.1').to_compressed())
127.1
>>> print(IP('127.1.0.1').to_compressed())
127.1.1
>>> print(IP('127.0.1.1').to_compressed())
127.0.1.1
... | python | def to_compressed(self):
"""
Compress an IP address to its shortest possible compressed form.
>>> print(IP('127.0.0.1').to_compressed())
127.1
>>> print(IP('127.1.0.1').to_compressed())
127.1.1
>>> print(IP('127.0.1.1').to_compressed())
127.0.1.1
... | [
"def",
"to_compressed",
"(",
"self",
")",
":",
"if",
"self",
".",
"v",
"==",
"4",
":",
"quads",
"=",
"self",
".",
"dq",
".",
"split",
"(",
"'.'",
")",
"try",
":",
"zero",
"=",
"quads",
".",
"index",
"(",
"'0'",
")",
"if",
"zero",
"==",
"1",
"... | Compress an IP address to its shortest possible compressed form.
>>> print(IP('127.0.0.1').to_compressed())
127.1
>>> print(IP('127.1.0.1').to_compressed())
127.1.1
>>> print(IP('127.0.1.1').to_compressed())
127.0.1.1
>>> print(IP('2001:1234:0000:0000:0000:0000:0... | [
"Compress",
"an",
"IP",
"address",
"to",
"its",
"shortest",
"possible",
"compressed",
"form",
"."
] | train | https://github.com/tehmaze/ipcalc/blob/d436b95d2783347c3e0084d76ec3c52d1f5d2f0b/ipcalc.py#L420-L472 |
tehmaze/ipcalc | ipcalc.py | IP.to_ipv4 | def to_ipv4(self):
"""
Convert (an IPv6) IP address to an IPv4 address, if possible.
Only works for IPv4-compat (::/96), IPv4-mapped (::ffff/96), and 6-to-4
(2002::/16) addresses.
>>> ip = IP('2002:c000:022a::')
>>> print(ip.to_ipv4())
192.0.2.42
"""
... | python | def to_ipv4(self):
"""
Convert (an IPv6) IP address to an IPv4 address, if possible.
Only works for IPv4-compat (::/96), IPv4-mapped (::ffff/96), and 6-to-4
(2002::/16) addresses.
>>> ip = IP('2002:c000:022a::')
>>> print(ip.to_ipv4())
192.0.2.42
"""
... | [
"def",
"to_ipv4",
"(",
"self",
")",
":",
"if",
"self",
".",
"v",
"==",
"4",
":",
"return",
"self",
"else",
":",
"if",
"self",
".",
"bin",
"(",
")",
".",
"startswith",
"(",
"'0'",
"*",
"96",
")",
":",
"return",
"IP",
"(",
"int",
"(",
"self",
"... | Convert (an IPv6) IP address to an IPv4 address, if possible.
Only works for IPv4-compat (::/96), IPv4-mapped (::ffff/96), and 6-to-4
(2002::/16) addresses.
>>> ip = IP('2002:c000:022a::')
>>> print(ip.to_ipv4())
192.0.2.42 | [
"Convert",
"(",
"an",
"IPv6",
")",
"IP",
"address",
"to",
"an",
"IPv4",
"address",
"if",
"possible",
"."
] | train | https://github.com/tehmaze/ipcalc/blob/d436b95d2783347c3e0084d76ec3c52d1f5d2f0b/ipcalc.py#L474-L496 |
tehmaze/ipcalc | ipcalc.py | IP.from_bin | def from_bin(cls, value):
"""Initialize a new network from binary notation."""
value = value.lstrip('b')
if len(value) == 32:
return cls(int(value, 2))
elif len(value) == 128:
return cls(int(value, 2))
else:
return ValueError('%r: invalid binar... | python | def from_bin(cls, value):
"""Initialize a new network from binary notation."""
value = value.lstrip('b')
if len(value) == 32:
return cls(int(value, 2))
elif len(value) == 128:
return cls(int(value, 2))
else:
return ValueError('%r: invalid binar... | [
"def",
"from_bin",
"(",
"cls",
",",
"value",
")",
":",
"value",
"=",
"value",
".",
"lstrip",
"(",
"'b'",
")",
"if",
"len",
"(",
"value",
")",
"==",
"32",
":",
"return",
"cls",
"(",
"int",
"(",
"value",
",",
"2",
")",
")",
"elif",
"len",
"(",
... | Initialize a new network from binary notation. | [
"Initialize",
"a",
"new",
"network",
"from",
"binary",
"notation",
"."
] | train | https://github.com/tehmaze/ipcalc/blob/d436b95d2783347c3e0084d76ec3c52d1f5d2f0b/ipcalc.py#L499-L507 |
tehmaze/ipcalc | ipcalc.py | IP.from_hex | def from_hex(cls, value):
"""Initialize a new network from hexadecimal notation."""
if len(value) == 8:
return cls(int(value, 16))
elif len(value) == 32:
return cls(int(value, 16))
else:
raise ValueError('%r: invalid hexadecimal notation' % (value,)) | python | def from_hex(cls, value):
"""Initialize a new network from hexadecimal notation."""
if len(value) == 8:
return cls(int(value, 16))
elif len(value) == 32:
return cls(int(value, 16))
else:
raise ValueError('%r: invalid hexadecimal notation' % (value,)) | [
"def",
"from_hex",
"(",
"cls",
",",
"value",
")",
":",
"if",
"len",
"(",
"value",
")",
"==",
"8",
":",
"return",
"cls",
"(",
"int",
"(",
"value",
",",
"16",
")",
")",
"elif",
"len",
"(",
"value",
")",
"==",
"32",
":",
"return",
"cls",
"(",
"i... | Initialize a new network from hexadecimal notation. | [
"Initialize",
"a",
"new",
"network",
"from",
"hexadecimal",
"notation",
"."
] | train | https://github.com/tehmaze/ipcalc/blob/d436b95d2783347c3e0084d76ec3c52d1f5d2f0b/ipcalc.py#L510-L517 |
tehmaze/ipcalc | ipcalc.py | IP.to_ipv6 | def to_ipv6(self, ip_type='6-to-4'):
"""
Convert (an IPv4) IP address to an IPv6 address.
>>> ip = IP('192.0.2.42')
>>> print(ip.to_ipv6())
2002:c000:022a:0000:0000:0000:0000:0000
>>> print(ip.to_ipv6('compat'))
0000:0000:0000:0000:0000:0000:c000:022a
>... | python | def to_ipv6(self, ip_type='6-to-4'):
"""
Convert (an IPv4) IP address to an IPv6 address.
>>> ip = IP('192.0.2.42')
>>> print(ip.to_ipv6())
2002:c000:022a:0000:0000:0000:0000:0000
>>> print(ip.to_ipv6('compat'))
0000:0000:0000:0000:0000:0000:c000:022a
>... | [
"def",
"to_ipv6",
"(",
"self",
",",
"ip_type",
"=",
"'6-to-4'",
")",
":",
"assert",
"ip_type",
"in",
"[",
"'6-to-4'",
",",
"'compat'",
",",
"'mapped'",
"]",
",",
"'Conversion ip_type not supported'",
"if",
"self",
".",
"v",
"==",
"4",
":",
"if",
"ip_type",... | Convert (an IPv4) IP address to an IPv6 address.
>>> ip = IP('192.0.2.42')
>>> print(ip.to_ipv6())
2002:c000:022a:0000:0000:0000:0000:0000
>>> print(ip.to_ipv6('compat'))
0000:0000:0000:0000:0000:0000:c000:022a
>>> print(ip.to_ipv6('mapped'))
0000:0000:0000:000... | [
"Convert",
"(",
"an",
"IPv4",
")",
"IP",
"address",
"to",
"an",
"IPv6",
"address",
"."
] | train | https://github.com/tehmaze/ipcalc/blob/d436b95d2783347c3e0084d76ec3c52d1f5d2f0b/ipcalc.py#L519-L542 |
tehmaze/ipcalc | ipcalc.py | IP.to_reverse | def to_reverse(self):
"""Convert the IP address to a PTR record.
Using the .in-addr.arpa zone for IPv4 and .ip6.arpa for IPv6 addresses.
>>> ip = IP('192.0.2.42')
>>> print(ip.to_reverse())
42.2.0.192.in-addr.arpa
>>> print(ip.to_ipv6().to_reverse())
0.0.0.0.0.0... | python | def to_reverse(self):
"""Convert the IP address to a PTR record.
Using the .in-addr.arpa zone for IPv4 and .ip6.arpa for IPv6 addresses.
>>> ip = IP('192.0.2.42')
>>> print(ip.to_reverse())
42.2.0.192.in-addr.arpa
>>> print(ip.to_ipv6().to_reverse())
0.0.0.0.0.0... | [
"def",
"to_reverse",
"(",
"self",
")",
":",
"if",
"self",
".",
"v",
"==",
"4",
":",
"return",
"'.'",
".",
"join",
"(",
"list",
"(",
"self",
".",
"dq",
".",
"split",
"(",
"'.'",
")",
"[",
":",
":",
"-",
"1",
"]",
")",
"+",
"[",
"'in-addr'",
... | Convert the IP address to a PTR record.
Using the .in-addr.arpa zone for IPv4 and .ip6.arpa for IPv6 addresses.
>>> ip = IP('192.0.2.42')
>>> print(ip.to_reverse())
42.2.0.192.in-addr.arpa
>>> print(ip.to_ipv6().to_reverse())
0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.a.2.... | [
"Convert",
"the",
"IP",
"address",
"to",
"a",
"PTR",
"record",
"."
] | train | https://github.com/tehmaze/ipcalc/blob/d436b95d2783347c3e0084d76ec3c52d1f5d2f0b/ipcalc.py#L544-L558 |
tehmaze/ipcalc | ipcalc.py | Network.netmask_long | def netmask_long(self):
"""
Network netmask derived from subnet size, as long.
>>> localnet = Network('127.0.0.1/8')
>>> print(localnet.netmask_long())
4278190080
"""
if self.version() == 4:
return (MAX_IPV4 >> (32 - self.mask)) << (32 - self.mask)
... | python | def netmask_long(self):
"""
Network netmask derived from subnet size, as long.
>>> localnet = Network('127.0.0.1/8')
>>> print(localnet.netmask_long())
4278190080
"""
if self.version() == 4:
return (MAX_IPV4 >> (32 - self.mask)) << (32 - self.mask)
... | [
"def",
"netmask_long",
"(",
"self",
")",
":",
"if",
"self",
".",
"version",
"(",
")",
"==",
"4",
":",
"return",
"(",
"MAX_IPV4",
">>",
"(",
"32",
"-",
"self",
".",
"mask",
")",
")",
"<<",
"(",
"32",
"-",
"self",
".",
"mask",
")",
"else",
":",
... | Network netmask derived from subnet size, as long.
>>> localnet = Network('127.0.0.1/8')
>>> print(localnet.netmask_long())
4278190080 | [
"Network",
"netmask",
"derived",
"from",
"subnet",
"size",
"as",
"long",
"."
] | train | https://github.com/tehmaze/ipcalc/blob/d436b95d2783347c3e0084d76ec3c52d1f5d2f0b/ipcalc.py#L595-L606 |
tehmaze/ipcalc | ipcalc.py | Network.broadcast_long | def broadcast_long(self):
"""
Broadcast address, as long.
>>> localnet = Network('127.0.0.1/8')
>>> print(localnet.broadcast_long())
2147483647
"""
if self.version() == 4:
return self.network_long() | (MAX_IPV4 - self.netmask_long())
else:
... | python | def broadcast_long(self):
"""
Broadcast address, as long.
>>> localnet = Network('127.0.0.1/8')
>>> print(localnet.broadcast_long())
2147483647
"""
if self.version() == 4:
return self.network_long() | (MAX_IPV4 - self.netmask_long())
else:
... | [
"def",
"broadcast_long",
"(",
"self",
")",
":",
"if",
"self",
".",
"version",
"(",
")",
"==",
"4",
":",
"return",
"self",
".",
"network_long",
"(",
")",
"|",
"(",
"MAX_IPV4",
"-",
"self",
".",
"netmask_long",
"(",
")",
")",
"else",
":",
"return",
"... | Broadcast address, as long.
>>> localnet = Network('127.0.0.1/8')
>>> print(localnet.broadcast_long())
2147483647 | [
"Broadcast",
"address",
"as",
"long",
"."
] | train | https://github.com/tehmaze/ipcalc/blob/d436b95d2783347c3e0084d76ec3c52d1f5d2f0b/ipcalc.py#L640-L652 |
tehmaze/ipcalc | ipcalc.py | Network.host_first | def host_first(self):
"""First available host in this subnet."""
if (self.version() == 4 and self.mask > 30) or \
(self.version() == 6 and self.mask > 126):
return self
else:
return IP(self.network_long() + 1, version=self.version()) | python | def host_first(self):
"""First available host in this subnet."""
if (self.version() == 4 and self.mask > 30) or \
(self.version() == 6 and self.mask > 126):
return self
else:
return IP(self.network_long() + 1, version=self.version()) | [
"def",
"host_first",
"(",
"self",
")",
":",
"if",
"(",
"self",
".",
"version",
"(",
")",
"==",
"4",
"and",
"self",
".",
"mask",
">",
"30",
")",
"or",
"(",
"self",
".",
"version",
"(",
")",
"==",
"6",
"and",
"self",
".",
"mask",
">",
"126",
")... | First available host in this subnet. | [
"First",
"available",
"host",
"in",
"this",
"subnet",
"."
] | train | https://github.com/tehmaze/ipcalc/blob/d436b95d2783347c3e0084d76ec3c52d1f5d2f0b/ipcalc.py#L654-L660 |
tehmaze/ipcalc | ipcalc.py | Network.host_last | def host_last(self):
"""Last available host in this subnet."""
if (self.version() == 4 and self.mask == 32) or \
(self.version() == 6 and self.mask == 128):
return self
elif (self.version() == 4 and self.mask == 31) or \
(self.version() == 6 and self.m... | python | def host_last(self):
"""Last available host in this subnet."""
if (self.version() == 4 and self.mask == 32) or \
(self.version() == 6 and self.mask == 128):
return self
elif (self.version() == 4 and self.mask == 31) or \
(self.version() == 6 and self.m... | [
"def",
"host_last",
"(",
"self",
")",
":",
"if",
"(",
"self",
".",
"version",
"(",
")",
"==",
"4",
"and",
"self",
".",
"mask",
"==",
"32",
")",
"or",
"(",
"self",
".",
"version",
"(",
")",
"==",
"6",
"and",
"self",
".",
"mask",
"==",
"128",
"... | Last available host in this subnet. | [
"Last",
"available",
"host",
"in",
"this",
"subnet",
"."
] | train | https://github.com/tehmaze/ipcalc/blob/d436b95d2783347c3e0084d76ec3c52d1f5d2f0b/ipcalc.py#L662-L671 |
tehmaze/ipcalc | ipcalc.py | Network.check_collision | def check_collision(self, other):
"""Check another network against the given network."""
other = Network(other)
return self.network_long() <= other.network_long() <= self.broadcast_long() or \
other.network_long() <= self.network_long() <= other.broadcast_long() | python | def check_collision(self, other):
"""Check another network against the given network."""
other = Network(other)
return self.network_long() <= other.network_long() <= self.broadcast_long() or \
other.network_long() <= self.network_long() <= other.broadcast_long() | [
"def",
"check_collision",
"(",
"self",
",",
"other",
")",
":",
"other",
"=",
"Network",
"(",
"other",
")",
"return",
"self",
".",
"network_long",
"(",
")",
"<=",
"other",
".",
"network_long",
"(",
")",
"<=",
"self",
".",
"broadcast_long",
"(",
")",
"or... | Check another network against the given network. | [
"Check",
"another",
"network",
"against",
"the",
"given",
"network",
"."
] | train | https://github.com/tehmaze/ipcalc/blob/d436b95d2783347c3e0084d76ec3c52d1f5d2f0b/ipcalc.py#L673-L677 |
django-fluent/django-fluent-dashboard | fluent_dashboard/items.py | CmsModelList.init_with_context | def init_with_context(self, context):
"""
Initialize the menu.
"""
# Apply the include/exclude patterns:
listitems = self._visible_models(context['request'])
# Convert to a similar data structure like the dashboard icons have.
# This allows sorting the items iden... | python | def init_with_context(self, context):
"""
Initialize the menu.
"""
# Apply the include/exclude patterns:
listitems = self._visible_models(context['request'])
# Convert to a similar data structure like the dashboard icons have.
# This allows sorting the items iden... | [
"def",
"init_with_context",
"(",
"self",
",",
"context",
")",
":",
"# Apply the include/exclude patterns:",
"listitems",
"=",
"self",
".",
"_visible_models",
"(",
"context",
"[",
"'request'",
"]",
")",
"# Convert to a similar data structure like the dashboard icons have.",
... | Initialize the menu. | [
"Initialize",
"the",
"menu",
"."
] | train | https://github.com/django-fluent/django-fluent-dashboard/blob/aee7ef39e0586cd160036b13b7944b69cd2b4b8c/fluent_dashboard/items.py#L27-L50 |
django-fluent/django-fluent-dashboard | fluent_dashboard/items.py | ReturnToSiteItem.init_with_context | def init_with_context(self, context):
"""
Find the current URL based on the context.
It uses :func:`get_edited_object` to find the model,
and calls ``get_absolute_url()`` to get the frontend URL.
"""
super(ReturnToSiteItem, self).init_with_context(context)
# See ... | python | def init_with_context(self, context):
"""
Find the current URL based on the context.
It uses :func:`get_edited_object` to find the model,
and calls ``get_absolute_url()`` to get the frontend URL.
"""
super(ReturnToSiteItem, self).init_with_context(context)
# See ... | [
"def",
"init_with_context",
"(",
"self",
",",
"context",
")",
":",
"super",
"(",
"ReturnToSiteItem",
",",
"self",
")",
".",
"init_with_context",
"(",
"context",
")",
"# See if the current page is being edited, update URL accordingly.",
"edited_model",
"=",
"self",
".",
... | Find the current URL based on the context.
It uses :func:`get_edited_object` to find the model,
and calls ``get_absolute_url()`` to get the frontend URL. | [
"Find",
"the",
"current",
"URL",
"based",
"on",
"the",
"context",
".",
"It",
"uses",
":",
"func",
":",
"get_edited_object",
"to",
"find",
"the",
"model",
"and",
"calls",
"get_absolute_url",
"()",
"to",
"get",
"the",
"frontend",
"URL",
"."
] | train | https://github.com/django-fluent/django-fluent-dashboard/blob/aee7ef39e0586cd160036b13b7944b69cd2b4b8c/fluent_dashboard/items.py#L82-L99 |
django-fluent/django-fluent-dashboard | fluent_dashboard/items.py | ReturnToSiteItem.get_edited_object | def get_edited_object(self, request):
"""
Return the object which is currently being edited.
Returns ``None`` if the match could not be made.
"""
resolvermatch = urls.resolve(request.path_info)
if resolvermatch.namespace == 'admin' and resolvermatch.url_name and resolverm... | python | def get_edited_object(self, request):
"""
Return the object which is currently being edited.
Returns ``None`` if the match could not be made.
"""
resolvermatch = urls.resolve(request.path_info)
if resolvermatch.namespace == 'admin' and resolvermatch.url_name and resolverm... | [
"def",
"get_edited_object",
"(",
"self",
",",
"request",
")",
":",
"resolvermatch",
"=",
"urls",
".",
"resolve",
"(",
"request",
".",
"path_info",
")",
"if",
"resolvermatch",
".",
"namespace",
"==",
"'admin'",
"and",
"resolvermatch",
".",
"url_name",
"and",
... | Return the object which is currently being edited.
Returns ``None`` if the match could not be made. | [
"Return",
"the",
"object",
"which",
"is",
"currently",
"being",
"edited",
".",
"Returns",
"None",
"if",
"the",
"match",
"could",
"not",
"be",
"made",
"."
] | train | https://github.com/django-fluent/django-fluent-dashboard/blob/aee7ef39e0586cd160036b13b7944b69cd2b4b8c/fluent_dashboard/items.py#L101-L122 |
django-fluent/django-fluent-dashboard | fluent_dashboard/items.py | ReturnToSiteItem.get_object_by_natural_key | def get_object_by_natural_key(self, app_label, model_name, object_id):
"""
Return a model based on a natural key.
This is a utility function for :func:`get_edited_object`.
"""
try:
model_type = ContentType.objects.get_by_natural_key(app_label, model_name)
exce... | python | def get_object_by_natural_key(self, app_label, model_name, object_id):
"""
Return a model based on a natural key.
This is a utility function for :func:`get_edited_object`.
"""
try:
model_type = ContentType.objects.get_by_natural_key(app_label, model_name)
exce... | [
"def",
"get_object_by_natural_key",
"(",
"self",
",",
"app_label",
",",
"model_name",
",",
"object_id",
")",
":",
"try",
":",
"model_type",
"=",
"ContentType",
".",
"objects",
".",
"get_by_natural_key",
"(",
"app_label",
",",
"model_name",
")",
"except",
"Conten... | Return a model based on a natural key.
This is a utility function for :func:`get_edited_object`. | [
"Return",
"a",
"model",
"based",
"on",
"a",
"natural",
"key",
".",
"This",
"is",
"a",
"utility",
"function",
"for",
":",
"func",
":",
"get_edited_object",
"."
] | train | https://github.com/django-fluent/django-fluent-dashboard/blob/aee7ef39e0586cd160036b13b7944b69cd2b4b8c/fluent_dashboard/items.py#L124-L143 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.