docstring stringlengths 52 499 | function stringlengths 67 35.2k | __index_level_0__ int64 52.6k 1.16M |
|---|---|---|
sets the dot notated property to the passed in value
args:
prop: a string of the property to retreive
"a.b.c" ~ dictionary['a']['b']['c']
value: the value to set the prop object | def set(self, prop, value):
prop_parts = prop.split(".")
if self.copy_dict:
new_dict = copy.deepcopy(self.obj)
else:
new_dict = self.obj
pointer = None
parts_length = len(prop_parts) - 1
for i, part in enumerate(prop_parts):
i... | 1,120,939 |
Return a list of 2-tuples - the argument name and its default value or
a special value that indicates there is no default value.
Args:
args: list of argument name
defaults: tuple of default values | def _get_args_and_defaults(args, defaults):
defaults = defaults or []
args_and_defaults = [(argument, default) for (argument, default)
in zip_longest(args[::-1], defaults[::-1],
fillvalue=NoDefault)]
return args_and_defaults[::-1] | 1,121,023 |
Return all methods of cls that are parseable i.e. have been decorated
by '@create_parser'.
Args:
cls: the class currently being decorated
Note:
classmethods will not be included as they can only be referenced once
the class has been defined
Returns:
a 2-tuple with the p... | def _get_parseable_methods(cls):
_LOG.debug("Retrieving parseable methods for '%s'", cls.__name__)
init_parser = None
methods_to_parse = {}
for name, obj in vars(cls).items():
# Every callable object that has a 'parser' attribute will be
# added as a subparser.
# This won't ... | 1,121,025 |
Create a default description for the parser and help message for the
agurments if they are missing.
Args:
func: the method we are creating a parser for
args: the argument names of the method
description: a potentially existing description created from the
function docstring
... | def _get_default_help_message(func, args, description=None, args_help=None):
if description is None:
description = "Argument parsing for %s" % func.__name__
args_help = args_help or {}
# If an argument is missing a help message we create a simple one
for argument in [arg_name for arg_name i... | 1,121,026 |
Return an ArgumentParser for the given function. Arguments are defined
from the function arguments and their associated defaults.
Args:
func: function for which we want an ArgumentParser
types: types to which the command line arguments should be converted to
args_and_defaults: list ... | def _get_arg_parser(func, types, args_and_defaults, delimiter_chars):
_LOG.debug("Creating ArgumentParser for '%s'", func.__name__)
(description, arg_help) = _prepare_doc(
func, [x for (x, _) in args_and_defaults], delimiter_chars)
parser = argparse.ArgumentParser(description=description)
f... | 1,121,027 |
Return the given arguments if it is not None else sys.argv if it contains
something, an empty list otherwise.
Args:
args: argument to be parsed
sys_argv: arguments of the command line i.e. sys.argv | def _get_args_to_parse(args, sys_argv):
arguments = args if args is not None else sys_argv[1:]
_LOG.debug("Parsing arguments: %s", arguments)
return arguments | 1,121,028 |
Returns the method that is linked to the 'call' method of the parser
Args:
func: the decorated function
Raises:
ParseThisError if the decorated method is __init__, __init__ can
only be decorated in a class decorated by parse_class | def _get_parser_call_method(func):
func_name = func.__name__
parser = func.parser
def inner_call(instance=None, args=None):
_LOG.debug("Calling %s.parser.call", func_name)
# Defer this check in the method call so that __init__ can be
# decorated in class decorated with... | 1,121,030 |
Retrieve the name of the function argument linked to the given parser.
Args:
parser: a function parser | def _get_args_name_from_parser(parser):
# Retrieve the 'action' destination of the method parser i.e. its
# argument name. The HelpAction is ignored.
return [action.dest for action in parser._actions if not
isinstance(action, argparse._HelpAction)] | 1,121,031 |
Actually calls the callable with the namespace parsed from the command
line.
Args:
callable_obj: a callable object
arg_names: name of the function arguments
namespace: the namespace object parsed from the command line | def _call(callable_obj, arg_names, namespace):
arguments = {arg_name: getattr(namespace, arg_name)
for arg_name in arg_names}
return callable_obj(**arguments) | 1,121,032 |
Call the method, retrieved from obj, with the correct arguments via
the namespace
Args:
obj: any kind of object
method_name: method to be called
namespace: an argparse.Namespace object containing parsed command
line arguments | def _call_method_from_namespace(obj, method_name, namespace):
method = getattr(obj, method_name)
method_parser = method.parser
arg_names = _get_args_name_from_parser(method_parser)
if method_name == "__init__":
return _call(obj, arg_names, namespace)
return _call(method, arg_names, name... | 1,121,033 |
Create an instance of Action
Arguments:
name: -- the name of this action
Keyword arguments:
action -- the function that will be performed when this action is called | def __init__(self, name, action, *args, **kwargs):
self.args = args
self.kwargs = kwargs
self.name = name
self._action = action
pass | 1,121,260 |
Carries out the action on the provided flow_unit
Arguments:
flow_unit - the flow_unit instance that will have the processing carried out upon it.
Keyword arguments:
as required by the action function for this Action instance. | def __call__(self, flow_unit, *args, **kwargs):
self._action(flow_unit, *args, **kwargs) | 1,121,261 |
Create an instance of Transition
Arguments:
state: -- a State object associated with this transition
action: -- a Action object that is allowed for the state | def __init__(self, state, action, *args, **kwargs):
self.state = state
self.action = action | 1,121,264 |
Scan `path` for viruses using ``clamscan`` program.
Args:
path (str): Relative or absolute path of file/directory you need to
scan.
Returns:
dict: ``{filename: ("FOUND", "virus type")}`` or blank dict.
Raises:
AssertionError: When the internal file doesn't exis... | def scan_file(path):
path = os.path.abspath(path)
assert os.path.exists(path), "Unreachable file '%s'." % path
result = sh.clamscan(path, no_summary=True, infected=True, _ok_code=[0, 1])
return _parse_result(result) | 1,121,371 |
Save cahce to the disk.
Args:
cache (set): Set with cached data. | def save_cache(cache):
with open(settings.DUP_FILTER_FILE, "w") as f:
f.write(
json.dumps(list(cache))
) | 1,121,391 |
Deduplication function, which compares `publication` with samples stored in
`cache`. If the match NOT is found, `publication` is returned, else None.
Args:
publication (obj): :class:`.Publication` instance.
cache (obj): Cache which is used for lookups.
Returns:
obj/None: Depends wh... | def filter_publication(publication, cache=_CACHE):
if cache is None:
cache = load_cache()
if publication._get_hash() in cache:
return None
cache.update(
[publication._get_hash()]
)
save_cache(cache)
return publication | 1,121,393 |
Decorator for simple in-place decorator mocking for tests
Args:
to_patch: the string path of the function to patch
module_name: complete string path of the module to reload
decorator (optional): replacement decorator. By default a pass-through
will be used.
Returns:
... | def tinsel(to_patch, module_name, decorator=mock_decorator):
def fn_decorator(function):
def wrapper(*args, **kwargs):
with patch(to_patch, decorator):
m = importlib.import_module(module_name)
reload(m)
function(*args, **kwargs)
r... | 1,121,436 |
Render list of `trees` to HTML.
Args:
trees (list): List of :class:`.Tree`.
path_composer (fn reference): Function used to compose paths from UUID.
Look at :func:`.compose_tree_path` from :mod:`.web_tools`.
Returns:
str: HTML representation of trees. | def render_trees(trees, path_composer):
trees = list(trees) # by default, this is set
def create_pub_cache(trees):
sub_pubs_uuids = sum((x.collect_publications() for x in trees), [])
uuid_mapping = {
uuid: search_pubs_by_uuid(uuid)
for uuid in set(sub_pub... | 1,121,531 |
Cut a wire (undo a wire() call)
Arguments:
- name (str): name of the wire
Keyword Arguments:
- disconnect (bool): if True also disconnect all connections on the
specified wire | def cut(self, name, disconnect=False):
wire = getattr(self, name, None)
if wire and isinstance(wire, Wire):
if name != "main":
delattr(self, name)
if disconnect:
wire.disconnect()
wire.off("receive", self.on_receive)
... | 1,121,615 |
Compose path to the ``resources`` directory for given `fn`.
Args:
fn (str): Filename of file in ``resources`` directory.
Returns:
str: Absolute path to the file in resources directory. | def _resource_context(fn):
return os.path.join(
os.path.dirname(__file__),
DES_DIR,
fn
) | 1,121,669 |
Compose contract and create PDF.
Args:
firma (str): firma
pravni_forma (str): pravni_forma
sidlo (str): sidlo
ic (str): ic
dic (str): dic
zastoupen (str): zastoupen
Returns:
obj: StringIO file instance containing PDF file. | def get_contract(firma, pravni_forma, sidlo, ic, dic, zastoupen):
contract_fn = _resource_context(
"Licencni_smlouva_o_dodavani_elektronickych_publikaci"
"_a_jejich_uziti.rst"
)
# load contract
with open(contract_fn) as f:
contract = f.read()#.decode("utf-8").encode("utf-8"... | 1,121,670 |
Generate review from `review_struct`.
Args:
review_struct (obj): :class:`.GenerateReview` instance.
Returns:
obj: StringIO file instance containing PDF file. | def get_review(review_struct):
review_fn = _resource_context("review.rst")
# read review template
with open(review_fn) as f:
review = f.read()
# generate qr code
with NamedTemporaryFile(suffix=".png") as qr_file:
url = pyqrcode.create(review_struct.internal_url)
url.pn... | 1,121,671 |
Calls the first function matching the urls pattern and method.
Args:
url (str): Url for which to call a matching function.
method (str, optional): The method used while registering a
function.
Defaults to None
args (dict, optional): Additional... | def call(self, url, method=None, args=None):
if not args:
args = {}
if sys.version_info.major == 3:
data = urllib.parse.urlparse(url)
path = data.path.rstrip('/') + '/'
_args = dict(urllib.parse.parse_qs(data.query,
... | 1,121,705 |
Initialise a new ScanResult.
Args:
addr (str): Device hardware address in xx:xx:xx:xx:xx:xx format.
raw_addr (bytearray): Device hardware address as raw bytes.
name (str): Device name (if available) as ASCII text.
rssi (float): Latest RSSI from the scan result fo... | def __init__(self, addr, raw_addr, name=None, rssi=0):
self.addr = addr
self.raw_addr = raw_addr
self.name = name
self.rssi = rssi
self._age = time.time() | 1,121,766 |
Retrieve a device with a given address or name from the results.
Args:
addr_or_name (str): a string containing either a BLE address in xx:xx:xx:xx:xx:xx
format, or a plain device name. The supplied value is checked as an address
first and if that fails to pro... | def get_device(self, addr_or_name):
if addr_or_name in self._devices:
return self._devices[addr_or_name]
for v in self._devices.values():
if v == addr_or_name:
return v
return None | 1,121,770 |
Set calibration state for attached IMUs.
Args:
enabled (bool): True to apply calibration to IMU data (if available).
False to output uncalibrated data.
imus (list): indicates which IMUs the calibration state should be set on.
Empty list or [0, 1, 2, 3, 4] will ... | def set_calibration(self, enabled, imus):
if len(imus) == 0:
imus = list(range(MAX_IMUS))
for i in imus:
if i < 0 or i >= MAX_IMUS:
logger.warn('Invalid IMU index {} in set_calibration'.format(i))
continue
self.imus[i]._use_ca... | 1,121,773 |
Returns the current (R, G, B) colour of the SK8-ExtAna LED.
Args:
cached (bool): if True, returns the locally cached state of the LED (based
on the last call to :meth:`set_extana_led`). Otherwise query the device
for the current state.
Returns:
a... | def get_extana_led(self, cached=True):
if cached and self.led_state is not None:
return self.led_state
extana_led = self.get_characteristic_handle_from_uuid(UUID_EXTANA_LED)
if extana_led is None:
logger.warn('Failed to find handle for ExtAna LED')
r... | 1,121,778 |
Returns the SK8 device BLE name.
Args:
cached (bool): if True, returns the locally cached copy of the name. If this is
set to False, or the name is not cached, it will read from the device instead.
Returns:
str. The current device name. May be `None` if an error... | def get_device_name(self, cached=True):
if cached and self.name is not None:
return self.name
device_name = self.get_characteristic_handle_from_uuid(UUID_DEVICE_NAME)
if device_name is None:
logger.warn('Failed to find handle for device name')
return... | 1,121,784 |
Sets a new BLE device name for this SK8.
Args:
new_name (str): the new device name as an ASCII string, max 20 characters.
Returns:
True if the name was updated successfully, False otherwise. | def set_device_name(self, new_name):
device_name = self.get_characteristic_handle_from_uuid(UUID_DEVICE_NAME)
if device_name is None:
logger.warn('Failed to find handle for device name')
return False
if len(new_name) > MAX_DEVICE_NAME_LEN:
l... | 1,121,785 |
Returns the SK8 device firmware version.
Args:
cached (bool): if True, returns the locally cached copy of the firmware version.
If this is set to False, or the version is not cached, it will read from
the device instead.
Returns:
str. The curren... | def get_firmware_version(self, cached=True):
if cached and self.firmware_version != 'unknown':
return self.firmware_version
firmware_version = self.get_characteristic_handle_from_uuid(UUID_FIRMWARE_REVISION)
if firmware_version is None:
logger.warn('Failed to fi... | 1,121,786 |
Can be used to check if an SK8-ExtAna device is currently connected.
NOTE: do not attempt to call while data streaming is active!
Args:
cached (bool): if True, use the cached value of the connected hardware
state rather than querying the device. Set to False to force a q... | def has_extana(self, cached=True):
if cached and self.hardware != -1:
return True if (self.hardware & EXT_HW_EXTANA) else False
result = self._check_hardware()
return True if (result & EXT_HW_EXTANA) != 0 else False | 1,121,790 |
Can be used to check if an external IMU chain is currently connected.
NOTE: do not attempt to call while data streaming is active!
Args:
cached (bool): if True, use the cached value of the connected hardware
state rather than querying the device. Set to False to force a ... | def has_imus(self, cached=True):
if cached and self.hardware != -1:
return True if (self.hardware & EXT_HW_IMUS) else False
result = self._check_hardware()
return True if (result & EXT_HW_IMUS) != 0 else False | 1,121,791 |
Given a characteristic UUID, return its handle.
Args:
uuid (str): a string containing the hex-encoded UUID
Returns:
None if an error occurs, otherwise an integer handle. | def get_characteristic_handle_from_uuid(self, uuid):
ch = self.get_characteristic_from_uuid(uuid)
return None if ch is None else ch.char_handle | 1,121,792 |
Given a characteristic UUID, return a :class:`Characteristic` object
containing information about that characteristic
Args:
uuid (str): a string containing the hex-encoded UUID
Returns:
None if an error occurs, otherwise a :class:`Characteristic` object | def get_characteristic_from_uuid(self, uuid):
if uuid in self.uuid_chars:
logger.debug('Returning cached info for char: {}'.format(uuid))
return self.uuid_chars[uuid]
for service in self.services.values():
char = service.get_characteristic_by_uuid(uuid)
... | 1,121,793 |
Utility function to retrieve the client characteristic configuration
descriptor handle for a given characteristic.
Args:
uuid (str): a string containing the hex-encoded UUID
Returns:
None if an error occurs, otherwise an integer handle. | def get_ccc_handle_from_uuid(self, uuid):
if uuid in self.uuid_cccds:
return self.uuid_cccds[uuid].handle
char = self.get_characteristic_from_uuid(uuid)
if char is None:
return None
ccc = char.get_descriptor_by_uuid(UUID_GATT_CCC)
if cc... | 1,121,794 |
Lookup information about a given GATT service.
Args:
uuid (str): a string containing the hex-encoded service UUID
Returns:
None if an error occurs, otherwise a :class:`Service` object. | def get_service(self, uuid):
if uuid in self.services:
return self.services[uuid]
if pp_hex(uuid) in self.services:
return self.services[pp_hex(uuid)]
return None | 1,121,797 |
Given a characteristic handle, return the :class:`Service` object that
the handle belongs to.
Args:
handle (int): the characteristic handle
Returns:
None if no service matches the given handle, otherwise a :class:`Service` object. | def get_service_for_handle(self, handle):
for s in self.services.values():
if s.start_handle <= handle and s.end_handle >= handle:
return s
return None | 1,121,798 |
Open the serial connection to a dongle at the supplied address.
Args:
address (str): the serial port address of the BLED112 dongle, e.g. 'COM5'
hard_reset (bool): not currently used
Returns:
True if a connection with the dongle was established, False otherwise. | def init(self, address, hard_reset=False):
self.address = address
if hard_reset:
# TODO (needs more work to be usable)
# if not Dongle._hard_reset(address):
# return False
# time.sleep(2.0)
pass
# TODO timeout not working... | 1,121,802 |
Run a BLE scan for a defined interval and return results.
Alternative to :meth:`begin_scan/:meth:`end_scan`.
Args:
timeout (float): time in seconds to run the scanning process for
interval (int): BLE scan interval, in units of 625us
window (int): BLE scan w... | def scan_devices(self, devnames, timeout=DEF_TIMEOUT, interval=DEF_SCAN_INTERVAL, window=DEF_SCAN_WINDOW):
# TODO validate params and state
logger.debug('configuring scan parameters')
self.api.ble_cmd_gap_set_scan_parameters(interval, window, 1)
self._set_state(self._STATE_CON... | 1,121,812 |
If possible, set the input buffer to a previous history item.
Parameters:
-----------
substring : str, optional
If specified, search for an item with this substring.
as_prefix : bool, optional
If True, the substring must match at the beginning (default).
... | def history_previous(self, substring='', as_prefix=True):
index = self._history_index
replace = False
while index > 0:
index -= 1
history = self._get_edited_history(index)
if (as_prefix and history.startswith(substring)) \
or (not as_p... | 1,121,855 |
If possible, set the input buffer to a subsequent history item.
Parameters:
-----------
substring : str, optional
If specified, search for an item with this substring.
as_prefix : bool, optional
If True, the substring must match at the beginning (default).
... | def history_next(self, substring='', as_prefix=True):
index = self._history_index
replace = False
while self._history_index < len(self._history):
index += 1
history = self._get_edited_history(index)
if (as_prefix and history.startswith(substring)) \
... | 1,121,856 |
Initialize class and spawn self as Base Class w/o nargs
Args:
option_strings (list): list of str giving command line flags that
call this action
dest (str): Namespace reference to value
nargs (str): number of args as special char or int
... | def __init__(self, option_strings, dest, nargs=None, **kwargs):
# Only accept a single value to analyze
if nargs is not None:
raise ValueError('nargs not allowed for ThreadCheck')
# Call self again but without nargs
super(CheckThreads, self).__init__(option_strings... | 1,121,914 |
Adds new children nodes after filtering for duplicates
Args:
children (list): list of OmniTree nodes to add as children | def add_children(self, children):
self._children += [c for c in children if c not in self._children] | 1,121,934 |
Adds new parent nodes after filtering for duplicates
Args:
parents (list): list of OmniTree nodes to add as parents | def add_parents(self, parents):
self._parents += [p for p in parents if p not in self._parents] | 1,121,935 |
View the details of a manager position.
Parameters:
request is an HTTP request
managerTitle is the URL title of the manager. | def manager_view(request, managerTitle):
targetManager = get_object_or_404(Manager, url_title=managerTitle)
if not targetManager.active:
messages.add_message(request, messages.ERROR, MESSAGES['INACTIVE_MANAGER'].format(managerTitle=targetManager.title))
return HttpResponseRedirect(reverse(... | 1,122,106 |
View to modify an existing manager.
Parameters:
request is an HTTP request
managerTitle is URL title of the manager. | def edit_manager_view(request, managerTitle):
targetManager = get_object_or_404(Manager, url_title=managerTitle)
form = ManagerForm(
request.POST or None,
instance=targetManager,
)
if form.is_valid():
manager = form.save()
messages.add_message(request, messages.S... | 1,122,109 |
View to edit a new request type. Restricted to presidents and superadmins.
Parameters:
request is an HTTP request
typeName is the request type's URL name. | def edit_request_type_view(request, typeName):
requestType = get_object_or_404(RequestType, url_name=typeName)
form = RequestTypeForm(
request.POST or None,
instance=requestType,
)
if form.is_valid():
rtype = form.save()
messages.add_message(request, messages.SUC... | 1,122,112 |
An flask application factory, as explained here:
http://flask.pocoo.org/docs/patterns/appfactories/
Arguments:
object_name: the python path of the config object,
e.g. webapp.settings.ProdConfig
env: The name of the current environment, e.g. prod or dev | def create_app(object_name):
app = Flask(__name__)
app.config.from_object(object_name)
# initialize the cache
cache.init_app(app)
# initialize the debug tool bar
debug_toolbar.init_app(app)
# initialize SQLAlchemy
db.init_app(app)
return app | 1,122,141 |
Loads the file_locations into the triplestores
args:
file_locations: list of tuples to load
[('vocabularies', [list of vocabs to load])
('directory', '/directory/path')
('filepath', '/path/to/a/file')
('package_all',... | def load(self, file_locations=[], **kwargs):
self.__set_cache_dir__(**kwargs)
conn = self.__get_conn__(**kwargs)
self.set_load_state(**kwargs)
super(DefinitionManager, self).load(file_locations, **kwargs)
if not file_locations:
file_locations = self.__file_lo... | 1,122,290 |
sets the cache directory by test write permissions for various
locations
args:
directories: list of directories to test. First one with read-write
permissions is selected. | def __set_cache_dir__(self, cache_dirs=[], **kwargs):
# add a path for a subfolder 'vocabularies'
test_dirs = [self.vocab_dir] + cache_dirs
try:
test_dirs += [os.path.join(__CFG__.CACHE_DATA_PATH,
"vocabularies")]
except (Runtim... | 1,122,291 |
loads a vocabulary into the defintion triplestore
args:
vocab_name: the prefix, uri or filename of a vocabulary | def load_vocab(self, vocab_name, **kwargs):
log.setLevel(kwargs.get("log_level", self.log_level))
vocab = self.get_vocab(vocab_name , **kwargs)
if vocab['filename'] in self.loaded:
if self.loaded_times.get(vocab['filename'],
datetime.datetime(2001,1,1)... | 1,122,292 |
dictionary for the specified vocabulary
args:
vocab_name: the name or uri of the vocab to return | def __get_vocab_dict__(self, vocab_name, **kwargs):
try:
vocab_dict = self.vocab_map[vocab_name].copy()
except KeyError:
vocab_dict = {key: value for key, value in self.vocab_map.items()
if vocab_name in value.values()}
vocab_name = ... | 1,122,293 |
Returns data stream of an rdf vocabulary
args:
vocab_name: the name or uri of the vocab to return | def get_vocab(self, vocab_name, **kwargs):
vocab_dict = self.__get_vocab_dict__(vocab_name, **kwargs)
filepaths = list(set([os.path.join(self.cache_dir,
vocab_dict['filename']),
os.path.join(self.vocab_dir,
... | 1,122,294 |
Removes the vocab from the definiton triplestore
args:
vocab_name: the name or uri of the vocab to return | def drop_vocab(self, vocab_name, **kwargs):
vocab_dict = self.__get_vocab_dict__(vocab_name, **kwargs)
return self.drop_file(vocab_dict['filename'], **kwargs) | 1,122,295 |
runs the extractor
Args:
-----
output: ['filepath', None] | def run(self, tag=None, output=None, **kwargs):
start = datetime.datetime.now()
count = 0
if tag:
tag = Uri(tag)
xml_generator = etree.iterparse(self.source,
#events=("start", "end"),
... | 1,122,556 |
Initialize Keywords
Args:
name -- keyword name
value -- Optional value, otherwise name is used
value is setup as *value to detect if the parameter is supplied, while
still supporting None. If no value is supplied then name should be used.
If any value is supplie... | def __init__(self, name, *value):
self.name = name
self.key = name
self.value = name if len(value) != 1 else value[0]
self.description = "Matches {!r} and maps it to {!r}".format(name, self.value) | 1,122,654 |
Create a dictonary type from a dictionary of other types
Args:
validator_map -- a mapping from names to types
Examples:
>>> Dict({'a': int, 'b': int})('a:1,b:2')
{'a': 1, 'b': 2}
>>> Dict({'a': str, 'b': int})('a:asdf b=1234')
{'a': 'asdf', 'b': 1234}
... | def __init__(self, validator_map):
self.validators = dict(validator_map)
v_sorted = sorted(self.validators.items(), key=lambda t: t[0])
self.validator_descriptions = ['{}:<{}>'.format(k, v) for k, v in v_sorted]
self.name = 'dict({})'.format(', '.join(self.validator_descriptions... | 1,122,659 |
Send an email from the user (a gmail) to the receiver.
Args:
subject (str): Subject of the email.
message (str): A message.
filepaths (list(str)): Filepaths to files to be attached.
config (defaultdict): A defaultdict. | async def send_with_attachments(subject, message, filepaths, config):
email_ = MIMEMultipart()
email_.attach(MIMEText(message))
email_["Subject"] = subject
email_["From"] = get_attribute_from_config(config, EMAIL_SECTION_KEY, USER_KEY)
email_["To"] = get_attribute_from_config(config, EMAIL_SECT... | 1,122,805 |
Take a list of filepaths and attach the files to a MIMEMultipart.
Args:
filepaths (list(str)): A list of filepaths.
email_ (email.MIMEMultipart): A MIMEMultipart email_. | def _attach_files(filepaths, email_):
for filepath in filepaths:
base = os.path.basename(filepath)
with open(filepath, "rb") as file:
part = MIMEApplication(file.read(), Name=base)
part["Content-Disposition"] = 'attachment; filename="%s"' % base
email_.attach... | 1,122,806 |
Send an email.
Args:
email_ (email.MIMEMultipart): The email to send.
config (defaultdict): A defaultdict. | async def _send_email(email_, config, loop=asyncio.get_event_loop()):
smtp_server = get_attribute_from_config(config, EMAIL_SECTION_KEY, SMTP_SERVER_KEY)
smtp_port = int(get_attribute_from_config(config, EMAIL_SECTION_KEY, SMTP_PORT_KEY))
user = get_attribute_from_config(config, EMAIL_SECTION_KEY, USER... | 1,122,807 |
Send files using the config.ini settings.
Args:
filepaths (list(str)): A list of filepaths. | async def send_files_preconf(filepaths, config_path=CONFIG_PATH):
config = read_config(config_path)
subject = "PDF files from pdfebc"
message = ""
await send_with_attachments(subject, message, filepaths, config) | 1,122,808 |
return a submagic menu by name, and create it if needed
parameters:
-----------
menulabel : str
Label for the menu
Will infere the menu name from the identifier at creation if menulabel not given.
To do so you have too give menuidentifier as a CamelCassedStr... | def _get_magic_menu(self,menuidentifier, menulabel=None):
menu = self._magic_menu_dict.get(menuidentifier,None)
if not menu :
if not menulabel:
menulabel = re.sub("([a-zA-Z]+)([A-Z][a-z])","\g<1> \g<2>",menuidentifier)
menu = QtGui.QMenu(menulabel,self.ma... | 1,123,285 |
Method to procces subscribe channel's messages
This method reads a message and processes the content in different
outputs like stdout, stderr, pyout and status
Arguments:
sub_msg: message receive from kernel in the sub socket channel
capture by kernel ... | def handle_iopub(self):
while self.km.sub_channel.msg_ready():
sub_msg = self.km.sub_channel.get_msg()
msg_type = sub_msg['header']['msg_type']
parent = sub_msg["parent_header"]
if (not parent) or self.session_id == parent['session']:
if m... | 1,123,620 |
Summary:
Validate file checksum using md5 hash
Args:
file: file object to verify integrity
hash_file: md5 reference checksum file
Returns:
Valid (True) | False, TYPE: bool | def valid_checksum(file, hash_file):
bits = 4096
# calc md5 hash
hash_md5 = hashlib.md5()
with open(file, "rb") as f:
for chunk in iter(lambda: f.read(bits), b""):
hash_md5.update(chunk)
# locate hash signature for file, validate
with open(hash_file) as c:
for li... | 1,123,672 |
Create a daemon which is controllable via jsonrpc with decorator
Args:
pidfile (str): path to create pid file
logger (logging.Logger): logger for the daemon
port (int):
host (str): | def __init__(self, pidfile, logger, port = 64042, host = 'localhost'):
super(RemoteControllerDeamon, self).__init__(pidfile, logger)
self.__port = port
self.__host = host
for name in dir(self):
method = getattr(self, name)
if hasattr(method, 'registered_f... | 1,123,956 |
Set all configuration specified in :attr:`REQUIRED_SETTINGS`.
Args:
configuration (str): Configuration file content.
Returns:
str: Updated configuration. | def update_configuration(configuration):
for key, val in REQUIRED_SETTINGS.items():
if val in ["$username", "$groupname"]:
val = get_username()
configuration = conf_writer.add_or_update(configuration, key, val)
return configuration | 1,124,411 |
Creates configuration file and the directory where it should be stored and
set correct permissions.
Args:
cnf_file (str): Path to the configuration file.
uid (int): User ID - will be used for chown.
overwrite (bool): Overwrite the configuration with :attr:`CLEAN_CONFIG`. | def create_config(cnf_file, uid, overwrite):
conf = None
# needed also on suse, because pyClamd module
if not os.path.exists(settings.DEB_CONF_PATH):
os.makedirs(settings.DEB_CONF_PATH, 0755)
os.chown(settings.DEB_CONF_PATH, uid, -1)
if not os.path.exists(cnf_file): # create... | 1,124,412 |
Create log file and set necessary permissions.
Args:
log_file (str): Path to the log file.
uid (int): User ID - will be used for chown. | def create_log(log_file, uid):
if not os.path.exists(log_file): # create new log file
dir_name = os.path.dirname(log_file)
if not os.path.exists(dir_name):
os.makedirs(dir_name, 0755)
os.chown(dir_name, uid, -1)
with open(log_file, "w") as f:
f.writ... | 1,124,413 |
Create configuration and log file. Restart the daemon when configuration
is done.
Args:
conf_file (str): Path to the configuration file.
overwrite (bool): Overwrite the configuration file with `clean` config? | def main(conf_file, overwrite, logger):
uid = pwd.getpwnam(get_username()).pw_uid
# stop the daemon
logger.info("Stopping the daemon.")
sh.service(get_service_name(), "stop")
# create files
logger.info("Creating config file.")
create_config(
cnf_file=conf_file,
uid=uid... | 1,124,414 |
If the callback is callable, format the string with the args and make a call.
Otherwise, do nothing.
Args:
callback (function): May or may not be callable.
formattable_string (str): A string with '{}'s inserted.
*args: A variable amount of arguments for the string formatting. Must corre... | def if_callable_call_with_formatted_string(callback, formattable_string, *args):
try:
formatted_string = formattable_string.format(*args)
except IndexError:
raise ValueError("Mismatch metween amount of insertion points in the formattable string\n"
"and the amount of... | 1,124,518 |
Convert text file to JSON.
Arguments:
domain: domain name of updating target
action: True ; for PUT/POST HTTP method
False; for DELETE HTTP method
filename: text file of bulk updating (default is False)
record: json record of updating single record (default ... | def set_json(domain, action, filename=False, record=False):
o = JSONConverter(domain)
if filename:
# for 'bulk_create/bulk_delete'
with open(filename, 'r') as f:
o.separate_input_file(f)
for item in o.separated_list:
o.read_records(item.splitlines())... | 1,124,876 |
Set options of command line.
Arguments:
prs: parser object of argparse
keyword: processing keyword
required: True is required option (default is False) | def set_option(prs, keyword, required=False):
if keyword == 'server':
prs.add_argument(
'-s', dest='server', required=True,
help='specify TonicDNS Server hostname or IP address')
if keyword == 'username':
prs.add_argument('-u', dest='username', required=True,
... | 1,124,888 |
Set options of connecting to TonicDNS API server
Arguments:
prs: parser object of argparse
conn: dictionary of connection information | def conn_options(prs, conn):
if conn.get('server') and conn.get('username') and conn.get('password'):
prs.set_defaults(server=conn.get('server'),
username=conn.get('username'),
password=conn.get('password'))
elif conn.get('server') and conn.get('us... | 1,124,889 |
Retrieve records.
Arguments:
prs: parser object of argparse
conn: dictionary of connection information | def parse_get(prs, conn):
prs_get = prs.add_parser(
'get', help='retrieve all zones or records with a specific zone')
prs_get.add_argument('--domain', action='store',
help='specify domain FQDN')
conn_options(prs_get, conn)
set_option(prs_get, 'search')
prs_get.s... | 1,124,892 |
Create record.
Arguments:
prs: parser object of argparse
conn: dictionary of connection information | def parse_create(prs, conn):
prs_create = prs.add_parser(
'create', help='create record of specific zone')
set_option(prs_create, 'domain')
conn_options(prs_create, conn)
prs_create.set_defaults(func=create) | 1,124,893 |
Create bulk_records.
Arguments:
prs: parser object of argparse
conn: dictionary of connection information | def parse_bulk_create(prs, conn):
prs_create = prs.add_parser(
'bulk_create', help='create bulk records of specific zone')
set_option(prs_create, 'infile')
conn_options(prs_create, conn)
prs_create.add_argument('--domain', action='store',
help='create records wit... | 1,124,894 |
Delete record.
Arguments:
prs: parser object of argparse
conn: dictionary of connection information | def parse_delete(prs, conn):
prs_delete = prs.add_parser(
'delete', help='delete a record of specific zone')
set_option(prs_delete, 'domain')
conn_options(prs_delete, conn)
prs_delete.set_defaults(func=delete) | 1,124,895 |
Delete bulk_records.
Arguments:
prs: parser object of argparse
conn: dictionary of connection information | def parse_bulk_delete(prs, conn):
prs_delete = prs.add_parser(
'bulk_delete', help='delete bulk records of specific zone')
set_option(prs_delete, 'infile')
conn_options(prs_delete, conn)
prs_delete.add_argument('--domain', action='store',
help='delete records wit... | 1,124,896 |
Update a record.
Arguments:
prs: parser object of argparse
conn: dictionary of connection information | def parse_update(prs, conn):
prs_update = prs.add_parser(
'update', help='update record of specific zone')
set_option(prs_update, 'domain')
set_option(prs_update, 'update')
conn_options(prs_update, conn)
prs_update.set_defaults(func=update) | 1,124,897 |
Retrieve template.
Arguments:
prs: parser object of argparse
conn: dictionary of connection information | def parse_get_tmpl(prs, conn):
prs_tmpl_get = prs.add_parser(
'tmpl_get', help='retrieve templates')
set_option(prs_tmpl_get, 'template')
conn_options(prs_tmpl_get, conn)
prs_tmpl_get.set_defaults(func=retrieve_tmpl) | 1,124,898 |
Delete template.
Arguments:
prs: parser object of argparse
conn: dictionary of connection information | def parse_delete_tmpl(prs, conn):
prs_tmpl_delete = prs.add_parser(
'tmpl_delete', help='delete template')
set_option(prs_tmpl_delete, 'template', required=True)
conn_options(prs_tmpl_delete, conn)
prs_tmpl_delete.set_defaults(func=delete_tmpl) | 1,124,899 |
Update SOA serial.
Arguments:
prs: parser object of argparse
conn: dictionary of connection information | def parse_update_soa(prs, conn):
prs_soa = prs.add_parser('soa', help='update SOA record')
prs_soa.add_argument('--domain', action='store', required=True,
help='specify domain FQDN')
prs_soa.add_argument('--mname', action='store',
help='specify MNAME of... | 1,124,900 |
Create zone.
Arguments:
prs: parser object of argparse
conn: dictionary of connection information | def parse_create_zone(prs, conn):
prs_zone_create = prs.add_parser('zone_create', help='create zone')
prs_zone_create.add_argument(
'--domain', action='store', required=True, help='specify zone')
prs_zone_create.add_argument('--dnsaddr', action='store', required=True,
... | 1,124,901 |
Delete zone.
Arguments:
prs: parser object of argparse
conn: dictionary of connection information | def parse_delete_zone(prs, conn):
prs_zone_delete = prs.add_parser('zone_delete', help='delete zone')
prs_zone_delete.add_argument('--domain', action='store', required=True,
help='specify zone')
conn_options(prs_zone_delete, conn)
prs_zone_delete.set_defaults(func=d... | 1,124,902 |
event handler bound to the receive event of the
link the server is wired too.
Arguments:
- message (message.Message): incoming message
Keyword arguments:
- event_origin (connection.Link) | def on_receive(self, message=None, wire=None, event_origin=None):
self.trigger("before_call", message)
fn_name = message.data
pmsg = self.prepare_message
try:
for handler in self.handlers:
handler.incoming(message, self)
fn = self.get... | 1,124,923 |
destroy remote instance of widget
Arguments:
- id (str): widget id
- name (str): widget type name | def detach_remote(self, id, name):
if name in self.widgets:
if id in self.widgets[name]:
del self.widgets[name] | 1,124,939 |
create remote instance of widget
Arguments:
- id (str): widget id
- name (str): widget type name
Keyword Arguments:
- any further arguments you wish to pass
to the widget constructor | def attach_remote(self, id, name, **kwargs):
client_id = id.split(".")[0]
widget = self.make_widget(
id,
name,
dispatcher=ProxyDispatcher(
self,
link=getattr(self.clients[client_id], "link", None)
),
*... | 1,124,940 |
Get the signature of the current state of the repository
TODO right now `get_signature` is an effectful process in that
it adds all untracked file to staging. This is the only way to get
accruate diff on new files. This is ok because we only use it on a
disposable copy of the repo.
... | def get_signature(self, base_commit=None):
if base_commit is None:
base_commit = 'HEAD'
self.run('add', '-A', self.path)
sha = self.run('rev-parse', '--verify', base_commit).strip()
diff = self.run('diff', sha).strip()
if len(diff) == 0:
try:
... | 1,125,083 |
Install the repository hook for this repo.
Args:
hook_name (str)
hook_content (str) | def install_hook(self, hook_name, hook_content):
hook_path = os.path.join(self.path, '.git/hooks', hook_name)
with open(hook_path, 'w') as f:
f.write(hook_content)
os.chmod(hook_path, stat.S_IEXEC | stat.S_IREAD | stat.S_IWRITE) | 1,125,084 |
This function reads the fixup array and apply the correct values
to the underlying binary stream. This function changes the bin_view
in memory.
Args:
bin_view (memoryview of bytearray) - The binary stream
fx_offset (int) - Offset to the fixup array
fx_count (int) - Number of element... | def apply_fixup_array(bin_view, fx_offset, fx_count, entry_size):
fx_array = bin_view[fx_offset:fx_offset+(2 * fx_count)]
#the array is composed of the signature + substitutions, so fix that
fx_len = fx_count - 1
#we can infer the sector size based on the entry size
sector_size = int(entry_size... | 1,125,382 |
This function allows a simple a way to iterate over a "complex" iterable, for example,
if the input [12, [23], (4, 3), "lkjasddf"], this will return an Iterable that returns
12, 23, 4, 3 and "lkjasddf".
Args:
iterable (Iterable) - A complex iterable that will be flattened
Returns:
(Ite... | def flatten(iterable):
return itertools.chain.from_iterable(a if isinstance(a,Iterable) and not isinstance(a, str) else [a] for a in iterable) | 1,125,383 |
Returns the size, in bytes, of a file. Expects an object that supports
seek and tell methods.
Args:
file_object (file_object) - The object that represents the file
Returns:
(int): size of the file, in bytes | def get_file_size(file_object):
position = file_object.tell()
file_object.seek(0, 2)
file_size = file_object.tell()
file_object.seek(position, 0)
return file_size | 1,125,384 |
Convert `name` to the ASCII vector.
Example:
>>> name_to_vector("ing. Franta Putšálek")
['putsalek', 'franta', 'ing']
Args:
name (str): Name which will be vectorized.
Returns:
list: Vector created from name. | def name_to_vector(name):
if not isinstance(name, unicode):
name = name.decode("utf-8")
name = name.lower()
name = unicodedata.normalize('NFKD', name).encode('ascii', 'ignore')
name = "".join(filter(lambda x: x.isalpha() or x == " ", list(name)))
return sorted(name.split(), key=lambda... | 1,125,795 |
Compare two names in complicated, but more error prone way.
Algorithm is using vector comparison.
Example:
>>> compare_names("Franta Putšálek", "ing. Franta Putšálek")
100.0
>>> compare_names("F. Putšálek", "ing. Franta Putšálek")
50.0
Args:
first (str): Fisst name... | def compare_names(first, second):
first = name_to_vector(first)
second = name_to_vector(second)
zipped = zip(first, second)
if not zipped:
return 0
similarity_factor = 0
for fitem, _ in zipped:
if fitem in second:
similarity_factor += 1
return (float(simi... | 1,125,796 |
Filter publications based at data from Aleph.
Args:
publication (obj): :class:`.Publication` instance.
Returns:
obj/None: None if the publication was found in Aleph or `publication` \
if not. | def filter_publication(publication, cmp_authors=True):
query = None
isbn_query = False
# there can be ISBN query or book title query
if publication.optionals and publication.optionals.ISBN:
query = aleph.ISBNQuery(publication.optionals.ISBN)
isbn_query = True
else:
quer... | 1,125,797 |
A context manager that grabs the lock and releases it when done.
This blocks until the lock can be acquired.
Args:
vcs (easyci.vcs.base.Vcs)
lock_object (Lock)
wait (boolean) - whether to wait for the lock or error out
Raises:
Timeout | def lock(vcs, lock_object, wait=True):
if wait:
timeout = -1
else:
timeout = 0
lock_path = _get_lock_path(vcs, lock_object)
lock = filelock.FileLock(lock_path)
with lock.acquire(timeout=timeout):
yield | 1,125,890 |
Turns a string into a datetime.date object. This will only work if the
format can be "guessed", so the string must have one of the formats from
VALID_DATE_FORMATS_TEXT.
Args:
date_str (str) a string that represents a date
Returns:
datetime.date object
Raises:
ValueError if ... | def datestr2date(date_str):
if any(c not in '0123456789-/' for c in date_str):
raise ValueError('Illegal character in date string')
if '/' in date_str:
try:
m, d, y = date_str.split('/')
except:
raise ValueError('Date {} must have no or exactly 2 slashes. {}'... | 1,126,083 |
Turns a datetime.date object into a string. The string must have one of the
formats from VALID_DATE_FORMATS_TEXT to make it compatible with
datestr2date.
Args:
date (datetime.date) the date to be translated
fmt (str) a format string.
Returns:
(str) that represents a date.
R... | def date2datestr(date, fmt='yyyymmdd'):
if '-' in fmt:
if not fmt.index('d') < fmt.index('m') < fmt.index('y'):
raise ValueError('Invalid format string. {}'.format(
VALID_DATE_FORMATS_TEXT))
d, m, y = fmt.split('-')
elif '/' in fmt:
if not fmt.index('... | 1,126,084 |
Returns the last weekday before date
Args:
date (datetime or datetime.date)
Returns:
(datetime or datetime.date)
Raises:
- | def previous_weekday(date):
weekday = date.weekday()
if weekday == 0:
n_days = 3
elif weekday == 6:
n_days = 2
else:
n_days = 1
return date - datetime.timedelta(days=n_days) | 1,126,085 |
Return the first weekday after date
Args:
date (datetime or datetime.date)
Returns:
(datetime or datetime.date)
Raises:
- | def next_weekday(date):
n_days = 7 - date.weekday()
if n_days > 3:
n_days = 1
return date + datetime.timedelta(days=n_days) | 1,126,086 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.