partition stringclasses 3
values | func_name stringlengths 1 134 | docstring stringlengths 1 46.9k | path stringlengths 4 223 | original_string stringlengths 75 104k | code stringlengths 75 104k | docstring_tokens listlengths 1 1.97k | repo stringlengths 7 55 | language stringclasses 1
value | url stringlengths 87 315 | code_tokens listlengths 19 28.4k | sha stringlengths 40 40 |
|---|---|---|---|---|---|---|---|---|---|---|---|
train | quantized | Returns *values* quantized to *steps* increments. All items in *values* are
assumed to be between *input_min* and *input_max* (which default to 0 and
1 respectively), and the output will be in the same range.
For example, to quantize values between 0 and 1 to 5 "steps" (0.0, 0.25,
0.5, 0.75, 1.0)::
... | gpiozero/tools.py | def quantized(values, steps, input_min=0, input_max=1):
"""
Returns *values* quantized to *steps* increments. All items in *values* are
assumed to be between *input_min* and *input_max* (which default to 0 and
1 respectively), and the output will be in the same range.
For example, to quantize value... | def quantized(values, steps, input_min=0, input_max=1):
"""
Returns *values* quantized to *steps* increments. All items in *values* are
assumed to be between *input_min* and *input_max* (which default to 0 and
1 respectively), and the output will be in the same range.
For example, to quantize value... | [
"Returns",
"*",
"values",
"*",
"quantized",
"to",
"*",
"steps",
"*",
"increments",
".",
"All",
"items",
"in",
"*",
"values",
"*",
"are",
"assumed",
"to",
"be",
"between",
"*",
"input_min",
"*",
"and",
"*",
"input_max",
"*",
"(",
"which",
"default",
"to... | RPi-Distro/python-gpiozero | python | https://github.com/RPi-Distro/python-gpiozero/blob/7b67374fd0c8c4fde5586d9bad9531f076db9c0c/gpiozero/tools.py#L211-L238 | [
"def",
"quantized",
"(",
"values",
",",
"steps",
",",
"input_min",
"=",
"0",
",",
"input_max",
"=",
"1",
")",
":",
"values",
"=",
"_normalize",
"(",
"values",
")",
"if",
"steps",
"<",
"1",
":",
"raise",
"ValueError",
"(",
"\"steps must be 1 or larger\"",
... | 7b67374fd0c8c4fde5586d9bad9531f076db9c0c |
train | booleanized | Returns True for each item in *values* between *min_value* and
*max_value*, and False otherwise. *hysteresis* can optionally be used to
add `hysteresis`_ which prevents the output value rapidly flipping when
the input value is fluctuating near the *min_value* or *max_value*
thresholds. For example, to l... | gpiozero/tools.py | def booleanized(values, min_value, max_value, hysteresis=0):
"""
Returns True for each item in *values* between *min_value* and
*max_value*, and False otherwise. *hysteresis* can optionally be used to
add `hysteresis`_ which prevents the output value rapidly flipping when
the input value is fluctuat... | def booleanized(values, min_value, max_value, hysteresis=0):
"""
Returns True for each item in *values* between *min_value* and
*max_value*, and False otherwise. *hysteresis* can optionally be used to
add `hysteresis`_ which prevents the output value rapidly flipping when
the input value is fluctuat... | [
"Returns",
"True",
"for",
"each",
"item",
"in",
"*",
"values",
"*",
"between",
"*",
"min_value",
"*",
"and",
"*",
"max_value",
"*",
"and",
"False",
"otherwise",
".",
"*",
"hysteresis",
"*",
"can",
"optionally",
"be",
"used",
"to",
"add",
"hysteresis",
"_... | RPi-Distro/python-gpiozero | python | https://github.com/RPi-Distro/python-gpiozero/blob/7b67374fd0c8c4fde5586d9bad9531f076db9c0c/gpiozero/tools.py#L241-L301 | [
"def",
"booleanized",
"(",
"values",
",",
"min_value",
",",
"max_value",
",",
"hysteresis",
"=",
"0",
")",
":",
"values",
"=",
"_normalize",
"(",
"values",
")",
"if",
"min_value",
">=",
"max_value",
":",
"raise",
"ValueError",
"(",
"'min_value must be smaller ... | 7b67374fd0c8c4fde5586d9bad9531f076db9c0c |
train | all_values | Returns the `logical conjunction`_ of all supplied values (the result is
only :data:`True` if and only if all input values are simultaneously
:data:`True`). One or more *values* can be specified. For example, to light
an :class:`~gpiozero.LED` only when *both* buttons are pressed::
from gpiozero im... | gpiozero/tools.py | def all_values(*values):
"""
Returns the `logical conjunction`_ of all supplied values (the result is
only :data:`True` if and only if all input values are simultaneously
:data:`True`). One or more *values* can be specified. For example, to light
an :class:`~gpiozero.LED` only when *both* buttons ar... | def all_values(*values):
"""
Returns the `logical conjunction`_ of all supplied values (the result is
only :data:`True` if and only if all input values are simultaneously
:data:`True`). One or more *values* can be specified. For example, to light
an :class:`~gpiozero.LED` only when *both* buttons ar... | [
"Returns",
"the",
"logical",
"conjunction",
"_",
"of",
"all",
"supplied",
"values",
"(",
"the",
"result",
"is",
"only",
":",
"data",
":",
"True",
"if",
"and",
"only",
"if",
"all",
"input",
"values",
"are",
"simultaneously",
":",
"data",
":",
"True",
")",... | RPi-Distro/python-gpiozero | python | https://github.com/RPi-Distro/python-gpiozero/blob/7b67374fd0c8c4fde5586d9bad9531f076db9c0c/gpiozero/tools.py#L304-L328 | [
"def",
"all_values",
"(",
"*",
"values",
")",
":",
"print",
"(",
"\"here\"",
")",
"values",
"=",
"[",
"_normalize",
"(",
"v",
")",
"for",
"v",
"in",
"values",
"]",
"for",
"v",
"in",
"zip",
"(",
"*",
"values",
")",
":",
"yield",
"all",
"(",
"v",
... | 7b67374fd0c8c4fde5586d9bad9531f076db9c0c |
train | any_values | Returns the `logical disjunction`_ of all supplied values (the result is
:data:`True` if any of the input values are currently :data:`True`). One or
more *values* can be specified. For example, to light an
:class:`~gpiozero.LED` when *any* button is pressed::
from gpiozero import LED, Button
... | gpiozero/tools.py | def any_values(*values):
"""
Returns the `logical disjunction`_ of all supplied values (the result is
:data:`True` if any of the input values are currently :data:`True`). One or
more *values* can be specified. For example, to light an
:class:`~gpiozero.LED` when *any* button is pressed::
fr... | def any_values(*values):
"""
Returns the `logical disjunction`_ of all supplied values (the result is
:data:`True` if any of the input values are currently :data:`True`). One or
more *values* can be specified. For example, to light an
:class:`~gpiozero.LED` when *any* button is pressed::
fr... | [
"Returns",
"the",
"logical",
"disjunction",
"_",
"of",
"all",
"supplied",
"values",
"(",
"the",
"result",
"is",
":",
"data",
":",
"True",
"if",
"any",
"of",
"the",
"input",
"values",
"are",
"currently",
":",
"data",
":",
"True",
")",
".",
"One",
"or",
... | RPi-Distro/python-gpiozero | python | https://github.com/RPi-Distro/python-gpiozero/blob/7b67374fd0c8c4fde5586d9bad9531f076db9c0c/gpiozero/tools.py#L331-L354 | [
"def",
"any_values",
"(",
"*",
"values",
")",
":",
"values",
"=",
"[",
"_normalize",
"(",
"v",
")",
"for",
"v",
"in",
"values",
"]",
"for",
"v",
"in",
"zip",
"(",
"*",
"values",
")",
":",
"yield",
"any",
"(",
"v",
")"
] | 7b67374fd0c8c4fde5586d9bad9531f076db9c0c |
train | averaged | Returns the mean of all supplied values. One or more *values* can be
specified. For example, to light a :class:`~gpiozero.PWMLED` as the average
of several potentiometers connected to an :class:`~gpiozero.MCP3008` ADC::
from gpiozero import MCP3008, PWMLED
from gpiozero.tools import averaged
... | gpiozero/tools.py | def averaged(*values):
"""
Returns the mean of all supplied values. One or more *values* can be
specified. For example, to light a :class:`~gpiozero.PWMLED` as the average
of several potentiometers connected to an :class:`~gpiozero.MCP3008` ADC::
from gpiozero import MCP3008, PWMLED
fro... | def averaged(*values):
"""
Returns the mean of all supplied values. One or more *values* can be
specified. For example, to light a :class:`~gpiozero.PWMLED` as the average
of several potentiometers connected to an :class:`~gpiozero.MCP3008` ADC::
from gpiozero import MCP3008, PWMLED
fro... | [
"Returns",
"the",
"mean",
"of",
"all",
"supplied",
"values",
".",
"One",
"or",
"more",
"*",
"values",
"*",
"can",
"be",
"specified",
".",
"For",
"example",
"to",
"light",
"a",
":",
"class",
":",
"~gpiozero",
".",
"PWMLED",
"as",
"the",
"average",
"of",... | RPi-Distro/python-gpiozero | python | https://github.com/RPi-Distro/python-gpiozero/blob/7b67374fd0c8c4fde5586d9bad9531f076db9c0c/gpiozero/tools.py#L357-L378 | [
"def",
"averaged",
"(",
"*",
"values",
")",
":",
"values",
"=",
"[",
"_normalize",
"(",
"v",
")",
"for",
"v",
"in",
"values",
"]",
"for",
"v",
"in",
"zip",
"(",
"*",
"values",
")",
":",
"yield",
"mean",
"(",
"v",
")"
] | 7b67374fd0c8c4fde5586d9bad9531f076db9c0c |
train | summed | Returns the sum of all supplied values. One or more *values* can be
specified. For example, to light a :class:`~gpiozero.PWMLED` as the
(scaled) sum of several potentiometers connected to an
:class:`~gpiozero.MCP3008` ADC::
from gpiozero import MCP3008, PWMLED
from gpiozero.tools import sum... | gpiozero/tools.py | def summed(*values):
"""
Returns the sum of all supplied values. One or more *values* can be
specified. For example, to light a :class:`~gpiozero.PWMLED` as the
(scaled) sum of several potentiometers connected to an
:class:`~gpiozero.MCP3008` ADC::
from gpiozero import MCP3008, PWMLED
... | def summed(*values):
"""
Returns the sum of all supplied values. One or more *values* can be
specified. For example, to light a :class:`~gpiozero.PWMLED` as the
(scaled) sum of several potentiometers connected to an
:class:`~gpiozero.MCP3008` ADC::
from gpiozero import MCP3008, PWMLED
... | [
"Returns",
"the",
"sum",
"of",
"all",
"supplied",
"values",
".",
"One",
"or",
"more",
"*",
"values",
"*",
"can",
"be",
"specified",
".",
"For",
"example",
"to",
"light",
"a",
":",
"class",
":",
"~gpiozero",
".",
"PWMLED",
"as",
"the",
"(",
"scaled",
... | RPi-Distro/python-gpiozero | python | https://github.com/RPi-Distro/python-gpiozero/blob/7b67374fd0c8c4fde5586d9bad9531f076db9c0c/gpiozero/tools.py#L381-L403 | [
"def",
"summed",
"(",
"*",
"values",
")",
":",
"values",
"=",
"[",
"_normalize",
"(",
"v",
")",
"for",
"v",
"in",
"values",
"]",
"for",
"v",
"in",
"zip",
"(",
"*",
"values",
")",
":",
"yield",
"sum",
"(",
"v",
")"
] | 7b67374fd0c8c4fde5586d9bad9531f076db9c0c |
train | multiplied | Returns the product of all supplied values. One or more *values* can be
specified. For example, to light a :class:`~gpiozero.PWMLED` as the product
(i.e. multiplication) of several potentiometers connected to an
:class:`~gpiozero.MCP3008`
ADC::
from gpiozero import MCP3008, PWMLED
from ... | gpiozero/tools.py | def multiplied(*values):
"""
Returns the product of all supplied values. One or more *values* can be
specified. For example, to light a :class:`~gpiozero.PWMLED` as the product
(i.e. multiplication) of several potentiometers connected to an
:class:`~gpiozero.MCP3008`
ADC::
from gpiozero... | def multiplied(*values):
"""
Returns the product of all supplied values. One or more *values* can be
specified. For example, to light a :class:`~gpiozero.PWMLED` as the product
(i.e. multiplication) of several potentiometers connected to an
:class:`~gpiozero.MCP3008`
ADC::
from gpiozero... | [
"Returns",
"the",
"product",
"of",
"all",
"supplied",
"values",
".",
"One",
"or",
"more",
"*",
"values",
"*",
"can",
"be",
"specified",
".",
"For",
"example",
"to",
"light",
"a",
":",
"class",
":",
"~gpiozero",
".",
"PWMLED",
"as",
"the",
"product",
"(... | RPi-Distro/python-gpiozero | python | https://github.com/RPi-Distro/python-gpiozero/blob/7b67374fd0c8c4fde5586d9bad9531f076db9c0c/gpiozero/tools.py#L406-L434 | [
"def",
"multiplied",
"(",
"*",
"values",
")",
":",
"values",
"=",
"[",
"_normalize",
"(",
"v",
")",
"for",
"v",
"in",
"values",
"]",
"def",
"_product",
"(",
"it",
")",
":",
"p",
"=",
"1",
"for",
"n",
"in",
"it",
":",
"p",
"*=",
"n",
"return",
... | 7b67374fd0c8c4fde5586d9bad9531f076db9c0c |
train | queued | Queues up readings from *values* (the number of readings queued is
determined by *qsize*) and begins yielding values only when the queue is
full. For example, to "cascade" values along a sequence of LEDs::
from gpiozero import LEDBoard, Button
from gpiozero.tools import queued
from sign... | gpiozero/tools.py | def queued(values, qsize):
"""
Queues up readings from *values* (the number of readings queued is
determined by *qsize*) and begins yielding values only when the queue is
full. For example, to "cascade" values along a sequence of LEDs::
from gpiozero import LEDBoard, Button
from gpiozer... | def queued(values, qsize):
"""
Queues up readings from *values* (the number of readings queued is
determined by *qsize*) and begins yielding values only when the queue is
full. For example, to "cascade" values along a sequence of LEDs::
from gpiozero import LEDBoard, Button
from gpiozer... | [
"Queues",
"up",
"readings",
"from",
"*",
"values",
"*",
"(",
"the",
"number",
"of",
"readings",
"queued",
"is",
"determined",
"by",
"*",
"qsize",
"*",
")",
"and",
"begins",
"yielding",
"values",
"only",
"when",
"the",
"queue",
"is",
"full",
".",
"For",
... | RPi-Distro/python-gpiozero | python | https://github.com/RPi-Distro/python-gpiozero/blob/7b67374fd0c8c4fde5586d9bad9531f076db9c0c/gpiozero/tools.py#L437-L470 | [
"def",
"queued",
"(",
"values",
",",
"qsize",
")",
":",
"values",
"=",
"[",
"_normalize",
"(",
"v",
")",
"for",
"v",
"in",
"values",
"]",
"if",
"qsize",
"<",
"1",
":",
"raise",
"ValueError",
"(",
"\"qsize must be 1 or larger\"",
")",
"q",
"=",
"[",
"... | 7b67374fd0c8c4fde5586d9bad9531f076db9c0c |
train | smoothed | Queues up readings from *values* (the number of readings queued is
determined by *qsize*) and begins yielding the *average* of the last
*qsize* values when the queue is full. The larger the *qsize*, the more the
values are smoothed. For example, to smooth the analog values read from an
ADC::
fr... | gpiozero/tools.py | def smoothed(values, qsize, average=mean):
"""
Queues up readings from *values* (the number of readings queued is
determined by *qsize*) and begins yielding the *average* of the last
*qsize* values when the queue is full. The larger the *qsize*, the more the
values are smoothed. For example, to smoo... | def smoothed(values, qsize, average=mean):
"""
Queues up readings from *values* (the number of readings queued is
determined by *qsize*) and begins yielding the *average* of the last
*qsize* values when the queue is full. The larger the *qsize*, the more the
values are smoothed. For example, to smoo... | [
"Queues",
"up",
"readings",
"from",
"*",
"values",
"*",
"(",
"the",
"number",
"of",
"readings",
"queued",
"is",
"determined",
"by",
"*",
"qsize",
"*",
")",
"and",
"begins",
"yielding",
"the",
"*",
"average",
"*",
"of",
"the",
"last",
"*",
"qsize",
"*",... | RPi-Distro/python-gpiozero | python | https://github.com/RPi-Distro/python-gpiozero/blob/7b67374fd0c8c4fde5586d9bad9531f076db9c0c/gpiozero/tools.py#L473-L501 | [
"def",
"smoothed",
"(",
"values",
",",
"qsize",
",",
"average",
"=",
"mean",
")",
":",
"values",
"=",
"_normalize",
"(",
"values",
")",
"if",
"qsize",
"<",
"1",
":",
"raise",
"ValueError",
"(",
"\"qsize must be 1 or larger\"",
")",
"q",
"=",
"[",
"]",
... | 7b67374fd0c8c4fde5586d9bad9531f076db9c0c |
train | pre_delayed | Waits for *delay* seconds before returning each item from *values*. | gpiozero/tools.py | def pre_delayed(values, delay):
"""
Waits for *delay* seconds before returning each item from *values*.
"""
values = _normalize(values)
if delay < 0:
raise ValueError("delay must be 0 or larger")
for v in values:
sleep(delay)
yield v | def pre_delayed(values, delay):
"""
Waits for *delay* seconds before returning each item from *values*.
"""
values = _normalize(values)
if delay < 0:
raise ValueError("delay must be 0 or larger")
for v in values:
sleep(delay)
yield v | [
"Waits",
"for",
"*",
"delay",
"*",
"seconds",
"before",
"returning",
"each",
"item",
"from",
"*",
"values",
"*",
"."
] | RPi-Distro/python-gpiozero | python | https://github.com/RPi-Distro/python-gpiozero/blob/7b67374fd0c8c4fde5586d9bad9531f076db9c0c/gpiozero/tools.py#L504-L513 | [
"def",
"pre_delayed",
"(",
"values",
",",
"delay",
")",
":",
"values",
"=",
"_normalize",
"(",
"values",
")",
"if",
"delay",
"<",
"0",
":",
"raise",
"ValueError",
"(",
"\"delay must be 0 or larger\"",
")",
"for",
"v",
"in",
"values",
":",
"sleep",
"(",
"... | 7b67374fd0c8c4fde5586d9bad9531f076db9c0c |
train | post_delayed | Waits for *delay* seconds after returning each item from *values*. | gpiozero/tools.py | def post_delayed(values, delay):
"""
Waits for *delay* seconds after returning each item from *values*.
"""
values = _normalize(values)
if delay < 0:
raise ValueError("delay must be 0 or larger")
for v in values:
yield v
sleep(delay) | def post_delayed(values, delay):
"""
Waits for *delay* seconds after returning each item from *values*.
"""
values = _normalize(values)
if delay < 0:
raise ValueError("delay must be 0 or larger")
for v in values:
yield v
sleep(delay) | [
"Waits",
"for",
"*",
"delay",
"*",
"seconds",
"after",
"returning",
"each",
"item",
"from",
"*",
"values",
"*",
"."
] | RPi-Distro/python-gpiozero | python | https://github.com/RPi-Distro/python-gpiozero/blob/7b67374fd0c8c4fde5586d9bad9531f076db9c0c/gpiozero/tools.py#L516-L525 | [
"def",
"post_delayed",
"(",
"values",
",",
"delay",
")",
":",
"values",
"=",
"_normalize",
"(",
"values",
")",
"if",
"delay",
"<",
"0",
":",
"raise",
"ValueError",
"(",
"\"delay must be 0 or larger\"",
")",
"for",
"v",
"in",
"values",
":",
"yield",
"v",
... | 7b67374fd0c8c4fde5586d9bad9531f076db9c0c |
train | pre_periodic_filtered | Blocks the first *block* items from *values*, repeating the block after
every *repeat_after* items, if *repeat_after* is non-zero. For example, to
discard the first 50 values read from an ADC::
from gpiozero import MCP3008
from gpiozero.tools import pre_periodic_filtered
adc = MCP3008(... | gpiozero/tools.py | def pre_periodic_filtered(values, block, repeat_after):
"""
Blocks the first *block* items from *values*, repeating the block after
every *repeat_after* items, if *repeat_after* is non-zero. For example, to
discard the first 50 values read from an ADC::
from gpiozero import MCP3008
from... | def pre_periodic_filtered(values, block, repeat_after):
"""
Blocks the first *block* items from *values*, repeating the block after
every *repeat_after* items, if *repeat_after* is non-zero. For example, to
discard the first 50 values read from an ADC::
from gpiozero import MCP3008
from... | [
"Blocks",
"the",
"first",
"*",
"block",
"*",
"items",
"from",
"*",
"values",
"*",
"repeating",
"the",
"block",
"after",
"every",
"*",
"repeat_after",
"*",
"items",
"if",
"*",
"repeat_after",
"*",
"is",
"non",
"-",
"zero",
".",
"For",
"example",
"to",
"... | RPi-Distro/python-gpiozero | python | https://github.com/RPi-Distro/python-gpiozero/blob/7b67374fd0c8c4fde5586d9bad9531f076db9c0c/gpiozero/tools.py#L528-L571 | [
"def",
"pre_periodic_filtered",
"(",
"values",
",",
"block",
",",
"repeat_after",
")",
":",
"values",
"=",
"_normalize",
"(",
"values",
")",
"if",
"block",
"<",
"1",
":",
"raise",
"ValueError",
"(",
"\"block must be 1 or larger\"",
")",
"if",
"repeat_after",
"... | 7b67374fd0c8c4fde5586d9bad9531f076db9c0c |
train | post_periodic_filtered | After every *repeat_after* items, blocks the next *block* items from
*values*. Note that unlike :func:`pre_periodic_filtered`, *repeat_after*
can't be 0. For example, to block every tenth item read from an ADC::
from gpiozero import MCP3008
from gpiozero.tools import post_periodic_filtered
... | gpiozero/tools.py | def post_periodic_filtered(values, repeat_after, block):
"""
After every *repeat_after* items, blocks the next *block* items from
*values*. Note that unlike :func:`pre_periodic_filtered`, *repeat_after*
can't be 0. For example, to block every tenth item read from an ADC::
from gpiozero import M... | def post_periodic_filtered(values, repeat_after, block):
"""
After every *repeat_after* items, blocks the next *block* items from
*values*. Note that unlike :func:`pre_periodic_filtered`, *repeat_after*
can't be 0. For example, to block every tenth item read from an ADC::
from gpiozero import M... | [
"After",
"every",
"*",
"repeat_after",
"*",
"items",
"blocks",
"the",
"next",
"*",
"block",
"*",
"items",
"from",
"*",
"values",
"*",
".",
"Note",
"that",
"unlike",
":",
"func",
":",
"pre_periodic_filtered",
"*",
"repeat_after",
"*",
"can",
"t",
"be",
"0... | RPi-Distro/python-gpiozero | python | https://github.com/RPi-Distro/python-gpiozero/blob/7b67374fd0c8c4fde5586d9bad9531f076db9c0c/gpiozero/tools.py#L574-L601 | [
"def",
"post_periodic_filtered",
"(",
"values",
",",
"repeat_after",
",",
"block",
")",
":",
"values",
"=",
"_normalize",
"(",
"values",
")",
"if",
"repeat_after",
"<",
"1",
":",
"raise",
"ValueError",
"(",
"\"repeat_after must be 1 or larger\"",
")",
"if",
"blo... | 7b67374fd0c8c4fde5586d9bad9531f076db9c0c |
train | sin_values | Provides an infinite source of values representing a sine wave (from -1 to
+1) which repeats every *period* values. For example, to produce a "siren"
effect with a couple of LEDs that repeats once a second::
from gpiozero import PWMLED
from gpiozero.tools import sin_values, scaled, inverted
... | gpiozero/tools.py | def sin_values(period=360):
"""
Provides an infinite source of values representing a sine wave (from -1 to
+1) which repeats every *period* values. For example, to produce a "siren"
effect with a couple of LEDs that repeats once a second::
from gpiozero import PWMLED
from gpiozero.tools... | def sin_values(period=360):
"""
Provides an infinite source of values representing a sine wave (from -1 to
+1) which repeats every *period* values. For example, to produce a "siren"
effect with a couple of LEDs that repeats once a second::
from gpiozero import PWMLED
from gpiozero.tools... | [
"Provides",
"an",
"infinite",
"source",
"of",
"values",
"representing",
"a",
"sine",
"wave",
"(",
"from",
"-",
"1",
"to",
"+",
"1",
")",
"which",
"repeats",
"every",
"*",
"period",
"*",
"values",
".",
"For",
"example",
"to",
"produce",
"a",
"siren",
"e... | RPi-Distro/python-gpiozero | python | https://github.com/RPi-Distro/python-gpiozero/blob/7b67374fd0c8c4fde5586d9bad9531f076db9c0c/gpiozero/tools.py#L625-L649 | [
"def",
"sin_values",
"(",
"period",
"=",
"360",
")",
":",
"angles",
"=",
"(",
"2",
"*",
"pi",
"*",
"i",
"/",
"period",
"for",
"i",
"in",
"range",
"(",
"period",
")",
")",
"for",
"a",
"in",
"cycle",
"(",
"angles",
")",
":",
"yield",
"sin",
"(",
... | 7b67374fd0c8c4fde5586d9bad9531f076db9c0c |
train | cos_values | Provides an infinite source of values representing a cosine wave (from -1
to +1) which repeats every *period* values. For example, to produce a
"siren" effect with a couple of LEDs that repeats once a second::
from gpiozero import PWMLED
from gpiozero.tools import cos_values, scaled, inverted
... | gpiozero/tools.py | def cos_values(period=360):
"""
Provides an infinite source of values representing a cosine wave (from -1
to +1) which repeats every *period* values. For example, to produce a
"siren" effect with a couple of LEDs that repeats once a second::
from gpiozero import PWMLED
from gpiozero.too... | def cos_values(period=360):
"""
Provides an infinite source of values representing a cosine wave (from -1
to +1) which repeats every *period* values. For example, to produce a
"siren" effect with a couple of LEDs that repeats once a second::
from gpiozero import PWMLED
from gpiozero.too... | [
"Provides",
"an",
"infinite",
"source",
"of",
"values",
"representing",
"a",
"cosine",
"wave",
"(",
"from",
"-",
"1",
"to",
"+",
"1",
")",
"which",
"repeats",
"every",
"*",
"period",
"*",
"values",
".",
"For",
"example",
"to",
"produce",
"a",
"siren",
... | RPi-Distro/python-gpiozero | python | https://github.com/RPi-Distro/python-gpiozero/blob/7b67374fd0c8c4fde5586d9bad9531f076db9c0c/gpiozero/tools.py#L652-L676 | [
"def",
"cos_values",
"(",
"period",
"=",
"360",
")",
":",
"angles",
"=",
"(",
"2",
"*",
"pi",
"*",
"i",
"/",
"period",
"for",
"i",
"in",
"range",
"(",
"period",
")",
")",
"for",
"a",
"in",
"cycle",
"(",
"angles",
")",
":",
"yield",
"cos",
"(",
... | 7b67374fd0c8c4fde5586d9bad9531f076db9c0c |
train | ramping_values | Provides an infinite source of values representing a triangle wave (from 0
to 1 and back again) which repeats every *period* values. For example, to
pulse an LED once a second::
from gpiozero import PWMLED
from gpiozero.tools import ramping_values
from signal import pause
red =... | gpiozero/tools.py | def ramping_values(period=360):
"""
Provides an infinite source of values representing a triangle wave (from 0
to 1 and back again) which repeats every *period* values. For example, to
pulse an LED once a second::
from gpiozero import PWMLED
from gpiozero.tools import ramping_values
... | def ramping_values(period=360):
"""
Provides an infinite source of values representing a triangle wave (from 0
to 1 and back again) which repeats every *period* values. For example, to
pulse an LED once a second::
from gpiozero import PWMLED
from gpiozero.tools import ramping_values
... | [
"Provides",
"an",
"infinite",
"source",
"of",
"values",
"representing",
"a",
"triangle",
"wave",
"(",
"from",
"0",
"to",
"1",
"and",
"back",
"again",
")",
"which",
"repeats",
"every",
"*",
"period",
"*",
"values",
".",
"For",
"example",
"to",
"pulse",
"a... | RPi-Distro/python-gpiozero | python | https://github.com/RPi-Distro/python-gpiozero/blob/7b67374fd0c8c4fde5586d9bad9531f076db9c0c/gpiozero/tools.py#L702-L734 | [
"def",
"ramping_values",
"(",
"period",
"=",
"360",
")",
":",
"step",
"=",
"2",
"/",
"period",
"value",
"=",
"0",
"while",
"True",
":",
"yield",
"value",
"value",
"+=",
"step",
"if",
"isclose",
"(",
"value",
",",
"1",
",",
"abs_tol",
"=",
"1e-9",
"... | 7b67374fd0c8c4fde5586d9bad9531f076db9c0c |
train | OutputDevice.toggle | Reverse the state of the device. If it's on, turn it off; if it's off,
turn it on. | gpiozero/output_devices.py | def toggle(self):
"""
Reverse the state of the device. If it's on, turn it off; if it's off,
turn it on.
"""
with self._lock:
if self.is_active:
self.off()
else:
self.on() | def toggle(self):
"""
Reverse the state of the device. If it's on, turn it off; if it's off,
turn it on.
"""
with self._lock:
if self.is_active:
self.off()
else:
self.on() | [
"Reverse",
"the",
"state",
"of",
"the",
"device",
".",
"If",
"it",
"s",
"on",
"turn",
"it",
"off",
";",
"if",
"it",
"s",
"off",
"turn",
"it",
"on",
"."
] | RPi-Distro/python-gpiozero | python | https://github.com/RPi-Distro/python-gpiozero/blob/7b67374fd0c8c4fde5586d9bad9531f076db9c0c/gpiozero/output_devices.py#L123-L132 | [
"def",
"toggle",
"(",
"self",
")",
":",
"with",
"self",
".",
"_lock",
":",
"if",
"self",
".",
"is_active",
":",
"self",
".",
"off",
"(",
")",
"else",
":",
"self",
".",
"on",
"(",
")"
] | 7b67374fd0c8c4fde5586d9bad9531f076db9c0c |
train | PWMOutputDevice.blink | Make the device turn on and off repeatedly.
:param float on_time:
Number of seconds on. Defaults to 1 second.
:param float off_time:
Number of seconds off. Defaults to 1 second.
:param float fade_in_time:
Number of seconds to spend fading in. Defaults to 0.... | gpiozero/output_devices.py | def blink(
self, on_time=1, off_time=1, fade_in_time=0, fade_out_time=0,
n=None, background=True):
"""
Make the device turn on and off repeatedly.
:param float on_time:
Number of seconds on. Defaults to 1 second.
:param float off_time:
Nu... | def blink(
self, on_time=1, off_time=1, fade_in_time=0, fade_out_time=0,
n=None, background=True):
"""
Make the device turn on and off repeatedly.
:param float on_time:
Number of seconds on. Defaults to 1 second.
:param float off_time:
Nu... | [
"Make",
"the",
"device",
"turn",
"on",
"and",
"off",
"repeatedly",
"."
] | RPi-Distro/python-gpiozero | python | https://github.com/RPi-Distro/python-gpiozero/blob/7b67374fd0c8c4fde5586d9bad9531f076db9c0c/gpiozero/output_devices.py#L498-L534 | [
"def",
"blink",
"(",
"self",
",",
"on_time",
"=",
"1",
",",
"off_time",
"=",
"1",
",",
"fade_in_time",
"=",
"0",
",",
"fade_out_time",
"=",
"0",
",",
"n",
"=",
"None",
",",
"background",
"=",
"True",
")",
":",
"self",
".",
"_stop_blink",
"(",
")",
... | 7b67374fd0c8c4fde5586d9bad9531f076db9c0c |
train | TonalBuzzer.play | Play the given *tone*. This can either be an instance of
:class:`~gpiozero.tones.Tone` or can be anything that could be used to
construct an instance of :class:`~gpiozero.tones.Tone`.
For example::
>>> from gpiozero import TonalBuzzer
>>> from gpiozero.tones import Tone... | gpiozero/output_devices.py | def play(self, tone):
"""
Play the given *tone*. This can either be an instance of
:class:`~gpiozero.tones.Tone` or can be anything that could be used to
construct an instance of :class:`~gpiozero.tones.Tone`.
For example::
>>> from gpiozero import TonalBuzzer
... | def play(self, tone):
"""
Play the given *tone*. This can either be an instance of
:class:`~gpiozero.tones.Tone` or can be anything that could be used to
construct an instance of :class:`~gpiozero.tones.Tone`.
For example::
>>> from gpiozero import TonalBuzzer
... | [
"Play",
"the",
"given",
"*",
"tone",
"*",
".",
"This",
"can",
"either",
"be",
"an",
"instance",
"of",
":",
"class",
":",
"~gpiozero",
".",
"tones",
".",
"Tone",
"or",
"can",
"be",
"anything",
"that",
"could",
"be",
"used",
"to",
"construct",
"an",
"i... | RPi-Distro/python-gpiozero | python | https://github.com/RPi-Distro/python-gpiozero/blob/7b67374fd0c8c4fde5586d9bad9531f076db9c0c/gpiozero/output_devices.py#L669-L697 | [
"def",
"play",
"(",
"self",
",",
"tone",
")",
":",
"if",
"tone",
"is",
"None",
":",
"self",
".",
"value",
"=",
"None",
"else",
":",
"if",
"not",
"isinstance",
"(",
"tone",
",",
"Tone",
")",
":",
"tone",
"=",
"Tone",
"(",
"tone",
")",
"freq",
"=... | 7b67374fd0c8c4fde5586d9bad9531f076db9c0c |
train | TonalBuzzer.tone | Returns the :class:`~gpiozero.tones.Tone` that the buzzer is currently
playing, or :data:`None` if the buzzer is silent. This property can
also be set to play the specified tone. | gpiozero/output_devices.py | def tone(self):
"""
Returns the :class:`~gpiozero.tones.Tone` that the buzzer is currently
playing, or :data:`None` if the buzzer is silent. This property can
also be set to play the specified tone.
"""
if self.pwm_device.pin.frequency is None:
return None
... | def tone(self):
"""
Returns the :class:`~gpiozero.tones.Tone` that the buzzer is currently
playing, or :data:`None` if the buzzer is silent. This property can
also be set to play the specified tone.
"""
if self.pwm_device.pin.frequency is None:
return None
... | [
"Returns",
"the",
":",
"class",
":",
"~gpiozero",
".",
"tones",
".",
"Tone",
"that",
"the",
"buzzer",
"is",
"currently",
"playing",
"or",
":",
"data",
":",
"None",
"if",
"the",
"buzzer",
"is",
"silent",
".",
"This",
"property",
"can",
"also",
"be",
"se... | RPi-Distro/python-gpiozero | python | https://github.com/RPi-Distro/python-gpiozero/blob/7b67374fd0c8c4fde5586d9bad9531f076db9c0c/gpiozero/output_devices.py#L707-L716 | [
"def",
"tone",
"(",
"self",
")",
":",
"if",
"self",
".",
"pwm_device",
".",
"pin",
".",
"frequency",
"is",
"None",
":",
"return",
"None",
"else",
":",
"return",
"Tone",
".",
"from_frequency",
"(",
"self",
".",
"pwm_device",
".",
"pin",
".",
"frequency"... | 7b67374fd0c8c4fde5586d9bad9531f076db9c0c |
train | TonalBuzzer.value | Represents the state of the buzzer as a value between -1 (representing
the minimum tone) and 1 (representing the maximum tone). This can also
be the special value :data:`None` indicating that the buzzer is
currently silent. | gpiozero/output_devices.py | def value(self):
"""
Represents the state of the buzzer as a value between -1 (representing
the minimum tone) and 1 (representing the maximum tone). This can also
be the special value :data:`None` indicating that the buzzer is
currently silent.
"""
if self.pwm_dev... | def value(self):
"""
Represents the state of the buzzer as a value between -1 (representing
the minimum tone) and 1 (representing the maximum tone). This can also
be the special value :data:`None` indicating that the buzzer is
currently silent.
"""
if self.pwm_dev... | [
"Represents",
"the",
"state",
"of",
"the",
"buzzer",
"as",
"a",
"value",
"between",
"-",
"1",
"(",
"representing",
"the",
"minimum",
"tone",
")",
"and",
"1",
"(",
"representing",
"the",
"maximum",
"tone",
")",
".",
"This",
"can",
"also",
"be",
"the",
"... | RPi-Distro/python-gpiozero | python | https://github.com/RPi-Distro/python-gpiozero/blob/7b67374fd0c8c4fde5586d9bad9531f076db9c0c/gpiozero/output_devices.py#L723-L738 | [
"def",
"value",
"(",
"self",
")",
":",
"if",
"self",
".",
"pwm_device",
".",
"pin",
".",
"frequency",
"is",
"None",
":",
"return",
"None",
"else",
":",
"try",
":",
"return",
"log2",
"(",
"self",
".",
"pwm_device",
".",
"pin",
".",
"frequency",
"/",
... | 7b67374fd0c8c4fde5586d9bad9531f076db9c0c |
train | RGBLED.toggle | Toggle the state of the device. If the device is currently off
(:attr:`value` is ``(0, 0, 0)``), this changes it to "fully" on
(:attr:`value` is ``(1, 1, 1)``). If the device has a specific color,
this method inverts the color. | gpiozero/output_devices.py | def toggle(self):
"""
Toggle the state of the device. If the device is currently off
(:attr:`value` is ``(0, 0, 0)``), this changes it to "fully" on
(:attr:`value` is ``(1, 1, 1)``). If the device has a specific color,
this method inverts the color.
"""
r, g, b =... | def toggle(self):
"""
Toggle the state of the device. If the device is currently off
(:attr:`value` is ``(0, 0, 0)``), this changes it to "fully" on
(:attr:`value` is ``(1, 1, 1)``). If the device has a specific color,
this method inverts the color.
"""
r, g, b =... | [
"Toggle",
"the",
"state",
"of",
"the",
"device",
".",
"If",
"the",
"device",
"is",
"currently",
"off",
"(",
":",
"attr",
":",
"value",
"is",
"(",
"0",
"0",
"0",
")",
")",
"this",
"changes",
"it",
"to",
"fully",
"on",
"(",
":",
"attr",
":",
"value... | RPi-Distro/python-gpiozero | python | https://github.com/RPi-Distro/python-gpiozero/blob/7b67374fd0c8c4fde5586d9bad9531f076db9c0c/gpiozero/output_devices.py#L1021-L1029 | [
"def",
"toggle",
"(",
"self",
")",
":",
"r",
",",
"g",
",",
"b",
"=",
"self",
".",
"value",
"self",
".",
"value",
"=",
"(",
"1",
"-",
"r",
",",
"1",
"-",
"g",
",",
"1",
"-",
"b",
")"
] | 7b67374fd0c8c4fde5586d9bad9531f076db9c0c |
train | RGBLED.blink | Make the device turn on and off repeatedly.
:param float on_time:
Number of seconds on. Defaults to 1 second.
:param float off_time:
Number of seconds off. Defaults to 1 second.
:param float fade_in_time:
Number of seconds to spend fading in. Defaults to 0.... | gpiozero/output_devices.py | def blink(
self, on_time=1, off_time=1, fade_in_time=0, fade_out_time=0,
on_color=(1, 1, 1), off_color=(0, 0, 0), n=None, background=True):
"""
Make the device turn on and off repeatedly.
:param float on_time:
Number of seconds on. Defaults to 1 second.
... | def blink(
self, on_time=1, off_time=1, fade_in_time=0, fade_out_time=0,
on_color=(1, 1, 1), off_color=(0, 0, 0), n=None, background=True):
"""
Make the device turn on and off repeatedly.
:param float on_time:
Number of seconds on. Defaults to 1 second.
... | [
"Make",
"the",
"device",
"turn",
"on",
"and",
"off",
"repeatedly",
"."
] | RPi-Distro/python-gpiozero | python | https://github.com/RPi-Distro/python-gpiozero/blob/7b67374fd0c8c4fde5586d9bad9531f076db9c0c/gpiozero/output_devices.py#L1031-L1087 | [
"def",
"blink",
"(",
"self",
",",
"on_time",
"=",
"1",
",",
"off_time",
"=",
"1",
",",
"fade_in_time",
"=",
"0",
",",
"fade_out_time",
"=",
"0",
",",
"on_color",
"=",
"(",
"1",
",",
"1",
",",
"1",
")",
",",
"off_color",
"=",
"(",
"0",
",",
"0",... | 7b67374fd0c8c4fde5586d9bad9531f076db9c0c |
train | Motor.forward | Drive the motor forwards.
:param float speed:
The speed at which the motor should turn. Can be any value between
0 (stopped) and the default 1 (maximum speed) if *pwm* was
:data:`True` when the class was constructed (and only 0 or 1 if
not). | gpiozero/output_devices.py | def forward(self, speed=1):
"""
Drive the motor forwards.
:param float speed:
The speed at which the motor should turn. Can be any value between
0 (stopped) and the default 1 (maximum speed) if *pwm* was
:data:`True` when the class was constructed (and only 0... | def forward(self, speed=1):
"""
Drive the motor forwards.
:param float speed:
The speed at which the motor should turn. Can be any value between
0 (stopped) and the default 1 (maximum speed) if *pwm* was
:data:`True` when the class was constructed (and only 0... | [
"Drive",
"the",
"motor",
"forwards",
"."
] | RPi-Distro/python-gpiozero | python | https://github.com/RPi-Distro/python-gpiozero/blob/7b67374fd0c8c4fde5586d9bad9531f076db9c0c/gpiozero/output_devices.py#L1266-L1283 | [
"def",
"forward",
"(",
"self",
",",
"speed",
"=",
"1",
")",
":",
"if",
"not",
"0",
"<=",
"speed",
"<=",
"1",
":",
"raise",
"ValueError",
"(",
"'forward speed must be between 0 and 1'",
")",
"if",
"isinstance",
"(",
"self",
".",
"forward_device",
",",
"Digi... | 7b67374fd0c8c4fde5586d9bad9531f076db9c0c |
train | PhaseEnableMotor.value | Represents the speed of the motor as a floating point value between -1
(full speed backward) and 1 (full speed forward). | gpiozero/output_devices.py | def value(self):
"""
Represents the speed of the motor as a floating point value between -1
(full speed backward) and 1 (full speed forward).
"""
return (
-self.enable_device.value
if self.phase_device.is_active else
self.enable_device.value
... | def value(self):
"""
Represents the speed of the motor as a floating point value between -1
(full speed backward) and 1 (full speed forward).
"""
return (
-self.enable_device.value
if self.phase_device.is_active else
self.enable_device.value
... | [
"Represents",
"the",
"speed",
"of",
"the",
"motor",
"as",
"a",
"floating",
"point",
"value",
"between",
"-",
"1",
"(",
"full",
"speed",
"backward",
")",
"and",
"1",
"(",
"full",
"speed",
"forward",
")",
"."
] | RPi-Distro/python-gpiozero | python | https://github.com/RPi-Distro/python-gpiozero/blob/7b67374fd0c8c4fde5586d9bad9531f076db9c0c/gpiozero/output_devices.py#L1369-L1378 | [
"def",
"value",
"(",
"self",
")",
":",
"return",
"(",
"-",
"self",
".",
"enable_device",
".",
"value",
"if",
"self",
".",
"phase_device",
".",
"is_active",
"else",
"self",
".",
"enable_device",
".",
"value",
")"
] | 7b67374fd0c8c4fde5586d9bad9531f076db9c0c |
train | PhaseEnableMotor.forward | Drive the motor forwards.
:param float speed:
The speed at which the motor should turn. Can be any value between
0 (stopped) and the default 1 (maximum speed). | gpiozero/output_devices.py | def forward(self, speed=1):
"""
Drive the motor forwards.
:param float speed:
The speed at which the motor should turn. Can be any value between
0 (stopped) and the default 1 (maximum speed).
"""
if isinstance(self.enable_device, DigitalOutputDevice):
... | def forward(self, speed=1):
"""
Drive the motor forwards.
:param float speed:
The speed at which the motor should turn. Can be any value between
0 (stopped) and the default 1 (maximum speed).
"""
if isinstance(self.enable_device, DigitalOutputDevice):
... | [
"Drive",
"the",
"motor",
"forwards",
"."
] | RPi-Distro/python-gpiozero | python | https://github.com/RPi-Distro/python-gpiozero/blob/7b67374fd0c8c4fde5586d9bad9531f076db9c0c/gpiozero/output_devices.py#L1399-L1413 | [
"def",
"forward",
"(",
"self",
",",
"speed",
"=",
"1",
")",
":",
"if",
"isinstance",
"(",
"self",
".",
"enable_device",
",",
"DigitalOutputDevice",
")",
":",
"if",
"speed",
"not",
"in",
"(",
"0",
",",
"1",
")",
":",
"raise",
"ValueError",
"(",
"'forw... | 7b67374fd0c8c4fde5586d9bad9531f076db9c0c |
train | PhaseEnableMotor.backward | Drive the motor backwards.
:param float speed:
The speed at which the motor should turn. Can be any value between
0 (stopped) and the default 1 (maximum speed). | gpiozero/output_devices.py | def backward(self, speed=1):
"""
Drive the motor backwards.
:param float speed:
The speed at which the motor should turn. Can be any value between
0 (stopped) and the default 1 (maximum speed).
"""
if isinstance(self.enable_device, DigitalOutputDevice):
... | def backward(self, speed=1):
"""
Drive the motor backwards.
:param float speed:
The speed at which the motor should turn. Can be any value between
0 (stopped) and the default 1 (maximum speed).
"""
if isinstance(self.enable_device, DigitalOutputDevice):
... | [
"Drive",
"the",
"motor",
"backwards",
"."
] | RPi-Distro/python-gpiozero | python | https://github.com/RPi-Distro/python-gpiozero/blob/7b67374fd0c8c4fde5586d9bad9531f076db9c0c/gpiozero/output_devices.py#L1415-L1429 | [
"def",
"backward",
"(",
"self",
",",
"speed",
"=",
"1",
")",
":",
"if",
"isinstance",
"(",
"self",
".",
"enable_device",
",",
"DigitalOutputDevice",
")",
":",
"if",
"speed",
"not",
"in",
"(",
"0",
",",
"1",
")",
":",
"raise",
"ValueError",
"(",
"'bac... | 7b67374fd0c8c4fde5586d9bad9531f076db9c0c |
train | Servo.pulse_width | Returns the current pulse width controlling the servo. | gpiozero/output_devices.py | def pulse_width(self):
"""
Returns the current pulse width controlling the servo.
"""
if self.pwm_device.pin.frequency is None:
return None
else:
return self.pwm_device.pin.state * self.frame_width | def pulse_width(self):
"""
Returns the current pulse width controlling the servo.
"""
if self.pwm_device.pin.frequency is None:
return None
else:
return self.pwm_device.pin.state * self.frame_width | [
"Returns",
"the",
"current",
"pulse",
"width",
"controlling",
"the",
"servo",
"."
] | RPi-Distro/python-gpiozero | python | https://github.com/RPi-Distro/python-gpiozero/blob/7b67374fd0c8c4fde5586d9bad9531f076db9c0c/gpiozero/output_devices.py#L1550-L1557 | [
"def",
"pulse_width",
"(",
"self",
")",
":",
"if",
"self",
".",
"pwm_device",
".",
"pin",
".",
"frequency",
"is",
"None",
":",
"return",
"None",
"else",
":",
"return",
"self",
".",
"pwm_device",
".",
"pin",
".",
"state",
"*",
"self",
".",
"frame_width"... | 7b67374fd0c8c4fde5586d9bad9531f076db9c0c |
train | AngularServo.angle | The position of the servo as an angle measured in degrees. This will
only be accurate if :attr:`min_angle` and :attr:`max_angle` have been
set appropriately in the constructor.
This can also be the special value :data:`None` indicating that the
servo is currently "uncontrolled", i.e. th... | gpiozero/output_devices.py | def angle(self):
"""
The position of the servo as an angle measured in degrees. This will
only be accurate if :attr:`min_angle` and :attr:`max_angle` have been
set appropriately in the constructor.
This can also be the special value :data:`None` indicating that the
servo... | def angle(self):
"""
The position of the servo as an angle measured in degrees. This will
only be accurate if :attr:`min_angle` and :attr:`max_angle` have been
set appropriately in the constructor.
This can also be the special value :data:`None` indicating that the
servo... | [
"The",
"position",
"of",
"the",
"servo",
"as",
"an",
"angle",
"measured",
"in",
"degrees",
".",
"This",
"will",
"only",
"be",
"accurate",
"if",
":",
"attr",
":",
"min_angle",
"and",
":",
"attr",
":",
"max_angle",
"have",
"been",
"set",
"appropriately",
"... | RPi-Distro/python-gpiozero | python | https://github.com/RPi-Distro/python-gpiozero/blob/7b67374fd0c8c4fde5586d9bad9531f076db9c0c/gpiozero/output_devices.py#L1751-L1772 | [
"def",
"angle",
"(",
"self",
")",
":",
"result",
"=",
"self",
".",
"_get_value",
"(",
")",
"if",
"result",
"is",
"None",
":",
"return",
"None",
"else",
":",
"# NOTE: Why round(n, 12) here instead of 14? Angle ranges can be",
"# much larger than -1..1 so we need a little... | 7b67374fd0c8c4fde5586d9bad9531f076db9c0c |
train | Tone.from_midi | Construct a :class:`Tone` from a MIDI note, which must be an integer
in the range 0 to 127. For reference, A4 (`concert A`_ typically used
for tuning) is MIDI note #69.
.. _concert A: https://en.wikipedia.org/wiki/Concert_pitch | gpiozero/tones.py | def from_midi(cls, midi_note):
"""
Construct a :class:`Tone` from a MIDI note, which must be an integer
in the range 0 to 127. For reference, A4 (`concert A`_ typically used
for tuning) is MIDI note #69.
.. _concert A: https://en.wikipedia.org/wiki/Concert_pitch
"""
... | def from_midi(cls, midi_note):
"""
Construct a :class:`Tone` from a MIDI note, which must be an integer
in the range 0 to 127. For reference, A4 (`concert A`_ typically used
for tuning) is MIDI note #69.
.. _concert A: https://en.wikipedia.org/wiki/Concert_pitch
"""
... | [
"Construct",
"a",
":",
"class",
":",
"Tone",
"from",
"a",
"MIDI",
"note",
"which",
"must",
"be",
"an",
"integer",
"in",
"the",
"range",
"0",
"to",
"127",
".",
"For",
"reference",
"A4",
"(",
"concert",
"A",
"_",
"typically",
"used",
"for",
"tuning",
"... | RPi-Distro/python-gpiozero | python | https://github.com/RPi-Distro/python-gpiozero/blob/7b67374fd0c8c4fde5586d9bad9531f076db9c0c/gpiozero/tones.py#L167-L180 | [
"def",
"from_midi",
"(",
"cls",
",",
"midi_note",
")",
":",
"midi",
"=",
"int",
"(",
"midi_note",
")",
"if",
"0",
"<=",
"midi_note",
"<",
"128",
":",
"A4_midi",
"=",
"69",
"A4_freq",
"=",
"440",
"return",
"cls",
".",
"from_frequency",
"(",
"A4_freq",
... | 7b67374fd0c8c4fde5586d9bad9531f076db9c0c |
train | Tone.from_note | Construct a :class:`Tone` from a musical note which must consist of
a capital letter A through G, followed by an optional semi-tone
modifier ("b" for flat, "#" for sharp, or their Unicode equivalents),
followed by an octave number (0 through 9).
For example `concert A`_, the typical tun... | gpiozero/tones.py | def from_note(cls, note):
"""
Construct a :class:`Tone` from a musical note which must consist of
a capital letter A through G, followed by an optional semi-tone
modifier ("b" for flat, "#" for sharp, or their Unicode equivalents),
followed by an octave number (0 through 9).
... | def from_note(cls, note):
"""
Construct a :class:`Tone` from a musical note which must consist of
a capital letter A through G, followed by an optional semi-tone
modifier ("b" for flat, "#" for sharp, or their Unicode equivalents),
followed by an octave number (0 through 9).
... | [
"Construct",
"a",
":",
"class",
":",
"Tone",
"from",
"a",
"musical",
"note",
"which",
"must",
"consist",
"of",
"a",
"capital",
"letter",
"A",
"through",
"G",
"followed",
"by",
"an",
"optional",
"semi",
"-",
"tone",
"modifier",
"(",
"b",
"for",
"flat",
... | RPi-Distro/python-gpiozero | python | https://github.com/RPi-Distro/python-gpiozero/blob/7b67374fd0c8c4fde5586d9bad9531f076db9c0c/gpiozero/tones.py#L183-L205 | [
"def",
"from_note",
"(",
"cls",
",",
"note",
")",
":",
"if",
"isinstance",
"(",
"note",
",",
"bytes",
")",
":",
"note",
"=",
"note",
".",
"decode",
"(",
"'ascii'",
")",
"if",
"isinstance",
"(",
"note",
",",
"str",
")",
":",
"match",
"=",
"Tone",
... | 7b67374fd0c8c4fde5586d9bad9531f076db9c0c |
train | Tone.from_frequency | Construct a :class:`Tone` from a frequency specified in `Hz`_ which
must be a positive floating-point value in the range 0 < freq <= 20000.
.. _Hz: https://en.wikipedia.org/wiki/Hertz | gpiozero/tones.py | def from_frequency(cls, freq):
"""
Construct a :class:`Tone` from a frequency specified in `Hz`_ which
must be a positive floating-point value in the range 0 < freq <= 20000.
.. _Hz: https://en.wikipedia.org/wiki/Hertz
"""
if 0 < freq <= 20000:
return super(T... | def from_frequency(cls, freq):
"""
Construct a :class:`Tone` from a frequency specified in `Hz`_ which
must be a positive floating-point value in the range 0 < freq <= 20000.
.. _Hz: https://en.wikipedia.org/wiki/Hertz
"""
if 0 < freq <= 20000:
return super(T... | [
"Construct",
"a",
":",
"class",
":",
"Tone",
"from",
"a",
"frequency",
"specified",
"in",
"Hz",
"_",
"which",
"must",
"be",
"a",
"positive",
"floating",
"-",
"point",
"value",
"in",
"the",
"range",
"0",
"<",
"freq",
"<",
"=",
"20000",
"."
] | RPi-Distro/python-gpiozero | python | https://github.com/RPi-Distro/python-gpiozero/blob/7b67374fd0c8c4fde5586d9bad9531f076db9c0c/gpiozero/tones.py#L208-L217 | [
"def",
"from_frequency",
"(",
"cls",
",",
"freq",
")",
":",
"if",
"0",
"<",
"freq",
"<=",
"20000",
":",
"return",
"super",
"(",
"Tone",
",",
"cls",
")",
".",
"__new__",
"(",
"cls",
",",
"freq",
")",
"raise",
"ValueError",
"(",
"'invalid frequency: %.2f... | 7b67374fd0c8c4fde5586d9bad9531f076db9c0c |
train | Tone.midi | Return the (nearest) MIDI note to the tone's frequency. This will be an
integer number in the range 0 to 127. If the frequency is outside the
range represented by MIDI notes (which is approximately 8Hz to 12.5KHz)
:exc:`ValueError` exception will be raised. | gpiozero/tones.py | def midi(self):
"""
Return the (nearest) MIDI note to the tone's frequency. This will be an
integer number in the range 0 to 127. If the frequency is outside the
range represented by MIDI notes (which is approximately 8Hz to 12.5KHz)
:exc:`ValueError` exception will be raised.
... | def midi(self):
"""
Return the (nearest) MIDI note to the tone's frequency. This will be an
integer number in the range 0 to 127. If the frequency is outside the
range represented by MIDI notes (which is approximately 8Hz to 12.5KHz)
:exc:`ValueError` exception will be raised.
... | [
"Return",
"the",
"(",
"nearest",
")",
"MIDI",
"note",
"to",
"the",
"tone",
"s",
"frequency",
".",
"This",
"will",
"be",
"an",
"integer",
"number",
"in",
"the",
"range",
"0",
"to",
"127",
".",
"If",
"the",
"frequency",
"is",
"outside",
"the",
"range",
... | RPi-Distro/python-gpiozero | python | https://github.com/RPi-Distro/python-gpiozero/blob/7b67374fd0c8c4fde5586d9bad9531f076db9c0c/gpiozero/tones.py#L229-L239 | [
"def",
"midi",
"(",
"self",
")",
":",
"result",
"=",
"int",
"(",
"round",
"(",
"12",
"*",
"log2",
"(",
"self",
".",
"frequency",
"/",
"440",
")",
"+",
"69",
")",
")",
"if",
"0",
"<=",
"result",
"<",
"128",
":",
"return",
"result",
"raise",
"Val... | 7b67374fd0c8c4fde5586d9bad9531f076db9c0c |
train | Tone.note | Return the (nearest) note to the tone's frequency. This will be a
string in the form accepted by :meth:`from_note`. If the frequency is
outside the range represented by this format ("A0" is approximately
27.5Hz, and "G9" is approximately 12.5Khz) a :exc:`ValueError`
exception will be rai... | gpiozero/tones.py | def note(self):
"""
Return the (nearest) note to the tone's frequency. This will be a
string in the form accepted by :meth:`from_note`. If the frequency is
outside the range represented by this format ("A0" is approximately
27.5Hz, and "G9" is approximately 12.5Khz) a :exc:`Value... | def note(self):
"""
Return the (nearest) note to the tone's frequency. This will be a
string in the form accepted by :meth:`from_note`. If the frequency is
outside the range represented by this format ("A0" is approximately
27.5Hz, and "G9" is approximately 12.5Khz) a :exc:`Value... | [
"Return",
"the",
"(",
"nearest",
")",
"note",
"to",
"the",
"tone",
"s",
"frequency",
".",
"This",
"will",
"be",
"a",
"string",
"in",
"the",
"form",
"accepted",
"by",
":",
"meth",
":",
"from_note",
".",
"If",
"the",
"frequency",
"is",
"outside",
"the",
... | RPi-Distro/python-gpiozero | python | https://github.com/RPi-Distro/python-gpiozero/blob/7b67374fd0c8c4fde5586d9bad9531f076db9c0c/gpiozero/tones.py#L242-L259 | [
"def",
"note",
"(",
"self",
")",
":",
"offset",
"=",
"self",
".",
"midi",
"-",
"60",
"# self.midi - A4_midi + Tone.tones.index('A')",
"index",
"=",
"offset",
"%",
"12",
"# offset % len(Tone.tones)",
"octave",
"=",
"4",
"+",
"offset",
"//",
"12",
"if",
"0",
"... | 7b67374fd0c8c4fde5586d9bad9531f076db9c0c |
train | EventsMixin.active_time | The length of time (in seconds) that the device has been active for.
When the device is inactive, this is :data:`None`. | gpiozero/mixins.py | def active_time(self):
"""
The length of time (in seconds) that the device has been active for.
When the device is inactive, this is :data:`None`.
"""
if self._active_event.is_set():
return self.pin_factory.ticks_diff(self.pin_factory.ticks(),
... | def active_time(self):
"""
The length of time (in seconds) that the device has been active for.
When the device is inactive, this is :data:`None`.
"""
if self._active_event.is_set():
return self.pin_factory.ticks_diff(self.pin_factory.ticks(),
... | [
"The",
"length",
"of",
"time",
"(",
"in",
"seconds",
")",
"that",
"the",
"device",
"has",
"been",
"active",
"for",
".",
"When",
"the",
"device",
"is",
"inactive",
"this",
"is",
":",
"data",
":",
"None",
"."
] | RPi-Distro/python-gpiozero | python | https://github.com/RPi-Distro/python-gpiozero/blob/7b67374fd0c8c4fde5586d9bad9531f076db9c0c/gpiozero/mixins.py#L276-L285 | [
"def",
"active_time",
"(",
"self",
")",
":",
"if",
"self",
".",
"_active_event",
".",
"is_set",
"(",
")",
":",
"return",
"self",
".",
"pin_factory",
".",
"ticks_diff",
"(",
"self",
".",
"pin_factory",
".",
"ticks",
"(",
")",
",",
"self",
".",
"_last_ch... | 7b67374fd0c8c4fde5586d9bad9531f076db9c0c |
train | EventsMixin.inactive_time | The length of time (in seconds) that the device has been inactive for.
When the device is active, this is :data:`None`. | gpiozero/mixins.py | def inactive_time(self):
"""
The length of time (in seconds) that the device has been inactive for.
When the device is active, this is :data:`None`.
"""
if self._inactive_event.is_set():
return self.pin_factory.ticks_diff(self.pin_factory.ticks(),
... | def inactive_time(self):
"""
The length of time (in seconds) that the device has been inactive for.
When the device is active, this is :data:`None`.
"""
if self._inactive_event.is_set():
return self.pin_factory.ticks_diff(self.pin_factory.ticks(),
... | [
"The",
"length",
"of",
"time",
"(",
"in",
"seconds",
")",
"that",
"the",
"device",
"has",
"been",
"inactive",
"for",
".",
"When",
"the",
"device",
"is",
"active",
"this",
"is",
":",
"data",
":",
"None",
"."
] | RPi-Distro/python-gpiozero | python | https://github.com/RPi-Distro/python-gpiozero/blob/7b67374fd0c8c4fde5586d9bad9531f076db9c0c/gpiozero/mixins.py#L288-L297 | [
"def",
"inactive_time",
"(",
"self",
")",
":",
"if",
"self",
".",
"_inactive_event",
".",
"is_set",
"(",
")",
":",
"return",
"self",
".",
"pin_factory",
".",
"ticks_diff",
"(",
"self",
".",
"pin_factory",
".",
"ticks",
"(",
")",
",",
"self",
".",
"_las... | 7b67374fd0c8c4fde5586d9bad9531f076db9c0c |
train | HoldMixin.held_time | The length of time (in seconds) that the device has been held for.
This is counted from the first execution of the :attr:`when_held` event
rather than when the device activated, in contrast to
:attr:`~EventsMixin.active_time`. If the device is not currently held,
this is :data:`None`. | gpiozero/mixins.py | def held_time(self):
"""
The length of time (in seconds) that the device has been held for.
This is counted from the first execution of the :attr:`when_held` event
rather than when the device activated, in contrast to
:attr:`~EventsMixin.active_time`. If the device is not current... | def held_time(self):
"""
The length of time (in seconds) that the device has been held for.
This is counted from the first execution of the :attr:`when_held` event
rather than when the device activated, in contrast to
:attr:`~EventsMixin.active_time`. If the device is not current... | [
"The",
"length",
"of",
"time",
"(",
"in",
"seconds",
")",
"that",
"the",
"device",
"has",
"been",
"held",
"for",
".",
"This",
"is",
"counted",
"from",
"the",
"first",
"execution",
"of",
"the",
":",
"attr",
":",
"when_held",
"event",
"rather",
"than",
"... | RPi-Distro/python-gpiozero | python | https://github.com/RPi-Distro/python-gpiozero/blob/7b67374fd0c8c4fde5586d9bad9531f076db9c0c/gpiozero/mixins.py#L465-L477 | [
"def",
"held_time",
"(",
"self",
")",
":",
"if",
"self",
".",
"_held_from",
"is",
"not",
"None",
":",
"return",
"self",
".",
"pin_factory",
".",
"ticks_diff",
"(",
"self",
".",
"pin_factory",
".",
"ticks",
"(",
")",
",",
"self",
".",
"_held_from",
")",... | 7b67374fd0c8c4fde5586d9bad9531f076db9c0c |
train | LocalPiPin._call_when_changed | Overridden to provide default ticks from the local Pi factory.
.. warning::
The local pin factory uses a seconds-based monotonic value for
its ticks but you *must not* rely upon this behaviour. Ticks are
an opaque value that should only be compared with the associated
... | gpiozero/pins/local.py | def _call_when_changed(self, ticks=None, state=None):
"""
Overridden to provide default ticks from the local Pi factory.
.. warning::
The local pin factory uses a seconds-based monotonic value for
its ticks but you *must not* rely upon this behaviour. Ticks are
... | def _call_when_changed(self, ticks=None, state=None):
"""
Overridden to provide default ticks from the local Pi factory.
.. warning::
The local pin factory uses a seconds-based monotonic value for
its ticks but you *must not* rely upon this behaviour. Ticks are
... | [
"Overridden",
"to",
"provide",
"default",
"ticks",
"from",
"the",
"local",
"Pi",
"factory",
"."
] | RPi-Distro/python-gpiozero | python | https://github.com/RPi-Distro/python-gpiozero/blob/7b67374fd0c8c4fde5586d9bad9531f076db9c0c/gpiozero/pins/local.py#L128-L141 | [
"def",
"_call_when_changed",
"(",
"self",
",",
"ticks",
"=",
"None",
",",
"state",
"=",
"None",
")",
":",
"super",
"(",
"LocalPiPin",
",",
"self",
")",
".",
"_call_when_changed",
"(",
"self",
".",
"_factory",
".",
"ticks",
"(",
")",
"if",
"ticks",
"is"... | 7b67374fd0c8c4fde5586d9bad9531f076db9c0c |
train | VGGFace | Instantiates the VGGFace architectures.
Optionally loads weights pre-trained
on VGGFace datasets. Note that when using TensorFlow,
for best performance you should set
`image_data_format="channels_last"` in your Keras config
at ~/.keras/keras.json.
The model and the weights are compatible with bo... | keras_vggface/vggface.py | def VGGFace(include_top=True, model='vgg16', weights='vggface',
input_tensor=None, input_shape=None,
pooling=None,
classes=None):
"""Instantiates the VGGFace architectures.
Optionally loads weights pre-trained
on VGGFace datasets. Note that when using TensorFlow,
for ... | def VGGFace(include_top=True, model='vgg16', weights='vggface',
input_tensor=None, input_shape=None,
pooling=None,
classes=None):
"""Instantiates the VGGFace architectures.
Optionally loads weights pre-trained
on VGGFace datasets. Note that when using TensorFlow,
for ... | [
"Instantiates",
"the",
"VGGFace",
"architectures",
".",
"Optionally",
"loads",
"weights",
"pre",
"-",
"trained",
"on",
"VGGFace",
"datasets",
".",
"Note",
"that",
"when",
"using",
"TensorFlow",
"for",
"best",
"performance",
"you",
"should",
"set",
"image_data_form... | rcmalli/keras-vggface | python | https://github.com/rcmalli/keras-vggface/blob/60948a504bfd5dd74c98dce14889f0c5087c8500/keras_vggface/vggface.py#L12-L112 | [
"def",
"VGGFace",
"(",
"include_top",
"=",
"True",
",",
"model",
"=",
"'vgg16'",
",",
"weights",
"=",
"'vggface'",
",",
"input_tensor",
"=",
"None",
",",
"input_shape",
"=",
"None",
",",
"pooling",
"=",
"None",
",",
"classes",
"=",
"None",
")",
":",
"i... | 60948a504bfd5dd74c98dce14889f0c5087c8500 |
train | set_default_proxy | set_default_proxy(proxy_type, addr[, port[, rdns[, username, password]]])
Sets a default proxy which all further socksocket objects will use,
unless explicitly changed. All parameters are as for socket.set_proxy(). | genpac/pysocks/socks.py | def set_default_proxy(proxy_type=None, addr=None, port=None, rdns=True, username=None, password=None):
"""
set_default_proxy(proxy_type, addr[, port[, rdns[, username, password]]])
Sets a default proxy which all further socksocket objects will use,
unless explicitly changed. All parameters are as for s... | def set_default_proxy(proxy_type=None, addr=None, port=None, rdns=True, username=None, password=None):
"""
set_default_proxy(proxy_type, addr[, port[, rdns[, username, password]]])
Sets a default proxy which all further socksocket objects will use,
unless explicitly changed. All parameters are as for s... | [
"set_default_proxy",
"(",
"proxy_type",
"addr",
"[",
"port",
"[",
"rdns",
"[",
"username",
"password",
"]]]",
")"
] | JinnLynn/genpac | python | https://github.com/JinnLynn/genpac/blob/2f466d28f403a9a5624e02edcd538475fe475fc8/genpac/pysocks/socks.py#L146-L155 | [
"def",
"set_default_proxy",
"(",
"proxy_type",
"=",
"None",
",",
"addr",
"=",
"None",
",",
"port",
"=",
"None",
",",
"rdns",
"=",
"True",
",",
"username",
"=",
"None",
",",
"password",
"=",
"None",
")",
":",
"socksocket",
".",
"default_proxy",
"=",
"("... | 2f466d28f403a9a5624e02edcd538475fe475fc8 |
train | create_connection | create_connection(dest_pair, *[, timeout], **proxy_args) -> socket object
Like socket.create_connection(), but connects to proxy
before returning the socket object.
dest_pair - 2-tuple of (IP/hostname, port).
**proxy_args - Same args passed to socksocket.set_proxy() if present.
timeout - Optional ... | genpac/pysocks/socks.py | def create_connection(dest_pair, proxy_type=None, proxy_addr=None,
proxy_port=None, proxy_rdns=True,
proxy_username=None, proxy_password=None,
timeout=None, source_address=None,
socket_options=None):
"""create_connection(dest_pa... | def create_connection(dest_pair, proxy_type=None, proxy_addr=None,
proxy_port=None, proxy_rdns=True,
proxy_username=None, proxy_password=None,
timeout=None, source_address=None,
socket_options=None):
"""create_connection(dest_pa... | [
"create_connection",
"(",
"dest_pair",
"*",
"[",
"timeout",
"]",
"**",
"proxy_args",
")",
"-",
">",
"socket",
"object"
] | JinnLynn/genpac | python | https://github.com/JinnLynn/genpac/blob/2f466d28f403a9a5624e02edcd538475fe475fc8/genpac/pysocks/socks.py#L184-L241 | [
"def",
"create_connection",
"(",
"dest_pair",
",",
"proxy_type",
"=",
"None",
",",
"proxy_addr",
"=",
"None",
",",
"proxy_port",
"=",
"None",
",",
"proxy_rdns",
"=",
"True",
",",
"proxy_username",
"=",
"None",
",",
"proxy_password",
"=",
"None",
",",
"timeou... | 2f466d28f403a9a5624e02edcd538475fe475fc8 |
train | socksocket._readall | Receive EXACTLY the number of bytes requested from the file object.
Blocks until the required number of bytes have been received. | genpac/pysocks/socks.py | def _readall(self, file, count):
"""
Receive EXACTLY the number of bytes requested from the file object.
Blocks until the required number of bytes have been received.
"""
data = b""
while len(data) < count:
d = file.read(count - len(data))
if not d... | def _readall(self, file, count):
"""
Receive EXACTLY the number of bytes requested from the file object.
Blocks until the required number of bytes have been received.
"""
data = b""
while len(data) < count:
d = file.read(count - len(data))
if not d... | [
"Receive",
"EXACTLY",
"the",
"number",
"of",
"bytes",
"requested",
"from",
"the",
"file",
"object",
".",
"Blocks",
"until",
"the",
"required",
"number",
"of",
"bytes",
"have",
"been",
"received",
"."
] | JinnLynn/genpac | python | https://github.com/JinnLynn/genpac/blob/2f466d28f403a9a5624e02edcd538475fe475fc8/genpac/pysocks/socks.py#L297-L308 | [
"def",
"_readall",
"(",
"self",
",",
"file",
",",
"count",
")",
":",
"data",
"=",
"b\"\"",
"while",
"len",
"(",
"data",
")",
"<",
"count",
":",
"d",
"=",
"file",
".",
"read",
"(",
"count",
"-",
"len",
"(",
"data",
")",
")",
"if",
"not",
"d",
... | 2f466d28f403a9a5624e02edcd538475fe475fc8 |
train | socksocket.set_proxy | set_proxy(proxy_type, addr[, port[, rdns[, username[, password]]]])
Sets the proxy to be used.
proxy_type - The type of the proxy to be used. Three types
are supported: PROXY_TYPE_SOCKS4 (including socks4a),
PROXY_TYPE_SOCKS5 and PROXY_TYPE_HTTP
... | genpac/pysocks/socks.py | def set_proxy(self, proxy_type=None, addr=None, port=None, rdns=True, username=None, password=None):
"""set_proxy(proxy_type, addr[, port[, rdns[, username[, password]]]])
Sets the proxy to be used.
proxy_type - The type of the proxy to be used. Three types
are suppor... | def set_proxy(self, proxy_type=None, addr=None, port=None, rdns=True, username=None, password=None):
"""set_proxy(proxy_type, addr[, port[, rdns[, username[, password]]]])
Sets the proxy to be used.
proxy_type - The type of the proxy to be used. Three types
are suppor... | [
"set_proxy",
"(",
"proxy_type",
"addr",
"[",
"port",
"[",
"rdns",
"[",
"username",
"[",
"password",
"]]]]",
")",
"Sets",
"the",
"proxy",
"to",
"be",
"used",
"."
] | JinnLynn/genpac | python | https://github.com/JinnLynn/genpac/blob/2f466d28f403a9a5624e02edcd538475fe475fc8/genpac/pysocks/socks.py#L328-L348 | [
"def",
"set_proxy",
"(",
"self",
",",
"proxy_type",
"=",
"None",
",",
"addr",
"=",
"None",
",",
"port",
"=",
"None",
",",
"rdns",
"=",
"True",
",",
"username",
"=",
"None",
",",
"password",
"=",
"None",
")",
":",
"self",
".",
"proxy",
"=",
"(",
"... | 2f466d28f403a9a5624e02edcd538475fe475fc8 |
train | socksocket.bind | Implements proxy connection for UDP sockets,
which happens during the bind() phase. | genpac/pysocks/socks.py | def bind(self, *pos, **kw):
"""
Implements proxy connection for UDP sockets,
which happens during the bind() phase.
"""
proxy_type, proxy_addr, proxy_port, rdns, username, password = self.proxy
if not proxy_type or self.type != socket.SOCK_DGRAM:
return _orig_... | def bind(self, *pos, **kw):
"""
Implements proxy connection for UDP sockets,
which happens during the bind() phase.
"""
proxy_type, proxy_addr, proxy_port, rdns, username, password = self.proxy
if not proxy_type or self.type != socket.SOCK_DGRAM:
return _orig_... | [
"Implements",
"proxy",
"connection",
"for",
"UDP",
"sockets",
"which",
"happens",
"during",
"the",
"bind",
"()",
"phase",
"."
] | JinnLynn/genpac | python | https://github.com/JinnLynn/genpac/blob/2f466d28f403a9a5624e02edcd538475fe475fc8/genpac/pysocks/socks.py#L355-L390 | [
"def",
"bind",
"(",
"self",
",",
"*",
"pos",
",",
"*",
"*",
"kw",
")",
":",
"proxy_type",
",",
"proxy_addr",
",",
"proxy_port",
",",
"rdns",
",",
"username",
",",
"password",
"=",
"self",
".",
"proxy",
"if",
"not",
"proxy_type",
"or",
"self",
".",
... | 2f466d28f403a9a5624e02edcd538475fe475fc8 |
train | socksocket._negotiate_SOCKS5 | Negotiates a stream connection through a SOCKS5 server. | genpac/pysocks/socks.py | def _negotiate_SOCKS5(self, *dest_addr):
"""
Negotiates a stream connection through a SOCKS5 server.
"""
CONNECT = b"\x01"
self.proxy_peername, self.proxy_sockname = self._SOCKS5_request(self,
CONNECT, dest_addr) | def _negotiate_SOCKS5(self, *dest_addr):
"""
Negotiates a stream connection through a SOCKS5 server.
"""
CONNECT = b"\x01"
self.proxy_peername, self.proxy_sockname = self._SOCKS5_request(self,
CONNECT, dest_addr) | [
"Negotiates",
"a",
"stream",
"connection",
"through",
"a",
"SOCKS5",
"server",
"."
] | JinnLynn/genpac | python | https://github.com/JinnLynn/genpac/blob/2f466d28f403a9a5624e02edcd538475fe475fc8/genpac/pysocks/socks.py#L471-L477 | [
"def",
"_negotiate_SOCKS5",
"(",
"self",
",",
"*",
"dest_addr",
")",
":",
"CONNECT",
"=",
"b\"\\x01\"",
"self",
".",
"proxy_peername",
",",
"self",
".",
"proxy_sockname",
"=",
"self",
".",
"_SOCKS5_request",
"(",
"self",
",",
"CONNECT",
",",
"dest_addr",
")"... | 2f466d28f403a9a5624e02edcd538475fe475fc8 |
train | socksocket._SOCKS5_request | Send SOCKS5 request with given command (CMD field) and
address (DST field). Returns resolved DST address that was used. | genpac/pysocks/socks.py | def _SOCKS5_request(self, conn, cmd, dst):
"""
Send SOCKS5 request with given command (CMD field) and
address (DST field). Returns resolved DST address that was used.
"""
proxy_type, addr, port, rdns, username, password = self.proxy
writer = conn.makefile("wb")
r... | def _SOCKS5_request(self, conn, cmd, dst):
"""
Send SOCKS5 request with given command (CMD field) and
address (DST field). Returns resolved DST address that was used.
"""
proxy_type, addr, port, rdns, username, password = self.proxy
writer = conn.makefile("wb")
r... | [
"Send",
"SOCKS5",
"request",
"with",
"given",
"command",
"(",
"CMD",
"field",
")",
"and",
"address",
"(",
"DST",
"field",
")",
".",
"Returns",
"resolved",
"DST",
"address",
"that",
"was",
"used",
"."
] | JinnLynn/genpac | python | https://github.com/JinnLynn/genpac/blob/2f466d28f403a9a5624e02edcd538475fe475fc8/genpac/pysocks/socks.py#L479-L561 | [
"def",
"_SOCKS5_request",
"(",
"self",
",",
"conn",
",",
"cmd",
",",
"dst",
")",
":",
"proxy_type",
",",
"addr",
",",
"port",
",",
"rdns",
",",
"username",
",",
"password",
"=",
"self",
".",
"proxy",
"writer",
"=",
"conn",
".",
"makefile",
"(",
"\"wb... | 2f466d28f403a9a5624e02edcd538475fe475fc8 |
train | socksocket._write_SOCKS5_address | Return the host and port packed for the SOCKS5 protocol,
and the resolved address as a tuple object. | genpac/pysocks/socks.py | def _write_SOCKS5_address(self, addr, file):
"""
Return the host and port packed for the SOCKS5 protocol,
and the resolved address as a tuple object.
"""
host, port = addr
proxy_type, _, _, rdns, username, password = self.proxy
family_to_byte = {socket.AF_INET: b"... | def _write_SOCKS5_address(self, addr, file):
"""
Return the host and port packed for the SOCKS5 protocol,
and the resolved address as a tuple object.
"""
host, port = addr
proxy_type, _, _, rdns, username, password = self.proxy
family_to_byte = {socket.AF_INET: b"... | [
"Return",
"the",
"host",
"and",
"port",
"packed",
"for",
"the",
"SOCKS5",
"protocol",
"and",
"the",
"resolved",
"address",
"as",
"a",
"tuple",
"object",
"."
] | JinnLynn/genpac | python | https://github.com/JinnLynn/genpac/blob/2f466d28f403a9a5624e02edcd538475fe475fc8/genpac/pysocks/socks.py#L563-L603 | [
"def",
"_write_SOCKS5_address",
"(",
"self",
",",
"addr",
",",
"file",
")",
":",
"host",
",",
"port",
"=",
"addr",
"proxy_type",
",",
"_",
",",
"_",
",",
"rdns",
",",
"username",
",",
"password",
"=",
"self",
".",
"proxy",
"family_to_byte",
"=",
"{",
... | 2f466d28f403a9a5624e02edcd538475fe475fc8 |
train | socksocket._negotiate_SOCKS4 | Negotiates a connection through a SOCKS4 server. | genpac/pysocks/socks.py | def _negotiate_SOCKS4(self, dest_addr, dest_port):
"""
Negotiates a connection through a SOCKS4 server.
"""
proxy_type, addr, port, rdns, username, password = self.proxy
writer = self.makefile("wb")
reader = self.makefile("rb", 0) # buffering=0 renamed in Python 3
... | def _negotiate_SOCKS4(self, dest_addr, dest_port):
"""
Negotiates a connection through a SOCKS4 server.
"""
proxy_type, addr, port, rdns, username, password = self.proxy
writer = self.makefile("wb")
reader = self.makefile("rb", 0) # buffering=0 renamed in Python 3
... | [
"Negotiates",
"a",
"connection",
"through",
"a",
"SOCKS4",
"server",
"."
] | JinnLynn/genpac | python | https://github.com/JinnLynn/genpac/blob/2f466d28f403a9a5624e02edcd538475fe475fc8/genpac/pysocks/socks.py#L620-L677 | [
"def",
"_negotiate_SOCKS4",
"(",
"self",
",",
"dest_addr",
",",
"dest_port",
")",
":",
"proxy_type",
",",
"addr",
",",
"port",
",",
"rdns",
",",
"username",
",",
"password",
"=",
"self",
".",
"proxy",
"writer",
"=",
"self",
".",
"makefile",
"(",
"\"wb\""... | 2f466d28f403a9a5624e02edcd538475fe475fc8 |
train | socksocket._negotiate_HTTP | Negotiates a connection through an HTTP server.
NOTE: This currently only supports HTTP CONNECT-style proxies. | genpac/pysocks/socks.py | def _negotiate_HTTP(self, dest_addr, dest_port):
"""
Negotiates a connection through an HTTP server.
NOTE: This currently only supports HTTP CONNECT-style proxies.
"""
proxy_type, addr, port, rdns, username, password = self.proxy
# If we need to resolve locally, we do th... | def _negotiate_HTTP(self, dest_addr, dest_port):
"""
Negotiates a connection through an HTTP server.
NOTE: This currently only supports HTTP CONNECT-style proxies.
"""
proxy_type, addr, port, rdns, username, password = self.proxy
# If we need to resolve locally, we do th... | [
"Negotiates",
"a",
"connection",
"through",
"an",
"HTTP",
"server",
".",
"NOTE",
":",
"This",
"currently",
"only",
"supports",
"HTTP",
"CONNECT",
"-",
"style",
"proxies",
"."
] | JinnLynn/genpac | python | https://github.com/JinnLynn/genpac/blob/2f466d28f403a9a5624e02edcd538475fe475fc8/genpac/pysocks/socks.py#L679-L731 | [
"def",
"_negotiate_HTTP",
"(",
"self",
",",
"dest_addr",
",",
"dest_port",
")",
":",
"proxy_type",
",",
"addr",
",",
"port",
",",
"rdns",
",",
"username",
",",
"password",
"=",
"self",
".",
"proxy",
"# If we need to resolve locally, we do this now",
"addr",
"=",... | 2f466d28f403a9a5624e02edcd538475fe475fc8 |
train | socksocket.connect | Connects to the specified destination through a proxy.
Uses the same API as socket's connect().
To select the proxy server, use set_proxy().
dest_pair - 2-tuple of (IP/hostname, port). | genpac/pysocks/socks.py | def connect(self, dest_pair):
"""
Connects to the specified destination through a proxy.
Uses the same API as socket's connect().
To select the proxy server, use set_proxy().
dest_pair - 2-tuple of (IP/hostname, port).
"""
if len(dest_pair) != 2 or dest_pair[0].s... | def connect(self, dest_pair):
"""
Connects to the specified destination through a proxy.
Uses the same API as socket's connect().
To select the proxy server, use set_proxy().
dest_pair - 2-tuple of (IP/hostname, port).
"""
if len(dest_pair) != 2 or dest_pair[0].s... | [
"Connects",
"to",
"the",
"specified",
"destination",
"through",
"a",
"proxy",
".",
"Uses",
"the",
"same",
"API",
"as",
"socket",
"s",
"connect",
"()",
".",
"To",
"select",
"the",
"proxy",
"server",
"use",
"set_proxy",
"()",
"."
] | JinnLynn/genpac | python | https://github.com/JinnLynn/genpac/blob/2f466d28f403a9a5624e02edcd538475fe475fc8/genpac/pysocks/socks.py#L740-L821 | [
"def",
"connect",
"(",
"self",
",",
"dest_pair",
")",
":",
"if",
"len",
"(",
"dest_pair",
")",
"!=",
"2",
"or",
"dest_pair",
"[",
"0",
"]",
".",
"startswith",
"(",
"\"[\"",
")",
":",
"# Probably IPv6, not supported -- raise an error, and hope",
"# Happy Eyeballs... | 2f466d28f403a9a5624e02edcd538475fe475fc8 |
train | socksocket._proxy_addr | Return proxy address to connect to as tuple object | genpac/pysocks/socks.py | def _proxy_addr(self):
"""
Return proxy address to connect to as tuple object
"""
proxy_type, proxy_addr, proxy_port, rdns, username, password = self.proxy
proxy_port = proxy_port or DEFAULT_PORTS.get(proxy_type)
if not proxy_port:
raise GeneralProxyError("Inv... | def _proxy_addr(self):
"""
Return proxy address to connect to as tuple object
"""
proxy_type, proxy_addr, proxy_port, rdns, username, password = self.proxy
proxy_port = proxy_port or DEFAULT_PORTS.get(proxy_type)
if not proxy_port:
raise GeneralProxyError("Inv... | [
"Return",
"proxy",
"address",
"to",
"connect",
"to",
"as",
"tuple",
"object"
] | JinnLynn/genpac | python | https://github.com/JinnLynn/genpac/blob/2f466d28f403a9a5624e02edcd538475fe475fc8/genpac/pysocks/socks.py#L823-L831 | [
"def",
"_proxy_addr",
"(",
"self",
")",
":",
"proxy_type",
",",
"proxy_addr",
",",
"proxy_port",
",",
"rdns",
",",
"username",
",",
"password",
"=",
"self",
".",
"proxy",
"proxy_port",
"=",
"proxy_port",
"or",
"DEFAULT_PORTS",
".",
"get",
"(",
"proxy_type",
... | 2f466d28f403a9a5624e02edcd538475fe475fc8 |
train | PublicSuffixList._parse | PSL parser core | genpac/publicsuffixlist/__init__.py | def _parse(self, source, accept_encoded_idn, only_icann=False):
""" PSL parser core """
publicsuffix = set()
maxlabel = 0
section_is_icann = None
if isinstance(source, decodablestr):
source = source.splitlines()
ln = 0
for line in source:
... | def _parse(self, source, accept_encoded_idn, only_icann=False):
""" PSL parser core """
publicsuffix = set()
maxlabel = 0
section_is_icann = None
if isinstance(source, decodablestr):
source = source.splitlines()
ln = 0
for line in source:
... | [
"PSL",
"parser",
"core"
] | JinnLynn/genpac | python | https://github.com/JinnLynn/genpac/blob/2f466d28f403a9a5624e02edcd538475fe475fc8/genpac/publicsuffixlist/__init__.py#L81-L119 | [
"def",
"_parse",
"(",
"self",
",",
"source",
",",
"accept_encoded_idn",
",",
"only_icann",
"=",
"False",
")",
":",
"publicsuffix",
"=",
"set",
"(",
")",
"maxlabel",
"=",
"0",
"section_is_icann",
"=",
"None",
"if",
"isinstance",
"(",
"source",
",",
"decodab... | 2f466d28f403a9a5624e02edcd538475fe475fc8 |
train | PublicSuffixList.privatesuffix | Return shortest suffix assigned for an individual.
domain: str or unicode to parse. (Required)
accept_unknown: bool, assume unknown TLDs to be public suffix. (Default: object default)
Return None if domain has invalid format.
Return None if domain has no private part. | genpac/publicsuffixlist/__init__.py | def privatesuffix(self, domain, accept_unknown=None):
""" Return shortest suffix assigned for an individual.
domain: str or unicode to parse. (Required)
accept_unknown: bool, assume unknown TLDs to be public suffix. (Default: object default)
Return None if domain has invalid format.
... | def privatesuffix(self, domain, accept_unknown=None):
""" Return shortest suffix assigned for an individual.
domain: str or unicode to parse. (Required)
accept_unknown: bool, assume unknown TLDs to be public suffix. (Default: object default)
Return None if domain has invalid format.
... | [
"Return",
"shortest",
"suffix",
"assigned",
"for",
"an",
"individual",
"."
] | JinnLynn/genpac | python | https://github.com/JinnLynn/genpac/blob/2f466d28f403a9a5624e02edcd538475fe475fc8/genpac/publicsuffixlist/__init__.py#L125-L182 | [
"def",
"privatesuffix",
"(",
"self",
",",
"domain",
",",
"accept_unknown",
"=",
"None",
")",
":",
"if",
"accept_unknown",
"is",
"None",
":",
"accept_unknown",
"=",
"self",
".",
"accept_unknown",
"if",
"not",
"isinstance",
"(",
"domain",
",",
"basestr",
")",
... | 2f466d28f403a9a5624e02edcd538475fe475fc8 |
train | PublicSuffixList.privateparts | Return tuple of labels and the private suffix. | genpac/publicsuffixlist/__init__.py | def privateparts(self, domain):
""" Return tuple of labels and the private suffix. """
s = self.privatesuffix(domain)
if s is None:
return None
else:
# I know the domain is valid and ends with private suffix
pre = domain[0:-(len(s)+1)]
if p... | def privateparts(self, domain):
""" Return tuple of labels and the private suffix. """
s = self.privatesuffix(domain)
if s is None:
return None
else:
# I know the domain is valid and ends with private suffix
pre = domain[0:-(len(s)+1)]
if p... | [
"Return",
"tuple",
"of",
"labels",
"and",
"the",
"private",
"suffix",
"."
] | JinnLynn/genpac | python | https://github.com/JinnLynn/genpac/blob/2f466d28f403a9a5624e02edcd538475fe475fc8/genpac/publicsuffixlist/__init__.py#L249-L260 | [
"def",
"privateparts",
"(",
"self",
",",
"domain",
")",
":",
"s",
"=",
"self",
".",
"privatesuffix",
"(",
"domain",
")",
"if",
"s",
"is",
"None",
":",
"return",
"None",
"else",
":",
"# I know the domain is valid and ends with private suffix",
"pre",
"=",
"doma... | 2f466d28f403a9a5624e02edcd538475fe475fc8 |
train | PublicSuffixList.subdomain | Return so-called subdomain of specified depth in the private suffix. | genpac/publicsuffixlist/__init__.py | def subdomain(self, domain, depth):
""" Return so-called subdomain of specified depth in the private suffix. """
p = self.privateparts(domain)
if p is None or depth > len(p) - 1:
return None
else:
return ".".join(p[-(depth+1):]) | def subdomain(self, domain, depth):
""" Return so-called subdomain of specified depth in the private suffix. """
p = self.privateparts(domain)
if p is None or depth > len(p) - 1:
return None
else:
return ".".join(p[-(depth+1):]) | [
"Return",
"so",
"-",
"called",
"subdomain",
"of",
"specified",
"depth",
"in",
"the",
"private",
"suffix",
"."
] | JinnLynn/genpac | python | https://github.com/JinnLynn/genpac/blob/2f466d28f403a9a5624e02edcd538475fe475fc8/genpac/publicsuffixlist/__init__.py#L262-L268 | [
"def",
"subdomain",
"(",
"self",
",",
"domain",
",",
"depth",
")",
":",
"p",
"=",
"self",
".",
"privateparts",
"(",
"domain",
")",
"if",
"p",
"is",
"None",
"or",
"depth",
">",
"len",
"(",
"p",
")",
"-",
"1",
":",
"return",
"None",
"else",
":",
... | 2f466d28f403a9a5624e02edcd538475fe475fc8 |
train | updatePSL | Updates a local copy of PSL file
:param psl_file: path for the file to store the list. Default: PSLFILE | genpac/publicsuffixlist/update.py | def updatePSL(psl_file=PSLFILE):
""" Updates a local copy of PSL file
:param psl_file: path for the file to store the list. Default: PSLFILE
"""
if requests is None:
raise Exception("Please install python-requests http(s) library. $ sudo pip install requests")
r = requests.get(PSLURL)
... | def updatePSL(psl_file=PSLFILE):
""" Updates a local copy of PSL file
:param psl_file: path for the file to store the list. Default: PSLFILE
"""
if requests is None:
raise Exception("Please install python-requests http(s) library. $ sudo pip install requests")
r = requests.get(PSLURL)
... | [
"Updates",
"a",
"local",
"copy",
"of",
"PSL",
"file"
] | JinnLynn/genpac | python | https://github.com/JinnLynn/genpac/blob/2f466d28f403a9a5624e02edcd538475fe475fc8/genpac/publicsuffixlist/update.py#L22-L50 | [
"def",
"updatePSL",
"(",
"psl_file",
"=",
"PSLFILE",
")",
":",
"if",
"requests",
"is",
"None",
":",
"raise",
"Exception",
"(",
"\"Please install python-requests http(s) library. $ sudo pip install requests\"",
")",
"r",
"=",
"requests",
".",
"get",
"(",
"PSLURL",
")... | 2f466d28f403a9a5624e02edcd538475fe475fc8 |
train | HtmlListFormatter.get_marked_up_list | an updated version of pygments.formatter.format_unencoded | gdbgui/htmllistformatter.py | def get_marked_up_list(self, tokensource):
"""an updated version of pygments.formatter.format_unencoded"""
# import ipdb; ipdb.set_trace()
source = self._format_lines(tokensource)
if self.hl_lines:
source = self._highlight_lines(source)
if not self.nowrap:
... | def get_marked_up_list(self, tokensource):
"""an updated version of pygments.formatter.format_unencoded"""
# import ipdb; ipdb.set_trace()
source = self._format_lines(tokensource)
if self.hl_lines:
source = self._highlight_lines(source)
if not self.nowrap:
... | [
"an",
"updated",
"version",
"of",
"pygments",
".",
"formatter",
".",
"format_unencoded"
] | cs01/gdbgui | python | https://github.com/cs01/gdbgui/blob/5367f87554f8f7c671d1f4596c133bf1303154f0/gdbgui/htmllistformatter.py#L9-L36 | [
"def",
"get_marked_up_list",
"(",
"self",
",",
"tokensource",
")",
":",
"# import ipdb; ipdb.set_trace()",
"source",
"=",
"self",
".",
"_format_lines",
"(",
"tokensource",
")",
"if",
"self",
".",
"hl_lines",
":",
"source",
"=",
"self",
".",
"_highlight_lines",
"... | 5367f87554f8f7c671d1f4596c133bf1303154f0 |
train | get_ssl_context | Get ssl context from private key and certificate paths.
The return value is used when calling Flask.
i.e. app.run(ssl_context=get_ssl_context(,,,)) | gdbgui/SSLify.py | def get_ssl_context(private_key, certificate):
"""Get ssl context from private key and certificate paths.
The return value is used when calling Flask.
i.e. app.run(ssl_context=get_ssl_context(,,,))
"""
if (
certificate
and os.path.isfile(certificate)
and private_key
a... | def get_ssl_context(private_key, certificate):
"""Get ssl context from private key and certificate paths.
The return value is used when calling Flask.
i.e. app.run(ssl_context=get_ssl_context(,,,))
"""
if (
certificate
and os.path.isfile(certificate)
and private_key
a... | [
"Get",
"ssl",
"context",
"from",
"private",
"key",
"and",
"certificate",
"paths",
".",
"The",
"return",
"value",
"is",
"used",
"when",
"calling",
"Flask",
".",
"i",
".",
"e",
".",
"app",
".",
"run",
"(",
"ssl_context",
"=",
"get_ssl_context",
"(",
"))"
] | cs01/gdbgui | python | https://github.com/cs01/gdbgui/blob/5367f87554f8f7c671d1f4596c133bf1303154f0/gdbgui/SSLify.py#L90-L104 | [
"def",
"get_ssl_context",
"(",
"private_key",
",",
"certificate",
")",
":",
"if",
"(",
"certificate",
"and",
"os",
".",
"path",
".",
"isfile",
"(",
"certificate",
")",
"and",
"private_key",
"and",
"os",
".",
"path",
".",
"isfile",
"(",
"private_key",
")",
... | 5367f87554f8f7c671d1f4596c133bf1303154f0 |
train | SSLify.init_app | Configures the specified Flask app to enforce SSL. | gdbgui/SSLify.py | def init_app(self, app):
"""Configures the specified Flask app to enforce SSL."""
app.config.setdefault("SSLIFY_SUBDOMAINS", False)
app.config.setdefault("SSLIFY_PERMANENT", False)
app.config.setdefault("SSLIFY_SKIPS", None)
self.hsts_include_subdomains = (
self.hsts... | def init_app(self, app):
"""Configures the specified Flask app to enforce SSL."""
app.config.setdefault("SSLIFY_SUBDOMAINS", False)
app.config.setdefault("SSLIFY_PERMANENT", False)
app.config.setdefault("SSLIFY_SKIPS", None)
self.hsts_include_subdomains = (
self.hsts... | [
"Configures",
"the",
"specified",
"Flask",
"app",
"to",
"enforce",
"SSL",
"."
] | cs01/gdbgui | python | https://github.com/cs01/gdbgui/blob/5367f87554f8f7c671d1f4596c133bf1303154f0/gdbgui/SSLify.py#L28-L41 | [
"def",
"init_app",
"(",
"self",
",",
"app",
")",
":",
"app",
".",
"config",
".",
"setdefault",
"(",
"\"SSLIFY_SUBDOMAINS\"",
",",
"False",
")",
"app",
".",
"config",
".",
"setdefault",
"(",
"\"SSLIFY_PERMANENT\"",
",",
"False",
")",
"app",
".",
"config",
... | 5367f87554f8f7c671d1f4596c133bf1303154f0 |
train | SSLify.set_hsts_header | Adds HSTS header to each response. | gdbgui/SSLify.py | def set_hsts_header(self, response):
"""Adds HSTS header to each response."""
# Should we add STS header?
if request.is_secure and not self.skip:
response.headers.setdefault("Strict-Transport-Security", self.hsts_header)
return response | def set_hsts_header(self, response):
"""Adds HSTS header to each response."""
# Should we add STS header?
if request.is_secure and not self.skip:
response.headers.setdefault("Strict-Transport-Security", self.hsts_header)
return response | [
"Adds",
"HSTS",
"header",
"to",
"each",
"response",
"."
] | cs01/gdbgui | python | https://github.com/cs01/gdbgui/blob/5367f87554f8f7c671d1f4596c133bf1303154f0/gdbgui/SSLify.py#L82-L87 | [
"def",
"set_hsts_header",
"(",
"self",
",",
"response",
")",
":",
"# Should we add STS header?",
"if",
"request",
".",
"is_secure",
"and",
"not",
"self",
".",
"skip",
":",
"response",
".",
"headers",
".",
"setdefault",
"(",
"\"Strict-Transport-Security\"",
",",
... | 5367f87554f8f7c671d1f4596c133bf1303154f0 |
train | csrf_protect_all_post_and_cross_origin_requests | returns None upon success | gdbgui/backend.py | def csrf_protect_all_post_and_cross_origin_requests():
"""returns None upon success"""
success = None
if is_cross_origin(request):
logger.warning("Received cross origin request. Aborting")
abort(403)
if request.method in ["POST", "PUT"]:
token = session.get("csrf_token")
... | def csrf_protect_all_post_and_cross_origin_requests():
"""returns None upon success"""
success = None
if is_cross_origin(request):
logger.warning("Received cross origin request. Aborting")
abort(403)
if request.method in ["POST", "PUT"]:
token = session.get("csrf_token")
... | [
"returns",
"None",
"upon",
"success"
] | cs01/gdbgui | python | https://github.com/cs01/gdbgui/blob/5367f87554f8f7c671d1f4596c133bf1303154f0/gdbgui/backend.py#L116-L133 | [
"def",
"csrf_protect_all_post_and_cross_origin_requests",
"(",
")",
":",
"success",
"=",
"None",
"if",
"is_cross_origin",
"(",
"request",
")",
":",
"logger",
".",
"warning",
"(",
"\"Received cross origin request. Aborting\"",
")",
"abort",
"(",
"403",
")",
"if",
"re... | 5367f87554f8f7c671d1f4596c133bf1303154f0 |
train | is_cross_origin | Compare headers HOST and ORIGIN. Remove protocol prefix from ORIGIN, then
compare. Return true if they are not equal
example HTTP_HOST: '127.0.0.1:5000'
example HTTP_ORIGIN: 'http://127.0.0.1:5000' | gdbgui/backend.py | def is_cross_origin(request):
"""Compare headers HOST and ORIGIN. Remove protocol prefix from ORIGIN, then
compare. Return true if they are not equal
example HTTP_HOST: '127.0.0.1:5000'
example HTTP_ORIGIN: 'http://127.0.0.1:5000'
"""
origin = request.environ.get("HTTP_ORIGIN")
host = reques... | def is_cross_origin(request):
"""Compare headers HOST and ORIGIN. Remove protocol prefix from ORIGIN, then
compare. Return true if they are not equal
example HTTP_HOST: '127.0.0.1:5000'
example HTTP_ORIGIN: 'http://127.0.0.1:5000'
"""
origin = request.environ.get("HTTP_ORIGIN")
host = reques... | [
"Compare",
"headers",
"HOST",
"and",
"ORIGIN",
".",
"Remove",
"protocol",
"prefix",
"from",
"ORIGIN",
"then",
"compare",
".",
"Return",
"true",
"if",
"they",
"are",
"not",
"equal",
"example",
"HTTP_HOST",
":",
"127",
".",
"0",
".",
"0",
".",
"1",
":",
... | cs01/gdbgui | python | https://github.com/cs01/gdbgui/blob/5367f87554f8f7c671d1f4596c133bf1303154f0/gdbgui/backend.py#L136-L152 | [
"def",
"is_cross_origin",
"(",
"request",
")",
":",
"origin",
"=",
"request",
".",
"environ",
".",
"get",
"(",
"\"HTTP_ORIGIN\"",
")",
"host",
"=",
"request",
".",
"environ",
".",
"get",
"(",
"\"HTTP_HOST\"",
")",
"if",
"origin",
"is",
"None",
":",
"# or... | 5367f87554f8f7c671d1f4596c133bf1303154f0 |
train | csrf_protect | A decorator to add csrf protection by validing the X_CSRFTOKEN
field in request header | gdbgui/backend.py | def csrf_protect(f):
"""A decorator to add csrf protection by validing the X_CSRFTOKEN
field in request header"""
@wraps(f)
def wrapper(*args, **kwargs):
token = session.get("csrf_token", None)
if token is None or token != request.environ.get("HTTP_X_CSRFTOKEN"):
logger.warn... | def csrf_protect(f):
"""A decorator to add csrf protection by validing the X_CSRFTOKEN
field in request header"""
@wraps(f)
def wrapper(*args, **kwargs):
token = session.get("csrf_token", None)
if token is None or token != request.environ.get("HTTP_X_CSRFTOKEN"):
logger.warn... | [
"A",
"decorator",
"to",
"add",
"csrf",
"protection",
"by",
"validing",
"the",
"X_CSRFTOKEN",
"field",
"in",
"request",
"header"
] | cs01/gdbgui | python | https://github.com/cs01/gdbgui/blob/5367f87554f8f7c671d1f4596c133bf1303154f0/gdbgui/backend.py#L155-L168 | [
"def",
"csrf_protect",
"(",
"f",
")",
":",
"@",
"wraps",
"(",
"f",
")",
"def",
"wrapper",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"token",
"=",
"session",
".",
"get",
"(",
"\"csrf_token\"",
",",
"None",
")",
"if",
"token",
"is",
"Non... | 5367f87554f8f7c671d1f4596c133bf1303154f0 |
train | setup_backend | Run the server of the gdb gui | gdbgui/backend.py | def setup_backend(
serve=True,
host=DEFAULT_HOST,
port=DEFAULT_PORT,
debug=False,
open_browser=True,
browsername=None,
testing=False,
private_key=None,
certificate=None,
LLDB=False,
):
"""Run the server of the gdb gui"""
app.config["LLDB"] = LLDB
kwargs = {}
ssl_... | def setup_backend(
serve=True,
host=DEFAULT_HOST,
port=DEFAULT_PORT,
debug=False,
open_browser=True,
browsername=None,
testing=False,
private_key=None,
certificate=None,
LLDB=False,
):
"""Run the server of the gdb gui"""
app.config["LLDB"] = LLDB
kwargs = {}
ssl_... | [
"Run",
"the",
"server",
"of",
"the",
"gdb",
"gui"
] | cs01/gdbgui | python | https://github.com/cs01/gdbgui/blob/5367f87554f8f7c671d1f4596c133bf1303154f0/gdbgui/backend.py#L180-L260 | [
"def",
"setup_backend",
"(",
"serve",
"=",
"True",
",",
"host",
"=",
"DEFAULT_HOST",
",",
"port",
"=",
"DEFAULT_PORT",
",",
"debug",
"=",
"False",
",",
"open_browser",
"=",
"True",
",",
"browsername",
"=",
"None",
",",
"testing",
"=",
"False",
",",
"priv... | 5367f87554f8f7c671d1f4596c133bf1303154f0 |
train | dbprint | print only if app.debug is truthy | gdbgui/backend.py | def dbprint(*args):
"""print only if app.debug is truthy"""
if app and app.debug:
if USING_WINDOWS:
print("DEBUG: " + " ".join(args))
else:
CYELLOW2 = "\33[93m"
NORMAL = "\033[0m"
print(CYELLOW2 + "DEBUG: " + " ".join(args) + NORMAL) | def dbprint(*args):
"""print only if app.debug is truthy"""
if app and app.debug:
if USING_WINDOWS:
print("DEBUG: " + " ".join(args))
else:
CYELLOW2 = "\33[93m"
NORMAL = "\033[0m"
print(CYELLOW2 + "DEBUG: " + " ".join(args) + NORMAL) | [
"print",
"only",
"if",
"app",
".",
"debug",
"is",
"truthy"
] | cs01/gdbgui | python | https://github.com/cs01/gdbgui/blob/5367f87554f8f7c671d1f4596c133bf1303154f0/gdbgui/backend.py#L283-L292 | [
"def",
"dbprint",
"(",
"*",
"args",
")",
":",
"if",
"app",
"and",
"app",
".",
"debug",
":",
"if",
"USING_WINDOWS",
":",
"print",
"(",
"\"DEBUG: \"",
"+",
"\" \"",
".",
"join",
"(",
"args",
")",
")",
"else",
":",
"CYELLOW2",
"=",
"\"\\33[93m\"",
"NORM... | 5367f87554f8f7c671d1f4596c133bf1303154f0 |
train | run_gdb_command | Endpoint for a websocket route.
Runs a gdb command.
Responds only if an error occurs when trying to write the command to
gdb | gdbgui/backend.py | def run_gdb_command(message):
"""
Endpoint for a websocket route.
Runs a gdb command.
Responds only if an error occurs when trying to write the command to
gdb
"""
controller = _state.get_controller_from_client_id(request.sid)
if controller is not None:
try:
# the comm... | def run_gdb_command(message):
"""
Endpoint for a websocket route.
Runs a gdb command.
Responds only if an error occurs when trying to write the command to
gdb
"""
controller = _state.get_controller_from_client_id(request.sid)
if controller is not None:
try:
# the comm... | [
"Endpoint",
"for",
"a",
"websocket",
"route",
".",
"Runs",
"a",
"gdb",
"command",
".",
"Responds",
"only",
"if",
"an",
"error",
"occurs",
"when",
"trying",
"to",
"write",
"the",
"command",
"to",
"gdb"
] | cs01/gdbgui | python | https://github.com/cs01/gdbgui/blob/5367f87554f8f7c671d1f4596c133bf1303154f0/gdbgui/backend.py#L347-L366 | [
"def",
"run_gdb_command",
"(",
"message",
")",
":",
"controller",
"=",
"_state",
".",
"get_controller_from_client_id",
"(",
"request",
".",
"sid",
")",
"if",
"controller",
"is",
"not",
"None",
":",
"try",
":",
"# the command (string) or commands (list) to run",
"cmd... | 5367f87554f8f7c671d1f4596c133bf1303154f0 |
train | send_msg_to_clients | Send message to all clients | gdbgui/backend.py | def send_msg_to_clients(client_ids, msg, error=False):
"""Send message to all clients"""
if error:
stream = "stderr"
else:
stream = "stdout"
response = [{"message": None, "type": "console", "payload": msg, "stream": stream}]
for client_id in client_ids:
logger.info("emiting... | def send_msg_to_clients(client_ids, msg, error=False):
"""Send message to all clients"""
if error:
stream = "stderr"
else:
stream = "stdout"
response = [{"message": None, "type": "console", "payload": msg, "stream": stream}]
for client_id in client_ids:
logger.info("emiting... | [
"Send",
"message",
"to",
"all",
"clients"
] | cs01/gdbgui | python | https://github.com/cs01/gdbgui/blob/5367f87554f8f7c671d1f4596c133bf1303154f0/gdbgui/backend.py#L369-L382 | [
"def",
"send_msg_to_clients",
"(",
"client_ids",
",",
"msg",
",",
"error",
"=",
"False",
")",
":",
"if",
"error",
":",
"stream",
"=",
"\"stderr\"",
"else",
":",
"stream",
"=",
"\"stdout\"",
"response",
"=",
"[",
"{",
"\"message\"",
":",
"None",
",",
"\"t... | 5367f87554f8f7c671d1f4596c133bf1303154f0 |
train | read_and_forward_gdb_output | A task that runs on a different thread, and emits websocket messages
of gdb responses | gdbgui/backend.py | def read_and_forward_gdb_output():
"""A task that runs on a different thread, and emits websocket messages
of gdb responses"""
while True:
socketio.sleep(0.05)
controllers_to_remove = []
controller_items = _state.controller_to_client_ids.items()
for controller, client_ids in... | def read_and_forward_gdb_output():
"""A task that runs on a different thread, and emits websocket messages
of gdb responses"""
while True:
socketio.sleep(0.05)
controllers_to_remove = []
controller_items = _state.controller_to_client_ids.items()
for controller, client_ids in... | [
"A",
"task",
"that",
"runs",
"on",
"a",
"different",
"thread",
"and",
"emits",
"websocket",
"messages",
"of",
"gdb",
"responses"
] | cs01/gdbgui | python | https://github.com/cs01/gdbgui/blob/5367f87554f8f7c671d1f4596c133bf1303154f0/gdbgui/backend.py#L418-L460 | [
"def",
"read_and_forward_gdb_output",
"(",
")",
":",
"while",
"True",
":",
"socketio",
".",
"sleep",
"(",
"0.05",
")",
"controllers_to_remove",
"=",
"[",
"]",
"controller_items",
"=",
"_state",
".",
"controller_to_client_ids",
".",
"items",
"(",
")",
"for",
"c... | 5367f87554f8f7c671d1f4596c133bf1303154f0 |
train | get_extra_files | returns a list of files that should be watched by the Flask server
when in debug mode to trigger a reload of the server | gdbgui/backend.py | def get_extra_files():
"""returns a list of files that should be watched by the Flask server
when in debug mode to trigger a reload of the server
"""
FILES_TO_SKIP = ["src/gdbgui.js"]
THIS_DIR = os.path.dirname(os.path.abspath(__file__))
extra_dirs = [THIS_DIR]
extra_files = []
for extra... | def get_extra_files():
"""returns a list of files that should be watched by the Flask server
when in debug mode to trigger a reload of the server
"""
FILES_TO_SKIP = ["src/gdbgui.js"]
THIS_DIR = os.path.dirname(os.path.abspath(__file__))
extra_dirs = [THIS_DIR]
extra_files = []
for extra... | [
"returns",
"a",
"list",
"of",
"files",
"that",
"should",
"be",
"watched",
"by",
"the",
"Flask",
"server",
"when",
"in",
"debug",
"mode",
"to",
"trigger",
"a",
"reload",
"of",
"the",
"server"
] | cs01/gdbgui | python | https://github.com/cs01/gdbgui/blob/5367f87554f8f7c671d1f4596c133bf1303154f0/gdbgui/backend.py#L471-L487 | [
"def",
"get_extra_files",
"(",
")",
":",
"FILES_TO_SKIP",
"=",
"[",
"\"src/gdbgui.js\"",
"]",
"THIS_DIR",
"=",
"os",
".",
"path",
".",
"dirname",
"(",
"os",
".",
"path",
".",
"abspath",
"(",
"__file__",
")",
")",
"extra_dirs",
"=",
"[",
"THIS_DIR",
"]",
... | 5367f87554f8f7c671d1f4596c133bf1303154f0 |
train | gdbgui | Render the main gdbgui interface | gdbgui/backend.py | def gdbgui():
"""Render the main gdbgui interface"""
interpreter = "lldb" if app.config["LLDB"] else "gdb"
gdbpid = request.args.get("gdbpid", 0)
initial_gdb_user_command = request.args.get("initial_gdb_user_command", "")
add_csrf_token_to_session()
THEMES = ["monokai", "light"]
# fmt: off... | def gdbgui():
"""Render the main gdbgui interface"""
interpreter = "lldb" if app.config["LLDB"] else "gdb"
gdbpid = request.args.get("gdbpid", 0)
initial_gdb_user_command = request.args.get("initial_gdb_user_command", "")
add_csrf_token_to_session()
THEMES = ["monokai", "light"]
# fmt: off... | [
"Render",
"the",
"main",
"gdbgui",
"interface"
] | cs01/gdbgui | python | https://github.com/cs01/gdbgui/blob/5367f87554f8f7c671d1f4596c133bf1303154f0/gdbgui/backend.py#L525-L562 | [
"def",
"gdbgui",
"(",
")",
":",
"interpreter",
"=",
"\"lldb\"",
"if",
"app",
".",
"config",
"[",
"\"LLDB\"",
"]",
"else",
"\"gdb\"",
"gdbpid",
"=",
"request",
".",
"args",
".",
"get",
"(",
"\"gdbpid\"",
",",
"0",
")",
"initial_gdb_user_command",
"=",
"re... | 5367f87554f8f7c671d1f4596c133bf1303154f0 |
train | get_last_modified_unix_sec | Get last modified unix time for a given file | gdbgui/backend.py | def get_last_modified_unix_sec():
"""Get last modified unix time for a given file"""
path = request.args.get("path")
if path and os.path.isfile(path):
try:
last_modified = os.path.getmtime(path)
return jsonify({"path": path, "last_modified_unix_sec": last_modified})
... | def get_last_modified_unix_sec():
"""Get last modified unix time for a given file"""
path = request.args.get("path")
if path and os.path.isfile(path):
try:
last_modified = os.path.getmtime(path)
return jsonify({"path": path, "last_modified_unix_sec": last_modified})
... | [
"Get",
"last",
"modified",
"unix",
"time",
"for",
"a",
"given",
"file"
] | cs01/gdbgui | python | https://github.com/cs01/gdbgui/blob/5367f87554f8f7c671d1f4596c133bf1303154f0/gdbgui/backend.py#L654-L666 | [
"def",
"get_last_modified_unix_sec",
"(",
")",
":",
"path",
"=",
"request",
".",
"args",
".",
"get",
"(",
"\"path\"",
")",
"if",
"path",
"and",
"os",
".",
"path",
".",
"isfile",
"(",
"path",
")",
":",
"try",
":",
"last_modified",
"=",
"os",
".",
"pat... | 5367f87554f8f7c671d1f4596c133bf1303154f0 |
train | read_file | Read a file and return its contents as an array | gdbgui/backend.py | def read_file():
"""Read a file and return its contents as an array"""
path = request.args.get("path")
start_line = int(request.args.get("start_line"))
end_line = int(request.args.get("end_line"))
start_line = max(1, start_line) # make sure it's not negative
try:
highlight = json.load... | def read_file():
"""Read a file and return its contents as an array"""
path = request.args.get("path")
start_line = int(request.args.get("start_line"))
end_line = int(request.args.get("end_line"))
start_line = max(1, start_line) # make sure it's not negative
try:
highlight = json.load... | [
"Read",
"a",
"file",
"and",
"return",
"its",
"contents",
"as",
"an",
"array"
] | cs01/gdbgui | python | https://github.com/cs01/gdbgui/blob/5367f87554f8f7c671d1f4596c133bf1303154f0/gdbgui/backend.py#L671-L743 | [
"def",
"read_file",
"(",
")",
":",
"path",
"=",
"request",
".",
"args",
".",
"get",
"(",
"\"path\"",
")",
"start_line",
"=",
"int",
"(",
"request",
".",
"args",
".",
"get",
"(",
"\"start_line\"",
")",
")",
"end_line",
"=",
"int",
"(",
"request",
".",... | 5367f87554f8f7c671d1f4596c133bf1303154f0 |
train | main | Entry point from command line | gdbgui/backend.py | def main():
"""Entry point from command line"""
parser = get_parser()
args = parser.parse_args()
if args.debug:
logger.setLevel(logging.NOTSET)
initialize_preferences()
if args.version:
print(__version__)
return
cmd = args.cmd or args.args
if args.no_browser ... | def main():
"""Entry point from command line"""
parser = get_parser()
args = parser.parse_args()
if args.debug:
logger.setLevel(logging.NOTSET)
initialize_preferences()
if args.version:
print(__version__)
return
cmd = args.cmd or args.args
if args.no_browser ... | [
"Entry",
"point",
"from",
"command",
"line"
] | cs01/gdbgui | python | https://github.com/cs01/gdbgui/blob/5367f87554f8f7c671d1f4596c133bf1303154f0/gdbgui/backend.py#L927-L997 | [
"def",
"main",
"(",
")",
":",
"parser",
"=",
"get_parser",
"(",
")",
"args",
"=",
"parser",
".",
"parse_args",
"(",
")",
"if",
"args",
".",
"debug",
":",
"logger",
".",
"setLevel",
"(",
"logging",
".",
"NOTSET",
")",
"initialize_preferences",
"(",
")",... | 5367f87554f8f7c671d1f4596c133bf1303154f0 |
train | warn_startup_with_shell_off | return True if user may need to turn shell off
if mac OS version is 16 (sierra) or higher, may need to set shell off due
to os's security requirements
http://stackoverflow.com/questions/39702871/gdb-kind-of-doesnt-work-on-macos-sierra | gdbgui/backend.py | def warn_startup_with_shell_off(platform, gdb_args):
"""return True if user may need to turn shell off
if mac OS version is 16 (sierra) or higher, may need to set shell off due
to os's security requirements
http://stackoverflow.com/questions/39702871/gdb-kind-of-doesnt-work-on-macos-sierra
"""
d... | def warn_startup_with_shell_off(platform, gdb_args):
"""return True if user may need to turn shell off
if mac OS version is 16 (sierra) or higher, may need to set shell off due
to os's security requirements
http://stackoverflow.com/questions/39702871/gdb-kind-of-doesnt-work-on-macos-sierra
"""
d... | [
"return",
"True",
"if",
"user",
"may",
"need",
"to",
"turn",
"shell",
"off",
"if",
"mac",
"OS",
"version",
"is",
"16",
"(",
"sierra",
")",
"or",
"higher",
"may",
"need",
"to",
"set",
"shell",
"off",
"due",
"to",
"os",
"s",
"security",
"requirements",
... | cs01/gdbgui | python | https://github.com/cs01/gdbgui/blob/5367f87554f8f7c671d1f4596c133bf1303154f0/gdbgui/backend.py#L1000-L1011 | [
"def",
"warn_startup_with_shell_off",
"(",
"platform",
",",
"gdb_args",
")",
":",
"darwin_match",
"=",
"re",
".",
"match",
"(",
"\"darwin-(\\d+)\\..*\"",
",",
"platform",
")",
"on_darwin",
"=",
"darwin_match",
"is",
"not",
"None",
"and",
"int",
"(",
"darwin_matc... | 5367f87554f8f7c671d1f4596c133bf1303154f0 |
train | BotAI.main_base_ramp | Returns the Ramp instance of the closest main-ramp to start location. Look in game_info.py for more information | sc2/bot_ai.py | def main_base_ramp(self) -> "Ramp":
""" Returns the Ramp instance of the closest main-ramp to start location. Look in game_info.py for more information """
if hasattr(self, "cached_main_base_ramp"):
return self.cached_main_base_ramp
self.cached_main_base_ramp = min(
{ramp... | def main_base_ramp(self) -> "Ramp":
""" Returns the Ramp instance of the closest main-ramp to start location. Look in game_info.py for more information """
if hasattr(self, "cached_main_base_ramp"):
return self.cached_main_base_ramp
self.cached_main_base_ramp = min(
{ramp... | [
"Returns",
"the",
"Ramp",
"instance",
"of",
"the",
"closest",
"main",
"-",
"ramp",
"to",
"start",
"location",
".",
"Look",
"in",
"game_info",
".",
"py",
"for",
"more",
"information"
] | Dentosal/python-sc2 | python | https://github.com/Dentosal/python-sc2/blob/608bd25f04e89d39cef68b40101d8e9a8a7f1634/sc2/bot_ai.py#L74-L82 | [
"def",
"main_base_ramp",
"(",
"self",
")",
"->",
"\"Ramp\"",
":",
"if",
"hasattr",
"(",
"self",
",",
"\"cached_main_base_ramp\"",
")",
":",
"return",
"self",
".",
"cached_main_base_ramp",
"self",
".",
"cached_main_base_ramp",
"=",
"min",
"(",
"{",
"ramp",
"for... | 608bd25f04e89d39cef68b40101d8e9a8a7f1634 |
train | BotAI.expansion_locations | List of possible expansion locations. | sc2/bot_ai.py | def expansion_locations(self) -> Dict[Point2, Units]:
"""List of possible expansion locations."""
# RESOURCE_SPREAD_THRESHOLD = 144
RESOURCE_SPREAD_THRESHOLD = 225
geysers = self.state.vespene_geyser
all_resources = self.state.resources
# Group nearby minerals together t... | def expansion_locations(self) -> Dict[Point2, Units]:
"""List of possible expansion locations."""
# RESOURCE_SPREAD_THRESHOLD = 144
RESOURCE_SPREAD_THRESHOLD = 225
geysers = self.state.vespene_geyser
all_resources = self.state.resources
# Group nearby minerals together t... | [
"List",
"of",
"possible",
"expansion",
"locations",
"."
] | Dentosal/python-sc2 | python | https://github.com/Dentosal/python-sc2/blob/608bd25f04e89d39cef68b40101d8e9a8a7f1634/sc2/bot_ai.py#L85-L130 | [
"def",
"expansion_locations",
"(",
"self",
")",
"->",
"Dict",
"[",
"Point2",
",",
"Units",
"]",
":",
"# RESOURCE_SPREAD_THRESHOLD = 144",
"RESOURCE_SPREAD_THRESHOLD",
"=",
"225",
"geysers",
"=",
"self",
".",
"state",
".",
"vespene_geyser",
"all_resources",
"=",
"s... | 608bd25f04e89d39cef68b40101d8e9a8a7f1634 |
train | BotAI.get_available_abilities | Returns available abilities of one or more units. | sc2/bot_ai.py | async def get_available_abilities(self, units: Union[List[Unit], Units], ignore_resource_requirements=False) -> List[List[AbilityId]]:
""" Returns available abilities of one or more units. """
# right know only checks cooldown, energy cost, and whether the ability has been researched
return awai... | async def get_available_abilities(self, units: Union[List[Unit], Units], ignore_resource_requirements=False) -> List[List[AbilityId]]:
""" Returns available abilities of one or more units. """
# right know only checks cooldown, energy cost, and whether the ability has been researched
return awai... | [
"Returns",
"available",
"abilities",
"of",
"one",
"or",
"more",
"units",
"."
] | Dentosal/python-sc2 | python | https://github.com/Dentosal/python-sc2/blob/608bd25f04e89d39cef68b40101d8e9a8a7f1634/sc2/bot_ai.py#L132-L135 | [
"async",
"def",
"get_available_abilities",
"(",
"self",
",",
"units",
":",
"Union",
"[",
"List",
"[",
"Unit",
"]",
",",
"Units",
"]",
",",
"ignore_resource_requirements",
"=",
"False",
")",
"->",
"List",
"[",
"List",
"[",
"AbilityId",
"]",
"]",
":",
"# r... | 608bd25f04e89d39cef68b40101d8e9a8a7f1634 |
train | BotAI.expand_now | Takes new expansion. | sc2/bot_ai.py | async def expand_now(self, building: UnitTypeId=None, max_distance: Union[int, float]=10, location: Optional[Point2]=None):
"""Takes new expansion."""
if not building:
# self.race is never Race.Random
start_townhall_type = {Race.Protoss: UnitTypeId.NEXUS, Race.Terran: UnitTypeId... | async def expand_now(self, building: UnitTypeId=None, max_distance: Union[int, float]=10, location: Optional[Point2]=None):
"""Takes new expansion."""
if not building:
# self.race is never Race.Random
start_townhall_type = {Race.Protoss: UnitTypeId.NEXUS, Race.Terran: UnitTypeId... | [
"Takes",
"new",
"expansion",
"."
] | Dentosal/python-sc2 | python | https://github.com/Dentosal/python-sc2/blob/608bd25f04e89d39cef68b40101d8e9a8a7f1634/sc2/bot_ai.py#L137-L151 | [
"async",
"def",
"expand_now",
"(",
"self",
",",
"building",
":",
"UnitTypeId",
"=",
"None",
",",
"max_distance",
":",
"Union",
"[",
"int",
",",
"float",
"]",
"=",
"10",
",",
"location",
":",
"Optional",
"[",
"Point2",
"]",
"=",
"None",
")",
":",
"if"... | 608bd25f04e89d39cef68b40101d8e9a8a7f1634 |
train | BotAI.get_next_expansion | Find next expansion location. | sc2/bot_ai.py | async def get_next_expansion(self) -> Optional[Point2]:
"""Find next expansion location."""
closest = None
distance = math.inf
for el in self.expansion_locations:
def is_near_to_expansion(t):
return t.position.distance_to(el) < self.EXPANSION_GAP_THRESHOLD
... | async def get_next_expansion(self) -> Optional[Point2]:
"""Find next expansion location."""
closest = None
distance = math.inf
for el in self.expansion_locations:
def is_near_to_expansion(t):
return t.position.distance_to(el) < self.EXPANSION_GAP_THRESHOLD
... | [
"Find",
"next",
"expansion",
"location",
"."
] | Dentosal/python-sc2 | python | https://github.com/Dentosal/python-sc2/blob/608bd25f04e89d39cef68b40101d8e9a8a7f1634/sc2/bot_ai.py#L153-L175 | [
"async",
"def",
"get_next_expansion",
"(",
"self",
")",
"->",
"Optional",
"[",
"Point2",
"]",
":",
"closest",
"=",
"None",
"distance",
"=",
"math",
".",
"inf",
"for",
"el",
"in",
"self",
".",
"expansion_locations",
":",
"def",
"is_near_to_expansion",
"(",
... | 608bd25f04e89d39cef68b40101d8e9a8a7f1634 |
train | BotAI.distribute_workers | Distributes workers across all the bases taken.
WARNING: This is quite slow when there are lots of workers or multiple bases. | sc2/bot_ai.py | async def distribute_workers(self):
"""
Distributes workers across all the bases taken.
WARNING: This is quite slow when there are lots of workers or multiple bases.
"""
# TODO:
# OPTIMIZE: Assign idle workers smarter
# OPTIMIZE: Never use same worker mutltiple t... | async def distribute_workers(self):
"""
Distributes workers across all the bases taken.
WARNING: This is quite slow when there are lots of workers or multiple bases.
"""
# TODO:
# OPTIMIZE: Assign idle workers smarter
# OPTIMIZE: Never use same worker mutltiple t... | [
"Distributes",
"workers",
"across",
"all",
"the",
"bases",
"taken",
".",
"WARNING",
":",
"This",
"is",
"quite",
"slow",
"when",
"there",
"are",
"lots",
"of",
"workers",
"or",
"multiple",
"bases",
"."
] | Dentosal/python-sc2 | python | https://github.com/Dentosal/python-sc2/blob/608bd25f04e89d39cef68b40101d8e9a8a7f1634/sc2/bot_ai.py#L177-L241 | [
"async",
"def",
"distribute_workers",
"(",
"self",
")",
":",
"# TODO:",
"# OPTIMIZE: Assign idle workers smarter",
"# OPTIMIZE: Never use same worker mutltiple times",
"owned_expansions",
"=",
"self",
".",
"owned_expansions",
"worker_pool",
"=",
"[",
"]",
"actions",
"=",
"[... | 608bd25f04e89d39cef68b40101d8e9a8a7f1634 |
train | BotAI.owned_expansions | List of expansions owned by the player. | sc2/bot_ai.py | def owned_expansions(self):
"""List of expansions owned by the player."""
owned = {}
for el in self.expansion_locations:
def is_near_to_expansion(t):
return t.position.distance_to(el) < self.EXPANSION_GAP_THRESHOLD
th = next((x for x in self.townhalls if... | def owned_expansions(self):
"""List of expansions owned by the player."""
owned = {}
for el in self.expansion_locations:
def is_near_to_expansion(t):
return t.position.distance_to(el) < self.EXPANSION_GAP_THRESHOLD
th = next((x for x in self.townhalls if... | [
"List",
"of",
"expansions",
"owned",
"by",
"the",
"player",
"."
] | Dentosal/python-sc2 | python | https://github.com/Dentosal/python-sc2/blob/608bd25f04e89d39cef68b40101d8e9a8a7f1634/sc2/bot_ai.py#L244-L256 | [
"def",
"owned_expansions",
"(",
"self",
")",
":",
"owned",
"=",
"{",
"}",
"for",
"el",
"in",
"self",
".",
"expansion_locations",
":",
"def",
"is_near_to_expansion",
"(",
"t",
")",
":",
"return",
"t",
".",
"position",
".",
"distance_to",
"(",
"el",
")",
... | 608bd25f04e89d39cef68b40101d8e9a8a7f1634 |
train | BotAI.can_feed | Checks if you have enough free supply to build the unit | sc2/bot_ai.py | def can_feed(self, unit_type: UnitTypeId) -> bool:
""" Checks if you have enough free supply to build the unit """
required = self._game_data.units[unit_type.value]._proto.food_required
return required == 0 or self.supply_left >= required | def can_feed(self, unit_type: UnitTypeId) -> bool:
""" Checks if you have enough free supply to build the unit """
required = self._game_data.units[unit_type.value]._proto.food_required
return required == 0 or self.supply_left >= required | [
"Checks",
"if",
"you",
"have",
"enough",
"free",
"supply",
"to",
"build",
"the",
"unit"
] | Dentosal/python-sc2 | python | https://github.com/Dentosal/python-sc2/blob/608bd25f04e89d39cef68b40101d8e9a8a7f1634/sc2/bot_ai.py#L258-L261 | [
"def",
"can_feed",
"(",
"self",
",",
"unit_type",
":",
"UnitTypeId",
")",
"->",
"bool",
":",
"required",
"=",
"self",
".",
"_game_data",
".",
"units",
"[",
"unit_type",
".",
"value",
"]",
".",
"_proto",
".",
"food_required",
"return",
"required",
"==",
"... | 608bd25f04e89d39cef68b40101d8e9a8a7f1634 |
train | BotAI.can_afford | Tests if the player has enough resources to build a unit or cast an ability. | sc2/bot_ai.py | def can_afford(self, item_id: Union[UnitTypeId, UpgradeId, AbilityId], check_supply_cost: bool=True) -> "CanAffordWrapper":
"""Tests if the player has enough resources to build a unit or cast an ability."""
enough_supply = True
if isinstance(item_id, UnitTypeId):
unit = self._game_da... | def can_afford(self, item_id: Union[UnitTypeId, UpgradeId, AbilityId], check_supply_cost: bool=True) -> "CanAffordWrapper":
"""Tests if the player has enough resources to build a unit or cast an ability."""
enough_supply = True
if isinstance(item_id, UnitTypeId):
unit = self._game_da... | [
"Tests",
"if",
"the",
"player",
"has",
"enough",
"resources",
"to",
"build",
"a",
"unit",
"or",
"cast",
"an",
"ability",
"."
] | Dentosal/python-sc2 | python | https://github.com/Dentosal/python-sc2/blob/608bd25f04e89d39cef68b40101d8e9a8a7f1634/sc2/bot_ai.py#L263-L276 | [
"def",
"can_afford",
"(",
"self",
",",
"item_id",
":",
"Union",
"[",
"UnitTypeId",
",",
"UpgradeId",
",",
"AbilityId",
"]",
",",
"check_supply_cost",
":",
"bool",
"=",
"True",
")",
"->",
"\"CanAffordWrapper\"",
":",
"enough_supply",
"=",
"True",
"if",
"isins... | 608bd25f04e89d39cef68b40101d8e9a8a7f1634 |
train | BotAI.can_cast | Tests if a unit has an ability available and enough energy to cast it.
See data_pb2.py (line 161) for the numbers 1-5 to make sense | sc2/bot_ai.py | async def can_cast(self, unit: Unit, ability_id: AbilityId, target: Optional[Union[Unit, Point2, Point3]]=None, only_check_energy_and_cooldown: bool=False, cached_abilities_of_unit: List[AbilityId]=None) -> bool:
"""Tests if a unit has an ability available and enough energy to cast it.
See data_pb2.py (... | async def can_cast(self, unit: Unit, ability_id: AbilityId, target: Optional[Union[Unit, Point2, Point3]]=None, only_check_energy_and_cooldown: bool=False, cached_abilities_of_unit: List[AbilityId]=None) -> bool:
"""Tests if a unit has an ability available and enough energy to cast it.
See data_pb2.py (... | [
"Tests",
"if",
"a",
"unit",
"has",
"an",
"ability",
"available",
"and",
"enough",
"energy",
"to",
"cast",
"it",
".",
"See",
"data_pb2",
".",
"py",
"(",
"line",
"161",
")",
"for",
"the",
"numbers",
"1",
"-",
"5",
"to",
"make",
"sense"
] | Dentosal/python-sc2 | python | https://github.com/Dentosal/python-sc2/blob/608bd25f04e89d39cef68b40101d8e9a8a7f1634/sc2/bot_ai.py#L278-L304 | [
"async",
"def",
"can_cast",
"(",
"self",
",",
"unit",
":",
"Unit",
",",
"ability_id",
":",
"AbilityId",
",",
"target",
":",
"Optional",
"[",
"Union",
"[",
"Unit",
",",
"Point2",
",",
"Point3",
"]",
"]",
"=",
"None",
",",
"only_check_energy_and_cooldown",
... | 608bd25f04e89d39cef68b40101d8e9a8a7f1634 |
train | BotAI.select_build_worker | Select a worker to build a bulding with. | sc2/bot_ai.py | def select_build_worker(self, pos: Union[Unit, Point2, Point3], force: bool=False) -> Optional[Unit]:
"""Select a worker to build a bulding with."""
workers = self.workers.closer_than(20, pos) or self.workers
for worker in workers.prefer_close_to(pos).prefer_idle:
if not worker.orde... | def select_build_worker(self, pos: Union[Unit, Point2, Point3], force: bool=False) -> Optional[Unit]:
"""Select a worker to build a bulding with."""
workers = self.workers.closer_than(20, pos) or self.workers
for worker in workers.prefer_close_to(pos).prefer_idle:
if not worker.orde... | [
"Select",
"a",
"worker",
"to",
"build",
"a",
"bulding",
"with",
"."
] | Dentosal/python-sc2 | python | https://github.com/Dentosal/python-sc2/blob/608bd25f04e89d39cef68b40101d8e9a8a7f1634/sc2/bot_ai.py#L306-L316 | [
"def",
"select_build_worker",
"(",
"self",
",",
"pos",
":",
"Union",
"[",
"Unit",
",",
"Point2",
",",
"Point3",
"]",
",",
"force",
":",
"bool",
"=",
"False",
")",
"->",
"Optional",
"[",
"Unit",
"]",
":",
"workers",
"=",
"self",
".",
"workers",
".",
... | 608bd25f04e89d39cef68b40101d8e9a8a7f1634 |
train | BotAI.can_place | Tests if a building can be placed in the given location. | sc2/bot_ai.py | async def can_place(self, building: Union[AbilityData, AbilityId, UnitTypeId], position: Point2) -> bool:
"""Tests if a building can be placed in the given location."""
assert isinstance(building, (AbilityData, AbilityId, UnitTypeId))
if isinstance(building, UnitTypeId):
building =... | async def can_place(self, building: Union[AbilityData, AbilityId, UnitTypeId], position: Point2) -> bool:
"""Tests if a building can be placed in the given location."""
assert isinstance(building, (AbilityData, AbilityId, UnitTypeId))
if isinstance(building, UnitTypeId):
building =... | [
"Tests",
"if",
"a",
"building",
"can",
"be",
"placed",
"in",
"the",
"given",
"location",
"."
] | Dentosal/python-sc2 | python | https://github.com/Dentosal/python-sc2/blob/608bd25f04e89d39cef68b40101d8e9a8a7f1634/sc2/bot_ai.py#L318-L329 | [
"async",
"def",
"can_place",
"(",
"self",
",",
"building",
":",
"Union",
"[",
"AbilityData",
",",
"AbilityId",
",",
"UnitTypeId",
"]",
",",
"position",
":",
"Point2",
")",
"->",
"bool",
":",
"assert",
"isinstance",
"(",
"building",
",",
"(",
"AbilityData",... | 608bd25f04e89d39cef68b40101d8e9a8a7f1634 |
train | BotAI.find_placement | Finds a placement location for building. | sc2/bot_ai.py | async def find_placement(self, building: UnitTypeId, near: Union[Unit, Point2, Point3], max_distance: int=20, random_alternative: bool=True, placement_step: int=2) -> Optional[Point2]:
"""Finds a placement location for building."""
assert isinstance(building, (AbilityId, UnitTypeId))
assert isi... | async def find_placement(self, building: UnitTypeId, near: Union[Unit, Point2, Point3], max_distance: int=20, random_alternative: bool=True, placement_step: int=2) -> Optional[Point2]:
"""Finds a placement location for building."""
assert isinstance(building, (AbilityId, UnitTypeId))
assert isi... | [
"Finds",
"a",
"placement",
"location",
"for",
"building",
"."
] | Dentosal/python-sc2 | python | https://github.com/Dentosal/python-sc2/blob/608bd25f04e89d39cef68b40101d8e9a8a7f1634/sc2/bot_ai.py#L331-L364 | [
"async",
"def",
"find_placement",
"(",
"self",
",",
"building",
":",
"UnitTypeId",
",",
"near",
":",
"Union",
"[",
"Unit",
",",
"Point2",
",",
"Point3",
"]",
",",
"max_distance",
":",
"int",
"=",
"20",
",",
"random_alternative",
":",
"bool",
"=",
"True",... | 608bd25f04e89d39cef68b40101d8e9a8a7f1634 |
train | BotAI.already_pending_upgrade | Check if an upgrade is being researched
Return values:
0: not started
0 < x < 1: researching
1: finished | sc2/bot_ai.py | def already_pending_upgrade(self, upgrade_type: UpgradeId) -> Union[int, float]:
""" Check if an upgrade is being researched
Return values:
0: not started
0 < x < 1: researching
1: finished
"""
assert isinstance(upgrade_type, UpgradeId)
if upgrade_type in ... | def already_pending_upgrade(self, upgrade_type: UpgradeId) -> Union[int, float]:
""" Check if an upgrade is being researched
Return values:
0: not started
0 < x < 1: researching
1: finished
"""
assert isinstance(upgrade_type, UpgradeId)
if upgrade_type in ... | [
"Check",
"if",
"an",
"upgrade",
"is",
"being",
"researched",
"Return",
"values",
":",
"0",
":",
"not",
"started",
"0",
"<",
"x",
"<",
"1",
":",
"researching",
"1",
":",
"finished"
] | Dentosal/python-sc2 | python | https://github.com/Dentosal/python-sc2/blob/608bd25f04e89d39cef68b40101d8e9a8a7f1634/sc2/bot_ai.py#L366-L386 | [
"def",
"already_pending_upgrade",
"(",
"self",
",",
"upgrade_type",
":",
"UpgradeId",
")",
"->",
"Union",
"[",
"int",
",",
"float",
"]",
":",
"assert",
"isinstance",
"(",
"upgrade_type",
",",
"UpgradeId",
")",
"if",
"upgrade_type",
"in",
"self",
".",
"state"... | 608bd25f04e89d39cef68b40101d8e9a8a7f1634 |
train | BotAI.already_pending | Returns a number of buildings or units already in progress, or if a
worker is en route to build it. This also includes queued orders for
workers and build queues of buildings.
If all_units==True, then build queues of other units (such as Carriers
(Interceptors) or Oracles (Stasis Ward))... | sc2/bot_ai.py | def already_pending(self, unit_type: Union[UpgradeId, UnitTypeId], all_units: bool=False) -> int:
"""
Returns a number of buildings or units already in progress, or if a
worker is en route to build it. This also includes queued orders for
workers and build queues of buildings.
I... | def already_pending(self, unit_type: Union[UpgradeId, UnitTypeId], all_units: bool=False) -> int:
"""
Returns a number of buildings or units already in progress, or if a
worker is en route to build it. This also includes queued orders for
workers and build queues of buildings.
I... | [
"Returns",
"a",
"number",
"of",
"buildings",
"or",
"units",
"already",
"in",
"progress",
"or",
"if",
"a",
"worker",
"is",
"en",
"route",
"to",
"build",
"it",
".",
"This",
"also",
"includes",
"queued",
"orders",
"for",
"workers",
"and",
"build",
"queues",
... | Dentosal/python-sc2 | python | https://github.com/Dentosal/python-sc2/blob/608bd25f04e89d39cef68b40101d8e9a8a7f1634/sc2/bot_ai.py#L388-L413 | [
"def",
"already_pending",
"(",
"self",
",",
"unit_type",
":",
"Union",
"[",
"UpgradeId",
",",
"UnitTypeId",
"]",
",",
"all_units",
":",
"bool",
"=",
"False",
")",
"->",
"int",
":",
"# TODO / FIXME: SCV building a structure might be counted as two units",
"if",
"isin... | 608bd25f04e89d39cef68b40101d8e9a8a7f1634 |
train | BotAI.build | Build a building. | sc2/bot_ai.py | async def build(self, building: UnitTypeId, near: Union[Point2, Point3], max_distance: int=20, unit: Optional[Unit]=None, random_alternative: bool=True, placement_step: int=2):
"""Build a building."""
if isinstance(near, Unit):
near = near.position.to2
elif near is not None:
... | async def build(self, building: UnitTypeId, near: Union[Point2, Point3], max_distance: int=20, unit: Optional[Unit]=None, random_alternative: bool=True, placement_step: int=2):
"""Build a building."""
if isinstance(near, Unit):
near = near.position.to2
elif near is not None:
... | [
"Build",
"a",
"building",
"."
] | Dentosal/python-sc2 | python | https://github.com/Dentosal/python-sc2/blob/608bd25f04e89d39cef68b40101d8e9a8a7f1634/sc2/bot_ai.py#L415-L432 | [
"async",
"def",
"build",
"(",
"self",
",",
"building",
":",
"UnitTypeId",
",",
"near",
":",
"Union",
"[",
"Point2",
",",
"Point3",
"]",
",",
"max_distance",
":",
"int",
"=",
"20",
",",
"unit",
":",
"Optional",
"[",
"Unit",
"]",
"=",
"None",
",",
"r... | 608bd25f04e89d39cef68b40101d8e9a8a7f1634 |
train | BotAI.chat_send | Send a chat message. | sc2/bot_ai.py | async def chat_send(self, message: str):
"""Send a chat message."""
assert isinstance(message, str)
await self._client.chat_send(message, False) | async def chat_send(self, message: str):
"""Send a chat message."""
assert isinstance(message, str)
await self._client.chat_send(message, False) | [
"Send",
"a",
"chat",
"message",
"."
] | Dentosal/python-sc2 | python | https://github.com/Dentosal/python-sc2/blob/608bd25f04e89d39cef68b40101d8e9a8a7f1634/sc2/bot_ai.py#L462-L465 | [
"async",
"def",
"chat_send",
"(",
"self",
",",
"message",
":",
"str",
")",
":",
"assert",
"isinstance",
"(",
"message",
",",
"str",
")",
"await",
"self",
".",
"_client",
".",
"chat_send",
"(",
"message",
",",
"False",
")"
] | 608bd25f04e89d39cef68b40101d8e9a8a7f1634 |
train | BotAI.get_terrain_height | Returns terrain height at a position. Caution: terrain height is not anywhere near a unit's z-coordinate. | sc2/bot_ai.py | def get_terrain_height(self, pos: Union[Point2, Point3, Unit]) -> int:
""" Returns terrain height at a position. Caution: terrain height is not anywhere near a unit's z-coordinate. """
assert isinstance(pos, (Point2, Point3, Unit))
pos = pos.position.to2.rounded
return self._game_info.te... | def get_terrain_height(self, pos: Union[Point2, Point3, Unit]) -> int:
""" Returns terrain height at a position. Caution: terrain height is not anywhere near a unit's z-coordinate. """
assert isinstance(pos, (Point2, Point3, Unit))
pos = pos.position.to2.rounded
return self._game_info.te... | [
"Returns",
"terrain",
"height",
"at",
"a",
"position",
".",
"Caution",
":",
"terrain",
"height",
"is",
"not",
"anywhere",
"near",
"a",
"unit",
"s",
"z",
"-",
"coordinate",
"."
] | Dentosal/python-sc2 | python | https://github.com/Dentosal/python-sc2/blob/608bd25f04e89d39cef68b40101d8e9a8a7f1634/sc2/bot_ai.py#L468-L472 | [
"def",
"get_terrain_height",
"(",
"self",
",",
"pos",
":",
"Union",
"[",
"Point2",
",",
"Point3",
",",
"Unit",
"]",
")",
"->",
"int",
":",
"assert",
"isinstance",
"(",
"pos",
",",
"(",
"Point2",
",",
"Point3",
",",
"Unit",
")",
")",
"pos",
"=",
"po... | 608bd25f04e89d39cef68b40101d8e9a8a7f1634 |
train | BotAI.in_placement_grid | Returns True if you can place something at a position. Remember, buildings usually use 2x2, 3x3 or 5x5 of these grid points.
Caution: some x and y offset might be required, see ramp code:
https://github.com/Dentosal/python-sc2/blob/master/sc2/game_info.py#L17-L18 | sc2/bot_ai.py | def in_placement_grid(self, pos: Union[Point2, Point3, Unit]) -> bool:
""" Returns True if you can place something at a position. Remember, buildings usually use 2x2, 3x3 or 5x5 of these grid points.
Caution: some x and y offset might be required, see ramp code:
https://github.com/Dentosal/pytho... | def in_placement_grid(self, pos: Union[Point2, Point3, Unit]) -> bool:
""" Returns True if you can place something at a position. Remember, buildings usually use 2x2, 3x3 or 5x5 of these grid points.
Caution: some x and y offset might be required, see ramp code:
https://github.com/Dentosal/pytho... | [
"Returns",
"True",
"if",
"you",
"can",
"place",
"something",
"at",
"a",
"position",
".",
"Remember",
"buildings",
"usually",
"use",
"2x2",
"3x3",
"or",
"5x5",
"of",
"these",
"grid",
"points",
".",
"Caution",
":",
"some",
"x",
"and",
"y",
"offset",
"might... | Dentosal/python-sc2 | python | https://github.com/Dentosal/python-sc2/blob/608bd25f04e89d39cef68b40101d8e9a8a7f1634/sc2/bot_ai.py#L474-L480 | [
"def",
"in_placement_grid",
"(",
"self",
",",
"pos",
":",
"Union",
"[",
"Point2",
",",
"Point3",
",",
"Unit",
"]",
")",
"->",
"bool",
":",
"assert",
"isinstance",
"(",
"pos",
",",
"(",
"Point2",
",",
"Point3",
",",
"Unit",
")",
")",
"pos",
"=",
"po... | 608bd25f04e89d39cef68b40101d8e9a8a7f1634 |
train | BotAI.in_pathing_grid | Returns True if a unit can pass through a grid point. | sc2/bot_ai.py | def in_pathing_grid(self, pos: Union[Point2, Point3, Unit]) -> bool:
""" Returns True if a unit can pass through a grid point. """
assert isinstance(pos, (Point2, Point3, Unit))
pos = pos.position.to2.rounded
return self._game_info.pathing_grid[pos] == 0 | def in_pathing_grid(self, pos: Union[Point2, Point3, Unit]) -> bool:
""" Returns True if a unit can pass through a grid point. """
assert isinstance(pos, (Point2, Point3, Unit))
pos = pos.position.to2.rounded
return self._game_info.pathing_grid[pos] == 0 | [
"Returns",
"True",
"if",
"a",
"unit",
"can",
"pass",
"through",
"a",
"grid",
"point",
"."
] | Dentosal/python-sc2 | python | https://github.com/Dentosal/python-sc2/blob/608bd25f04e89d39cef68b40101d8e9a8a7f1634/sc2/bot_ai.py#L482-L486 | [
"def",
"in_pathing_grid",
"(",
"self",
",",
"pos",
":",
"Union",
"[",
"Point2",
",",
"Point3",
",",
"Unit",
"]",
")",
"->",
"bool",
":",
"assert",
"isinstance",
"(",
"pos",
",",
"(",
"Point2",
",",
"Point3",
",",
"Unit",
")",
")",
"pos",
"=",
"pos"... | 608bd25f04e89d39cef68b40101d8e9a8a7f1634 |
train | BotAI.is_visible | Returns True if you have vision on a grid point. | sc2/bot_ai.py | def is_visible(self, pos: Union[Point2, Point3, Unit]) -> bool:
""" Returns True if you have vision on a grid point. """
# more info: https://github.com/Blizzard/s2client-proto/blob/9906df71d6909511907d8419b33acc1a3bd51ec0/s2clientprotocol/spatial.proto#L19
assert isinstance(pos, (Point2, Point3... | def is_visible(self, pos: Union[Point2, Point3, Unit]) -> bool:
""" Returns True if you have vision on a grid point. """
# more info: https://github.com/Blizzard/s2client-proto/blob/9906df71d6909511907d8419b33acc1a3bd51ec0/s2clientprotocol/spatial.proto#L19
assert isinstance(pos, (Point2, Point3... | [
"Returns",
"True",
"if",
"you",
"have",
"vision",
"on",
"a",
"grid",
"point",
"."
] | Dentosal/python-sc2 | python | https://github.com/Dentosal/python-sc2/blob/608bd25f04e89d39cef68b40101d8e9a8a7f1634/sc2/bot_ai.py#L488-L493 | [
"def",
"is_visible",
"(",
"self",
",",
"pos",
":",
"Union",
"[",
"Point2",
",",
"Point3",
",",
"Unit",
"]",
")",
"->",
"bool",
":",
"# more info: https://github.com/Blizzard/s2client-proto/blob/9906df71d6909511907d8419b33acc1a3bd51ec0/s2clientprotocol/spatial.proto#L19",
"ass... | 608bd25f04e89d39cef68b40101d8e9a8a7f1634 |
train | BotAI.has_creep | Returns True if there is creep on the grid point. | sc2/bot_ai.py | def has_creep(self, pos: Union[Point2, Point3, Unit]) -> bool:
""" Returns True if there is creep on the grid point. """
assert isinstance(pos, (Point2, Point3, Unit))
pos = pos.position.to2.rounded
return self.state.creep[pos] != 0 | def has_creep(self, pos: Union[Point2, Point3, Unit]) -> bool:
""" Returns True if there is creep on the grid point. """
assert isinstance(pos, (Point2, Point3, Unit))
pos = pos.position.to2.rounded
return self.state.creep[pos] != 0 | [
"Returns",
"True",
"if",
"there",
"is",
"creep",
"on",
"the",
"grid",
"point",
"."
] | Dentosal/python-sc2 | python | https://github.com/Dentosal/python-sc2/blob/608bd25f04e89d39cef68b40101d8e9a8a7f1634/sc2/bot_ai.py#L495-L499 | [
"def",
"has_creep",
"(",
"self",
",",
"pos",
":",
"Union",
"[",
"Point2",
",",
"Point3",
",",
"Unit",
"]",
")",
"->",
"bool",
":",
"assert",
"isinstance",
"(",
"pos",
",",
"(",
"Point2",
",",
"Point3",
",",
"Unit",
")",
")",
"pos",
"=",
"pos",
".... | 608bd25f04e89d39cef68b40101d8e9a8a7f1634 |
train | BotAI._prepare_start | Ran until game start to set game and player data. | sc2/bot_ai.py | def _prepare_start(self, client, player_id, game_info, game_data):
"""Ran until game start to set game and player data."""
self._client: "Client" = client
self._game_info: "GameInfo" = game_info
self._game_data: GameData = game_data
self.player_id: int = player_id
self.r... | def _prepare_start(self, client, player_id, game_info, game_data):
"""Ran until game start to set game and player data."""
self._client: "Client" = client
self._game_info: "GameInfo" = game_info
self._game_data: GameData = game_data
self.player_id: int = player_id
self.r... | [
"Ran",
"until",
"game",
"start",
"to",
"set",
"game",
"and",
"player",
"data",
"."
] | Dentosal/python-sc2 | python | https://github.com/Dentosal/python-sc2/blob/608bd25f04e89d39cef68b40101d8e9a8a7f1634/sc2/bot_ai.py#L501-L510 | [
"def",
"_prepare_start",
"(",
"self",
",",
"client",
",",
"player_id",
",",
"game_info",
",",
"game_data",
")",
":",
"self",
".",
"_client",
":",
"\"Client\"",
"=",
"client",
"self",
".",
"_game_info",
":",
"\"GameInfo\"",
"=",
"game_info",
"self",
".",
"_... | 608bd25f04e89d39cef68b40101d8e9a8a7f1634 |
train | BotAI._prepare_first_step | First step extra preparations. Must not be called before _prepare_step. | sc2/bot_ai.py | def _prepare_first_step(self):
"""First step extra preparations. Must not be called before _prepare_step."""
if self.townhalls:
self._game_info.player_start_location = self.townhalls.first.position
self._game_info.map_ramps = self._game_info._find_ramps() | def _prepare_first_step(self):
"""First step extra preparations. Must not be called before _prepare_step."""
if self.townhalls:
self._game_info.player_start_location = self.townhalls.first.position
self._game_info.map_ramps = self._game_info._find_ramps() | [
"First",
"step",
"extra",
"preparations",
".",
"Must",
"not",
"be",
"called",
"before",
"_prepare_step",
"."
] | Dentosal/python-sc2 | python | https://github.com/Dentosal/python-sc2/blob/608bd25f04e89d39cef68b40101d8e9a8a7f1634/sc2/bot_ai.py#L512-L516 | [
"def",
"_prepare_first_step",
"(",
"self",
")",
":",
"if",
"self",
".",
"townhalls",
":",
"self",
".",
"_game_info",
".",
"player_start_location",
"=",
"self",
".",
"townhalls",
".",
"first",
".",
"position",
"self",
".",
"_game_info",
".",
"map_ramps",
"=",... | 608bd25f04e89d39cef68b40101d8e9a8a7f1634 |
train | BotAI._prepare_step | Set attributes from new state before on_step. | sc2/bot_ai.py | def _prepare_step(self, state):
"""Set attributes from new state before on_step."""
self.state: GameState = state
# Required for events
self._units_previous_map.clear()
for unit in self.units:
self._units_previous_map[unit.tag] = unit
self.units: Units = stat... | def _prepare_step(self, state):
"""Set attributes from new state before on_step."""
self.state: GameState = state
# Required for events
self._units_previous_map.clear()
for unit in self.units:
self._units_previous_map[unit.tag] = unit
self.units: Units = stat... | [
"Set",
"attributes",
"from",
"new",
"state",
"before",
"on_step",
"."
] | Dentosal/python-sc2 | python | https://github.com/Dentosal/python-sc2/blob/608bd25f04e89d39cef68b40101d8e9a8a7f1634/sc2/bot_ai.py#L518-L538 | [
"def",
"_prepare_step",
"(",
"self",
",",
"state",
")",
":",
"self",
".",
"state",
":",
"GameState",
"=",
"state",
"# Required for events",
"self",
".",
"_units_previous_map",
".",
"clear",
"(",
")",
"for",
"unit",
"in",
"self",
".",
"units",
":",
"self",
... | 608bd25f04e89d39cef68b40101d8e9a8a7f1634 |
train | BotAI.issue_events | This function will be automatically run from main.py and triggers the following functions:
- on_unit_created
- on_unit_destroyed
- on_building_construction_complete | sc2/bot_ai.py | async def issue_events(self):
""" This function will be automatically run from main.py and triggers the following functions:
- on_unit_created
- on_unit_destroyed
- on_building_construction_complete
"""
await self._issue_unit_dead_events()
await self._issue_unit_a... | async def issue_events(self):
""" This function will be automatically run from main.py and triggers the following functions:
- on_unit_created
- on_unit_destroyed
- on_building_construction_complete
"""
await self._issue_unit_dead_events()
await self._issue_unit_a... | [
"This",
"function",
"will",
"be",
"automatically",
"run",
"from",
"main",
".",
"py",
"and",
"triggers",
"the",
"following",
"functions",
":",
"-",
"on_unit_created",
"-",
"on_unit_destroyed",
"-",
"on_building_construction_complete"
] | Dentosal/python-sc2 | python | https://github.com/Dentosal/python-sc2/blob/608bd25f04e89d39cef68b40101d8e9a8a7f1634/sc2/bot_ai.py#L540-L549 | [
"async",
"def",
"issue_events",
"(",
"self",
")",
":",
"await",
"self",
".",
"_issue_unit_dead_events",
"(",
")",
"await",
"self",
".",
"_issue_unit_added_events",
"(",
")",
"for",
"unit",
"in",
"self",
".",
"units",
".",
"structure",
":",
"await",
"self",
... | 608bd25f04e89d39cef68b40101d8e9a8a7f1634 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.