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 | Runner.get_fact_cache | Get the entire fact cache only if the fact_cache_type is 'jsonfile' | ansible_runner/runner.py | def get_fact_cache(self, host):
'''
Get the entire fact cache only if the fact_cache_type is 'jsonfile'
'''
if self.config.fact_cache_type != 'jsonfile':
raise Exception('Unsupported fact cache type. Only "jsonfile" is supported for reading and writing facts from ansible-run... | def get_fact_cache(self, host):
'''
Get the entire fact cache only if the fact_cache_type is 'jsonfile'
'''
if self.config.fact_cache_type != 'jsonfile':
raise Exception('Unsupported fact cache type. Only "jsonfile" is supported for reading and writing facts from ansible-run... | [
"Get",
"the",
"entire",
"fact",
"cache",
"only",
"if",
"the",
"fact_cache_type",
"is",
"jsonfile"
] | ansible/ansible-runner | python | https://github.com/ansible/ansible-runner/blob/8ce485480a5d0b602428d9d64a752e06fb46cdb8/ansible_runner/runner.py#L345-L355 | [
"def",
"get_fact_cache",
"(",
"self",
",",
"host",
")",
":",
"if",
"self",
".",
"config",
".",
"fact_cache_type",
"!=",
"'jsonfile'",
":",
"raise",
"Exception",
"(",
"'Unsupported fact cache type. Only \"jsonfile\" is supported for reading and writing facts from ansible-runn... | 8ce485480a5d0b602428d9d64a752e06fb46cdb8 |
train | Runner.set_fact_cache | Set the entire fact cache data only if the fact_cache_type is 'jsonfile' | ansible_runner/runner.py | def set_fact_cache(self, host, data):
'''
Set the entire fact cache data only if the fact_cache_type is 'jsonfile'
'''
if self.config.fact_cache_type != 'jsonfile':
raise Exception('Unsupported fact cache type. Only "jsonfile" is supported for reading and writing facts from ... | def set_fact_cache(self, host, data):
'''
Set the entire fact cache data only if the fact_cache_type is 'jsonfile'
'''
if self.config.fact_cache_type != 'jsonfile':
raise Exception('Unsupported fact cache type. Only "jsonfile" is supported for reading and writing facts from ... | [
"Set",
"the",
"entire",
"fact",
"cache",
"data",
"only",
"if",
"the",
"fact_cache_type",
"is",
"jsonfile"
] | ansible/ansible-runner | python | https://github.com/ansible/ansible-runner/blob/8ce485480a5d0b602428d9d64a752e06fb46cdb8/ansible_runner/runner.py#L357-L367 | [
"def",
"set_fact_cache",
"(",
"self",
",",
"host",
",",
"data",
")",
":",
"if",
"self",
".",
"config",
".",
"fact_cache_type",
"!=",
"'jsonfile'",
":",
"raise",
"Exception",
"(",
"'Unsupported fact cache type. Only \"jsonfile\" is supported for reading and writing facts ... | 8ce485480a5d0b602428d9d64a752e06fb46cdb8 |
train | init_runner | Initialize the Runner() instance
This function will properly initialize both run() and run_async()
functions in the same way and return a value instance of Runner.
See parameters given to :py:func:`ansible_runner.interface.run` | ansible_runner/interface.py | def init_runner(**kwargs):
'''
Initialize the Runner() instance
This function will properly initialize both run() and run_async()
functions in the same way and return a value instance of Runner.
See parameters given to :py:func:`ansible_runner.interface.run`
'''
dump_artifacts(kwargs)
... | def init_runner(**kwargs):
'''
Initialize the Runner() instance
This function will properly initialize both run() and run_async()
functions in the same way and return a value instance of Runner.
See parameters given to :py:func:`ansible_runner.interface.run`
'''
dump_artifacts(kwargs)
... | [
"Initialize",
"the",
"Runner",
"()",
"instance"
] | ansible/ansible-runner | python | https://github.com/ansible/ansible-runner/blob/8ce485480a5d0b602428d9d64a752e06fb46cdb8/ansible_runner/interface.py#L34-L71 | [
"def",
"init_runner",
"(",
"*",
"*",
"kwargs",
")",
":",
"dump_artifacts",
"(",
"kwargs",
")",
"debug",
"=",
"kwargs",
".",
"pop",
"(",
"'debug'",
",",
"None",
")",
"logfile",
"=",
"kwargs",
".",
"pop",
"(",
"'logfile'",
",",
"None",
")",
"if",
"not"... | 8ce485480a5d0b602428d9d64a752e06fb46cdb8 |
train | run_async | Runs an Ansible Runner task in the background which will start immediately. Returns the thread object and a Runner object.
This uses the same parameters as :py:func:`ansible_runner.interface.run`
:returns: A tuple containing a :py:class:`threading.Thread` object and a :py:class:`ansible_runner.runner.Runner` ... | ansible_runner/interface.py | def run_async(**kwargs):
'''
Runs an Ansible Runner task in the background which will start immediately. Returns the thread object and a Runner object.
This uses the same parameters as :py:func:`ansible_runner.interface.run`
:returns: A tuple containing a :py:class:`threading.Thread` object and a :py:... | def run_async(**kwargs):
'''
Runs an Ansible Runner task in the background which will start immediately. Returns the thread object and a Runner object.
This uses the same parameters as :py:func:`ansible_runner.interface.run`
:returns: A tuple containing a :py:class:`threading.Thread` object and a :py:... | [
"Runs",
"an",
"Ansible",
"Runner",
"task",
"in",
"the",
"background",
"which",
"will",
"start",
"immediately",
".",
"Returns",
"the",
"thread",
"object",
"and",
"a",
"Runner",
"object",
"."
] | ansible/ansible-runner | python | https://github.com/ansible/ansible-runner/blob/8ce485480a5d0b602428d9d64a752e06fb46cdb8/ansible_runner/interface.py#L166-L177 | [
"def",
"run_async",
"(",
"*",
"*",
"kwargs",
")",
":",
"r",
"=",
"init_runner",
"(",
"*",
"*",
"kwargs",
")",
"runner_thread",
"=",
"threading",
".",
"Thread",
"(",
"target",
"=",
"r",
".",
"run",
")",
"runner_thread",
".",
"start",
"(",
")",
"return... | 8ce485480a5d0b602428d9d64a752e06fb46cdb8 |
train | isplaybook | Inspects the object and returns if it is a playbook
Args:
obj (object): The object to be inspected by this function
Returns:
boolean: True if the object is a list and False if it is not | ansible_runner/utils.py | def isplaybook(obj):
'''
Inspects the object and returns if it is a playbook
Args:
obj (object): The object to be inspected by this function
Returns:
boolean: True if the object is a list and False if it is not
'''
return isinstance(obj, Iterable) and (not isinstance(obj, strin... | def isplaybook(obj):
'''
Inspects the object and returns if it is a playbook
Args:
obj (object): The object to be inspected by this function
Returns:
boolean: True if the object is a list and False if it is not
'''
return isinstance(obj, Iterable) and (not isinstance(obj, strin... | [
"Inspects",
"the",
"object",
"and",
"returns",
"if",
"it",
"is",
"a",
"playbook"
] | ansible/ansible-runner | python | https://github.com/ansible/ansible-runner/blob/8ce485480a5d0b602428d9d64a752e06fb46cdb8/ansible_runner/utils.py#L39-L49 | [
"def",
"isplaybook",
"(",
"obj",
")",
":",
"return",
"isinstance",
"(",
"obj",
",",
"Iterable",
")",
"and",
"(",
"not",
"isinstance",
"(",
"obj",
",",
"string_types",
")",
"and",
"not",
"isinstance",
"(",
"obj",
",",
"Mapping",
")",
")"
] | 8ce485480a5d0b602428d9d64a752e06fb46cdb8 |
train | check_isolation_executable_installed | Check that proot is installed. | ansible_runner/utils.py | def check_isolation_executable_installed(isolation_executable):
'''
Check that proot is installed.
'''
cmd = [isolation_executable, '--version']
try:
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
proc.communicate()
... | def check_isolation_executable_installed(isolation_executable):
'''
Check that proot is installed.
'''
cmd = [isolation_executable, '--version']
try:
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
proc.communicate()
... | [
"Check",
"that",
"proot",
"is",
"installed",
"."
] | ansible/ansible-runner | python | https://github.com/ansible/ansible-runner/blob/8ce485480a5d0b602428d9d64a752e06fb46cdb8/ansible_runner/utils.py#L65-L78 | [
"def",
"check_isolation_executable_installed",
"(",
"isolation_executable",
")",
":",
"cmd",
"=",
"[",
"isolation_executable",
",",
"'--version'",
"]",
"try",
":",
"proc",
"=",
"subprocess",
".",
"Popen",
"(",
"cmd",
",",
"stdout",
"=",
"subprocess",
".",
"PIPE"... | 8ce485480a5d0b602428d9d64a752e06fb46cdb8 |
train | dump_artifact | Write the artifact to disk at the specified path
Args:
obj (string): The string object to be dumped to disk in the specified
path. The artifact filename will be automatically created
path (string): The full path to the artifacts data directory.
filename (string, optional): Th... | ansible_runner/utils.py | def dump_artifact(obj, path, filename=None):
'''
Write the artifact to disk at the specified path
Args:
obj (string): The string object to be dumped to disk in the specified
path. The artifact filename will be automatically created
path (string): The full path to the artifacts... | def dump_artifact(obj, path, filename=None):
'''
Write the artifact to disk at the specified path
Args:
obj (string): The string object to be dumped to disk in the specified
path. The artifact filename will be automatically created
path (string): The full path to the artifacts... | [
"Write",
"the",
"artifact",
"to",
"disk",
"at",
"the",
"specified",
"path"
] | ansible/ansible-runner | python | https://github.com/ansible/ansible-runner/blob/8ce485480a5d0b602428d9d64a752e06fb46cdb8/ansible_runner/utils.py#L81-L130 | [
"def",
"dump_artifact",
"(",
"obj",
",",
"path",
",",
"filename",
"=",
"None",
")",
":",
"p_sha1",
"=",
"None",
"if",
"not",
"os",
".",
"path",
".",
"exists",
"(",
"path",
")",
":",
"os",
".",
"makedirs",
"(",
"path",
",",
"mode",
"=",
"0o700",
"... | 8ce485480a5d0b602428d9d64a752e06fb46cdb8 |
train | dump_artifacts | Introspect the kwargs and dump objects to disk | ansible_runner/utils.py | def dump_artifacts(kwargs):
'''
Introspect the kwargs and dump objects to disk
'''
private_data_dir = kwargs.get('private_data_dir')
if not private_data_dir:
private_data_dir = tempfile.mkdtemp()
kwargs['private_data_dir'] = private_data_dir
if not os.path.exists(private_data_di... | def dump_artifacts(kwargs):
'''
Introspect the kwargs and dump objects to disk
'''
private_data_dir = kwargs.get('private_data_dir')
if not private_data_dir:
private_data_dir = tempfile.mkdtemp()
kwargs['private_data_dir'] = private_data_dir
if not os.path.exists(private_data_di... | [
"Introspect",
"the",
"kwargs",
"and",
"dump",
"objects",
"to",
"disk"
] | ansible/ansible-runner | python | https://github.com/ansible/ansible-runner/blob/8ce485480a5d0b602428d9d64a752e06fb46cdb8/ansible_runner/utils.py#L144-L205 | [
"def",
"dump_artifacts",
"(",
"kwargs",
")",
":",
"private_data_dir",
"=",
"kwargs",
".",
"get",
"(",
"'private_data_dir'",
")",
"if",
"not",
"private_data_dir",
":",
"private_data_dir",
"=",
"tempfile",
".",
"mkdtemp",
"(",
")",
"kwargs",
"[",
"'private_data_di... | 8ce485480a5d0b602428d9d64a752e06fb46cdb8 |
train | open_fifo_write | open_fifo_write opens the fifo named pipe in a new thread.
This blocks the thread until an external process (such as ssh-agent)
reads data from the pipe. | ansible_runner/utils.py | def open_fifo_write(path, data):
'''open_fifo_write opens the fifo named pipe in a new thread.
This blocks the thread until an external process (such as ssh-agent)
reads data from the pipe.
'''
os.mkfifo(path, stat.S_IRUSR | stat.S_IWUSR)
threading.Thread(target=lambda p, d: open(p, 'wb').write(... | def open_fifo_write(path, data):
'''open_fifo_write opens the fifo named pipe in a new thread.
This blocks the thread until an external process (such as ssh-agent)
reads data from the pipe.
'''
os.mkfifo(path, stat.S_IRUSR | stat.S_IWUSR)
threading.Thread(target=lambda p, d: open(p, 'wb').write(... | [
"open_fifo_write",
"opens",
"the",
"fifo",
"named",
"pipe",
"in",
"a",
"new",
"thread",
".",
"This",
"blocks",
"the",
"thread",
"until",
"an",
"external",
"process",
"(",
"such",
"as",
"ssh",
"-",
"agent",
")",
"reads",
"data",
"from",
"the",
"pipe",
"."... | ansible/ansible-runner | python | https://github.com/ansible/ansible-runner/blob/8ce485480a5d0b602428d9d64a752e06fb46cdb8/ansible_runner/utils.py#L337-L344 | [
"def",
"open_fifo_write",
"(",
"path",
",",
"data",
")",
":",
"os",
".",
"mkfifo",
"(",
"path",
",",
"stat",
".",
"S_IRUSR",
"|",
"stat",
".",
"S_IWUSR",
")",
"threading",
".",
"Thread",
"(",
"target",
"=",
"lambda",
"p",
",",
"d",
":",
"open",
"("... | 8ce485480a5d0b602428d9d64a752e06fb46cdb8 |
train | encode_pdf_date | Encode Python datetime object as PDF date string
From Adobe pdfmark manual:
(D:YYYYMMDDHHmmSSOHH'mm')
D: is an optional prefix. YYYY is the year. All fields after the year are
optional. MM is the month (01-12), DD is the day (01-31), HH is the
hour (00-23), mm are the minutes (00-59), and SS are th... | src/pikepdf/models/metadata.py | def encode_pdf_date(d: datetime) -> str:
"""Encode Python datetime object as PDF date string
From Adobe pdfmark manual:
(D:YYYYMMDDHHmmSSOHH'mm')
D: is an optional prefix. YYYY is the year. All fields after the year are
optional. MM is the month (01-12), DD is the day (01-31), HH is the
hour (0... | def encode_pdf_date(d: datetime) -> str:
"""Encode Python datetime object as PDF date string
From Adobe pdfmark manual:
(D:YYYYMMDDHHmmSSOHH'mm')
D: is an optional prefix. YYYY is the year. All fields after the year are
optional. MM is the month (01-12), DD is the day (01-31), HH is the
hour (0... | [
"Encode",
"Python",
"datetime",
"object",
"as",
"PDF",
"date",
"string"
] | pikepdf/pikepdf | python | https://github.com/pikepdf/pikepdf/blob/07154f4dec007e2e9c0c6a8c07b964fd06bc5f77/src/pikepdf/models/metadata.py#L96-L124 | [
"def",
"encode_pdf_date",
"(",
"d",
":",
"datetime",
")",
"->",
"str",
":",
"# The formatting of %Y is not consistent as described in",
"# https://bugs.python.org/issue13305 and underspecification in libc.",
"# So explicitly format the year with leading zeros",
"s",
"=",
"\"{:04d}\"",
... | 07154f4dec007e2e9c0c6a8c07b964fd06bc5f77 |
train | decode_pdf_date | Decode a pdfmark date to a Python datetime object
A pdfmark date is a string in a paritcular format. See the pdfmark
Reference for the specification. | src/pikepdf/models/metadata.py | def decode_pdf_date(s: str) -> datetime:
"""Decode a pdfmark date to a Python datetime object
A pdfmark date is a string in a paritcular format. See the pdfmark
Reference for the specification.
"""
if isinstance(s, String):
s = str(s)
if s.startswith('D:'):
s = s[2:]
# Lite... | def decode_pdf_date(s: str) -> datetime:
"""Decode a pdfmark date to a Python datetime object
A pdfmark date is a string in a paritcular format. See the pdfmark
Reference for the specification.
"""
if isinstance(s, String):
s = str(s)
if s.startswith('D:'):
s = s[2:]
# Lite... | [
"Decode",
"a",
"pdfmark",
"date",
"to",
"a",
"Python",
"datetime",
"object"
] | pikepdf/pikepdf | python | https://github.com/pikepdf/pikepdf/blob/07154f4dec007e2e9c0c6a8c07b964fd06bc5f77/src/pikepdf/models/metadata.py#L127-L148 | [
"def",
"decode_pdf_date",
"(",
"s",
":",
"str",
")",
"->",
"datetime",
":",
"if",
"isinstance",
"(",
"s",
",",
"String",
")",
":",
"s",
"=",
"str",
"(",
"s",
")",
"if",
"s",
".",
"startswith",
"(",
"'D:'",
")",
":",
"s",
"=",
"s",
"[",
"2",
"... | 07154f4dec007e2e9c0c6a8c07b964fd06bc5f77 |
train | PdfMetadata.load_from_docinfo | Populate the XMP metadata object with DocumentInfo
Arguments:
docinfo: a DocumentInfo, e.g pdf.docinfo
delete_missing: if the entry is not DocumentInfo, delete the equivalent
from XMP
raise_failure: if True, raise any failure to convert docinfo;
... | src/pikepdf/models/metadata.py | def load_from_docinfo(self, docinfo, delete_missing=False, raise_failure=False):
"""Populate the XMP metadata object with DocumentInfo
Arguments:
docinfo: a DocumentInfo, e.g pdf.docinfo
delete_missing: if the entry is not DocumentInfo, delete the equivalent
from... | def load_from_docinfo(self, docinfo, delete_missing=False, raise_failure=False):
"""Populate the XMP metadata object with DocumentInfo
Arguments:
docinfo: a DocumentInfo, e.g pdf.docinfo
delete_missing: if the entry is not DocumentInfo, delete the equivalent
from... | [
"Populate",
"the",
"XMP",
"metadata",
"object",
"with",
"DocumentInfo"
] | pikepdf/pikepdf | python | https://github.com/pikepdf/pikepdf/blob/07154f4dec007e2e9c0c6a8c07b964fd06bc5f77/src/pikepdf/models/metadata.py#L257-L294 | [
"def",
"load_from_docinfo",
"(",
"self",
",",
"docinfo",
",",
"delete_missing",
"=",
"False",
",",
"raise_failure",
"=",
"False",
")",
":",
"for",
"uri",
",",
"shortkey",
",",
"docinfo_name",
",",
"converter",
"in",
"self",
".",
"DOCINFO_MAPPING",
":",
"qnam... | 07154f4dec007e2e9c0c6a8c07b964fd06bc5f77 |
train | PdfMetadata._update_docinfo | Update the PDF's DocumentInfo dictionary to match XMP metadata
The standard mapping is described here:
https://www.pdfa.org/pdfa-metadata-xmp-rdf-dublin-core/ | src/pikepdf/models/metadata.py | def _update_docinfo(self):
"""Update the PDF's DocumentInfo dictionary to match XMP metadata
The standard mapping is described here:
https://www.pdfa.org/pdfa-metadata-xmp-rdf-dublin-core/
"""
self._pdf.docinfo # Touch object to ensure it exists
for uri, element, do... | def _update_docinfo(self):
"""Update the PDF's DocumentInfo dictionary to match XMP metadata
The standard mapping is described here:
https://www.pdfa.org/pdfa-metadata-xmp-rdf-dublin-core/
"""
self._pdf.docinfo # Touch object to ensure it exists
for uri, element, do... | [
"Update",
"the",
"PDF",
"s",
"DocumentInfo",
"dictionary",
"to",
"match",
"XMP",
"metadata"
] | pikepdf/pikepdf | python | https://github.com/pikepdf/pikepdf/blob/07154f4dec007e2e9c0c6a8c07b964fd06bc5f77/src/pikepdf/models/metadata.py#L329-L364 | [
"def",
"_update_docinfo",
"(",
"self",
")",
":",
"self",
".",
"_pdf",
".",
"docinfo",
"# Touch object to ensure it exists",
"for",
"uri",
",",
"element",
",",
"docinfo_name",
",",
"converter",
"in",
"self",
".",
"DOCINFO_MAPPING",
":",
"qname",
"=",
"QName",
"... | 07154f4dec007e2e9c0c6a8c07b964fd06bc5f77 |
train | PdfMetadata._apply_changes | Serialize our changes back to the PDF in memory
Depending how we are initialized, leave our metadata mark and producer. | src/pikepdf/models/metadata.py | def _apply_changes(self):
"""Serialize our changes back to the PDF in memory
Depending how we are initialized, leave our metadata mark and producer.
"""
if self.mark:
self[QName(XMP_NS_XMP, 'MetadataDate')] = datetime.now().isoformat()
self[QName(XMP_NS_PDF, 'Pro... | def _apply_changes(self):
"""Serialize our changes back to the PDF in memory
Depending how we are initialized, leave our metadata mark and producer.
"""
if self.mark:
self[QName(XMP_NS_XMP, 'MetadataDate')] = datetime.now().isoformat()
self[QName(XMP_NS_PDF, 'Pro... | [
"Serialize",
"our",
"changes",
"back",
"to",
"the",
"PDF",
"in",
"memory"
] | pikepdf/pikepdf | python | https://github.com/pikepdf/pikepdf/blob/07154f4dec007e2e9c0c6a8c07b964fd06bc5f77/src/pikepdf/models/metadata.py#L377-L390 | [
"def",
"_apply_changes",
"(",
"self",
")",
":",
"if",
"self",
".",
"mark",
":",
"self",
"[",
"QName",
"(",
"XMP_NS_XMP",
",",
"'MetadataDate'",
")",
"]",
"=",
"datetime",
".",
"now",
"(",
")",
".",
"isoformat",
"(",
")",
"self",
"[",
"QName",
"(",
... | 07154f4dec007e2e9c0c6a8c07b964fd06bc5f77 |
train | PdfMetadata._qname | Convert name to an XML QName
e.g. pdf:Producer -> {http://ns.adobe.com/pdf/1.3/}Producer | src/pikepdf/models/metadata.py | def _qname(self, name):
"""Convert name to an XML QName
e.g. pdf:Producer -> {http://ns.adobe.com/pdf/1.3/}Producer
"""
if isinstance(name, QName):
return name
if not isinstance(name, str):
raise TypeError("{} must be str".format(name))
if name ==... | def _qname(self, name):
"""Convert name to an XML QName
e.g. pdf:Producer -> {http://ns.adobe.com/pdf/1.3/}Producer
"""
if isinstance(name, QName):
return name
if not isinstance(name, str):
raise TypeError("{} must be str".format(name))
if name ==... | [
"Convert",
"name",
"to",
"an",
"XML",
"QName"
] | pikepdf/pikepdf | python | https://github.com/pikepdf/pikepdf/blob/07154f4dec007e2e9c0c6a8c07b964fd06bc5f77/src/pikepdf/models/metadata.py#L392-L407 | [
"def",
"_qname",
"(",
"self",
",",
"name",
")",
":",
"if",
"isinstance",
"(",
"name",
",",
"QName",
")",
":",
"return",
"name",
"if",
"not",
"isinstance",
"(",
"name",
",",
"str",
")",
":",
"raise",
"TypeError",
"(",
"\"{} must be str\"",
".",
"format"... | 07154f4dec007e2e9c0c6a8c07b964fd06bc5f77 |
train | PdfMetadata._prefix_from_uri | Given a fully qualified XML name, find a prefix
e.g. {http://ns.adobe.com/pdf/1.3/}Producer -> pdf:Producer | src/pikepdf/models/metadata.py | def _prefix_from_uri(self, uriname):
"""Given a fully qualified XML name, find a prefix
e.g. {http://ns.adobe.com/pdf/1.3/}Producer -> pdf:Producer
"""
uripart, tag = uriname.split('}', maxsplit=1)
uri = uripart.replace('{', '')
return self.REVERSE_NS[uri] + ':' + tag | def _prefix_from_uri(self, uriname):
"""Given a fully qualified XML name, find a prefix
e.g. {http://ns.adobe.com/pdf/1.3/}Producer -> pdf:Producer
"""
uripart, tag = uriname.split('}', maxsplit=1)
uri = uripart.replace('{', '')
return self.REVERSE_NS[uri] + ':' + tag | [
"Given",
"a",
"fully",
"qualified",
"XML",
"name",
"find",
"a",
"prefix"
] | pikepdf/pikepdf | python | https://github.com/pikepdf/pikepdf/blob/07154f4dec007e2e9c0c6a8c07b964fd06bc5f77/src/pikepdf/models/metadata.py#L409-L416 | [
"def",
"_prefix_from_uri",
"(",
"self",
",",
"uriname",
")",
":",
"uripart",
",",
"tag",
"=",
"uriname",
".",
"split",
"(",
"'}'",
",",
"maxsplit",
"=",
"1",
")",
"uri",
"=",
"uripart",
".",
"replace",
"(",
"'{'",
",",
"''",
")",
"return",
"self",
... | 07154f4dec007e2e9c0c6a8c07b964fd06bc5f77 |
train | PdfMetadata._get_subelements | Gather the sub-elements attached to a node
Gather rdf:Bag and and rdf:Seq into set and list respectively. For
alternate languages values, take the first language only for
simplicity. | src/pikepdf/models/metadata.py | def _get_subelements(self, node):
"""Gather the sub-elements attached to a node
Gather rdf:Bag and and rdf:Seq into set and list respectively. For
alternate languages values, take the first language only for
simplicity.
"""
items = node.find('rdf:Alt', self.NS)
i... | def _get_subelements(self, node):
"""Gather the sub-elements attached to a node
Gather rdf:Bag and and rdf:Seq into set and list respectively. For
alternate languages values, take the first language only for
simplicity.
"""
items = node.find('rdf:Alt', self.NS)
i... | [
"Gather",
"the",
"sub",
"-",
"elements",
"attached",
"to",
"a",
"node"
] | pikepdf/pikepdf | python | https://github.com/pikepdf/pikepdf/blob/07154f4dec007e2e9c0c6a8c07b964fd06bc5f77/src/pikepdf/models/metadata.py#L418-L440 | [
"def",
"_get_subelements",
"(",
"self",
",",
"node",
")",
":",
"items",
"=",
"node",
".",
"find",
"(",
"'rdf:Alt'",
",",
"self",
".",
"NS",
")",
"if",
"items",
"is",
"not",
"None",
":",
"try",
":",
"return",
"items",
"[",
"0",
"]",
".",
"text",
"... | 07154f4dec007e2e9c0c6a8c07b964fd06bc5f77 |
train | PdfMetadata._get_elements | Get elements from XMP
Core routine to find elements matching name within the XMP and yield
them.
For XMP spec 7.9.2.2, rdf:Description with property attributes,
we yield the node which will have the desired as one of its attributes.
qname is returned so that the node.attrib can... | src/pikepdf/models/metadata.py | def _get_elements(self, name=''):
"""Get elements from XMP
Core routine to find elements matching name within the XMP and yield
them.
For XMP spec 7.9.2.2, rdf:Description with property attributes,
we yield the node which will have the desired as one of its attributes.
... | def _get_elements(self, name=''):
"""Get elements from XMP
Core routine to find elements matching name within the XMP and yield
them.
For XMP spec 7.9.2.2, rdf:Description with property attributes,
we yield the node which will have the desired as one of its attributes.
... | [
"Get",
"elements",
"from",
"XMP"
] | pikepdf/pikepdf | python | https://github.com/pikepdf/pikepdf/blob/07154f4dec007e2e9c0c6a8c07b964fd06bc5f77/src/pikepdf/models/metadata.py#L450-L488 | [
"def",
"_get_elements",
"(",
"self",
",",
"name",
"=",
"''",
")",
":",
"qname",
"=",
"self",
".",
"_qname",
"(",
"name",
")",
"rdf",
"=",
"self",
".",
"_get_rdf_root",
"(",
")",
"for",
"rdfdesc",
"in",
"rdf",
".",
"findall",
"(",
"'rdf:Description[@rdf... | 07154f4dec007e2e9c0c6a8c07b964fd06bc5f77 |
train | PdfMetadata.pdfa_status | Returns the PDF/A conformance level claimed by this PDF, or False
A PDF may claim to PDF/A compliant without this being true. Use an
independent verifier such as veraPDF to test if a PDF is truly
conformant.
Returns:
str: The conformance level of the PDF/A, or an empty stri... | src/pikepdf/models/metadata.py | def pdfa_status(self):
"""Returns the PDF/A conformance level claimed by this PDF, or False
A PDF may claim to PDF/A compliant without this being true. Use an
independent verifier such as veraPDF to test if a PDF is truly
conformant.
Returns:
str: The conformance le... | def pdfa_status(self):
"""Returns the PDF/A conformance level claimed by this PDF, or False
A PDF may claim to PDF/A compliant without this being true. Use an
independent verifier such as veraPDF to test if a PDF is truly
conformant.
Returns:
str: The conformance le... | [
"Returns",
"the",
"PDF",
"/",
"A",
"conformance",
"level",
"claimed",
"by",
"this",
"PDF",
"or",
"False"
] | pikepdf/pikepdf | python | https://github.com/pikepdf/pikepdf/blob/07154f4dec007e2e9c0c6a8c07b964fd06bc5f77/src/pikepdf/models/metadata.py#L607-L624 | [
"def",
"pdfa_status",
"(",
"self",
")",
":",
"key_part",
"=",
"QName",
"(",
"XMP_NS_PDFA_ID",
",",
"'part'",
")",
"key_conformance",
"=",
"QName",
"(",
"XMP_NS_PDFA_ID",
",",
"'conformance'",
")",
"try",
":",
"return",
"self",
"[",
"key_part",
"]",
"+",
"s... | 07154f4dec007e2e9c0c6a8c07b964fd06bc5f77 |
train | PdfImageBase.colorspace | PDF name of the colorspace that best describes this image | src/pikepdf/models/image.py | def colorspace(self):
"""PDF name of the colorspace that best describes this image"""
if self.image_mask:
return None # Undefined for image masks
if self._colorspaces:
if self._colorspaces[0] in self.SIMPLE_COLORSPACES:
return self._colorspaces[0]
... | def colorspace(self):
"""PDF name of the colorspace that best describes this image"""
if self.image_mask:
return None # Undefined for image masks
if self._colorspaces:
if self._colorspaces[0] in self.SIMPLE_COLORSPACES:
return self._colorspaces[0]
... | [
"PDF",
"name",
"of",
"the",
"colorspace",
"that",
"best",
"describes",
"this",
"image"
] | pikepdf/pikepdf | python | https://github.com/pikepdf/pikepdf/blob/07154f4dec007e2e9c0c6a8c07b964fd06bc5f77/src/pikepdf/models/image.py#L110-L129 | [
"def",
"colorspace",
"(",
"self",
")",
":",
"if",
"self",
".",
"image_mask",
":",
"return",
"None",
"# Undefined for image masks",
"if",
"self",
".",
"_colorspaces",
":",
"if",
"self",
".",
"_colorspaces",
"[",
"0",
"]",
"in",
"self",
".",
"SIMPLE_COLORSPACE... | 07154f4dec007e2e9c0c6a8c07b964fd06bc5f77 |
train | PdfImageBase.mode | ``PIL.Image.mode`` equivalent for this image | src/pikepdf/models/image.py | def mode(self):
"""``PIL.Image.mode`` equivalent for this image"""
m = ''
if self.indexed:
m = 'P'
elif self.bits_per_component == 1:
m = '1'
elif self.bits_per_component == 8:
if self.colorspace == '/DeviceRGB':
m = 'RGB'
... | def mode(self):
"""``PIL.Image.mode`` equivalent for this image"""
m = ''
if self.indexed:
m = 'P'
elif self.bits_per_component == 1:
m = '1'
elif self.bits_per_component == 8:
if self.colorspace == '/DeviceRGB':
m = 'RGB'
... | [
"PIL",
".",
"Image",
".",
"mode",
"equivalent",
"for",
"this",
"image"
] | pikepdf/pikepdf | python | https://github.com/pikepdf/pikepdf/blob/07154f4dec007e2e9c0c6a8c07b964fd06bc5f77/src/pikepdf/models/image.py#L154-L170 | [
"def",
"mode",
"(",
"self",
")",
":",
"m",
"=",
"''",
"if",
"self",
".",
"indexed",
":",
"m",
"=",
"'P'",
"elif",
"self",
".",
"bits_per_component",
"==",
"1",
":",
"m",
"=",
"'1'",
"elif",
"self",
".",
"bits_per_component",
"==",
"8",
":",
"if",
... | 07154f4dec007e2e9c0c6a8c07b964fd06bc5f77 |
train | PdfImageBase.palette | Retrieves the color palette for this image
:returns: (base_colorspace: str, palette: bytes)
:rtype: tuple | src/pikepdf/models/image.py | def palette(self):
"""Retrieves the color palette for this image
:returns: (base_colorspace: str, palette: bytes)
:rtype: tuple
"""
if not self.indexed:
return None
_idx, base, hival, lookup = None, None, None, None
try:
_idx, base, hival... | def palette(self):
"""Retrieves the color palette for this image
:returns: (base_colorspace: str, palette: bytes)
:rtype: tuple
"""
if not self.indexed:
return None
_idx, base, hival, lookup = None, None, None, None
try:
_idx, base, hival... | [
"Retrieves",
"the",
"color",
"palette",
"for",
"this",
"image"
] | pikepdf/pikepdf | python | https://github.com/pikepdf/pikepdf/blob/07154f4dec007e2e9c0c6a8c07b964fd06bc5f77/src/pikepdf/models/image.py#L188-L211 | [
"def",
"palette",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"indexed",
":",
"return",
"None",
"_idx",
",",
"base",
",",
"hival",
",",
"lookup",
"=",
"None",
",",
"None",
",",
"None",
",",
"None",
"try",
":",
"_idx",
",",
"base",
",",
"hiva... | 07154f4dec007e2e9c0c6a8c07b964fd06bc5f77 |
train | PdfImage._from_pil_image | Insert a PIL image into a PDF (rudimentary)
:param pdf: the PDF to attach the image to
:type pdf: pikepdf.Pdf
:param page: the page to attach the image to
:param name: the name to set the image
:param image: image
:type image: PIL.Image.Image | src/pikepdf/models/image.py | def _from_pil_image(cls, *, pdf, page, name, image): # pragma: no cover
"""Insert a PIL image into a PDF (rudimentary)
:param pdf: the PDF to attach the image to
:type pdf: pikepdf.Pdf
:param page: the page to attach the image to
:param name: the name to set the image
:... | def _from_pil_image(cls, *, pdf, page, name, image): # pragma: no cover
"""Insert a PIL image into a PDF (rudimentary)
:param pdf: the PDF to attach the image to
:type pdf: pikepdf.Pdf
:param page: the page to attach the image to
:param name: the name to set the image
:... | [
"Insert",
"a",
"PIL",
"image",
"into",
"a",
"PDF",
"(",
"rudimentary",
")"
] | pikepdf/pikepdf | python | https://github.com/pikepdf/pikepdf/blob/07154f4dec007e2e9c0c6a8c07b964fd06bc5f77/src/pikepdf/models/image.py#L250-L276 | [
"def",
"_from_pil_image",
"(",
"cls",
",",
"*",
",",
"pdf",
",",
"page",
",",
"name",
",",
"image",
")",
":",
"# pragma: no cover",
"data",
"=",
"image",
".",
"tobytes",
"(",
")",
"imstream",
"=",
"Stream",
"(",
"pdf",
",",
"data",
")",
"imstream",
"... | 07154f4dec007e2e9c0c6a8c07b964fd06bc5f77 |
train | PdfImage._extract_direct | Attempt to extract the image directly to a usable image file
If there is no way to extract the image without decompressing or
transcoding then raise an exception. The type and format of image
generated will vary.
Args:
stream: Writable stream to write data to | src/pikepdf/models/image.py | def _extract_direct(self, *, stream):
"""Attempt to extract the image directly to a usable image file
If there is no way to extract the image without decompressing or
transcoding then raise an exception. The type and format of image
generated will vary.
Args:
stream... | def _extract_direct(self, *, stream):
"""Attempt to extract the image directly to a usable image file
If there is no way to extract the image without decompressing or
transcoding then raise an exception. The type and format of image
generated will vary.
Args:
stream... | [
"Attempt",
"to",
"extract",
"the",
"image",
"directly",
"to",
"a",
"usable",
"image",
"file"
] | pikepdf/pikepdf | python | https://github.com/pikepdf/pikepdf/blob/07154f4dec007e2e9c0c6a8c07b964fd06bc5f77/src/pikepdf/models/image.py#L286-L326 | [
"def",
"_extract_direct",
"(",
"self",
",",
"*",
",",
"stream",
")",
":",
"def",
"normal_dct_rgb",
"(",
")",
":",
"# Normal DCTDecode RGB images have the default value of",
"# /ColorTransform 1 and are actually in YUV. Such a file can be",
"# saved as a standard JPEG. RGB JPEGs wit... | 07154f4dec007e2e9c0c6a8c07b964fd06bc5f77 |
train | PdfImage._extract_to_stream | Attempt to extract the image directly to a usable image file
If possible, the compressed data is extracted and inserted into
a compressed image file format without transcoding the compressed
content. If this is not possible, the data will be decompressed
and extracted to an appropriate ... | src/pikepdf/models/image.py | def _extract_to_stream(self, *, stream):
"""Attempt to extract the image directly to a usable image file
If possible, the compressed data is extracted and inserted into
a compressed image file format without transcoding the compressed
content. If this is not possible, the data will be d... | def _extract_to_stream(self, *, stream):
"""Attempt to extract the image directly to a usable image file
If possible, the compressed data is extracted and inserted into
a compressed image file format without transcoding the compressed
content. If this is not possible, the data will be d... | [
"Attempt",
"to",
"extract",
"the",
"image",
"directly",
"to",
"a",
"usable",
"image",
"file"
] | pikepdf/pikepdf | python | https://github.com/pikepdf/pikepdf/blob/07154f4dec007e2e9c0c6a8c07b964fd06bc5f77/src/pikepdf/models/image.py#L362-L392 | [
"def",
"_extract_to_stream",
"(",
"self",
",",
"*",
",",
"stream",
")",
":",
"try",
":",
"return",
"self",
".",
"_extract_direct",
"(",
"stream",
"=",
"stream",
")",
"except",
"UnsupportedImageTypeError",
":",
"pass",
"im",
"=",
"self",
".",
"_extract_transc... | 07154f4dec007e2e9c0c6a8c07b964fd06bc5f77 |
train | PdfImage.extract_to | Attempt to extract the image directly to a usable image file
If possible, the compressed data is extracted and inserted into
a compressed image file format without transcoding the compressed
content. If this is not possible, the data will be decompressed
and extracted to an appropriate ... | src/pikepdf/models/image.py | def extract_to(self, *, stream=None, fileprefix=''):
"""Attempt to extract the image directly to a usable image file
If possible, the compressed data is extracted and inserted into
a compressed image file format without transcoding the compressed
content. If this is not possible, the da... | def extract_to(self, *, stream=None, fileprefix=''):
"""Attempt to extract the image directly to a usable image file
If possible, the compressed data is extracted and inserted into
a compressed image file format without transcoding the compressed
content. If this is not possible, the da... | [
"Attempt",
"to",
"extract",
"the",
"image",
"directly",
"to",
"a",
"usable",
"image",
"file"
] | pikepdf/pikepdf | python | https://github.com/pikepdf/pikepdf/blob/07154f4dec007e2e9c0c6a8c07b964fd06bc5f77/src/pikepdf/models/image.py#L394-L437 | [
"def",
"extract_to",
"(",
"self",
",",
"*",
",",
"stream",
"=",
"None",
",",
"fileprefix",
"=",
"''",
")",
":",
"if",
"bool",
"(",
"stream",
")",
"==",
"bool",
"(",
"fileprefix",
")",
":",
"raise",
"ValueError",
"(",
"\"Cannot set both stream and fileprefi... | 07154f4dec007e2e9c0c6a8c07b964fd06bc5f77 |
train | PdfImage.as_pil_image | Extract the image as a Pillow Image, using decompression as necessary
Returns:
PIL.Image.Image | src/pikepdf/models/image.py | def as_pil_image(self):
"""Extract the image as a Pillow Image, using decompression as necessary
Returns:
PIL.Image.Image
"""
from PIL import Image
try:
bio = BytesIO()
self._extract_direct(stream=bio)
bio.seek(0)
retu... | def as_pil_image(self):
"""Extract the image as a Pillow Image, using decompression as necessary
Returns:
PIL.Image.Image
"""
from PIL import Image
try:
bio = BytesIO()
self._extract_direct(stream=bio)
bio.seek(0)
retu... | [
"Extract",
"the",
"image",
"as",
"a",
"Pillow",
"Image",
"using",
"decompression",
"as",
"necessary"
] | pikepdf/pikepdf | python | https://github.com/pikepdf/pikepdf/blob/07154f4dec007e2e9c0c6a8c07b964fd06bc5f77/src/pikepdf/models/image.py#L447-L467 | [
"def",
"as_pil_image",
"(",
"self",
")",
":",
"from",
"PIL",
"import",
"Image",
"try",
":",
"bio",
"=",
"BytesIO",
"(",
")",
"self",
".",
"_extract_direct",
"(",
"stream",
"=",
"bio",
")",
"bio",
".",
"seek",
"(",
"0",
")",
"return",
"Image",
".",
... | 07154f4dec007e2e9c0c6a8c07b964fd06bc5f77 |
train | PdfImage._generate_ccitt_header | Construct a CCITT G3 or G4 header from the PDF metadata | src/pikepdf/models/image.py | def _generate_ccitt_header(self, data):
"""Construct a CCITT G3 or G4 header from the PDF metadata"""
# https://stackoverflow.com/questions/2641770/
# https://www.itu.int/itudoc/itu-t/com16/tiff-fx/docs/tiff6.pdf
if not self.decode_parms:
raise ValueError("/CCITTFaxDecode wi... | def _generate_ccitt_header(self, data):
"""Construct a CCITT G3 or G4 header from the PDF metadata"""
# https://stackoverflow.com/questions/2641770/
# https://www.itu.int/itudoc/itu-t/com16/tiff-fx/docs/tiff6.pdf
if not self.decode_parms:
raise ValueError("/CCITTFaxDecode wi... | [
"Construct",
"a",
"CCITT",
"G3",
"or",
"G4",
"header",
"from",
"the",
"PDF",
"metadata"
] | pikepdf/pikepdf | python | https://github.com/pikepdf/pikepdf/blob/07154f4dec007e2e9c0c6a8c07b964fd06bc5f77/src/pikepdf/models/image.py#L469-L504 | [
"def",
"_generate_ccitt_header",
"(",
"self",
",",
"data",
")",
":",
"# https://stackoverflow.com/questions/2641770/",
"# https://www.itu.int/itudoc/itu-t/com16/tiff-fx/docs/tiff6.pdf",
"if",
"not",
"self",
".",
"decode_parms",
":",
"raise",
"ValueError",
"(",
"\"/CCITTFaxDecod... | 07154f4dec007e2e9c0c6a8c07b964fd06bc5f77 |
train | PdfImage._repr_png_ | Display hook for IPython/Jupyter | src/pikepdf/models/image.py | def _repr_png_(self):
"""Display hook for IPython/Jupyter"""
b = BytesIO()
im = self.as_pil_image()
im.save(b, 'PNG')
return b.getvalue() | def _repr_png_(self):
"""Display hook for IPython/Jupyter"""
b = BytesIO()
im = self.as_pil_image()
im.save(b, 'PNG')
return b.getvalue() | [
"Display",
"hook",
"for",
"IPython",
"/",
"Jupyter"
] | pikepdf/pikepdf | python | https://github.com/pikepdf/pikepdf/blob/07154f4dec007e2e9c0c6a8c07b964fd06bc5f77/src/pikepdf/models/image.py#L515-L520 | [
"def",
"_repr_png_",
"(",
"self",
")",
":",
"b",
"=",
"BytesIO",
"(",
")",
"im",
"=",
"self",
".",
"as_pil_image",
"(",
")",
"im",
".",
"save",
"(",
"b",
",",
"'PNG'",
")",
"return",
"b",
".",
"getvalue",
"(",
")"
] | 07154f4dec007e2e9c0c6a8c07b964fd06bc5f77 |
train | augments | Attach methods of a Python support class to an existing class
This monkeypatches all methods defined in the support class onto an
existing class. Example:
.. code-block:: python
@augments(ClassDefinedInCpp)
class SupportClass:
def foo(self):
pass
The Pytho... | src/pikepdf/_methods.py | def augments(cls_cpp):
"""Attach methods of a Python support class to an existing class
This monkeypatches all methods defined in the support class onto an
existing class. Example:
.. code-block:: python
@augments(ClassDefinedInCpp)
class SupportClass:
def foo(self):
... | def augments(cls_cpp):
"""Attach methods of a Python support class to an existing class
This monkeypatches all methods defined in the support class onto an
existing class. Example:
.. code-block:: python
@augments(ClassDefinedInCpp)
class SupportClass:
def foo(self):
... | [
"Attach",
"methods",
"of",
"a",
"Python",
"support",
"class",
"to",
"an",
"existing",
"class"
] | pikepdf/pikepdf | python | https://github.com/pikepdf/pikepdf/blob/07154f4dec007e2e9c0c6a8c07b964fd06bc5f77/src/pikepdf/_methods.py#L28-L73 | [
"def",
"augments",
"(",
"cls_cpp",
")",
":",
"def",
"class_augment",
"(",
"cls",
",",
"cls_cpp",
"=",
"cls_cpp",
")",
":",
"for",
"name",
",",
"fn",
"in",
"inspect",
".",
"getmembers",
"(",
"cls",
",",
"inspect",
".",
"isfunction",
")",
":",
"fn",
".... | 07154f4dec007e2e9c0c6a8c07b964fd06bc5f77 |
train | _single_page_pdf | Construct a single page PDF from the provided page in memory | src/pikepdf/_methods.py | def _single_page_pdf(page):
"""Construct a single page PDF from the provided page in memory"""
pdf = Pdf.new()
pdf.pages.append(page)
bio = BytesIO()
pdf.save(bio)
bio.seek(0)
return bio.read() | def _single_page_pdf(page):
"""Construct a single page PDF from the provided page in memory"""
pdf = Pdf.new()
pdf.pages.append(page)
bio = BytesIO()
pdf.save(bio)
bio.seek(0)
return bio.read() | [
"Construct",
"a",
"single",
"page",
"PDF",
"from",
"the",
"provided",
"page",
"in",
"memory"
] | pikepdf/pikepdf | python | https://github.com/pikepdf/pikepdf/blob/07154f4dec007e2e9c0c6a8c07b964fd06bc5f77/src/pikepdf/_methods.py#L76-L83 | [
"def",
"_single_page_pdf",
"(",
"page",
")",
":",
"pdf",
"=",
"Pdf",
".",
"new",
"(",
")",
"pdf",
".",
"pages",
".",
"append",
"(",
"page",
")",
"bio",
"=",
"BytesIO",
"(",
")",
"pdf",
".",
"save",
"(",
"bio",
")",
"bio",
".",
"seek",
"(",
"0",... | 07154f4dec007e2e9c0c6a8c07b964fd06bc5f77 |
train | _mudraw | Use mupdf draw to rasterize the PDF in the memory buffer | src/pikepdf/_methods.py | def _mudraw(buffer, fmt):
"""Use mupdf draw to rasterize the PDF in the memory buffer"""
with NamedTemporaryFile(suffix='.pdf') as tmp_in:
tmp_in.write(buffer)
tmp_in.seek(0)
tmp_in.flush()
proc = run(
['mudraw', '-F', fmt, '-o', '-', tmp_in.name], stdout=PIPE, stder... | def _mudraw(buffer, fmt):
"""Use mupdf draw to rasterize the PDF in the memory buffer"""
with NamedTemporaryFile(suffix='.pdf') as tmp_in:
tmp_in.write(buffer)
tmp_in.seek(0)
tmp_in.flush()
proc = run(
['mudraw', '-F', fmt, '-o', '-', tmp_in.name], stdout=PIPE, stder... | [
"Use",
"mupdf",
"draw",
"to",
"rasterize",
"the",
"PDF",
"in",
"the",
"memory",
"buffer"
] | pikepdf/pikepdf | python | https://github.com/pikepdf/pikepdf/blob/07154f4dec007e2e9c0c6a8c07b964fd06bc5f77/src/pikepdf/_methods.py#L86-L98 | [
"def",
"_mudraw",
"(",
"buffer",
",",
"fmt",
")",
":",
"with",
"NamedTemporaryFile",
"(",
"suffix",
"=",
"'.pdf'",
")",
"as",
"tmp_in",
":",
"tmp_in",
".",
"write",
"(",
"buffer",
")",
"tmp_in",
".",
"seek",
"(",
"0",
")",
"tmp_in",
".",
"flush",
"("... | 07154f4dec007e2e9c0c6a8c07b964fd06bc5f77 |
train | PdfMatrix.rotated | Concatenates a rotation matrix on this matrix | src/pikepdf/models/matrix.py | def rotated(self, angle_degrees_ccw):
"""Concatenates a rotation matrix on this matrix"""
angle = angle_degrees_ccw / 180.0 * pi
c, s = cos(angle), sin(angle)
return self @ PdfMatrix((c, s, -s, c, 0, 0)) | def rotated(self, angle_degrees_ccw):
"""Concatenates a rotation matrix on this matrix"""
angle = angle_degrees_ccw / 180.0 * pi
c, s = cos(angle), sin(angle)
return self @ PdfMatrix((c, s, -s, c, 0, 0)) | [
"Concatenates",
"a",
"rotation",
"matrix",
"on",
"this",
"matrix"
] | pikepdf/pikepdf | python | https://github.com/pikepdf/pikepdf/blob/07154f4dec007e2e9c0c6a8c07b964fd06bc5f77/src/pikepdf/models/matrix.py#L85-L89 | [
"def",
"rotated",
"(",
"self",
",",
"angle_degrees_ccw",
")",
":",
"angle",
"=",
"angle_degrees_ccw",
"/",
"180.0",
"*",
"pi",
"c",
",",
"s",
"=",
"cos",
"(",
"angle",
")",
",",
"sin",
"(",
"angle",
")",
"return",
"self",
"@",
"PdfMatrix",
"(",
"(",
... | 07154f4dec007e2e9c0c6a8c07b964fd06bc5f77 |
train | PdfMatrix.shorthand | Return the 6-tuple (a,b,c,d,e,f) that describes this matrix | src/pikepdf/models/matrix.py | def shorthand(self):
"""Return the 6-tuple (a,b,c,d,e,f) that describes this matrix"""
return (self.a, self.b, self.c, self.d, self.e, self.f) | def shorthand(self):
"""Return the 6-tuple (a,b,c,d,e,f) that describes this matrix"""
return (self.a, self.b, self.c, self.d, self.e, self.f) | [
"Return",
"the",
"6",
"-",
"tuple",
"(",
"a",
"b",
"c",
"d",
"e",
"f",
")",
"that",
"describes",
"this",
"matrix"
] | pikepdf/pikepdf | python | https://github.com/pikepdf/pikepdf/blob/07154f4dec007e2e9c0c6a8c07b964fd06bc5f77/src/pikepdf/models/matrix.py#L96-L98 | [
"def",
"shorthand",
"(",
"self",
")",
":",
"return",
"(",
"self",
".",
"a",
",",
"self",
".",
"b",
",",
"self",
".",
"c",
",",
"self",
".",
"d",
",",
"self",
".",
"e",
",",
"self",
".",
"f",
")"
] | 07154f4dec007e2e9c0c6a8c07b964fd06bc5f77 |
train | PdfMatrix.encode | Encode this matrix in binary suitable for including in a PDF | src/pikepdf/models/matrix.py | def encode(self):
"""Encode this matrix in binary suitable for including in a PDF"""
return '{:.6f} {:.6f} {:.6f} {:.6f} {:.6f} {:.6f}'.format(
self.a, self.b, self.c, self.d, self.e, self.f
).encode() | def encode(self):
"""Encode this matrix in binary suitable for including in a PDF"""
return '{:.6f} {:.6f} {:.6f} {:.6f} {:.6f} {:.6f}'.format(
self.a, self.b, self.c, self.d, self.e, self.f
).encode() | [
"Encode",
"this",
"matrix",
"in",
"binary",
"suitable",
"for",
"including",
"in",
"a",
"PDF"
] | pikepdf/pikepdf | python | https://github.com/pikepdf/pikepdf/blob/07154f4dec007e2e9c0c6a8c07b964fd06bc5f77/src/pikepdf/models/matrix.py#L124-L128 | [
"def",
"encode",
"(",
"self",
")",
":",
"return",
"'{:.6f} {:.6f} {:.6f} {:.6f} {:.6f} {:.6f}'",
".",
"format",
"(",
"self",
".",
"a",
",",
"self",
".",
"b",
",",
"self",
".",
"c",
",",
"self",
".",
"d",
",",
"self",
".",
"e",
",",
"self",
".",
"f",
... | 07154f4dec007e2e9c0c6a8c07b964fd06bc5f77 |
train | parse_content_stream | Parse a PDF content stream into a sequence of instructions.
A PDF content stream is list of instructions that describe where to render
the text and graphics in a PDF. This is the starting point for analyzing
PDFs.
If the input is a page and page.Contents is an array, then the content
stream is aut... | src/pikepdf/models/__init__.py | def parse_content_stream(page_or_stream, operators=''):
"""
Parse a PDF content stream into a sequence of instructions.
A PDF content stream is list of instructions that describe where to render
the text and graphics in a PDF. This is the starting point for analyzing
PDFs.
If the input is a pa... | def parse_content_stream(page_or_stream, operators=''):
"""
Parse a PDF content stream into a sequence of instructions.
A PDF content stream is list of instructions that describe where to render
the text and graphics in a PDF. This is the starting point for analyzing
PDFs.
If the input is a pa... | [
"Parse",
"a",
"PDF",
"content",
"stream",
"into",
"a",
"sequence",
"of",
"instructions",
"."
] | pikepdf/pikepdf | python | https://github.com/pikepdf/pikepdf/blob/07154f4dec007e2e9c0c6a8c07b964fd06bc5f77/src/pikepdf/models/__init__.py#L14-L73 | [
"def",
"parse_content_stream",
"(",
"page_or_stream",
",",
"operators",
"=",
"''",
")",
":",
"if",
"not",
"isinstance",
"(",
"page_or_stream",
",",
"Object",
")",
":",
"raise",
"TypeError",
"(",
"\"stream must a PDF object\"",
")",
"if",
"(",
"page_or_stream",
"... | 07154f4dec007e2e9c0c6a8c07b964fd06bc5f77 |
train | _Page.has_text | Check if this page print text
Search the content stream for any of the four text showing operators.
We ignore text positioning operators because some editors might
generate maintain these even if text is deleted etc.
This cannot detect raster text (text in a bitmap), text rendered as
... | src/pikepdf/models/__init__.py | def has_text(self):
"""Check if this page print text
Search the content stream for any of the four text showing operators.
We ignore text positioning operators because some editors might
generate maintain these even if text is deleted etc.
This cannot detect raster text (text i... | def has_text(self):
"""Check if this page print text
Search the content stream for any of the four text showing operators.
We ignore text positioning operators because some editors might
generate maintain these even if text is deleted etc.
This cannot detect raster text (text i... | [
"Check",
"if",
"this",
"page",
"print",
"text"
] | pikepdf/pikepdf | python | https://github.com/pikepdf/pikepdf/blob/07154f4dec007e2e9c0c6a8c07b964fd06bc5f77/src/pikepdf/models/__init__.py#L98-L114 | [
"def",
"has_text",
"(",
"self",
")",
":",
"text_showing_operators",
"=",
"\"\"\"TJ \" ' Tj\"\"\"",
"text_showing_insts",
"=",
"parse_content_stream",
"(",
"self",
".",
"obj",
",",
"text_showing_operators",
")",
"if",
"len",
"(",
"text_showing_insts",
")",
">",
"0",
... | 07154f4dec007e2e9c0c6a8c07b964fd06bc5f77 |
train | _group_matching | Groups Tokens that have beginning and end. | sqlparse/engine/grouping.py | def _group_matching(tlist, cls):
"""Groups Tokens that have beginning and end."""
opens = []
tidx_offset = 0
for idx, token in enumerate(list(tlist)):
tidx = idx - tidx_offset
if token.is_whitespace:
# ~50% of tokens will be whitespace. Will checking early
# for ... | def _group_matching(tlist, cls):
"""Groups Tokens that have beginning and end."""
opens = []
tidx_offset = 0
for idx, token in enumerate(list(tlist)):
tidx = idx - tidx_offset
if token.is_whitespace:
# ~50% of tokens will be whitespace. Will checking early
# for ... | [
"Groups",
"Tokens",
"that",
"have",
"beginning",
"and",
"end",
"."
] | andialbrecht/sqlparse | python | https://github.com/andialbrecht/sqlparse/blob/913b56e34edc7e3025feea4744dbd762774805c3/sqlparse/engine/grouping.py#L18-L50 | [
"def",
"_group_matching",
"(",
"tlist",
",",
"cls",
")",
":",
"opens",
"=",
"[",
"]",
"tidx_offset",
"=",
"0",
"for",
"idx",
",",
"token",
"in",
"enumerate",
"(",
"list",
"(",
"tlist",
")",
")",
":",
"tidx",
"=",
"idx",
"-",
"tidx_offset",
"if",
"t... | 913b56e34edc7e3025feea4744dbd762774805c3 |
train | group_order | Group together Identifier and Asc/Desc token | sqlparse/engine/grouping.py | def group_order(tlist):
"""Group together Identifier and Asc/Desc token"""
tidx, token = tlist.token_next_by(t=T.Keyword.Order)
while token:
pidx, prev_ = tlist.token_prev(tidx)
if imt(prev_, i=sql.Identifier, t=T.Number):
tlist.group_tokens(sql.Identifier, pidx, tidx)
... | def group_order(tlist):
"""Group together Identifier and Asc/Desc token"""
tidx, token = tlist.token_next_by(t=T.Keyword.Order)
while token:
pidx, prev_ = tlist.token_prev(tidx)
if imt(prev_, i=sql.Identifier, t=T.Number):
tlist.group_tokens(sql.Identifier, pidx, tidx)
... | [
"Group",
"together",
"Identifier",
"and",
"Asc",
"/",
"Desc",
"token"
] | andialbrecht/sqlparse | python | https://github.com/andialbrecht/sqlparse/blob/913b56e34edc7e3025feea4744dbd762774805c3/sqlparse/engine/grouping.py#L308-L316 | [
"def",
"group_order",
"(",
"tlist",
")",
":",
"tidx",
",",
"token",
"=",
"tlist",
".",
"token_next_by",
"(",
"t",
"=",
"T",
".",
"Keyword",
".",
"Order",
")",
"while",
"token",
":",
"pidx",
",",
"prev_",
"=",
"tlist",
".",
"token_prev",
"(",
"tidx",
... | 913b56e34edc7e3025feea4744dbd762774805c3 |
train | _group | Groups together tokens that are joined by a middle token. i.e. x < y | sqlparse/engine/grouping.py | def _group(tlist, cls, match,
valid_prev=lambda t: True,
valid_next=lambda t: True,
post=None,
extend=True,
recurse=True
):
"""Groups together tokens that are joined by a middle token. i.e. x < y"""
tidx_offset = 0
pidx, prev_ = None, None
... | def _group(tlist, cls, match,
valid_prev=lambda t: True,
valid_next=lambda t: True,
post=None,
extend=True,
recurse=True
):
"""Groups together tokens that are joined by a middle token. i.e. x < y"""
tidx_offset = 0
pidx, prev_ = None, None
... | [
"Groups",
"together",
"tokens",
"that",
"are",
"joined",
"by",
"a",
"middle",
"token",
".",
"i",
".",
"e",
".",
"x",
"<",
"y"
] | andialbrecht/sqlparse | python | https://github.com/andialbrecht/sqlparse/blob/913b56e34edc7e3025feea4744dbd762774805c3/sqlparse/engine/grouping.py#L375-L405 | [
"def",
"_group",
"(",
"tlist",
",",
"cls",
",",
"match",
",",
"valid_prev",
"=",
"lambda",
"t",
":",
"True",
",",
"valid_next",
"=",
"lambda",
"t",
":",
"True",
",",
"post",
"=",
"None",
",",
"extend",
"=",
"True",
",",
"recurse",
"=",
"True",
")",... | 913b56e34edc7e3025feea4744dbd762774805c3 |
train | StatementSplitter._reset | Set the filter attributes to its default values | sqlparse/engine/statement_splitter.py | def _reset(self):
"""Set the filter attributes to its default values"""
self._in_declare = False
self._is_create = False
self._begin_depth = 0
self.consume_ws = False
self.tokens = []
self.level = 0 | def _reset(self):
"""Set the filter attributes to its default values"""
self._in_declare = False
self._is_create = False
self._begin_depth = 0
self.consume_ws = False
self.tokens = []
self.level = 0 | [
"Set",
"the",
"filter",
"attributes",
"to",
"its",
"default",
"values"
] | andialbrecht/sqlparse | python | https://github.com/andialbrecht/sqlparse/blob/913b56e34edc7e3025feea4744dbd762774805c3/sqlparse/engine/statement_splitter.py#L18-L26 | [
"def",
"_reset",
"(",
"self",
")",
":",
"self",
".",
"_in_declare",
"=",
"False",
"self",
".",
"_is_create",
"=",
"False",
"self",
".",
"_begin_depth",
"=",
"0",
"self",
".",
"consume_ws",
"=",
"False",
"self",
".",
"tokens",
"=",
"[",
"]",
"self",
"... | 913b56e34edc7e3025feea4744dbd762774805c3 |
train | StatementSplitter._change_splitlevel | Get the new split level (increase, decrease or remain equal) | sqlparse/engine/statement_splitter.py | def _change_splitlevel(self, ttype, value):
"""Get the new split level (increase, decrease or remain equal)"""
# parenthesis increase/decrease a level
if ttype is T.Punctuation and value == '(':
return 1
elif ttype is T.Punctuation and value == ')':
return -1
... | def _change_splitlevel(self, ttype, value):
"""Get the new split level (increase, decrease or remain equal)"""
# parenthesis increase/decrease a level
if ttype is T.Punctuation and value == '(':
return 1
elif ttype is T.Punctuation and value == ')':
return -1
... | [
"Get",
"the",
"new",
"split",
"level",
"(",
"increase",
"decrease",
"or",
"remain",
"equal",
")"
] | andialbrecht/sqlparse | python | https://github.com/andialbrecht/sqlparse/blob/913b56e34edc7e3025feea4744dbd762774805c3/sqlparse/engine/statement_splitter.py#L28-L78 | [
"def",
"_change_splitlevel",
"(",
"self",
",",
"ttype",
",",
"value",
")",
":",
"# parenthesis increase/decrease a level",
"if",
"ttype",
"is",
"T",
".",
"Punctuation",
"and",
"value",
"==",
"'('",
":",
"return",
"1",
"elif",
"ttype",
"is",
"T",
".",
"Punctu... | 913b56e34edc7e3025feea4744dbd762774805c3 |
train | StatementSplitter.process | Process the stream | sqlparse/engine/statement_splitter.py | def process(self, stream):
"""Process the stream"""
EOS_TTYPE = T.Whitespace, T.Comment.Single
# Run over all stream tokens
for ttype, value in stream:
# Yield token if we finished a statement and there's no whitespaces
# It will count newline token as a non whit... | def process(self, stream):
"""Process the stream"""
EOS_TTYPE = T.Whitespace, T.Comment.Single
# Run over all stream tokens
for ttype, value in stream:
# Yield token if we finished a statement and there's no whitespaces
# It will count newline token as a non whit... | [
"Process",
"the",
"stream"
] | andialbrecht/sqlparse | python | https://github.com/andialbrecht/sqlparse/blob/913b56e34edc7e3025feea4744dbd762774805c3/sqlparse/engine/statement_splitter.py#L80-L108 | [
"def",
"process",
"(",
"self",
",",
"stream",
")",
":",
"EOS_TTYPE",
"=",
"T",
".",
"Whitespace",
",",
"T",
".",
"Comment",
".",
"Single",
"# Run over all stream tokens",
"for",
"ttype",
",",
"value",
"in",
"stream",
":",
"# Yield token if we finished a statemen... | 913b56e34edc7e3025feea4744dbd762774805c3 |
train | validate_options | Validates options. | sqlparse/formatter.py | def validate_options(options):
"""Validates options."""
kwcase = options.get('keyword_case')
if kwcase not in [None, 'upper', 'lower', 'capitalize']:
raise SQLParseError('Invalid value for keyword_case: '
'{0!r}'.format(kwcase))
idcase = options.get('identifier_case'... | def validate_options(options):
"""Validates options."""
kwcase = options.get('keyword_case')
if kwcase not in [None, 'upper', 'lower', 'capitalize']:
raise SQLParseError('Invalid value for keyword_case: '
'{0!r}'.format(kwcase))
idcase = options.get('identifier_case'... | [
"Validates",
"options",
"."
] | andialbrecht/sqlparse | python | https://github.com/andialbrecht/sqlparse/blob/913b56e34edc7e3025feea4744dbd762774805c3/sqlparse/formatter.py#L15-L130 | [
"def",
"validate_options",
"(",
"options",
")",
":",
"kwcase",
"=",
"options",
".",
"get",
"(",
"'keyword_case'",
")",
"if",
"kwcase",
"not",
"in",
"[",
"None",
",",
"'upper'",
",",
"'lower'",
",",
"'capitalize'",
"]",
":",
"raise",
"SQLParseError",
"(",
... | 913b56e34edc7e3025feea4744dbd762774805c3 |
train | build_filter_stack | Setup and return a filter stack.
Args:
stack: :class:`~sqlparse.filters.FilterStack` instance
options: Dictionary with options validated by validate_options. | sqlparse/formatter.py | def build_filter_stack(stack, options):
"""Setup and return a filter stack.
Args:
stack: :class:`~sqlparse.filters.FilterStack` instance
options: Dictionary with options validated by validate_options.
"""
# Token filter
if options.get('keyword_case'):
stack.preprocess.append(
... | def build_filter_stack(stack, options):
"""Setup and return a filter stack.
Args:
stack: :class:`~sqlparse.filters.FilterStack` instance
options: Dictionary with options validated by validate_options.
"""
# Token filter
if options.get('keyword_case'):
stack.preprocess.append(
... | [
"Setup",
"and",
"return",
"a",
"filter",
"stack",
"."
] | andialbrecht/sqlparse | python | https://github.com/andialbrecht/sqlparse/blob/913b56e34edc7e3025feea4744dbd762774805c3/sqlparse/formatter.py#L133-L199 | [
"def",
"build_filter_stack",
"(",
"stack",
",",
"options",
")",
":",
"# Token filter",
"if",
"options",
".",
"get",
"(",
"'keyword_case'",
")",
":",
"stack",
".",
"preprocess",
".",
"append",
"(",
"filters",
".",
"KeywordCaseFilter",
"(",
"options",
"[",
"'k... | 913b56e34edc7e3025feea4744dbd762774805c3 |
train | split_unquoted_newlines | Split a string on all unquoted newlines.
Unlike str.splitlines(), this will ignore CR/LF/CR+LF if the requisite
character is inside of a string. | sqlparse/utils.py | def split_unquoted_newlines(stmt):
"""Split a string on all unquoted newlines.
Unlike str.splitlines(), this will ignore CR/LF/CR+LF if the requisite
character is inside of a string."""
text = text_type(stmt)
lines = SPLIT_REGEX.split(text)
outputlines = ['']
for line in lines:
if n... | def split_unquoted_newlines(stmt):
"""Split a string on all unquoted newlines.
Unlike str.splitlines(), this will ignore CR/LF/CR+LF if the requisite
character is inside of a string."""
text = text_type(stmt)
lines = SPLIT_REGEX.split(text)
outputlines = ['']
for line in lines:
if n... | [
"Split",
"a",
"string",
"on",
"all",
"unquoted",
"newlines",
"."
] | andialbrecht/sqlparse | python | https://github.com/andialbrecht/sqlparse/blob/913b56e34edc7e3025feea4744dbd762774805c3/sqlparse/utils.py#L38-L53 | [
"def",
"split_unquoted_newlines",
"(",
"stmt",
")",
":",
"text",
"=",
"text_type",
"(",
"stmt",
")",
"lines",
"=",
"SPLIT_REGEX",
".",
"split",
"(",
"text",
")",
"outputlines",
"=",
"[",
"''",
"]",
"for",
"line",
"in",
"lines",
":",
"if",
"not",
"line"... | 913b56e34edc7e3025feea4744dbd762774805c3 |
train | recurse | Function decorator to help with recursion
:param cls: Classes to not recurse over
:return: function | sqlparse/utils.py | def recurse(*cls):
"""Function decorator to help with recursion
:param cls: Classes to not recurse over
:return: function
"""
def wrap(f):
def wrapped_f(tlist):
for sgroup in tlist.get_sublists():
if not isinstance(sgroup, cls):
wrapped_f(sgro... | def recurse(*cls):
"""Function decorator to help with recursion
:param cls: Classes to not recurse over
:return: function
"""
def wrap(f):
def wrapped_f(tlist):
for sgroup in tlist.get_sublists():
if not isinstance(sgroup, cls):
wrapped_f(sgro... | [
"Function",
"decorator",
"to",
"help",
"with",
"recursion"
] | andialbrecht/sqlparse | python | https://github.com/andialbrecht/sqlparse/blob/913b56e34edc7e3025feea4744dbd762774805c3/sqlparse/utils.py#L65-L80 | [
"def",
"recurse",
"(",
"*",
"cls",
")",
":",
"def",
"wrap",
"(",
"f",
")",
":",
"def",
"wrapped_f",
"(",
"tlist",
")",
":",
"for",
"sgroup",
"in",
"tlist",
".",
"get_sublists",
"(",
")",
":",
"if",
"not",
"isinstance",
"(",
"sgroup",
",",
"cls",
... | 913b56e34edc7e3025feea4744dbd762774805c3 |
train | imt | Helper function to simplify comparisons Instance, Match and TokenType
:param token:
:param i: Class or Tuple/List of Classes
:param m: Tuple of TokenType & Value. Can be list of Tuple for multiple
:param t: TokenType or Tuple/List of TokenTypes
:return: bool | sqlparse/utils.py | def imt(token, i=None, m=None, t=None):
"""Helper function to simplify comparisons Instance, Match and TokenType
:param token:
:param i: Class or Tuple/List of Classes
:param m: Tuple of TokenType & Value. Can be list of Tuple for multiple
:param t: TokenType or Tuple/List of TokenTypes
:return:... | def imt(token, i=None, m=None, t=None):
"""Helper function to simplify comparisons Instance, Match and TokenType
:param token:
:param i: Class or Tuple/List of Classes
:param m: Tuple of TokenType & Value. Can be list of Tuple for multiple
:param t: TokenType or Tuple/List of TokenTypes
:return:... | [
"Helper",
"function",
"to",
"simplify",
"comparisons",
"Instance",
"Match",
"and",
"TokenType",
":",
"param",
"token",
":",
":",
"param",
"i",
":",
"Class",
"or",
"Tuple",
"/",
"List",
"of",
"Classes",
":",
"param",
"m",
":",
"Tuple",
"of",
"TokenType",
... | andialbrecht/sqlparse | python | https://github.com/andialbrecht/sqlparse/blob/913b56e34edc7e3025feea4744dbd762774805c3/sqlparse/utils.py#L83-L104 | [
"def",
"imt",
"(",
"token",
",",
"i",
"=",
"None",
",",
"m",
"=",
"None",
",",
"t",
"=",
"None",
")",
":",
"clss",
"=",
"i",
"types",
"=",
"[",
"t",
",",
"]",
"if",
"t",
"and",
"not",
"isinstance",
"(",
"t",
",",
"list",
")",
"else",
"t",
... | 913b56e34edc7e3025feea4744dbd762774805c3 |
train | parsestream | Parses sql statements from file-like object.
:param stream: A file-like object.
:param encoding: The encoding of the stream contents (optional).
:returns: A generator of :class:`~sqlparse.sql.Statement` instances. | sqlparse/__init__.py | def parsestream(stream, encoding=None):
"""Parses sql statements from file-like object.
:param stream: A file-like object.
:param encoding: The encoding of the stream contents (optional).
:returns: A generator of :class:`~sqlparse.sql.Statement` instances.
"""
stack = engine.FilterStack()
s... | def parsestream(stream, encoding=None):
"""Parses sql statements from file-like object.
:param stream: A file-like object.
:param encoding: The encoding of the stream contents (optional).
:returns: A generator of :class:`~sqlparse.sql.Statement` instances.
"""
stack = engine.FilterStack()
s... | [
"Parses",
"sql",
"statements",
"from",
"file",
"-",
"like",
"object",
"."
] | andialbrecht/sqlparse | python | https://github.com/andialbrecht/sqlparse/blob/913b56e34edc7e3025feea4744dbd762774805c3/sqlparse/__init__.py#L35-L44 | [
"def",
"parsestream",
"(",
"stream",
",",
"encoding",
"=",
"None",
")",
":",
"stack",
"=",
"engine",
".",
"FilterStack",
"(",
")",
"stack",
".",
"enable_grouping",
"(",
")",
"return",
"stack",
".",
"run",
"(",
"stream",
",",
"encoding",
")"
] | 913b56e34edc7e3025feea4744dbd762774805c3 |
train | format | Format *sql* according to *options*.
Available options are documented in :ref:`formatting`.
In addition to the formatting options this function accepts the
keyword "encoding" which determines the encoding of the statement.
:returns: The formatted SQL statement as string. | sqlparse/__init__.py | def format(sql, encoding=None, **options):
"""Format *sql* according to *options*.
Available options are documented in :ref:`formatting`.
In addition to the formatting options this function accepts the
keyword "encoding" which determines the encoding of the statement.
:returns: The formatted SQL ... | def format(sql, encoding=None, **options):
"""Format *sql* according to *options*.
Available options are documented in :ref:`formatting`.
In addition to the formatting options this function accepts the
keyword "encoding" which determines the encoding of the statement.
:returns: The formatted SQL ... | [
"Format",
"*",
"sql",
"*",
"according",
"to",
"*",
"options",
"*",
"."
] | andialbrecht/sqlparse | python | https://github.com/andialbrecht/sqlparse/blob/913b56e34edc7e3025feea4744dbd762774805c3/sqlparse/__init__.py#L47-L61 | [
"def",
"format",
"(",
"sql",
",",
"encoding",
"=",
"None",
",",
"*",
"*",
"options",
")",
":",
"stack",
"=",
"engine",
".",
"FilterStack",
"(",
")",
"options",
"=",
"formatter",
".",
"validate_options",
"(",
"options",
")",
"stack",
"=",
"formatter",
"... | 913b56e34edc7e3025feea4744dbd762774805c3 |
train | split | Split *sql* into single statements.
:param sql: A string containing one or more SQL statements.
:param encoding: The encoding of the statement (optional).
:returns: A list of strings. | sqlparse/__init__.py | def split(sql, encoding=None):
"""Split *sql* into single statements.
:param sql: A string containing one or more SQL statements.
:param encoding: The encoding of the statement (optional).
:returns: A list of strings.
"""
stack = engine.FilterStack()
return [text_type(stmt).strip() for stmt... | def split(sql, encoding=None):
"""Split *sql* into single statements.
:param sql: A string containing one or more SQL statements.
:param encoding: The encoding of the statement (optional).
:returns: A list of strings.
"""
stack = engine.FilterStack()
return [text_type(stmt).strip() for stmt... | [
"Split",
"*",
"sql",
"*",
"into",
"single",
"statements",
"."
] | andialbrecht/sqlparse | python | https://github.com/andialbrecht/sqlparse/blob/913b56e34edc7e3025feea4744dbd762774805c3/sqlparse/__init__.py#L64-L72 | [
"def",
"split",
"(",
"sql",
",",
"encoding",
"=",
"None",
")",
":",
"stack",
"=",
"engine",
".",
"FilterStack",
"(",
")",
"return",
"[",
"text_type",
"(",
"stmt",
")",
".",
"strip",
"(",
")",
"for",
"stmt",
"in",
"stack",
".",
"run",
"(",
"sql",
... | 913b56e34edc7e3025feea4744dbd762774805c3 |
train | Lexer.get_tokens | Return an iterable of (tokentype, value) pairs generated from
`text`. If `unfiltered` is set to `True`, the filtering mechanism
is bypassed even if filters are defined.
Also preprocess the text, i.e. expand tabs and strip it if
wanted and applies registered filters.
Split ``tex... | sqlparse/lexer.py | def get_tokens(text, encoding=None):
"""
Return an iterable of (tokentype, value) pairs generated from
`text`. If `unfiltered` is set to `True`, the filtering mechanism
is bypassed even if filters are defined.
Also preprocess the text, i.e. expand tabs and strip it if
wa... | def get_tokens(text, encoding=None):
"""
Return an iterable of (tokentype, value) pairs generated from
`text`. If `unfiltered` is set to `True`, the filtering mechanism
is bypassed even if filters are defined.
Also preprocess the text, i.e. expand tabs and strip it if
wa... | [
"Return",
"an",
"iterable",
"of",
"(",
"tokentype",
"value",
")",
"pairs",
"generated",
"from",
"text",
".",
"If",
"unfiltered",
"is",
"set",
"to",
"True",
"the",
"filtering",
"mechanism",
"is",
"bypassed",
"even",
"if",
"filters",
"are",
"defined",
"."
] | andialbrecht/sqlparse | python | https://github.com/andialbrecht/sqlparse/blob/913b56e34edc7e3025feea4744dbd762774805c3/sqlparse/lexer.py#L28-L73 | [
"def",
"get_tokens",
"(",
"text",
",",
"encoding",
"=",
"None",
")",
":",
"if",
"isinstance",
"(",
"text",
",",
"file_types",
")",
":",
"text",
"=",
"text",
".",
"read",
"(",
")",
"if",
"isinstance",
"(",
"text",
",",
"text_type",
")",
":",
"pass",
... | 913b56e34edc7e3025feea4744dbd762774805c3 |
train | ReindentFilter._flatten_up_to_token | Yields all tokens up to token but excluding current. | sqlparse/filters/reindent.py | def _flatten_up_to_token(self, token):
"""Yields all tokens up to token but excluding current."""
if token.is_group:
token = next(token.flatten())
for t in self._curr_stmt.flatten():
if t == token:
break
yield t | def _flatten_up_to_token(self, token):
"""Yields all tokens up to token but excluding current."""
if token.is_group:
token = next(token.flatten())
for t in self._curr_stmt.flatten():
if t == token:
break
yield t | [
"Yields",
"all",
"tokens",
"up",
"to",
"token",
"but",
"excluding",
"current",
"."
] | andialbrecht/sqlparse | python | https://github.com/andialbrecht/sqlparse/blob/913b56e34edc7e3025feea4744dbd762774805c3/sqlparse/filters/reindent.py#L30-L38 | [
"def",
"_flatten_up_to_token",
"(",
"self",
",",
"token",
")",
":",
"if",
"token",
".",
"is_group",
":",
"token",
"=",
"next",
"(",
"token",
".",
"flatten",
"(",
")",
")",
"for",
"t",
"in",
"self",
".",
"_curr_stmt",
".",
"flatten",
"(",
")",
":",
... | 913b56e34edc7e3025feea4744dbd762774805c3 |
train | Statement.get_type | Returns the type of a statement.
The returned value is a string holding an upper-cased reprint of
the first DML or DDL keyword. If the first token in this group
isn't a DML or DDL keyword "UNKNOWN" is returned.
Whitespaces and comments at the beginning of the statement
are igno... | sqlparse/sql.py | def get_type(self):
"""Returns the type of a statement.
The returned value is a string holding an upper-cased reprint of
the first DML or DDL keyword. If the first token in this group
isn't a DML or DDL keyword "UNKNOWN" is returned.
Whitespaces and comments at the beginning of... | def get_type(self):
"""Returns the type of a statement.
The returned value is a string holding an upper-cased reprint of
the first DML or DDL keyword. If the first token in this group
isn't a DML or DDL keyword "UNKNOWN" is returned.
Whitespaces and comments at the beginning of... | [
"Returns",
"the",
"type",
"of",
"a",
"statement",
"."
] | andialbrecht/sqlparse | python | https://github.com/andialbrecht/sqlparse/blob/913b56e34edc7e3025feea4744dbd762774805c3/sqlparse/sql.py#L400-L433 | [
"def",
"get_type",
"(",
"self",
")",
":",
"first_token",
"=",
"self",
".",
"token_first",
"(",
"skip_cm",
"=",
"True",
")",
"if",
"first_token",
"is",
"None",
":",
"# An \"empty\" statement that either has not tokens at all",
"# or only whitespace tokens.",
"return",
... | 913b56e34edc7e3025feea4744dbd762774805c3 |
train | Identifier.is_wildcard | Return ``True`` if this identifier contains a wildcard. | sqlparse/sql.py | def is_wildcard(self):
"""Return ``True`` if this identifier contains a wildcard."""
_, token = self.token_next_by(t=T.Wildcard)
return token is not None | def is_wildcard(self):
"""Return ``True`` if this identifier contains a wildcard."""
_, token = self.token_next_by(t=T.Wildcard)
return token is not None | [
"Return",
"True",
"if",
"this",
"identifier",
"contains",
"a",
"wildcard",
"."
] | andialbrecht/sqlparse | python | https://github.com/andialbrecht/sqlparse/blob/913b56e34edc7e3025feea4744dbd762774805c3/sqlparse/sql.py#L442-L445 | [
"def",
"is_wildcard",
"(",
"self",
")",
":",
"_",
",",
"token",
"=",
"self",
".",
"token_next_by",
"(",
"t",
"=",
"T",
".",
"Wildcard",
")",
"return",
"token",
"is",
"not",
"None"
] | 913b56e34edc7e3025feea4744dbd762774805c3 |
train | Identifier.get_typecast | Returns the typecast or ``None`` of this object as a string. | sqlparse/sql.py | def get_typecast(self):
"""Returns the typecast or ``None`` of this object as a string."""
midx, marker = self.token_next_by(m=(T.Punctuation, '::'))
nidx, next_ = self.token_next(midx, skip_ws=False)
return next_.value if next_ else None | def get_typecast(self):
"""Returns the typecast or ``None`` of this object as a string."""
midx, marker = self.token_next_by(m=(T.Punctuation, '::'))
nidx, next_ = self.token_next(midx, skip_ws=False)
return next_.value if next_ else None | [
"Returns",
"the",
"typecast",
"or",
"None",
"of",
"this",
"object",
"as",
"a",
"string",
"."
] | andialbrecht/sqlparse | python | https://github.com/andialbrecht/sqlparse/blob/913b56e34edc7e3025feea4744dbd762774805c3/sqlparse/sql.py#L447-L451 | [
"def",
"get_typecast",
"(",
"self",
")",
":",
"midx",
",",
"marker",
"=",
"self",
".",
"token_next_by",
"(",
"m",
"=",
"(",
"T",
".",
"Punctuation",
",",
"'::'",
")",
")",
"nidx",
",",
"next_",
"=",
"self",
".",
"token_next",
"(",
"midx",
",",
"ski... | 913b56e34edc7e3025feea4744dbd762774805c3 |
train | Identifier.get_ordering | Returns the ordering or ``None`` as uppercase string. | sqlparse/sql.py | def get_ordering(self):
"""Returns the ordering or ``None`` as uppercase string."""
_, ordering = self.token_next_by(t=T.Keyword.Order)
return ordering.normalized if ordering else None | def get_ordering(self):
"""Returns the ordering or ``None`` as uppercase string."""
_, ordering = self.token_next_by(t=T.Keyword.Order)
return ordering.normalized if ordering else None | [
"Returns",
"the",
"ordering",
"or",
"None",
"as",
"uppercase",
"string",
"."
] | andialbrecht/sqlparse | python | https://github.com/andialbrecht/sqlparse/blob/913b56e34edc7e3025feea4744dbd762774805c3/sqlparse/sql.py#L453-L456 | [
"def",
"get_ordering",
"(",
"self",
")",
":",
"_",
",",
"ordering",
"=",
"self",
".",
"token_next_by",
"(",
"t",
"=",
"T",
".",
"Keyword",
".",
"Order",
")",
"return",
"ordering",
".",
"normalized",
"if",
"ordering",
"else",
"None"
] | 913b56e34edc7e3025feea4744dbd762774805c3 |
train | Identifier.get_array_indices | Returns an iterator of index token lists | sqlparse/sql.py | def get_array_indices(self):
"""Returns an iterator of index token lists"""
for token in self.tokens:
if isinstance(token, SquareBrackets):
# Use [1:-1] index to discard the square brackets
yield token.tokens[1:-1] | def get_array_indices(self):
"""Returns an iterator of index token lists"""
for token in self.tokens:
if isinstance(token, SquareBrackets):
# Use [1:-1] index to discard the square brackets
yield token.tokens[1:-1] | [
"Returns",
"an",
"iterator",
"of",
"index",
"token",
"lists"
] | andialbrecht/sqlparse | python | https://github.com/andialbrecht/sqlparse/blob/913b56e34edc7e3025feea4744dbd762774805c3/sqlparse/sql.py#L458-L464 | [
"def",
"get_array_indices",
"(",
"self",
")",
":",
"for",
"token",
"in",
"self",
".",
"tokens",
":",
"if",
"isinstance",
"(",
"token",
",",
"SquareBrackets",
")",
":",
"# Use [1:-1] index to discard the square brackets",
"yield",
"token",
".",
"tokens",
"[",
"1"... | 913b56e34edc7e3025feea4744dbd762774805c3 |
train | IdentifierList.get_identifiers | Returns the identifiers.
Whitespaces and punctuations are not included in this generator. | sqlparse/sql.py | def get_identifiers(self):
"""Returns the identifiers.
Whitespaces and punctuations are not included in this generator.
"""
for token in self.tokens:
if not (token.is_whitespace or token.match(T.Punctuation, ',')):
yield token | def get_identifiers(self):
"""Returns the identifiers.
Whitespaces and punctuations are not included in this generator.
"""
for token in self.tokens:
if not (token.is_whitespace or token.match(T.Punctuation, ',')):
yield token | [
"Returns",
"the",
"identifiers",
"."
] | andialbrecht/sqlparse | python | https://github.com/andialbrecht/sqlparse/blob/913b56e34edc7e3025feea4744dbd762774805c3/sqlparse/sql.py#L470-L477 | [
"def",
"get_identifiers",
"(",
"self",
")",
":",
"for",
"token",
"in",
"self",
".",
"tokens",
":",
"if",
"not",
"(",
"token",
".",
"is_whitespace",
"or",
"token",
".",
"match",
"(",
"T",
".",
"Punctuation",
",",
"','",
")",
")",
":",
"yield",
"token"... | 913b56e34edc7e3025feea4744dbd762774805c3 |
train | Case.get_cases | Returns a list of 2-tuples (condition, value).
If an ELSE exists condition is None. | sqlparse/sql.py | def get_cases(self, skip_ws=False):
"""Returns a list of 2-tuples (condition, value).
If an ELSE exists condition is None.
"""
CONDITION = 1
VALUE = 2
ret = []
mode = CONDITION
for token in self.tokens:
# Set mode from the current statement
... | def get_cases(self, skip_ws=False):
"""Returns a list of 2-tuples (condition, value).
If an ELSE exists condition is None.
"""
CONDITION = 1
VALUE = 2
ret = []
mode = CONDITION
for token in self.tokens:
# Set mode from the current statement
... | [
"Returns",
"a",
"list",
"of",
"2",
"-",
"tuples",
"(",
"condition",
"value",
")",
"."
] | andialbrecht/sqlparse | python | https://github.com/andialbrecht/sqlparse/blob/913b56e34edc7e3025feea4744dbd762774805c3/sqlparse/sql.py#L554-L599 | [
"def",
"get_cases",
"(",
"self",
",",
"skip_ws",
"=",
"False",
")",
":",
"CONDITION",
"=",
"1",
"VALUE",
"=",
"2",
"ret",
"=",
"[",
"]",
"mode",
"=",
"CONDITION",
"for",
"token",
"in",
"self",
".",
"tokens",
":",
"# Set mode from the current statement",
... | 913b56e34edc7e3025feea4744dbd762774805c3 |
train | Function.get_parameters | Return a list of parameters. | sqlparse/sql.py | def get_parameters(self):
"""Return a list of parameters."""
parenthesis = self.tokens[-1]
for token in parenthesis.tokens:
if isinstance(token, IdentifierList):
return token.get_identifiers()
elif imt(token, i=(Function, Identifier), t=T.Literal):
... | def get_parameters(self):
"""Return a list of parameters."""
parenthesis = self.tokens[-1]
for token in parenthesis.tokens:
if isinstance(token, IdentifierList):
return token.get_identifiers()
elif imt(token, i=(Function, Identifier), t=T.Literal):
... | [
"Return",
"a",
"list",
"of",
"parameters",
"."
] | andialbrecht/sqlparse | python | https://github.com/andialbrecht/sqlparse/blob/913b56e34edc7e3025feea4744dbd762774805c3/sqlparse/sql.py#L605-L613 | [
"def",
"get_parameters",
"(",
"self",
")",
":",
"parenthesis",
"=",
"self",
".",
"tokens",
"[",
"-",
"1",
"]",
"for",
"token",
"in",
"parenthesis",
".",
"tokens",
":",
"if",
"isinstance",
"(",
"token",
",",
"IdentifierList",
")",
":",
"return",
"token",
... | 913b56e34edc7e3025feea4744dbd762774805c3 |
train | CompositeOutputDevice.on | Turn all the output devices on. | gpiozero/boards.py | def on(self):
"""
Turn all the output devices on.
"""
for device in self:
if isinstance(device, (OutputDevice, CompositeOutputDevice)):
device.on() | def on(self):
"""
Turn all the output devices on.
"""
for device in self:
if isinstance(device, (OutputDevice, CompositeOutputDevice)):
device.on() | [
"Turn",
"all",
"the",
"output",
"devices",
"on",
"."
] | RPi-Distro/python-gpiozero | python | https://github.com/RPi-Distro/python-gpiozero/blob/7b67374fd0c8c4fde5586d9bad9531f076db9c0c/gpiozero/boards.py#L110-L116 | [
"def",
"on",
"(",
"self",
")",
":",
"for",
"device",
"in",
"self",
":",
"if",
"isinstance",
"(",
"device",
",",
"(",
"OutputDevice",
",",
"CompositeOutputDevice",
")",
")",
":",
"device",
".",
"on",
"(",
")"
] | 7b67374fd0c8c4fde5586d9bad9531f076db9c0c |
train | CompositeOutputDevice.off | Turn all the output devices off. | gpiozero/boards.py | def off(self):
"""
Turn all the output devices off.
"""
for device in self:
if isinstance(device, (OutputDevice, CompositeOutputDevice)):
device.off() | def off(self):
"""
Turn all the output devices off.
"""
for device in self:
if isinstance(device, (OutputDevice, CompositeOutputDevice)):
device.off() | [
"Turn",
"all",
"the",
"output",
"devices",
"off",
"."
] | RPi-Distro/python-gpiozero | python | https://github.com/RPi-Distro/python-gpiozero/blob/7b67374fd0c8c4fde5586d9bad9531f076db9c0c/gpiozero/boards.py#L118-L124 | [
"def",
"off",
"(",
"self",
")",
":",
"for",
"device",
"in",
"self",
":",
"if",
"isinstance",
"(",
"device",
",",
"(",
"OutputDevice",
",",
"CompositeOutputDevice",
")",
")",
":",
"device",
".",
"off",
"(",
")"
] | 7b67374fd0c8c4fde5586d9bad9531f076db9c0c |
train | CompositeOutputDevice.toggle | Toggle all the output devices. For each device, if it's on, turn it
off; if it's off, turn it on. | gpiozero/boards.py | def toggle(self):
"""
Toggle all the output devices. For each device, if it's on, turn it
off; if it's off, turn it on.
"""
for device in self:
if isinstance(device, (OutputDevice, CompositeOutputDevice)):
device.toggle() | def toggle(self):
"""
Toggle all the output devices. For each device, if it's on, turn it
off; if it's off, turn it on.
"""
for device in self:
if isinstance(device, (OutputDevice, CompositeOutputDevice)):
device.toggle() | [
"Toggle",
"all",
"the",
"output",
"devices",
".",
"For",
"each",
"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/boards.py#L126-L133 | [
"def",
"toggle",
"(",
"self",
")",
":",
"for",
"device",
"in",
"self",
":",
"if",
"isinstance",
"(",
"device",
",",
"(",
"OutputDevice",
",",
"CompositeOutputDevice",
")",
")",
":",
"device",
".",
"toggle",
"(",
")"
] | 7b67374fd0c8c4fde5586d9bad9531f076db9c0c |
train | LEDBoard.on | If no arguments are specified, turn all the LEDs on. If arguments are
specified, they must be the indexes of the LEDs you wish to turn on.
For example::
from gpiozero import LEDBoard
leds = LEDBoard(2, 3, 4, 5)
leds.on(0) # turn on the first LED (pin 2)
... | gpiozero/boards.py | def on(self, *args):
"""
If no arguments are specified, turn all the LEDs on. If arguments are
specified, they must be the indexes of the LEDs you wish to turn on.
For example::
from gpiozero import LEDBoard
leds = LEDBoard(2, 3, 4, 5)
leds.on(0) ... | def on(self, *args):
"""
If no arguments are specified, turn all the LEDs on. If arguments are
specified, they must be the indexes of the LEDs you wish to turn on.
For example::
from gpiozero import LEDBoard
leds = LEDBoard(2, 3, 4, 5)
leds.on(0) ... | [
"If",
"no",
"arguments",
"are",
"specified",
"turn",
"all",
"the",
"LEDs",
"on",
".",
"If",
"arguments",
"are",
"specified",
"they",
"must",
"be",
"the",
"indexes",
"of",
"the",
"LEDs",
"you",
"wish",
"to",
"turn",
"on",
".",
"For",
"example",
"::"
] | RPi-Distro/python-gpiozero | python | https://github.com/RPi-Distro/python-gpiozero/blob/7b67374fd0c8c4fde5586d9bad9531f076db9c0c/gpiozero/boards.py#L424-L450 | [
"def",
"on",
"(",
"self",
",",
"*",
"args",
")",
":",
"self",
".",
"_stop_blink",
"(",
")",
"if",
"args",
":",
"for",
"index",
"in",
"args",
":",
"self",
"[",
"index",
"]",
".",
"on",
"(",
")",
"else",
":",
"super",
"(",
"LEDBoard",
",",
"self"... | 7b67374fd0c8c4fde5586d9bad9531f076db9c0c |
train | LEDBoard.off | If no arguments are specified, turn all the LEDs off. If arguments are
specified, they must be the indexes of the LEDs you wish to turn off.
For example::
from gpiozero import LEDBoard
leds = LEDBoard(2, 3, 4, 5)
leds.on() # turn on all LEDs
leds.of... | gpiozero/boards.py | def off(self, *args):
"""
If no arguments are specified, turn all the LEDs off. If arguments are
specified, they must be the indexes of the LEDs you wish to turn off.
For example::
from gpiozero import LEDBoard
leds = LEDBoard(2, 3, 4, 5)
leds.on() ... | def off(self, *args):
"""
If no arguments are specified, turn all the LEDs off. If arguments are
specified, they must be the indexes of the LEDs you wish to turn off.
For example::
from gpiozero import LEDBoard
leds = LEDBoard(2, 3, 4, 5)
leds.on() ... | [
"If",
"no",
"arguments",
"are",
"specified",
"turn",
"all",
"the",
"LEDs",
"off",
".",
"If",
"arguments",
"are",
"specified",
"they",
"must",
"be",
"the",
"indexes",
"of",
"the",
"LEDs",
"you",
"wish",
"to",
"turn",
"off",
".",
"For",
"example",
"::"
] | RPi-Distro/python-gpiozero | python | https://github.com/RPi-Distro/python-gpiozero/blob/7b67374fd0c8c4fde5586d9bad9531f076db9c0c/gpiozero/boards.py#L452-L478 | [
"def",
"off",
"(",
"self",
",",
"*",
"args",
")",
":",
"self",
".",
"_stop_blink",
"(",
")",
"if",
"args",
":",
"for",
"index",
"in",
"args",
":",
"self",
"[",
"index",
"]",
".",
"off",
"(",
")",
"else",
":",
"super",
"(",
"LEDBoard",
",",
"sel... | 7b67374fd0c8c4fde5586d9bad9531f076db9c0c |
train | LEDBoard.toggle | If no arguments are specified, toggle the state of all LEDs. If
arguments are specified, they must be the indexes of the LEDs you wish
to toggle. For example::
from gpiozero import LEDBoard
leds = LEDBoard(2, 3, 4, 5)
leds.toggle(0) # turn on the first LED (pin 2)... | gpiozero/boards.py | def toggle(self, *args):
"""
If no arguments are specified, toggle the state of all LEDs. If
arguments are specified, they must be the indexes of the LEDs you wish
to toggle. For example::
from gpiozero import LEDBoard
leds = LEDBoard(2, 3, 4, 5)
led... | def toggle(self, *args):
"""
If no arguments are specified, toggle the state of all LEDs. If
arguments are specified, they must be the indexes of the LEDs you wish
to toggle. For example::
from gpiozero import LEDBoard
leds = LEDBoard(2, 3, 4, 5)
led... | [
"If",
"no",
"arguments",
"are",
"specified",
"toggle",
"the",
"state",
"of",
"all",
"LEDs",
".",
"If",
"arguments",
"are",
"specified",
"they",
"must",
"be",
"the",
"indexes",
"of",
"the",
"LEDs",
"you",
"wish",
"to",
"toggle",
".",
"For",
"example",
"::... | RPi-Distro/python-gpiozero | python | https://github.com/RPi-Distro/python-gpiozero/blob/7b67374fd0c8c4fde5586d9bad9531f076db9c0c/gpiozero/boards.py#L480-L505 | [
"def",
"toggle",
"(",
"self",
",",
"*",
"args",
")",
":",
"self",
".",
"_stop_blink",
"(",
")",
"if",
"args",
":",
"for",
"index",
"in",
"args",
":",
"self",
"[",
"index",
"]",
".",
"toggle",
"(",
")",
"else",
":",
"super",
"(",
"LEDBoard",
",",
... | 7b67374fd0c8c4fde5586d9bad9531f076db9c0c |
train | LEDBoard.pulse | Make all LEDs fade in and out repeatedly. Note that this method will
only work if the *pwm* parameter was :data:`True` at construction time.
:param float fade_in_time:
Number of seconds to spend fading in. Defaults to 1.
:param float fade_out_time:
Number of seconds to ... | gpiozero/boards.py | def pulse(self, fade_in_time=1, fade_out_time=1, n=None, background=True):
"""
Make all LEDs fade in and out repeatedly. Note that this method will
only work if the *pwm* parameter was :data:`True` at construction time.
:param float fade_in_time:
Number of seconds to spend f... | def pulse(self, fade_in_time=1, fade_out_time=1, n=None, background=True):
"""
Make all LEDs fade in and out repeatedly. Note that this method will
only work if the *pwm* parameter was :data:`True` at construction time.
:param float fade_in_time:
Number of seconds to spend f... | [
"Make",
"all",
"LEDs",
"fade",
"in",
"and",
"out",
"repeatedly",
".",
"Note",
"that",
"this",
"method",
"will",
"only",
"work",
"if",
"the",
"*",
"pwm",
"*",
"parameter",
"was",
":",
"data",
":",
"True",
"at",
"construction",
"time",
"."
] | RPi-Distro/python-gpiozero | python | https://github.com/RPi-Distro/python-gpiozero/blob/7b67374fd0c8c4fde5586d9bad9531f076db9c0c/gpiozero/boards.py#L563-L586 | [
"def",
"pulse",
"(",
"self",
",",
"fade_in_time",
"=",
"1",
",",
"fade_out_time",
"=",
"1",
",",
"n",
"=",
"None",
",",
"background",
"=",
"True",
")",
":",
"on_time",
"=",
"off_time",
"=",
"0",
"self",
".",
"blink",
"(",
"on_time",
",",
"off_time",
... | 7b67374fd0c8c4fde5586d9bad9531f076db9c0c |
train | LEDBarGraph.value | The value of the LED bar graph. When no LEDs are lit, the value is 0.
When all LEDs are lit, the value is 1. Values between 0 and 1
light LEDs linearly from first to last. Values between 0 and -1
light LEDs linearly from last to first.
To light a particular number of LEDs, simply divide... | gpiozero/boards.py | def value(self):
"""
The value of the LED bar graph. When no LEDs are lit, the value is 0.
When all LEDs are lit, the value is 1. Values between 0 and 1
light LEDs linearly from first to last. Values between 0 and -1
light LEDs linearly from last to first.
To light a par... | def value(self):
"""
The value of the LED bar graph. When no LEDs are lit, the value is 0.
When all LEDs are lit, the value is 1. Values between 0 and 1
light LEDs linearly from first to last. Values between 0 and -1
light LEDs linearly from last to first.
To light a par... | [
"The",
"value",
"of",
"the",
"LED",
"bar",
"graph",
".",
"When",
"no",
"LEDs",
"are",
"lit",
"the",
"value",
"is",
"0",
".",
"When",
"all",
"LEDs",
"are",
"lit",
"the",
"value",
"is",
"1",
".",
"Values",
"between",
"0",
"and",
"1",
"light",
"LEDs",... | RPi-Distro/python-gpiozero | python | https://github.com/RPi-Distro/python-gpiozero/blob/7b67374fd0c8c4fde5586d9bad9531f076db9c0c/gpiozero/boards.py#L704-L730 | [
"def",
"value",
"(",
"self",
")",
":",
"result",
"=",
"sum",
"(",
"led",
".",
"value",
"for",
"led",
"in",
"self",
")",
"if",
"self",
"[",
"0",
"]",
".",
"value",
"<",
"self",
"[",
"-",
"1",
"]",
".",
"value",
":",
"result",
"=",
"-",
"result... | 7b67374fd0c8c4fde5586d9bad9531f076db9c0c |
train | LEDBarGraph.lit_count | The number of LEDs on the bar graph actually lit up. Note that just
like :attr:`value`, this can be negative if the LEDs are lit from last
to first. | gpiozero/boards.py | def lit_count(self):
"""
The number of LEDs on the bar graph actually lit up. Note that just
like :attr:`value`, this can be negative if the LEDs are lit from last
to first.
"""
lit_value = self.value * len(self)
if not isinstance(self[0], PWMLED):
lit... | def lit_count(self):
"""
The number of LEDs on the bar graph actually lit up. Note that just
like :attr:`value`, this can be negative if the LEDs are lit from last
to first.
"""
lit_value = self.value * len(self)
if not isinstance(self[0], PWMLED):
lit... | [
"The",
"number",
"of",
"LEDs",
"on",
"the",
"bar",
"graph",
"actually",
"lit",
"up",
".",
"Note",
"that",
"just",
"like",
":",
"attr",
":",
"value",
"this",
"can",
"be",
"negative",
"if",
"the",
"LEDs",
"are",
"lit",
"from",
"last",
"to",
"first",
".... | RPi-Distro/python-gpiozero | python | https://github.com/RPi-Distro/python-gpiozero/blob/7b67374fd0c8c4fde5586d9bad9531f076db9c0c/gpiozero/boards.py#L750-L759 | [
"def",
"lit_count",
"(",
"self",
")",
":",
"lit_value",
"=",
"self",
".",
"value",
"*",
"len",
"(",
"self",
")",
"if",
"not",
"isinstance",
"(",
"self",
"[",
"0",
"]",
",",
"PWMLED",
")",
":",
"lit_value",
"=",
"int",
"(",
"lit_value",
")",
"return... | 7b67374fd0c8c4fde5586d9bad9531f076db9c0c |
train | Robot.forward | Drive the robot forward by running both motors forward.
:param float speed:
Speed at which to drive the motors, as a value between 0 (stopped)
and 1 (full speed). The default is 1.
:param float curve_left:
The amount to curve left while moving forwards, by driving t... | gpiozero/boards.py | def forward(self, speed=1, **kwargs):
"""
Drive the robot forward by running both motors forward.
:param float speed:
Speed at which to drive the motors, as a value between 0 (stopped)
and 1 (full speed). The default is 1.
:param float curve_left:
Th... | def forward(self, speed=1, **kwargs):
"""
Drive the robot forward by running both motors forward.
:param float speed:
Speed at which to drive the motors, as a value between 0 (stopped)
and 1 (full speed). The default is 1.
:param float curve_left:
Th... | [
"Drive",
"the",
"robot",
"forward",
"by",
"running",
"both",
"motors",
"forward",
"."
] | RPi-Distro/python-gpiozero | python | https://github.com/RPi-Distro/python-gpiozero/blob/7b67374fd0c8c4fde5586d9bad9531f076db9c0c/gpiozero/boards.py#L1601-L1633 | [
"def",
"forward",
"(",
"self",
",",
"speed",
"=",
"1",
",",
"*",
"*",
"kwargs",
")",
":",
"curve_left",
"=",
"kwargs",
".",
"pop",
"(",
"'curve_left'",
",",
"0",
")",
"curve_right",
"=",
"kwargs",
".",
"pop",
"(",
"'curve_right'",
",",
"0",
")",
"i... | 7b67374fd0c8c4fde5586d9bad9531f076db9c0c |
train | Robot.left | Make the robot turn left by running the right motor forward and left
motor backward.
:param float speed:
Speed at which to drive the motors, as a value between 0 (stopped)
and 1 (full speed). The default is 1. | gpiozero/boards.py | def left(self, speed=1):
"""
Make the robot turn left by running the right motor forward and left
motor backward.
:param float speed:
Speed at which to drive the motors, as a value between 0 (stopped)
and 1 (full speed). The default is 1.
"""
self... | def left(self, speed=1):
"""
Make the robot turn left by running the right motor forward and left
motor backward.
:param float speed:
Speed at which to drive the motors, as a value between 0 (stopped)
and 1 (full speed). The default is 1.
"""
self... | [
"Make",
"the",
"robot",
"turn",
"left",
"by",
"running",
"the",
"right",
"motor",
"forward",
"and",
"left",
"motor",
"backward",
"."
] | RPi-Distro/python-gpiozero | python | https://github.com/RPi-Distro/python-gpiozero/blob/7b67374fd0c8c4fde5586d9bad9531f076db9c0c/gpiozero/boards.py#L1669-L1679 | [
"def",
"left",
"(",
"self",
",",
"speed",
"=",
"1",
")",
":",
"self",
".",
"right_motor",
".",
"forward",
"(",
"speed",
")",
"self",
".",
"left_motor",
".",
"backward",
"(",
"speed",
")"
] | 7b67374fd0c8c4fde5586d9bad9531f076db9c0c |
train | Robot.right | Make the robot turn right by running the left motor forward and right
motor backward.
:param float speed:
Speed at which to drive the motors, as a value between 0 (stopped)
and 1 (full speed). The default is 1. | gpiozero/boards.py | def right(self, speed=1):
"""
Make the robot turn right by running the left motor forward and right
motor backward.
:param float speed:
Speed at which to drive the motors, as a value between 0 (stopped)
and 1 (full speed). The default is 1.
"""
se... | def right(self, speed=1):
"""
Make the robot turn right by running the left motor forward and right
motor backward.
:param float speed:
Speed at which to drive the motors, as a value between 0 (stopped)
and 1 (full speed). The default is 1.
"""
se... | [
"Make",
"the",
"robot",
"turn",
"right",
"by",
"running",
"the",
"left",
"motor",
"forward",
"and",
"right",
"motor",
"backward",
"."
] | RPi-Distro/python-gpiozero | python | https://github.com/RPi-Distro/python-gpiozero/blob/7b67374fd0c8c4fde5586d9bad9531f076db9c0c/gpiozero/boards.py#L1681-L1691 | [
"def",
"right",
"(",
"self",
",",
"speed",
"=",
"1",
")",
":",
"self",
".",
"left_motor",
".",
"forward",
"(",
"speed",
")",
"self",
".",
"right_motor",
".",
"backward",
"(",
"speed",
")"
] | 7b67374fd0c8c4fde5586d9bad9531f076db9c0c |
train | PhaseEnableRobot.forward | Drive the robot forward by running both motors forward.
:param float speed:
Speed at which to drive the motors, as a value between 0 (stopped)
and 1 (full speed). The default is 1. | gpiozero/boards.py | def forward(self, speed=1):
"""
Drive the robot forward by running both motors forward.
:param float speed:
Speed at which to drive the motors, as a value between 0 (stopped)
and 1 (full speed). The default is 1.
"""
self.left_motor.forward(speed)
... | def forward(self, speed=1):
"""
Drive the robot forward by running both motors forward.
:param float speed:
Speed at which to drive the motors, as a value between 0 (stopped)
and 1 (full speed). The default is 1.
"""
self.left_motor.forward(speed)
... | [
"Drive",
"the",
"robot",
"forward",
"by",
"running",
"both",
"motors",
"forward",
"."
] | RPi-Distro/python-gpiozero | python | https://github.com/RPi-Distro/python-gpiozero/blob/7b67374fd0c8c4fde5586d9bad9531f076db9c0c/gpiozero/boards.py#L1848-L1857 | [
"def",
"forward",
"(",
"self",
",",
"speed",
"=",
"1",
")",
":",
"self",
".",
"left_motor",
".",
"forward",
"(",
"speed",
")",
"self",
".",
"right_motor",
".",
"forward",
"(",
"speed",
")"
] | 7b67374fd0c8c4fde5586d9bad9531f076db9c0c |
train | PhaseEnableRobot.backward | Drive the robot backward by running both motors backward.
:param float speed:
Speed at which to drive the motors, as a value between 0 (stopped)
and 1 (full speed). The default is 1. | gpiozero/boards.py | def backward(self, speed=1):
"""
Drive the robot backward by running both motors backward.
:param float speed:
Speed at which to drive the motors, as a value between 0 (stopped)
and 1 (full speed). The default is 1.
"""
self.left_motor.backward(speed)
... | def backward(self, speed=1):
"""
Drive the robot backward by running both motors backward.
:param float speed:
Speed at which to drive the motors, as a value between 0 (stopped)
and 1 (full speed). The default is 1.
"""
self.left_motor.backward(speed)
... | [
"Drive",
"the",
"robot",
"backward",
"by",
"running",
"both",
"motors",
"backward",
"."
] | RPi-Distro/python-gpiozero | python | https://github.com/RPi-Distro/python-gpiozero/blob/7b67374fd0c8c4fde5586d9bad9531f076db9c0c/gpiozero/boards.py#L1859-L1868 | [
"def",
"backward",
"(",
"self",
",",
"speed",
"=",
"1",
")",
":",
"self",
".",
"left_motor",
".",
"backward",
"(",
"speed",
")",
"self",
".",
"right_motor",
".",
"backward",
"(",
"speed",
")"
] | 7b67374fd0c8c4fde5586d9bad9531f076db9c0c |
train | PhaseEnableRobot.reverse | Reverse the robot's current motor directions. If the robot is currently
running full speed forward, it will run full speed backward. If the
robot is turning left at half-speed, it will turn right at half-speed.
If the robot is currently stopped it will remain stopped. | gpiozero/boards.py | def reverse(self):
"""
Reverse the robot's current motor directions. If the robot is currently
running full speed forward, it will run full speed backward. If the
robot is turning left at half-speed, it will turn right at half-speed.
If the robot is currently stopped it will rema... | def reverse(self):
"""
Reverse the robot's current motor directions. If the robot is currently
running full speed forward, it will run full speed backward. If the
robot is turning left at half-speed, it will turn right at half-speed.
If the robot is currently stopped it will rema... | [
"Reverse",
"the",
"robot",
"s",
"current",
"motor",
"directions",
".",
"If",
"the",
"robot",
"is",
"currently",
"running",
"full",
"speed",
"forward",
"it",
"will",
"run",
"full",
"speed",
"backward",
".",
"If",
"the",
"robot",
"is",
"turning",
"left",
"at... | RPi-Distro/python-gpiozero | python | https://github.com/RPi-Distro/python-gpiozero/blob/7b67374fd0c8c4fde5586d9bad9531f076db9c0c/gpiozero/boards.py#L1894-L1902 | [
"def",
"reverse",
"(",
"self",
")",
":",
"self",
".",
"left_motor",
".",
"value",
"=",
"-",
"self",
".",
"left_motor",
".",
"value",
"self",
".",
"right_motor",
".",
"value",
"=",
"-",
"self",
".",
"right_motor",
".",
"value"
] | 7b67374fd0c8c4fde5586d9bad9531f076db9c0c |
train | Factory.reserve_pins | Called to indicate that the device reserves the right to use the
specified *pins*. This should be done during device construction. If
pins are reserved, you must ensure that the reservation is released by
eventually called :meth:`release_pins`. | gpiozero/pins/__init__.py | def reserve_pins(self, requester, *pins):
"""
Called to indicate that the device reserves the right to use the
specified *pins*. This should be done during device construction. If
pins are reserved, you must ensure that the reservation is released by
eventually called :meth:`rel... | def reserve_pins(self, requester, *pins):
"""
Called to indicate that the device reserves the right to use the
specified *pins*. This should be done during device construction. If
pins are reserved, you must ensure that the reservation is released by
eventually called :meth:`rel... | [
"Called",
"to",
"indicate",
"that",
"the",
"device",
"reserves",
"the",
"right",
"to",
"use",
"the",
"specified",
"*",
"pins",
"*",
".",
"This",
"should",
"be",
"done",
"during",
"device",
"construction",
".",
"If",
"pins",
"are",
"reserved",
"you",
"must"... | RPi-Distro/python-gpiozero | python | https://github.com/RPi-Distro/python-gpiozero/blob/7b67374fd0c8c4fde5586d9bad9531f076db9c0c/gpiozero/pins/__init__.py#L85-L99 | [
"def",
"reserve_pins",
"(",
"self",
",",
"requester",
",",
"*",
"pins",
")",
":",
"with",
"self",
".",
"_res_lock",
":",
"for",
"pin",
"in",
"pins",
":",
"for",
"reserver_ref",
"in",
"self",
".",
"_reservations",
"[",
"pin",
"]",
":",
"reserver",
"=",
... | 7b67374fd0c8c4fde5586d9bad9531f076db9c0c |
train | Factory.release_pins | Releases the reservation of *reserver* against *pins*. This is
typically called during :meth:`~gpiozero.Device.close` to clean up
reservations taken during construction. Releasing a reservation that is
not currently held will be silently ignored (to permit clean-up after
failed / partia... | gpiozero/pins/__init__.py | def release_pins(self, reserver, *pins):
"""
Releases the reservation of *reserver* against *pins*. This is
typically called during :meth:`~gpiozero.Device.close` to clean up
reservations taken during construction. Releasing a reservation that is
not currently held will be silen... | def release_pins(self, reserver, *pins):
"""
Releases the reservation of *reserver* against *pins*. This is
typically called during :meth:`~gpiozero.Device.close` to clean up
reservations taken during construction. Releasing a reservation that is
not currently held will be silen... | [
"Releases",
"the",
"reservation",
"of",
"*",
"reserver",
"*",
"against",
"*",
"pins",
"*",
".",
"This",
"is",
"typically",
"called",
"during",
":",
"meth",
":",
"~gpiozero",
".",
"Device",
".",
"close",
"to",
"clean",
"up",
"reservations",
"taken",
"during... | RPi-Distro/python-gpiozero | python | https://github.com/RPi-Distro/python-gpiozero/blob/7b67374fd0c8c4fde5586d9bad9531f076db9c0c/gpiozero/pins/__init__.py#L101-L114 | [
"def",
"release_pins",
"(",
"self",
",",
"reserver",
",",
"*",
"pins",
")",
":",
"with",
"self",
".",
"_res_lock",
":",
"for",
"pin",
"in",
"pins",
":",
"self",
".",
"_reservations",
"[",
"pin",
"]",
"=",
"[",
"ref",
"for",
"ref",
"in",
"self",
"."... | 7b67374fd0c8c4fde5586d9bad9531f076db9c0c |
train | MockFactory.pin | The pin method for :class:`MockFactory` additionally takes a *pin_class*
attribute which can be used to override the class' :attr:`pin_class`
attribute. Any additional keyword arguments will be passed along to the
pin constructor (useful with things like :class:`MockConnectedPin` which
e... | gpiozero/pins/mock.py | def pin(self, spec, pin_class=None, **kwargs):
"""
The pin method for :class:`MockFactory` additionally takes a *pin_class*
attribute which can be used to override the class' :attr:`pin_class`
attribute. Any additional keyword arguments will be passed along to the
pin constructor... | def pin(self, spec, pin_class=None, **kwargs):
"""
The pin method for :class:`MockFactory` additionally takes a *pin_class*
attribute which can be used to override the class' :attr:`pin_class`
attribute. Any additional keyword arguments will be passed along to the
pin constructor... | [
"The",
"pin",
"method",
"for",
":",
"class",
":",
"MockFactory",
"additionally",
"takes",
"a",
"*",
"pin_class",
"*",
"attribute",
"which",
"can",
"be",
"used",
"to",
"override",
"the",
"class",
":",
"attr",
":",
"pin_class",
"attribute",
".",
"Any",
"addi... | RPi-Distro/python-gpiozero | python | https://github.com/RPi-Distro/python-gpiozero/blob/7b67374fd0c8c4fde5586d9bad9531f076db9c0c/gpiozero/pins/mock.py#L493-L513 | [
"def",
"pin",
"(",
"self",
",",
"spec",
",",
"pin_class",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"pin_class",
"is",
"None",
":",
"pin_class",
"=",
"self",
".",
"pin_class",
"n",
"=",
"self",
".",
"pi_info",
".",
"to_gpio",
"(",
"spec... | 7b67374fd0c8c4fde5586d9bad9531f076db9c0c |
train | pi_info | Returns a :class:`PiBoardInfo` instance containing information about a
*revision* of the Raspberry Pi.
:param str revision:
The revision of the Pi to return information about. If this is omitted
or :data:`None` (the default), then the library will attempt to determine
the model of Pi it... | gpiozero/pins/data.py | def pi_info(revision=None):
"""
Returns a :class:`PiBoardInfo` instance containing information about a
*revision* of the Raspberry Pi.
:param str revision:
The revision of the Pi to return information about. If this is omitted
or :data:`None` (the default), then the library will attempt... | def pi_info(revision=None):
"""
Returns a :class:`PiBoardInfo` instance containing information about a
*revision* of the Raspberry Pi.
:param str revision:
The revision of the Pi to return information about. If this is omitted
or :data:`None` (the default), then the library will attempt... | [
"Returns",
"a",
":",
"class",
":",
"PiBoardInfo",
"instance",
"containing",
"information",
"about",
"a",
"*",
"revision",
"*",
"of",
"the",
"Raspberry",
"Pi",
"."
] | RPi-Distro/python-gpiozero | python | https://github.com/RPi-Distro/python-gpiozero/blob/7b67374fd0c8c4fde5586d9bad9531f076db9c0c/gpiozero/pins/data.py#L1316-L1342 | [
"def",
"pi_info",
"(",
"revision",
"=",
"None",
")",
":",
"if",
"revision",
"is",
"None",
":",
"if",
"Device",
".",
"pin_factory",
"is",
"None",
":",
"Device",
".",
"pin_factory",
"=",
"Device",
".",
"_default_pin_factory",
"(",
")",
"result",
"=",
"Devi... | 7b67374fd0c8c4fde5586d9bad9531f076db9c0c |
train | PiBoardInfo.physical_pins | Return the physical pins supporting the specified *function* as tuples
of ``(header, pin_number)`` where *header* is a string specifying the
header containing the *pin_number*. Note that the return value is a
:class:`set` which is not indexable. Use :func:`physical_pin` if you
are expect... | gpiozero/pins/data.py | def physical_pins(self, function):
"""
Return the physical pins supporting the specified *function* as tuples
of ``(header, pin_number)`` where *header* is a string specifying the
header containing the *pin_number*. Note that the return value is a
:class:`set` which is not indexa... | def physical_pins(self, function):
"""
Return the physical pins supporting the specified *function* as tuples
of ``(header, pin_number)`` where *header* is a string specifying the
header containing the *pin_number*. Note that the return value is a
:class:`set` which is not indexa... | [
"Return",
"the",
"physical",
"pins",
"supporting",
"the",
"specified",
"*",
"function",
"*",
"as",
"tuples",
"of",
"(",
"header",
"pin_number",
")",
"where",
"*",
"header",
"*",
"is",
"a",
"string",
"specifying",
"the",
"header",
"containing",
"the",
"*",
... | RPi-Distro/python-gpiozero | python | https://github.com/RPi-Distro/python-gpiozero/blob/7b67374fd0c8c4fde5586d9bad9531f076db9c0c/gpiozero/pins/data.py#L1101-L1119 | [
"def",
"physical_pins",
"(",
"self",
",",
"function",
")",
":",
"return",
"{",
"(",
"header",
",",
"pin",
".",
"number",
")",
"for",
"(",
"header",
",",
"info",
")",
"in",
"self",
".",
"headers",
".",
"items",
"(",
")",
"for",
"pin",
"in",
"info",
... | 7b67374fd0c8c4fde5586d9bad9531f076db9c0c |
train | PiBoardInfo.physical_pin | Return the physical pin supporting the specified *function*. If no pins
support the desired *function*, this function raises :exc:`PinNoPins`.
If multiple pins support the desired *function*, :exc:`PinMultiplePins`
will be raised (use :func:`physical_pins` if you expect multiple pins
in ... | gpiozero/pins/data.py | def physical_pin(self, function):
"""
Return the physical pin supporting the specified *function*. If no pins
support the desired *function*, this function raises :exc:`PinNoPins`.
If multiple pins support the desired *function*, :exc:`PinMultiplePins`
will be raised (use :func:`... | def physical_pin(self, function):
"""
Return the physical pin supporting the specified *function*. If no pins
support the desired *function*, this function raises :exc:`PinNoPins`.
If multiple pins support the desired *function*, :exc:`PinMultiplePins`
will be raised (use :func:`... | [
"Return",
"the",
"physical",
"pin",
"supporting",
"the",
"specified",
"*",
"function",
"*",
".",
"If",
"no",
"pins",
"support",
"the",
"desired",
"*",
"function",
"*",
"this",
"function",
"raises",
":",
"exc",
":",
"PinNoPins",
".",
"If",
"multiple",
"pins... | RPi-Distro/python-gpiozero | python | https://github.com/RPi-Distro/python-gpiozero/blob/7b67374fd0c8c4fde5586d9bad9531f076db9c0c/gpiozero/pins/data.py#L1121-L1139 | [
"def",
"physical_pin",
"(",
"self",
",",
"function",
")",
":",
"result",
"=",
"self",
".",
"physical_pins",
"(",
"function",
")",
"if",
"len",
"(",
"result",
")",
">",
"1",
":",
"raise",
"PinMultiplePins",
"(",
"'multiple pins can be used for %s'",
"%",
"fun... | 7b67374fd0c8c4fde5586d9bad9531f076db9c0c |
train | PiBoardInfo.pulled_up | Returns a bool indicating whether a physical pull-up is attached to
the pin supporting the specified *function*. Either :exc:`PinNoPins`
or :exc:`PinMultiplePins` may be raised if the function is not
associated with a single pin.
:param str function:
The pin function you wis... | gpiozero/pins/data.py | def pulled_up(self, function):
"""
Returns a bool indicating whether a physical pull-up is attached to
the pin supporting the specified *function*. Either :exc:`PinNoPins`
or :exc:`PinMultiplePins` may be raised if the function is not
associated with a single pin.
:param... | def pulled_up(self, function):
"""
Returns a bool indicating whether a physical pull-up is attached to
the pin supporting the specified *function*. Either :exc:`PinNoPins`
or :exc:`PinMultiplePins` may be raised if the function is not
associated with a single pin.
:param... | [
"Returns",
"a",
"bool",
"indicating",
"whether",
"a",
"physical",
"pull",
"-",
"up",
"is",
"attached",
"to",
"the",
"pin",
"supporting",
"the",
"specified",
"*",
"function",
"*",
".",
"Either",
":",
"exc",
":",
"PinNoPins",
"or",
":",
"exc",
":",
"PinMul... | RPi-Distro/python-gpiozero | python | https://github.com/RPi-Distro/python-gpiozero/blob/7b67374fd0c8c4fde5586d9bad9531f076db9c0c/gpiozero/pins/data.py#L1141-L1157 | [
"def",
"pulled_up",
"(",
"self",
",",
"function",
")",
":",
"try",
":",
"header",
",",
"number",
"=",
"self",
".",
"physical_pin",
"(",
"function",
")",
"except",
"PinNoPins",
":",
"return",
"False",
"else",
":",
"return",
"self",
".",
"headers",
"[",
... | 7b67374fd0c8c4fde5586d9bad9531f076db9c0c |
train | PiBoardInfo.to_gpio | Parses a pin *spec*, returning the equivalent Broadcom GPIO port number
or raising a :exc:`ValueError` exception if the spec does not represent
a GPIO port.
The *spec* may be given in any of the following forms:
* An integer, which will be accepted as a GPIO number
* 'GPIOn' wh... | gpiozero/pins/data.py | def to_gpio(self, spec):
"""
Parses a pin *spec*, returning the equivalent Broadcom GPIO port number
or raising a :exc:`ValueError` exception if the spec does not represent
a GPIO port.
The *spec* may be given in any of the following forms:
* An integer, which will be a... | def to_gpio(self, spec):
"""
Parses a pin *spec*, returning the equivalent Broadcom GPIO port number
or raising a :exc:`ValueError` exception if the spec does not represent
a GPIO port.
The *spec* may be given in any of the following forms:
* An integer, which will be a... | [
"Parses",
"a",
"pin",
"*",
"spec",
"*",
"returning",
"the",
"equivalent",
"Broadcom",
"GPIO",
"port",
"number",
"or",
"raising",
"a",
":",
"exc",
":",
"ValueError",
"exception",
"if",
"the",
"spec",
"does",
"not",
"represent",
"a",
"GPIO",
"port",
"."
] | RPi-Distro/python-gpiozero | python | https://github.com/RPi-Distro/python-gpiozero/blob/7b67374fd0c8c4fde5586d9bad9531f076db9c0c/gpiozero/pins/data.py#L1159-L1252 | [
"def",
"to_gpio",
"(",
"self",
",",
"spec",
")",
":",
"if",
"isinstance",
"(",
"spec",
",",
"int",
")",
":",
"if",
"not",
"0",
"<=",
"spec",
"<",
"54",
":",
"raise",
"PinInvalidPin",
"(",
"'invalid GPIO port %d specified '",
"'(range 0..53) '",
"%",
"spec"... | 7b67374fd0c8c4fde5586d9bad9531f076db9c0c |
train | PiFactory.spi | Returns an SPI interface, for the specified SPI *port* and *device*, or
for the specified pins (*clock_pin*, *mosi_pin*, *miso_pin*, and
*select_pin*). Only one of the schemes can be used; attempting to mix
*port* and *device* with pin numbers will raise
:exc:`~gpiozero.SPIBadArgs`.
... | gpiozero/pins/pi.py | def spi(self, **spi_args):
"""
Returns an SPI interface, for the specified SPI *port* and *device*, or
for the specified pins (*clock_pin*, *mosi_pin*, *miso_pin*, and
*select_pin*). Only one of the schemes can be used; attempting to mix
*port* and *device* with pin numbers will... | def spi(self, **spi_args):
"""
Returns an SPI interface, for the specified SPI *port* and *device*, or
for the specified pins (*clock_pin*, *mosi_pin*, *miso_pin*, and
*select_pin*). Only one of the schemes can be used; attempting to mix
*port* and *device* with pin numbers will... | [
"Returns",
"an",
"SPI",
"interface",
"for",
"the",
"specified",
"SPI",
"*",
"port",
"*",
"and",
"*",
"device",
"*",
"or",
"for",
"the",
"specified",
"pins",
"(",
"*",
"clock_pin",
"*",
"*",
"mosi_pin",
"*",
"*",
"miso_pin",
"*",
"and",
"*",
"select_pin... | RPi-Distro/python-gpiozero | python | https://github.com/RPi-Distro/python-gpiozero/blob/7b67374fd0c8c4fde5586d9bad9531f076db9c0c/gpiozero/pins/pi.py#L123-L165 | [
"def",
"spi",
"(",
"self",
",",
"*",
"*",
"spi_args",
")",
":",
"spi_args",
",",
"kwargs",
"=",
"self",
".",
"_extract_spi_args",
"(",
"*",
"*",
"spi_args",
")",
"shared",
"=",
"'shared'",
"if",
"kwargs",
".",
"pop",
"(",
"'shared'",
",",
"False",
")... | 7b67374fd0c8c4fde5586d9bad9531f076db9c0c |
train | PiFactory._extract_spi_args | Given a set of keyword arguments, splits it into those relevant to SPI
implementations and all the rest. SPI arguments are augmented with
defaults and converted into the pin format (from the port/device
format) if necessary.
Returns a tuple of ``(spi_args, other_args)``. | gpiozero/pins/pi.py | def _extract_spi_args(self, **kwargs):
"""
Given a set of keyword arguments, splits it into those relevant to SPI
implementations and all the rest. SPI arguments are augmented with
defaults and converted into the pin format (from the port/device
format) if necessary.
Ret... | def _extract_spi_args(self, **kwargs):
"""
Given a set of keyword arguments, splits it into those relevant to SPI
implementations and all the rest. SPI arguments are augmented with
defaults and converted into the pin format (from the port/device
format) if necessary.
Ret... | [
"Given",
"a",
"set",
"of",
"keyword",
"arguments",
"splits",
"it",
"into",
"those",
"relevant",
"to",
"SPI",
"implementations",
"and",
"all",
"the",
"rest",
".",
"SPI",
"arguments",
"are",
"augmented",
"with",
"defaults",
"and",
"converted",
"into",
"the",
"... | RPi-Distro/python-gpiozero | python | https://github.com/RPi-Distro/python-gpiozero/blob/7b67374fd0c8c4fde5586d9bad9531f076db9c0c/gpiozero/pins/pi.py#L167-L227 | [
"def",
"_extract_spi_args",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"dev_defaults",
"=",
"{",
"'port'",
":",
"0",
",",
"'device'",
":",
"0",
",",
"}",
"default_hw",
"=",
"SPI_HARDWARE_PINS",
"[",
"dev_defaults",
"[",
"'port'",
"]",
"]",
"pin_defa... | 7b67374fd0c8c4fde5586d9bad9531f076db9c0c |
train | PiPin._call_when_changed | Called to fire the :attr:`when_changed` event handler; override this
in descendents if additional (currently redundant) parameters need
to be passed. | gpiozero/pins/pi.py | def _call_when_changed(self, ticks, state):
"""
Called to fire the :attr:`when_changed` event handler; override this
in descendents if additional (currently redundant) parameters need
to be passed.
"""
method = self._when_changed()
if method is None:
s... | def _call_when_changed(self, ticks, state):
"""
Called to fire the :attr:`when_changed` event handler; override this
in descendents if additional (currently redundant) parameters need
to be passed.
"""
method = self._when_changed()
if method is None:
s... | [
"Called",
"to",
"fire",
"the",
":",
"attr",
":",
"when_changed",
"event",
"handler",
";",
"override",
"this",
"in",
"descendents",
"if",
"additional",
"(",
"currently",
"redundant",
")",
"parameters",
"need",
"to",
"be",
"passed",
"."
] | RPi-Distro/python-gpiozero | python | https://github.com/RPi-Distro/python-gpiozero/blob/7b67374fd0c8c4fde5586d9bad9531f076db9c0c/gpiozero/pins/pi.py#L283-L293 | [
"def",
"_call_when_changed",
"(",
"self",
",",
"ticks",
",",
"state",
")",
":",
"method",
"=",
"self",
".",
"_when_changed",
"(",
")",
"if",
"method",
"is",
"None",
":",
"self",
".",
"when_changed",
"=",
"None",
"else",
":",
"method",
"(",
"ticks",
","... | 7b67374fd0c8c4fde5586d9bad9531f076db9c0c |
train | SPIDevice._int_to_words | Given a bit-pattern expressed an integer number, return a sequence of
the individual words that make up the pattern. The number of bits per
word will be obtained from the internal SPI interface. | gpiozero/spi_devices.py | def _int_to_words(self, pattern):
"""
Given a bit-pattern expressed an integer number, return a sequence of
the individual words that make up the pattern. The number of bits per
word will be obtained from the internal SPI interface.
"""
try:
bits_required = in... | def _int_to_words(self, pattern):
"""
Given a bit-pattern expressed an integer number, return a sequence of
the individual words that make up the pattern. The number of bits per
word will be obtained from the internal SPI interface.
"""
try:
bits_required = in... | [
"Given",
"a",
"bit",
"-",
"pattern",
"expressed",
"an",
"integer",
"number",
"return",
"a",
"sequence",
"of",
"the",
"individual",
"words",
"that",
"make",
"up",
"the",
"pattern",
".",
"The",
"number",
"of",
"bits",
"per",
"word",
"will",
"be",
"obtained",... | RPi-Distro/python-gpiozero | python | https://github.com/RPi-Distro/python-gpiozero/blob/7b67374fd0c8c4fde5586d9bad9531f076db9c0c/gpiozero/spi_devices.py#L77-L91 | [
"def",
"_int_to_words",
"(",
"self",
",",
"pattern",
")",
":",
"try",
":",
"bits_required",
"=",
"int",
"(",
"ceil",
"(",
"log",
"(",
"pattern",
",",
"2",
")",
")",
")",
"+",
"1",
"except",
"ValueError",
":",
"# pattern == 0 (technically speaking, no bits ar... | 7b67374fd0c8c4fde5586d9bad9531f076db9c0c |
train | SPIDevice._words_to_int | Given a sequence of words which each fit in the internal SPI
interface's number of bits per word, returns the value obtained by
concatenating each word into a single bit-string.
If *expected_bits* is specified, it limits the size of the output to
the specified number of bits (by masking... | gpiozero/spi_devices.py | def _words_to_int(self, words, expected_bits=None):
"""
Given a sequence of words which each fit in the internal SPI
interface's number of bits per word, returns the value obtained by
concatenating each word into a single bit-string.
If *expected_bits* is specified, it limits th... | def _words_to_int(self, words, expected_bits=None):
"""
Given a sequence of words which each fit in the internal SPI
interface's number of bits per word, returns the value obtained by
concatenating each word into a single bit-string.
If *expected_bits* is specified, it limits th... | [
"Given",
"a",
"sequence",
"of",
"words",
"which",
"each",
"fit",
"in",
"the",
"internal",
"SPI",
"interface",
"s",
"number",
"of",
"bits",
"per",
"word",
"returns",
"the",
"value",
"obtained",
"by",
"concatenating",
"each",
"word",
"into",
"a",
"single",
"... | RPi-Distro/python-gpiozero | python | https://github.com/RPi-Distro/python-gpiozero/blob/7b67374fd0c8c4fde5586d9bad9531f076db9c0c/gpiozero/spi_devices.py#L93-L107 | [
"def",
"_words_to_int",
"(",
"self",
",",
"words",
",",
"expected_bits",
"=",
"None",
")",
":",
"if",
"expected_bits",
"is",
"None",
":",
"expected_bits",
"=",
"len",
"(",
"words",
")",
"*",
"self",
".",
"_spi",
".",
"bits_per_word",
"shifts",
"=",
"rang... | 7b67374fd0c8c4fde5586d9bad9531f076db9c0c |
train | SPISoftwareBus.transfer | Writes data (a list of integer words where each word is assumed to have
:attr:`bits_per_word` bits or less) to the SPI interface, and reads an
equivalent number of words, returning them as a list of integers. | gpiozero/pins/spi.py | def transfer(self, data, clock_phase=False, lsb_first=False, bits_per_word=8):
"""
Writes data (a list of integer words where each word is assumed to have
:attr:`bits_per_word` bits or less) to the SPI interface, and reads an
equivalent number of words, returning them as a list of intege... | def transfer(self, data, clock_phase=False, lsb_first=False, bits_per_word=8):
"""
Writes data (a list of integer words where each word is assumed to have
:attr:`bits_per_word` bits or less) to the SPI interface, and reads an
equivalent number of words, returning them as a list of intege... | [
"Writes",
"data",
"(",
"a",
"list",
"of",
"integer",
"words",
"where",
"each",
"word",
"is",
"assumed",
"to",
"have",
":",
"attr",
":",
"bits_per_word",
"bits",
"or",
"less",
")",
"to",
"the",
"SPI",
"interface",
"and",
"reads",
"an",
"equivalent",
"numb... | RPi-Distro/python-gpiozero | python | https://github.com/RPi-Distro/python-gpiozero/blob/7b67374fd0c8c4fde5586d9bad9531f076db9c0c/gpiozero/pins/spi.py#L88-L125 | [
"def",
"transfer",
"(",
"self",
",",
"data",
",",
"clock_phase",
"=",
"False",
",",
"lsb_first",
"=",
"False",
",",
"bits_per_word",
"=",
"8",
")",
":",
"result",
"=",
"[",
"]",
"with",
"self",
".",
"lock",
":",
"# See https://en.wikipedia.org/wiki/Serial_Pe... | 7b67374fd0c8c4fde5586d9bad9531f076db9c0c |
train | PingServer.value | Returns :data:`True` if the host returned a single ping, and
:data:`False` otherwise. | gpiozero/internal_devices.py | def value(self):
"""
Returns :data:`True` if the host returned a single ping, and
:data:`False` otherwise.
"""
# XXX This is doing a DNS lookup every time it's queried; should we
# call gethostbyname in the constructor and ping that instead (good
# for consistency... | def value(self):
"""
Returns :data:`True` if the host returned a single ping, and
:data:`False` otherwise.
"""
# XXX This is doing a DNS lookup every time it's queried; should we
# call gethostbyname in the constructor and ping that instead (good
# for consistency... | [
"Returns",
":",
"data",
":",
"True",
"if",
"the",
"host",
"returned",
"a",
"single",
"ping",
"and",
":",
"data",
":",
"False",
"otherwise",
"."
] | RPi-Distro/python-gpiozero | python | https://github.com/RPi-Distro/python-gpiozero/blob/7b67374fd0c8c4fde5586d9bad9531f076db9c0c/gpiozero/internal_devices.py#L112-L129 | [
"def",
"value",
"(",
"self",
")",
":",
"# XXX This is doing a DNS lookup every time it's queried; should we",
"# call gethostbyname in the constructor and ping that instead (good",
"# for consistency, but what if the user *expects* the host to change",
"# address?)",
"with",
"io",
".",
"op... | 7b67374fd0c8c4fde5586d9bad9531f076db9c0c |
train | CPUTemperature.temperature | Returns the current CPU temperature in degrees celsius. | gpiozero/internal_devices.py | def temperature(self):
"""
Returns the current CPU temperature in degrees celsius.
"""
with io.open(self.sensor_file, 'r') as f:
return float(f.readline().strip()) / 1000 | def temperature(self):
"""
Returns the current CPU temperature in degrees celsius.
"""
with io.open(self.sensor_file, 'r') as f:
return float(f.readline().strip()) / 1000 | [
"Returns",
"the",
"current",
"CPU",
"temperature",
"in",
"degrees",
"celsius",
"."
] | RPi-Distro/python-gpiozero | python | https://github.com/RPi-Distro/python-gpiozero/blob/7b67374fd0c8c4fde5586d9bad9531f076db9c0c/gpiozero/internal_devices.py#L197-L202 | [
"def",
"temperature",
"(",
"self",
")",
":",
"with",
"io",
".",
"open",
"(",
"self",
".",
"sensor_file",
",",
"'r'",
")",
"as",
"f",
":",
"return",
"float",
"(",
"f",
".",
"readline",
"(",
")",
".",
"strip",
"(",
")",
")",
"/",
"1000"
] | 7b67374fd0c8c4fde5586d9bad9531f076db9c0c |
train | CPUTemperature.value | Returns the current CPU temperature as a value between 0.0
(representing the *min_temp* value) and 1.0 (representing the
*max_temp* value). These default to 0.0 and 100.0 respectively, hence
:attr:`value` is :attr:`temperature` divided by 100 by default. | gpiozero/internal_devices.py | def value(self):
"""
Returns the current CPU temperature as a value between 0.0
(representing the *min_temp* value) and 1.0 (representing the
*max_temp* value). These default to 0.0 and 100.0 respectively, hence
:attr:`value` is :attr:`temperature` divided by 100 by default.
... | def value(self):
"""
Returns the current CPU temperature as a value between 0.0
(representing the *min_temp* value) and 1.0 (representing the
*max_temp* value). These default to 0.0 and 100.0 respectively, hence
:attr:`value` is :attr:`temperature` divided by 100 by default.
... | [
"Returns",
"the",
"current",
"CPU",
"temperature",
"as",
"a",
"value",
"between",
"0",
".",
"0",
"(",
"representing",
"the",
"*",
"min_temp",
"*",
"value",
")",
"and",
"1",
".",
"0",
"(",
"representing",
"the",
"*",
"max_temp",
"*",
"value",
")",
".",
... | RPi-Distro/python-gpiozero | python | https://github.com/RPi-Distro/python-gpiozero/blob/7b67374fd0c8c4fde5586d9bad9531f076db9c0c/gpiozero/internal_devices.py#L205-L213 | [
"def",
"value",
"(",
"self",
")",
":",
"temp_range",
"=",
"self",
".",
"max_temp",
"-",
"self",
".",
"min_temp",
"return",
"(",
"self",
".",
"temperature",
"-",
"self",
".",
"min_temp",
")",
"/",
"temp_range"
] | 7b67374fd0c8c4fde5586d9bad9531f076db9c0c |
train | LoadAverage.load_average | Returns the current load average. | gpiozero/internal_devices.py | def load_average(self):
"""
Returns the current load average.
"""
with io.open(self.load_average_file, 'r') as f:
file_columns = f.readline().strip().split()
return float(file_columns[self._load_average_file_column]) | def load_average(self):
"""
Returns the current load average.
"""
with io.open(self.load_average_file, 'r') as f:
file_columns = f.readline().strip().split()
return float(file_columns[self._load_average_file_column]) | [
"Returns",
"the",
"current",
"load",
"average",
"."
] | RPi-Distro/python-gpiozero | python | https://github.com/RPi-Distro/python-gpiozero/blob/7b67374fd0c8c4fde5586d9bad9531f076db9c0c/gpiozero/internal_devices.py#L299-L305 | [
"def",
"load_average",
"(",
"self",
")",
":",
"with",
"io",
".",
"open",
"(",
"self",
".",
"load_average_file",
",",
"'r'",
")",
"as",
"f",
":",
"file_columns",
"=",
"f",
".",
"readline",
"(",
")",
".",
"strip",
"(",
")",
".",
"split",
"(",
")",
... | 7b67374fd0c8c4fde5586d9bad9531f076db9c0c |
train | LoadAverage.value | Returns the current load average as a value between 0.0 (representing
the *min_load_average* value) and 1.0 (representing the
*max_load_average* value). These default to 0.0 and 1.0 respectively. | gpiozero/internal_devices.py | def value(self):
"""
Returns the current load average as a value between 0.0 (representing
the *min_load_average* value) and 1.0 (representing the
*max_load_average* value). These default to 0.0 and 1.0 respectively.
"""
load_average_range = self.max_load_average - self.m... | def value(self):
"""
Returns the current load average as a value between 0.0 (representing
the *min_load_average* value) and 1.0 (representing the
*max_load_average* value). These default to 0.0 and 1.0 respectively.
"""
load_average_range = self.max_load_average - self.m... | [
"Returns",
"the",
"current",
"load",
"average",
"as",
"a",
"value",
"between",
"0",
".",
"0",
"(",
"representing",
"the",
"*",
"min_load_average",
"*",
"value",
")",
"and",
"1",
".",
"0",
"(",
"representing",
"the",
"*",
"max_load_average",
"*",
"value",
... | RPi-Distro/python-gpiozero | python | https://github.com/RPi-Distro/python-gpiozero/blob/7b67374fd0c8c4fde5586d9bad9531f076db9c0c/gpiozero/internal_devices.py#L308-L315 | [
"def",
"value",
"(",
"self",
")",
":",
"load_average_range",
"=",
"self",
".",
"max_load_average",
"-",
"self",
".",
"min_load_average",
"return",
"(",
"self",
".",
"load_average",
"-",
"self",
".",
"min_load_average",
")",
"/",
"load_average_range"
] | 7b67374fd0c8c4fde5586d9bad9531f076db9c0c |
train | TimeOfDay.value | Returns :data:`True` when the system clock reads between
:attr:`start_time` and :attr:`end_time`, and :data:`False` otherwise.
If :attr:`start_time` is greater than :attr:`end_time` (indicating a
period that crosses midnight), then this returns :data:`True` when the
current time is great... | gpiozero/internal_devices.py | def value(self):
"""
Returns :data:`True` when the system clock reads between
:attr:`start_time` and :attr:`end_time`, and :data:`False` otherwise.
If :attr:`start_time` is greater than :attr:`end_time` (indicating a
period that crosses midnight), then this returns :data:`True` w... | def value(self):
"""
Returns :data:`True` when the system clock reads between
:attr:`start_time` and :attr:`end_time`, and :data:`False` otherwise.
If :attr:`start_time` is greater than :attr:`end_time` (indicating a
period that crosses midnight), then this returns :data:`True` w... | [
"Returns",
":",
"data",
":",
"True",
"when",
"the",
"system",
"clock",
"reads",
"between",
":",
"attr",
":",
"start_time",
"and",
":",
"attr",
":",
"end_time",
"and",
":",
"data",
":",
"False",
"otherwise",
".",
"If",
":",
"attr",
":",
"start_time",
"i... | RPi-Distro/python-gpiozero | python | https://github.com/RPi-Distro/python-gpiozero/blob/7b67374fd0c8c4fde5586d9bad9531f076db9c0c/gpiozero/internal_devices.py#L415-L428 | [
"def",
"value",
"(",
"self",
")",
":",
"now",
"=",
"datetime",
".",
"utcnow",
"(",
")",
".",
"time",
"(",
")",
"if",
"self",
".",
"utc",
"else",
"datetime",
".",
"now",
"(",
")",
".",
"time",
"(",
")",
"if",
"self",
".",
"start_time",
"<",
"sel... | 7b67374fd0c8c4fde5586d9bad9531f076db9c0c |
train | DiskUsage.value | Returns the current disk usage as a value between 0.0 and 1.0 by
dividing :attr:`usage` by 100. | gpiozero/internal_devices.py | def value(self):
"""
Returns the current disk usage as a value between 0.0 and 1.0 by
dividing :attr:`usage` by 100.
"""
# This slightly convoluted calculation is equivalent to df's "Use%";
# it calculates the percentage of FS usage as a proportion of the
# space ... | def value(self):
"""
Returns the current disk usage as a value between 0.0 and 1.0 by
dividing :attr:`usage` by 100.
"""
# This slightly convoluted calculation is equivalent to df's "Use%";
# it calculates the percentage of FS usage as a proportion of the
# space ... | [
"Returns",
"the",
"current",
"disk",
"usage",
"as",
"a",
"value",
"between",
"0",
".",
"0",
"and",
"1",
".",
"0",
"by",
"dividing",
":",
"attr",
":",
"usage",
"by",
"100",
"."
] | RPi-Distro/python-gpiozero | python | https://github.com/RPi-Distro/python-gpiozero/blob/7b67374fd0c8c4fde5586d9bad9531f076db9c0c/gpiozero/internal_devices.py#L487-L500 | [
"def",
"value",
"(",
"self",
")",
":",
"# This slightly convoluted calculation is equivalent to df's \"Use%\";",
"# it calculates the percentage of FS usage as a proportion of the",
"# space available to *non-root users*. Technically this means it can",
"# exceed 100% (when FS is filled to the poi... | 7b67374fd0c8c4fde5586d9bad9531f076db9c0c |
train | inverted | Returns the inversion of the supplied values (*input_min* becomes
*input_max*, *input_max* becomes *input_min*, `input_min + 0.1` becomes
`input_max - 0.1`, etc.). 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 ... | gpiozero/tools.py | def inverted(values, input_min=0, input_max=1):
"""
Returns the inversion of the supplied values (*input_min* becomes
*input_max*, *input_max* becomes *input_min*, `input_min + 0.1` becomes
`input_max - 0.1`, etc.). All items in *values* are assumed to be between
*input_min* and *input_max* (which d... | def inverted(values, input_min=0, input_max=1):
"""
Returns the inversion of the supplied values (*input_min* becomes
*input_max*, *input_max* becomes *input_min*, `input_min + 0.1` becomes
`input_max - 0.1`, etc.). All items in *values* are assumed to be between
*input_min* and *input_max* (which d... | [
"Returns",
"the",
"inversion",
"of",
"the",
"supplied",
"values",
"(",
"*",
"input_min",
"*",
"becomes",
"*",
"input_max",
"*",
"*",
"input_max",
"*",
"becomes",
"*",
"input_min",
"*",
"input_min",
"+",
"0",
".",
"1",
"becomes",
"input_max",
"-",
"0",
".... | RPi-Distro/python-gpiozero | python | https://github.com/RPi-Distro/python-gpiozero/blob/7b67374fd0c8c4fde5586d9bad9531f076db9c0c/gpiozero/tools.py#L103-L126 | [
"def",
"inverted",
"(",
"values",
",",
"input_min",
"=",
"0",
",",
"input_max",
"=",
"1",
")",
":",
"values",
"=",
"_normalize",
"(",
"values",
")",
"if",
"input_min",
">=",
"input_max",
":",
"raise",
"ValueError",
"(",
"'input_min must be smaller than input_m... | 7b67374fd0c8c4fde5586d9bad9531f076db9c0c |
train | scaled | Returns *values* scaled from *output_min* to *output_max*, assuming that
all items in *values* lie between *input_min* and *input_max* (which
default to 0 and 1 respectively). For example, to control the direction of
a motor (which is represented as a value between -1 and 1) using a
potentiometer (which... | gpiozero/tools.py | def scaled(values, output_min, output_max, input_min=0, input_max=1):
"""
Returns *values* scaled from *output_min* to *output_max*, assuming that
all items in *values* lie between *input_min* and *input_max* (which
default to 0 and 1 respectively). For example, to control the direction of
a motor (... | def scaled(values, output_min, output_max, input_min=0, input_max=1):
"""
Returns *values* scaled from *output_min* to *output_max*, assuming that
all items in *values* lie between *input_min* and *input_max* (which
default to 0 and 1 respectively). For example, to control the direction of
a motor (... | [
"Returns",
"*",
"values",
"*",
"scaled",
"from",
"*",
"output_min",
"*",
"to",
"*",
"output_max",
"*",
"assuming",
"that",
"all",
"items",
"in",
"*",
"values",
"*",
"lie",
"between",
"*",
"input_min",
"*",
"and",
"*",
"input_max",
"*",
"(",
"which",
"d... | RPi-Distro/python-gpiozero | python | https://github.com/RPi-Distro/python-gpiozero/blob/7b67374fd0c8c4fde5586d9bad9531f076db9c0c/gpiozero/tools.py#L129-L160 | [
"def",
"scaled",
"(",
"values",
",",
"output_min",
",",
"output_max",
",",
"input_min",
"=",
"0",
",",
"input_max",
"=",
"1",
")",
":",
"values",
"=",
"_normalize",
"(",
"values",
")",
"if",
"input_min",
">=",
"input_max",
":",
"raise",
"ValueError",
"("... | 7b67374fd0c8c4fde5586d9bad9531f076db9c0c |
train | clamped | Returns *values* clamped from *output_min* to *output_max*, i.e. any items
less than *output_min* will be returned as *output_min* and any items
larger than *output_max* will be returned as *output_max* (these default to
0 and 1 respectively). For example::
from gpiozero import PWMLED, MCP3008
... | gpiozero/tools.py | def clamped(values, output_min=0, output_max=1):
"""
Returns *values* clamped from *output_min* to *output_max*, i.e. any items
less than *output_min* will be returned as *output_min* and any items
larger than *output_max* will be returned as *output_max* (these default to
0 and 1 respectively). For... | def clamped(values, output_min=0, output_max=1):
"""
Returns *values* clamped from *output_min* to *output_max*, i.e. any items
less than *output_min* will be returned as *output_min* and any items
larger than *output_max* will be returned as *output_max* (these default to
0 and 1 respectively). For... | [
"Returns",
"*",
"values",
"*",
"clamped",
"from",
"*",
"output_min",
"*",
"to",
"*",
"output_max",
"*",
"i",
".",
"e",
".",
"any",
"items",
"less",
"than",
"*",
"output_min",
"*",
"will",
"be",
"returned",
"as",
"*",
"output_min",
"*",
"and",
"any",
... | RPi-Distro/python-gpiozero | python | https://github.com/RPi-Distro/python-gpiozero/blob/7b67374fd0c8c4fde5586d9bad9531f076db9c0c/gpiozero/tools.py#L163-L185 | [
"def",
"clamped",
"(",
"values",
",",
"output_min",
"=",
"0",
",",
"output_max",
"=",
"1",
")",
":",
"values",
"=",
"_normalize",
"(",
"values",
")",
"if",
"output_min",
">=",
"output_max",
":",
"raise",
"ValueError",
"(",
"'output_min must be smaller than out... | 7b67374fd0c8c4fde5586d9bad9531f076db9c0c |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.