util Package

coroutines Module

leap.util.coroutines.coroutine(func)
leap.util.coroutines.launch_thread(target, args)

launch and demonize thread. :param target: target function that will run in thread :type target: function :param args: args to be passed to thread :type args: list

leap.util.coroutines.process_events(*args, **kwargs)
leap.util.coroutines.spawn_and_watch_process(command, args, observers=None)

spawns a subprocess with command, args, and launch a watcher thread. :param command: command to be executed in the subprocess :type command: str :param args: arguments :type args: list :param observers: tuple of observer functions to be called for each line in the subprocess output. :type observers: tuple :return: a tuple containing the child process instance, and watcher_thread, :rtype: (Subprocess, Thread)

leap.util.coroutines.watch_output(out, observers)

initializes dict of observer coroutines and pushes lines to each of them as they are received from the watched output. :param out: stdout of a process. :type out: fd :param observers: tuple of coroutines to send datafor each event :type observers: tuple

dicts Module

class leap.util.dicts.OrderedDict(*args, **kwds)

Bases: dict

Dictionary that remembers insertion order

clear() → None. Remove all items from od.
copy() → a shallow copy of od
classmethod fromkeys(S[, v]) → New ordered dictionary with keys from S

and values equal to v (which defaults to None).

items() → list of (key, value) pairs in od
iteritems()

od.iteritems -> an iterator over the (key, value) items in od

iterkeys() → an iterator over the keys in od
itervalues()

od.itervalues -> an iterator over the values in od

keys() → list of keys in od
pop(k[, d]) → v

remove specified key and return the corresponding value. If key is not found, d is returned if given, otherwise KeyError is raised.

popitem() → (k, v), return and remove a (key, value) pair.

Pairs are returned in LIFO order if last is true or FIFO order if false.

setdefault(k[, d]) → od.get(k,d), also set od[k]=d if k not in od
update(E, **F) → None. Update od from dict/iterable E and F.

If E is a dict instance, does: for k in E: od[k] = E[k] If E has a .keys() method, does: for k in E.keys():

od[k] = E[k]

Or if E is an iterable of items, does: for k, v in E: od[k] = v In either case, this is followed by: for k, v in F.items():

od[k] = v
values() → list of values in od
viewitems() → a set-like object providing a view on od's items
viewkeys() → a set-like object providing a view on od's keys
viewvalues() → an object providing a view on od's values

fileutil Module

leap.util.fileutil.check_and_fix_urw_only(_file)

test for 600 mode and try to set it if anything different found

leap.util.fileutil.extend_path()
leap.util.fileutil.is_user_executable(fpath)
leap.util.fileutil.mkdir_f(path)
leap.util.fileutil.mkdir_p(path)

implements mkdir -p functionality

leap.util.fileutil.which(program, path=None)

an implementation of which that extends the path with other locations, like sbin (f.i., openvpn binary is likely to be there) @param program: a string representing the binary we’re looking for.

leap_argparse Module

leap.util.leap_argparse.build_parser()

all the options for the leap arg parser Some of these could be switched on only if debug flag is present!

leap.util.leap_argparse.init_leapc_args()

misc Module

misc utils

exception leap.util.misc.ImproperlyConfigured

Bases: exceptions.Exception

leap.util.misc.get_openvpn_pids()
leap.util.misc.null_check(value, value_name)

translations Module

class leap.util.translations.LEAPTranslatable

Bases: dict

An extended dict that implements a .tr method so it can be translated on the fly by our magic translate method

locale = 'en'
tr(to=None)
leap.util.translations.logger = <logging.Logger object at 0xafcf98c>

here I could not do all that I wanted. the context is not getting passed to the xml file. Looks like pylupdate4 is somehow a hack that does not parse too well the python ast. I guess we could generate the xml for ourselves as a last recourse.

leap.util.translations.qtTranslate()

QCoreApplication.translate(str, str, str disambiguation=None, QCoreApplication.Encoding encoding=QCoreApplication.CodecForTr) -> QString QCoreApplication.translate(str, str, str, QCoreApplication.Encoding, int) -> QString

leap.util.translations.translate(*args, **kwargs)

our magic function. translate(Context, text, comment)

web Module

web related utilities

exception leap.util.web.UsageError

Bases: exceptions.Exception

leap.util.web.get_https_domain_and_port(full_domain)

returns a tuple with domain and port from a full_domain string that can contain a colon

Table Of Contents

Previous topic

testing Package

Next topic

tests Package

This Page