_id stringlengths 2 7 | title stringlengths 1 88 | partition stringclasses 3
values | text stringlengths 31 13.1k | language stringclasses 1
value | meta_information dict |
|---|---|---|---|---|---|
q18200 | Facts.load_facts | train | def load_facts(self, facts):
"""Load a set of facts into the CLIPS data base.
The C equivalent of the CLIPS load-facts command.
Facts can be loaded from a string or from a text file.
"""
facts = facts.encode()
if os.path.exists(facts):
ret = lib.EnvLoadFacts(self._env, facts)
| python | {
"resource": ""
} |
q18201 | Facts.save_facts | train | def save_facts(self, path, mode=SaveMode.LOCAL_SAVE):
"""Save the facts in the system to the specified file.
The Python equivalent of the CLIPS save-facts command.
"""
| python | {
"resource": ""
} |
q18202 | Fact.asserted | train | def asserted(self):
"""True if the fact has been asserted within CLIPS."""
# https://sourceforge.net/p/clipsrules/discussion/776945/thread/4f04bb9e/
| python | {
"resource": ""
} |
q18203 | Fact.template | train | def template(self):
"""The associated Template."""
return Template(
| python | {
"resource": ""
} |
q18204 | Fact.assertit | train | def assertit(self):
"""Assert the fact within the CLIPS environment."""
if self.asserted:
raise RuntimeError("Fact already | python | {
"resource": ""
} |
q18205 | Fact.retract | train | def retract(self):
"""Retract the fact from the CLIPS environment."""
if | python | {
"resource": ""
} |
q18206 | ImpliedFact.append | train | def append(self, value):
"""Append an element to the fact."""
| python | {
"resource": ""
} |
q18207 | ImpliedFact.extend | train | def extend(self, values):
"""Append multiple elements to the fact."""
if self.asserted:
| python | {
"resource": ""
} |
q18208 | ImpliedFact.assertit | train | def assertit(self):
"""Assert the fact within CLIPS."""
data = clips.data.DataObject(self._env)
data.value = list(self._multifield)
if lib.EnvPutFactSlot(
| python | {
"resource": ""
} |
q18209 | TemplateFact.update | train | def update(self, sequence=None, **mapping):
"""Add multiple elements to the fact."""
if sequence is not None:
if isinstance(sequence, dict):
for | python | {
"resource": ""
} |
q18210 | Template.name | train | def name(self):
"""Template name."""
return ffi.string(
| python | {
"resource": ""
} |
q18211 | Template.module | train | def module(self):
"""The module in which the Template is defined.
Python equivalent of the CLIPS deftemplate-module command.
"""
| python | {
"resource": ""
} |
q18212 | Template.watch | train | def watch(self, flag):
"""Whether or not the Template is being watched."""
| python | {
"resource": ""
} |
q18213 | Template.slots | train | def slots(self):
"""Iterate over the Slots of the Template."""
if self.implied:
return ()
data = clips.data.DataObject(self._env)
| python | {
"resource": ""
} |
q18214 | Template.new_fact | train | def new_fact(self):
"""Create a new Fact from this template."""
fact = lib.EnvCreateFact(self._env, self._tpl)
if fact == ffi.NULL:
| python | {
"resource": ""
} |
q18215 | Template.undefine | train | def undefine(self):
"""Undefine the Template.
Python equivalent of the CLIPS undeftemplate command.
| python | {
"resource": ""
} |
q18216 | TemplateSlot.multifield | train | def multifield(self):
"""True if the slot is a multifield slot."""
return | python | {
"resource": ""
} |
q18217 | TemplateSlot.default_type | train | def default_type(self):
"""The default value type for this Slot.
The Python equivalent of the CLIPS deftemplate-slot-defaultp function.
"""
| python | {
"resource": ""
} |
q18218 | Classes.instances_changed | train | def instances_changed(self):
"""True if any instance has changed."""
value = bool(lib.EnvGetInstancesChanged(self._env))
| python | {
"resource": ""
} |
q18219 | Classes.classes | train | def classes(self):
"""Iterate over the defined Classes."""
defclass = lib.EnvGetNextDefclass(self._env, ffi.NULL)
while defclass != ffi.NULL:
| python | {
"resource": ""
} |
q18220 | Classes.find_class | train | def find_class(self, name):
"""Find the Class by its name."""
defclass = lib.EnvFindDefclass(self._env, name.encode())
if defclass == ffi.NULL:
| python | {
"resource": ""
} |
q18221 | Classes.instances | train | def instances(self):
"""Iterate over the defined Instancees."""
definstance = lib.EnvGetNextInstance(self._env, ffi.NULL)
while definstance != ffi.NULL:
| python | {
"resource": ""
} |
q18222 | Classes.find_instance | train | def find_instance(self, name, module=None):
"""Find the Instance by its name."""
module = module if module is not None else ffi.NULL
definstance = lib.EnvFindInstance(self._env, module, name.encode(), 1)
| python | {
"resource": ""
} |
q18223 | Classes.load_instances | train | def load_instances(self, instances):
"""Load a set of instances into the CLIPS data base.
The C equivalent of the CLIPS load-instances command.
Instances can be loaded from a string,
from a file or from a binary file.
| python | {
"resource": ""
} |
q18224 | Classes.restore_instances | train | def restore_instances(self, instances):
"""Restore a set of instances into the CLIPS data base.
The Python equivalent of the CLIPS restore-instances command.
Instances can be passed as a set of strings or as a file.
"""
instances | python | {
"resource": ""
} |
q18225 | Classes.save_instances | train | def save_instances(self, path, binary=False, mode=SaveMode.LOCAL_SAVE):
"""Save the instances in the system to the specified file.
If binary is True, the instances will be saved in binary format.
The Python equivalent of the CLIPS save-instances command.
"""
if binary:
| python | {
"resource": ""
} |
q18226 | Classes.make_instance | train | def make_instance(self, command):
"""Create and initialize an instance of a user-defined class.
command must be a string in the form:
(<instance-name> of <class-name> <slot-override>*)
<slot-override> :== (<slot-name> <constant>*)
Python equivalent of the CLIPS make-instance command.
| python | {
"resource": ""
} |
q18227 | Class.name | train | def name(self):
"""Class name."""
return | python | {
"resource": ""
} |
q18228 | Class.module | train | def module(self):
"""The module in which the Class is defined.
Python equivalent of the CLIPS defglobal-module command.
"""
| python | {
"resource": ""
} |
q18229 | Class.watch_instances | train | def watch_instances(self, flag):
"""Whether or not the Class Instances are being watched."""
| python | {
"resource": ""
} |
q18230 | Class.watch_slots | train | def watch_slots(self, flag):
"""Whether or not the Class Slots are being watched."""
| python | {
"resource": ""
} |
q18231 | Class.new_instance | train | def new_instance(self, name):
"""Create a new raw instance from this Class.
No slot overrides or class default initializations
are performed for the instance.
| python | {
"resource": ""
} |
q18232 | Class.find_message_handler | train | def find_message_handler(self, handler_name, handler_type='primary'):
"""Returns the MessageHandler given its name and type for this class."""
ret = lib.EnvFindDefmessageHandler(
self._env, self._cls, | python | {
"resource": ""
} |
q18233 | Class.subclass | train | def subclass(self, klass):
"""True if the Class is a subclass of the given one."""
| python | {
"resource": ""
} |
q18234 | Class.superclass | train | def superclass(self, klass):
"""True if the Class is a superclass of the given one."""
| python | {
"resource": ""
} |
q18235 | Class.slots | train | def slots(self, inherited=False):
"""Iterate over the Slots of the class."""
data = clips.data.DataObject(self._env)
| python | {
"resource": ""
} |
q18236 | Class.instances | train | def instances(self):
"""Iterate over the instances of the class."""
ist = lib.EnvGetNextInstanceInClass(self._env, self._cls, ffi.NULL)
while ist != ffi.NULL:
| python | {
"resource": ""
} |
q18237 | Class.subclasses | train | def subclasses(self, inherited=False):
"""Iterate over the subclasses of the class.
This function is the Python equivalent
of the CLIPS class-subclasses command.
| python | {
"resource": ""
} |
q18238 | Class.superclasses | train | def superclasses(self, inherited=False):
"""Iterate over the superclasses of the class.
This function is the Python equivalent
of the CLIPS class-superclasses command.
"""
data = clips.data.DataObject(self._env)
lib.EnvClassSuperclasses(
| python | {
"resource": ""
} |
q18239 | Class.message_handlers | train | def message_handlers(self):
"""Iterate over the message handlers of the class."""
index = lib.EnvGetNextDefmessageHandler(self._env, self._cls, 0)
while index != 0:
| python | {
"resource": ""
} |
q18240 | Class.undefine | train | def undefine(self):
"""Undefine the Class.
Python equivalent of the CLIPS undefclass command.
The object becomes unusable after this method has been called.
""" | python | {
"resource": ""
} |
q18241 | FortranReader.include | train | def include(self):
"""
If the next line is an include statement, inserts the contents
of the included file into the pending buffer.
"""
if len(self.pending) == 0 or not self.pending[0].startswith('include '):
return
name = self.pending.pop(0)[8:].strip()[1:-1]
for b in [os.path.dirname(self.name)] + self.inc_dirs:
pname = os.path.abspath(os.path.expanduser(os.path.join(b, name)))
if os.path.isfile(pname):
name = pname
break
| python | {
"resource": ""
} |
q18242 | GraphData.register | train | def register(self,obj,cls=type(None),hist={}):
"""
Takes a FortranObject and adds it to the appropriate list, if
not already present.
"""
#~ ident = getattr(obj,'ident',obj)
if is_submodule(obj,cls):
if obj not in self.submodules: self.submodules[obj] = SubmodNode(obj,self)
elif is_module(obj,cls):
if obj not in self.modules: self.modules[obj] = ModNode(obj,self)
elif is_type(obj,cls):
if obj not in self.types: self.types[obj] = TypeNode(obj,self,hist)
elif is_proc(obj,cls):
if obj not in self.procedures: self.procedures[obj] = ProcNode(obj,self,hist)
elif is_program(obj,cls):
if | python | {
"resource": ""
} |
q18243 | GraphData.get_node | train | def get_node(self,obj,cls=type(None),hist={}):
"""
Returns the node corresponding to obj. If does not already exist
then it will create it.
"""
#~ ident = getattr(obj,'ident',obj)
if obj in self.modules and is_module(obj,cls):
return self.modules[obj]
elif obj in self.submodules and is_submodule(obj,cls):
return self.submodules[obj]
elif obj in self.types and is_type(obj,cls):
return self.types[obj]
elif obj in self.procedures and is_proc(obj,cls):
return self.procedures[obj]
elif obj in self.programs and is_program(obj,cls):
| python | {
"resource": ""
} |
q18244 | FortranGraph.add_to_graph | train | def add_to_graph(self, nodes, edges, nesting):
"""
Adds nodes and edges to the graph as long as the maximum number
of nodes is not exceeded.
All edges are expected to have a reference to an entry in nodes.
If the list of nodes is not added in the first hop due to graph
size limitations, they are stored in hopNodes.
If the graph was extended the function returns True, otherwise the
result will be False.
"""
if (len(nodes) + len(self.added)) > self.max_nodes:
if nesting < 2:
self.hopNodes = nodes
self.hopEdges = edges
self.truncated = nesting
return False
else:
for n in nodes:
self.dot.node(n.ident, **n.attribs)
| python | {
"resource": ""
} |
q18245 | ModuleGraph.add_nodes | train | def add_nodes(self, nodes, nesting=1):
"""
Adds nodes and edges for generating the graph showing the relationship
between modules and submodules listed in nodes.
"""
hopNodes = set() # nodes in this hop
hopEdges = [] # edges in this hop
# get nodes and edges for this hop
for i, n in zip(range(len(nodes)), nodes):
r, g, b = rainbowcolour(i, len(nodes))
colour = '#%02X%02X%02X' % (r, g, b)
for nu in n.uses:
if nu not in self.added:
hopNodes.add(nu)
hopEdges.append((n, nu, 'dashed', colour))
if hasattr(n, 'ancestor'):
if n.ancestor not in self.added:
| python | {
"resource": ""
} |
q18246 | FileGraph.add_nodes | train | def add_nodes(self, nodes, nesting=1):
"""
Adds edges showing dependencies between source files listed in
the nodes.
"""
hopNodes = set() # nodes in this hop
hopEdges = [] # edges in this hop
# get nodes and edges for this hop
for i, n in zip(range(len(nodes)), nodes):
r, g, b = rainbowcolour(i, len(nodes))
colour = '#%02X%02X%02X' % (r, g, b)
for ne in n.efferent:
if | python | {
"resource": ""
} |
q18247 | CallGraph.add_nodes | train | def add_nodes(self, nodes, nesting=1):
"""
Adds edges indicating the call-tree for the procedures listed in
the nodes.
"""
hopNodes = set() # nodes in this hop
hopEdges = [] # edges in this hop
# get nodes and edges for this hop
for i, n in zip(range(len(nodes)), nodes):
r, g, b = rainbowcolour(i, len(nodes))
colour = '#%02X%02X%02X' % (r, g, b)
for p in n.calls:
if p not in hopNodes:
hopNodes.add(p)
hopEdges.append((n, p, 'solid', colour))
for p in getattr(n, 'interfaces', []):
if p not in hopNodes:
hopNodes.add(p)
| python | {
"resource": ""
} |
q18248 | DefaultObjectPolicy.exception | train | def exception(self, url, exception):
'''What to return when there's an exception.'''
| python | {
"resource": ""
} |
q18249 | parse_date | train | def parse_date(string):
'''Return a timestamp for the provided datestring, described by RFC 7231.'''
parsed = email.utils.parsedate_tz(string)
| python | {
"resource": ""
} |
q18250 | HeaderWithDefaultPolicy.ttl | train | def ttl(self, response):
'''Get the ttl from headers.'''
# If max-age is specified in Cache-Control, use it and ignore any
# Expires header, as per RFC2616 Sec. 13.2.4.
cache_control = response.headers.get('cache-control')
if cache_control is not None:
for directive in cache_control.split(','):
name, _, value = directive.lower().partition('=')
name = name.strip()
if name in ('no-store', 'must-revalidate', 'no-cache'):
return max(self.minimum, 0)
elif name in ('s-maxage', 'max-age'):
try:
return max(self.minimum, int(value.strip()))
except ValueError:
logger.warn(
'Could not parse %s=%s', name, value, exc_info=1)
# Check the Expires header
expires = response.headers.get('expires')
if expires is not None:
# Evaluate the expiration relative to the server-provided date
| python | {
"resource": ""
} |
q18251 | ExpiringObject.get | train | def get(self):
'''Get the wrapped object.'''
if (self.obj is None) or (time.time() >= self.expires):
with self.lock:
self.expires, self.obj = self.factory()
| python | {
"resource": ""
} |
q18252 | BaseCache.get | train | def get(self, url):
'''Get the entity that corresponds to URL.'''
robots_url = Robots.robots_url(url)
if robots_url not in self.cache:
| python | {
"resource": ""
} |
q18253 | RobotsCache.allowed | train | def allowed(self, url, agent):
'''Return true if the provided URL is allowed to agent.'''
| python | {
"resource": ""
} |
q18254 | timer | train | def timer(name, count):
'''Time this block.'''
start = time.time()
try:
yield count
finally:
duration = time.time() - start
print(name)
print('=' * 10)
print('Total: %s' % duration)
| python | {
"resource": ""
} |
q18255 | add_command_arguments | train | def add_command_arguments(parser):
"""
Additional command line arguments for the behave management command
"""
parser.add_argument(
'--noinput',
'--no-input',
action='store_const',
const=False,
dest='interactive',
help='Tells Django to NOT prompt the user for input of any kind.',
)
parser.add_argument(
'--failfast', action='store_const', const=True, dest='failfast',
help=('Tells Django to stop running the '
'test suite after first failed test.'),
)
parser.add_argument(
'-r', '--reverse', action='store_const', const=True, dest='reverse',
help='Reverses test cases order.',
)
parser.add_argument(
'--use-existing-database',
action='store_true',
| python | {
"resource": ""
} |
q18256 | add_behave_arguments | train | def add_behave_arguments(parser): # noqa
"""
Additional command line arguments extracted directly from behave
"""
# Option strings that conflict with Django
conflicts = [
'--no-color',
'--version',
'-c',
'-k',
'-v',
'-S',
'--simple',
]
parser.add_argument(
'paths',
action='store',
nargs='*',
help="Feature directory, file or file location (FILE:LINE)."
)
for fixed, keywords in behave_options:
| python | {
"resource": ""
} |
q18257 | Command.add_arguments | train | def add_arguments(self, parser):
"""
Add behave's and our command line arguments to the command
"""
parser.usage = "%(prog)s [options] [ [DIR|FILE|FILE:LINE] ]+"
parser.description = """\
| python | {
"resource": ""
} |
q18258 | Command.get_behave_args | train | def get_behave_args(self, argv=sys.argv):
"""
Get a list of those command line arguments specified with the
management command that are meant as arguments for running behave.
"""
parser = BehaveArgsHelper().create_parser('manage.py', 'behave')
args, unknown = parser.parse_known_args(argv[2:])
behave_args = []
for option in unknown:
# Remove behave prefix
if option.startswith('--behave-'):
| python | {
"resource": ""
} |
q18259 | load_registered_fixtures | train | def load_registered_fixtures(context):
"""
Apply fixtures that are registered with the @fixtures decorator.
"""
# -- SELECT STEP REGISTRY:
# HINT: Newer behave versions use runner.step_registry
# to be able to support multiple runners, each with its own step_registry.
runner = context._runner # pylint: disable=protected-access
step_registry = getattr(runner, 'step_registry', None)
if not step_registry:
# -- BACKWARD-COMPATIBLE: Use module_step_registry
step_registry = | python | {
"resource": ""
} |
q18260 | BehaveHooksMixin.patch_context | train | def patch_context(self, context):
"""
Patches the context to add utility functions
Sets up the base_url, and the get_url() utility function.
"""
context.__class__ = PatchedContext
# Simply setting __class__ directly doesn't work
| python | {
"resource": ""
} |
q18261 | BehaveHooksMixin.setup_fixtures | train | def setup_fixtures(self, context):
"""
Sets up fixtures
"""
if getattr(context, 'fixtures', None):
context.test.fixtures = copy(context.fixtures)
if getattr(context, 'reset_sequences', None):
context.test.reset_sequences = context.reset_sequences
| python | {
"resource": ""
} |
q18262 | DenonAVR.exec_appcommand_post | train | def exec_appcommand_post(self, attribute_list):
"""
Prepare and execute a HTTP POST call to AppCommand.xml end point.
Returns XML ElementTree on success and None on fail.
"""
# Prepare POST XML body for AppCommand.xml
post_root = ET.Element("tx")
for attribute in attribute_list:
# Append tags for each attribute
item = ET.Element("cmd")
item.set("id", "1")
item.text = attribute
post_root.append(item)
# Buffer XML body as binary IO
body = BytesIO()
post_tree = ET.ElementTree(post_root)
| python | {
"resource": ""
} |
q18263 | DenonAVR.get_status_xml | train | def get_status_xml(self, command, suppress_errors=False):
"""Get status XML via HTTP and return it as XML ElementTree."""
# Get XML structure via HTTP get
res = requests.get("http://{host}:{port}{command}".format(
host=self._host, port=self._receiver_port, command=command),
timeout=self.timeout)
# Continue with XML processing only if HTTP status code = 200
if res.status_code == 200:
try:
# Return XML ElementTree
return ET.fromstring(res.text)
except ET.ParseError as err:
if not suppress_errors:
_LOGGER.error(
"Host %s returned malformed XML for end point %s",
| python | {
"resource": ""
} |
q18264 | DenonAVR.send_get_command | train | def send_get_command(self, command):
"""Send command via HTTP get to receiver."""
# Send commands via HTTP get
res = requests.get("http://{host}:{port}{command}".format(
host=self._host, port=self._receiver_port, command=command),
timeout=self.timeout)
if res.status_code == 200:
return True
else:
| python | {
"resource": ""
} |
q18265 | DenonAVR.send_post_command | train | def send_post_command(self, command, body):
"""Send command via HTTP post to receiver."""
# Send commands via HTTP post
res = requests.post("http://{host}:{port}{command}".format(
host=self._host, port=self._receiver_port, command=command),
data=body, timeout=self.timeout)
if res.status_code == 200:
return res.text
else:
| python | {
"resource": ""
} |
q18266 | DenonAVR.create_zones | train | def create_zones(self, add_zones):
"""Create instances of additional zones for the receiver."""
for zone, zname in add_zones.items():
# Name either set explicitly or name of Main Zone with suffix
zonename = "{} {}".format(self._name, zone) if (
| python | {
"resource": ""
} |
q18267 | DenonAVR._update_input_func_list | train | def _update_input_func_list(self):
"""
Update sources list from receiver.
Internal method which updates sources list of receiver after getting
sources and potential renaming information from receiver.
"""
# Get all sources and renaming information from receiver
# For structural information of the variables please see the methods
receiver_sources = self._get_receiver_sources()
if not receiver_sources:
_LOGGER.error("Receiver sources list empty. "
"Please check if device is powered on.")
return False
# First input_func_list determination of AVR-X receivers
if self._receiver_type in [AVR_X.type, AVR_X_2016.type]:
renamed_sources, deleted_sources, status_success = (
self._get_renamed_deleted_sourcesapp())
# Backup if previous try with AppCommand was not successful
if not status_success:
renamed_sources, deleted_sources = (
self._get_renamed_deleted_sources())
# Remove all deleted sources
if self._show_all_inputs is False:
for deleted_source in deleted_sources.items():
if deleted_source[1] == "DEL":
receiver_sources.pop(deleted_source[0], None)
# Clear and rebuild the sources lists
self._input_func_list.clear()
self._input_func_list_rev.clear()
self._netaudio_func_list.clear()
self._playing_func_list.clear()
for item in receiver_sources.items():
# Mapping of item[0] because some func names are inconsistant
# at AVR-X receivers
| python | {
"resource": ""
} |
q18268 | DenonAVR._get_receiver_name | train | def _get_receiver_name(self):
"""Get name of receiver from web interface if not set."""
# If name is not set yet, get it from Main Zone URL
if self._name is None and self._urls.mainzone is not None:
name_tag = {"FriendlyName": None}
try:
root = self.get_status_xml(self._urls.mainzone)
except (ValueError,
| python | {
"resource": ""
} |
q18269 | DenonAVR._get_zone_name | train | def _get_zone_name(self):
"""Get receivers zone name if not set yet."""
if self._name is None:
# Collect tags for AppCommand.xml call
tags = ["GetZoneName"]
# Execute call
root = self.exec_appcommand_post(tags)
# Check result
if root is None:
_LOGGER.error("Getting ZoneName failed.")
else:
zone = self._get_own_zone()
| python | {
"resource": ""
} |
q18270 | DenonAVR._get_receiver_sources | train | def _get_receiver_sources(self):
"""
Get sources list from receiver.
Internal method which queries device via HTTP to get the receiver's
input sources.
This method also determines the type of the receiver
(avr, avr-x, avr-x-2016).
"""
# Test if receiver is a AVR-X with port 80 for pre 2016 devices and
# port 8080 devices 2016 and later
r_types = [AVR_X, AVR_X_2016]
for r_type, port in r_types:
self._receiver_port = port
# This XML is needed to get the sources of the receiver
try:
root = self.get_status_xml(self._urls.deviceinfo,
suppress_errors=True)
except (ValueError, requests.exceptions.RequestException):
self._receiver_type = None
else:
# First test by CommApiVers
try:
if bool(DEVICEINFO_COMMAPI_PATTERN.search(
root.find("CommApiVers").text) is not None):
self._receiver_type = r_type
# receiver found break the loop
break
except AttributeError:
# AttributeError occurs when ModelName tag is not found.
# In this case there is no AVR-X device
self._receiver_type = None
# if first test did not find AVR-X device, check by model name
if self._receiver_type is None:
try:
if bool(DEVICEINFO_AVR_X_PATTERN.search(
root.find("ModelName").text) is not None):
self._receiver_type = r_type
# receiver found break the loop
break
except AttributeError:
# AttributeError occurs when ModelName tag is not found
# In this case there is no AVR-X device
self._receiver_type = None
# Set ports and update method
if self._receiver_type is None:
self._receiver_type = AVR.type
self._receiver_port = AVR.port
elif self._receiver_type == AVR_X_2016.type:
self._receiver_port = AVR_X_2016.port
else:
self._receiver_port = AVR_X.port
_LOGGER.info("Identified receiver type: '%s' on port: '%s'",
self._receiver_type, self._receiver_port)
# Not an AVR-X device, start determination of sources
if self._receiver_type == AVR.type:
# Sources list is equal to list of renamed sources.
| python | {
"resource": ""
} |
q18271 | DenonAVR._get_status_from_xml_tags | train | def _get_status_from_xml_tags(self, root, relevant_tags):
"""
Get relevant status tags from XML structure with this internal method.
Status is saved to internal attributes.
Return dictionary of tags not found in XML.
"""
for child in root:
if child.tag not in relevant_tags.keys():
continue
elif child.tag == "Power":
self._power = child[0].text
relevant_tags.pop(child.tag, None)
elif child.tag == "InputFuncSelect":
inputfunc = child[0].text
if inputfunc is not None:
try:
self._input_func = self._input_func_list_rev[inputfunc]
except KeyError:
_LOGGER.info(
"No mapping for source %s found", inputfunc)
self._input_func = inputfunc
finally:
| python | {
"resource": ""
} |
q18272 | DenonAVR.set_input_func | train | def set_input_func(self, input_func):
"""
Set input_func of device.
Valid values depend on the device and should be taken from
"input_func_list".
Return "True" on success and "False" on fail.
"""
# For selection of sources other names then at receiving sources
# have to be used
# AVR-X receiver needs source mapping to set input_func
if self._receiver_type in [AVR_X.type, AVR_X_2016.type]:
direct_mapping = False
try:
linp = CHANGE_INPUT_MAPPING[self._input_func_list[input_func]]
except KeyError:
direct_mapping = True
else:
direct_mapping = True
# AVR-nonX receiver and if no mapping was found get parameter for
# setting input_func directly
if direct_mapping is True:
try:
linp = self._input_func_list[input_func]
except KeyError:
_LOGGER.error("No mapping for input source %s", input_func)
return False | python | {
"resource": ""
} |
q18273 | DenonAVR._set_all_zone_stereo | train | def _set_all_zone_stereo(self, zst_on):
"""
Set All Zone Stereo option on the device.
Calls command to activate/deactivate the mode
Return "True" when successfully sent.
"""
command_url = self._urls.command_set_all_zone_stereo
if zst_on:
command_url += "ZST ON"
else:
command_url += "ZST OFF"
try:
| python | {
"resource": ""
} |
q18274 | DenonAVR.set_sound_mode | train | def set_sound_mode(self, sound_mode):
"""
Set sound_mode of device.
Valid values depend on the device and should be taken from
"sound_mode_list".
Return "True" on success and "False" on fail.
"""
if sound_mode == ALL_ZONE_STEREO:
if self._set_all_zone_stereo(True):
self._sound_mode_raw = ALL_ZONE_STEREO
return True
else:
return False
if self._sound_mode_raw == ALL_ZONE_STEREO:
if not self._set_all_zone_stereo(False):
return False
# For selection of sound mode other names then at receiving sound modes
# have to be used
# Therefore source mapping is needed to get sound_mode
| python | {
"resource": ""
} |
q18275 | DenonAVR.set_sound_mode_dict | train | def set_sound_mode_dict(self, sound_mode_dict):
"""Set the matching dictionary used to match the raw sound mode."""
error_msg = ("Syntax of sound mode dictionary not valid, "
"use: OrderedDict([('COMMAND', ['VALUE1','VALUE2'])])")
if isinstance(sound_mode_dict, dict):
mode_list = list(sound_mode_dict.values())
for sublist in mode_list:
if isinstance(sublist, list):
for element in sublist:
if not isinstance(element, str):
_LOGGER.error(error_msg)
return False
| python | {
"resource": ""
} |
q18276 | DenonAVR.construct_sm_match_dict | train | def construct_sm_match_dict(self):
"""
Construct the sm_match_dict.
Reverse the key value structure. The sm_match_dict is bigger,
but allows for direct matching using a dictionary key access.
The sound_mode_dict is uses externally to set this dictionary
because that has a nicer syntax.
"""
| python | {
"resource": ""
} |
q18277 | DenonAVR.match_sound_mode | train | def match_sound_mode(self, sound_mode_raw):
"""Match the raw_sound_mode to its corresponding sound_mode."""
try:
sound_mode = self._sm_match_dict[sound_mode_raw.upper()]
return sound_mode
except KeyError:
smr_up = sound_mode_raw.upper()
self._sound_mode_dict[smr_up] = [smr_up]
| python | {
"resource": ""
} |
q18278 | DenonAVR.toggle_play_pause | train | def toggle_play_pause(self):
"""Toggle play pause media player."""
# Use Play/Pause button only for sources which support NETAUDIO
if (self._state == STATE_PLAYING and
self._input_func in self._netaudio_func_list):
| python | {
"resource": ""
} |
q18279 | DenonAVR._play | train | def _play(self):
"""Send play command to receiver command via HTTP post."""
# Use pause command only for sources which support NETAUDIO
if self._input_func in self._netaudio_func_list:
body = {"cmd0": "PutNetAudioCommand/CurEnter",
"cmd1": "aspMainZone_WebUpdateStatus/",
"ZoneName": "MAIN ZONE"}
try:
if self.send_post_command(
| python | {
"resource": ""
} |
q18280 | DenonAVR._pause | train | def _pause(self):
"""Send pause command to receiver command via HTTP post."""
# Use pause command only for sources which support NETAUDIO
if self._input_func in self._netaudio_func_list:
body = {"cmd0": "PutNetAudioCommand/CurEnter",
"cmd1": "aspMainZone_WebUpdateStatus/",
"ZoneName": "MAIN ZONE"}
try:
if self.send_post_command(
| python | {
"resource": ""
} |
q18281 | DenonAVR.previous_track | train | def previous_track(self):
"""Send previous track command to receiver command via HTTP post."""
# Use previous track button only for sources which support NETAUDIO
if self._input_func in self._netaudio_func_list:
body = {"cmd0": "PutNetAudioCommand/CurUp",
"cmd1": "aspMainZone_WebUpdateStatus/",
"ZoneName": "MAIN ZONE"}
try:
| python | {
"resource": ""
} |
q18282 | DenonAVR.volume_up | train | def volume_up(self):
"""Volume up receiver via HTTP get command."""
try:
return bool(self.send_get_command(self._urls.command_volume_up))
except | python | {
"resource": ""
} |
q18283 | DenonAVR.volume_down | train | def volume_down(self):
"""Volume down receiver via HTTP get command."""
try:
return bool(self.send_get_command(self._urls.command_volume_down))
except | python | {
"resource": ""
} |
q18284 | DenonAVR.set_volume | train | def set_volume(self, volume):
"""
Set receiver volume via HTTP get command.
Volume is send in a format like -50.0.
Minimum is -80.0, maximum at 18.0
"""
if volume < -80 or volume > 18:
raise ValueError("Invalid volume")
try:
| python | {
"resource": ""
} |
q18285 | DenonAVR.mute | train | def mute(self, mute):
"""Mute receiver via HTTP get command."""
try:
if mute:
if self.send_get_command(self._urls.command_mute_on):
self._mute = STATE_ON
return True
else:
return False
else:
if self.send_get_command(self._urls.command_mute_off):
| python | {
"resource": ""
} |
q18286 | DenonAVRZones.sound_mode | train | def sound_mode(self):
"""Return the matched current sound mode as a string."""
| python | {
"resource": ""
} |
q18287 | identify_denonavr_receivers | train | def identify_denonavr_receivers():
"""
Identify DenonAVR using SSDP and SCPD queries.
Returns a list of dictionaries which includes all discovered Denon AVR
devices with keys "host", "modelName", "friendlyName", "presentationURL".
"""
# Sending SSDP broadcast message to get devices
devices = send_ssdp_broadcast()
# Check which responding device is a DenonAVR device and prepare output
receivers = | python | {
"resource": ""
} |
q18288 | send_ssdp_broadcast | train | def send_ssdp_broadcast():
"""
Send SSDP broadcast message to discover UPnP devices.
Returns a list of dictionaries with "address" (IP, PORT) and "URL"
of SCPD XML for all discovered devices.
"""
# Send up to three different broadcast messages
for i, ssdp_query in enumerate(SSDP_QUERIES):
# Prepare SSDP broadcast message
sock = socket.socket(
socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
sock.settimeout(2)
sock.sendto(ssdp_query.encode(), (SSDP_ADDR, SSDP_PORT))
# Collect all responses within the timeout period
res = []
try:
while True:
res.append(sock.recvfrom(10240))
except socket.timeout:
sock.close()
if res:
_LOGGER.debug("Got results after %s SSDP queries", i + 1)
sock.close()
break
# Prepare output of responding devices
devices = {}
device = {}
for entry in res:
device["address"] = entry[1]
# Some string operations to get the receivers URL
| python | {
"resource": ""
} |
q18289 | evaluate_scpd_xml | train | def evaluate_scpd_xml(url):
"""
Get and evaluate SCPD XML to identified URLs.
Returns dictionary with keys "host", "modelName", "friendlyName" and
"presentationURL" if a Denon AVR device was found and "False" if not.
"""
# Get SCPD XML via HTTP GET
try:
res = requests.get(url, timeout=2)
except requests.exceptions.RequestException as err:
_LOGGER.error(
"When trying to request %s the following error occurred: %s",
url, err)
raise ConnectionError
if res.status_code == 200:
try:
root = ET.fromstring(res.text)
# Look for manufacturer "Denon" in response.
# Using "try" in case tags are not available in XML
_LOGGER.debug("Device %s has manufacturer %s", url,
root.find(SCPD_DEVICE).find(SCPD_MANUFACTURER).text)
if (root.find(SCPD_DEVICE).find(
SCPD_MANUFACTURER).text in SUPPORTED_MANUFACTURERS and
root.find(SCPD_DEVICE).find(
SCPD_DEVICETYPE).text == DEVICETYPE_DENON):
device = {}
device["host"] = urlparse(
root.find(SCPD_DEVICE).find(
| python | {
"resource": ""
} |
q18290 | init_all_receivers | train | def init_all_receivers():
"""
Initialize all discovered Denon AVR receivers in LAN zone.
Returns a list of created Denon AVR instances.
By default SSDP broadcasts are sent up to 3 times with a 2 seconds timeout.
"""
receivers = discover()
init_receivers = []
for | python | {
"resource": ""
} |
q18291 | parse_auto_sub | train | def parse_auto_sub(text):
'''
Parses webvtt and returns timestamps for words and lines
Tested on automatically generated subtitles from YouTube
'''
pat = r'<(\d\d:\d\d:\d\d(\.\d+)?)>'
out = []
lines = []
data = text.split('\n')
data = [d for d in data if re.search(r'\d\d:\d\d:\d\d', d) is not None]
for i, d in enumerate(data): | python | {
"resource": ""
} |
q18292 | Timecode.tc_to_frames | train | def tc_to_frames(self, timecode):
"""Converts the given timecode to frames
"""
hours, minutes, seconds, frames = map(int, timecode.split(':'))
ffps = float(self._framerate)
if self.drop_frame:
# Number of drop frames is 6% of framerate rounded to nearest
# integer
drop_frames = int(round(ffps * .066666))
else:
drop_frames = 0
# We don't need the exact framerate anymore, we just need it rounded to
# nearest integer
ifps = self._int_framerate
# Number of frames per hour (non-drop)
hour_frames = ifps * 60 * 60
| python | {
"resource": ""
} |
q18293 | Timecode.frames_to_tc | train | def frames_to_tc(self, frames):
"""Converts frames back to timecode
:returns str: the string representation of the current time code
"""
if frames == 0:
return 0, 0, 0, 0
ffps = float(self._framerate)
if self.drop_frame:
# Number of frames to drop on the minute marks is the nearest
# integer to 6% of the framerate
drop_frames = int(round(ffps * .066666))
else:
drop_frames = 0
# Number of frames in an hour
frames_per_hour = int(round(ffps * 60 * 60))
# Number of frames in a day - timecode rolls over after 24 hours
frames_per_24_hours = frames_per_hour * 24
# Number of frames per ten minutes
frames_per_10_minutes = int(round(ffps * 60 * 10))
# Number of frames per minute is the round of the framerate * 60 minus
# the number of dropped frames
frames_per_minute = int(round(ffps)*60) - drop_frames
frame_number = frames - 1
if frame_number < 0:
# Negative time. Add 24 hours.
frame_number += frames_per_24_hours
# If frame_number is greater than 24 hrs, next operation will rollover
# | python | {
"resource": ""
} |
q18294 | make_edl | train | def make_edl(timestamps, name):
'''Converts an array of ordered timestamps into an EDL string'''
fpses = {}
out = "TITLE: {}\nFCM: NON-DROP FRAME\n\n".format(name)
rec_in = 0
for index, timestamp in enumerate(timestamps):
if timestamp['file'] not in fpses:
fpses[timestamp['file']] = get_fps(timestamp['file'])
fps = fpses[timestamp['file']]
n = str(index + 1).zfill(4)
time_in = timestamp['start']
time_out = timestamp['end']
duration = time_out - time_in
rec_out = | python | {
"resource": ""
} |
q18295 | convert_timespan | train | def convert_timespan(timespan):
"""Convert an srt timespan into a start and end timestamp."""
start, end = timespan.split('-->')
| python | {
"resource": ""
} |
q18296 | convert_timestamp | train | def convert_timestamp(timestamp):
"""Convert an srt timestamp into seconds."""
timestamp = timestamp.strip()
chunk, millis = timestamp.split(',')
hours, minutes, seconds = chunk.split(':')
hours = int(hours)
| python | {
"resource": ""
} |
q18297 | clean_srt | train | def clean_srt(srt):
"""Remove damaging line breaks and numbers from srt files and return a
dictionary.
"""
with open(srt, 'r') as f:
text = f.read()
text = re.sub(r'^\d+[\n\r]', '', text, flags=re.MULTILINE)
lines = text.splitlines()
output = OrderedDict()
key = ''
for line in lines:
| python | {
"resource": ""
} |
q18298 | cleanup_log_files | train | def cleanup_log_files(outputfile):
"""Search for and remove temp log files found in the output directory."""
| python | {
"resource": ""
} |
q18299 | demo_supercut | train | def demo_supercut(composition, padding):
"""Print out timespans to be cut followed by the line number in the srt."""
for i, c in enumerate(composition):
line = c['line']
start = c['start']
end = c['end']
if i > 0 | python | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.