ulauncher.utils package

Submodules

ulauncher.utils.AppCacheDb module

ulauncher.utils.AutostartPreference module

ulauncher.utils.Path module

exception ulauncher.utils.Path.InvalidPathError

Bases: RuntimeError

class ulauncher.utils.Path.Path(path)

Bases: object

exists() → bool
get_abs_path() → str
get_basename() → str
get_dirname() → str
get_existing_dir() → str

Example (assuming foo & bar do not exist):

>>> p = Path('/home/aleksandr/projects/foo/bar')
>>> p.get_existing_dir() == '/home/aleksandr/projects'
Returns:path to the last dir that exists in the user’s query
get_ext() → str
get_search_part() → str
Returns:remaining part of the query that goes after get_existing_dir()
get_user_path() → str
is_dir() → bool
is_exe() → bool

ulauncher.utils.Router module

exception ulauncher.utils.Router.RouteNotFound

Bases: ulauncher.utils.Router.RouterError

exception ulauncher.utils.Router.RoutePathEmpty

Bases: ulauncher.utils.Router.RouterError

class ulauncher.utils.Router.Router

Bases: object

Usage:

>>> rt = Router()
>>>
>>> class App:
>>>
>>>     @rt.route('get/user')
>>>     def get_user(self, url_params):
>>>         ...
>>>         return userObject
>>>
>>>     def on_request(self, url):
>>>         result = rt.dispatch(self, url) # will return userObject for /get/user path
dispatch(context, url)
route(path)
exception ulauncher.utils.Router.RouterError

Bases: RuntimeError

ulauncher.utils.Router.get_url_params(url)

ulauncher.utils.Settings module

ulauncher.utils.SimpleWebSocketServer module

The MIT License (MIT) Copyright (c) 2013 Dave P.

class ulauncher.utils.SimpleWebSocketServer.WebSocket(server, sock, address)

Bases: object

close(status=1000, reason='')

Send Close frame to the client. The underlying socket is only closed when the client acknowledges the Close frame.

status is the closing identifier. reason is the reason for the close.

handleClose()

Called when a websocket server gets a Close frame from a client.

handleConnected()

Called when a websocket client connects to the server.

handleMessage()

Called when websocket frame is received. To access the frame data call self.data.

If the frame is Text then self.data is a unicode object. If the frame is Binary then self.data is a bytearray object.

sendFragment(data)

see sendFragmentStart()

If data is a unicode object then the frame is sent as Text. If the data is a bytearray object then the frame is sent as Binary.

sendFragmentEnd(data)

see sendFragmentEnd()

If data is a unicode object then the frame is sent as Text. If the data is a bytearray object then the frame is sent as Binary.

sendFragmentStart(data)

Send the start of a data fragment stream to a websocket client. Subsequent data should be sent using sendFragment(). A fragment stream is completed when sendFragmentEnd() is called.

If data is a unicode object then the frame is sent as Text. If the data is a bytearray object then the frame is sent as Binary.

sendMessage(data)

Send websocket data frame to the client.

If data is a unicode object then the frame is sent as Text. If the data is a bytearray object then the frame is sent as Binary.

class ulauncher.utils.SimpleWebSocketServer.SimpleWebSocketServer(host, port, websocketclass, selectInterval=0.1)

Bases: object

close()
serveforever()
class ulauncher.utils.SimpleWebSocketServer.SimpleSSLWebSocketServer(host, port, websocketclass, certfile, keyfile, version=<_SSLMethod.PROTOCOL_TLSv1: 3>, selectInterval=0.1)

Bases: ulauncher.utils.SimpleWebSocketServer.SimpleWebSocketServer

ulauncher.utils.SortedCollection module

class ulauncher.utils.SortedCollection.SortedCollection(iterable=(), key=None)

Bases: object

Sequence sorted by a key function.

SortedCollection() is much easier to work with than using bisect() directly. It supports key functions like those use in sorted(), min(), and max(). The result of the key function call is saved so that keys can be searched efficiently.

Instead of returning an insertion-point which can be hard to interpret, the five find-methods return a specific item in the sequence. They can scan for exact matches, the last item less-than-or-equal to a key, or the first item greater-than-or-equal to a key.

Once found, an item’s ordinal position can be located with the index() method. New items can be added with the insert() and insert_right() methods. Old items can be deleted with the remove() method.

The usual sequence methods are provided to support indexing, slicing, length lookup, clearing, copying, forward and reverse iteration, contains checking, item counts, item removal, and a nice looking repr.

Finding and indexing are O(log n) operations while iteration and insertion are O(n). The initial sort is O(n log n).

The key function is stored in the ‘key’ attribute for easy introspection or so that you can assign a new key function (triggering an automatic re-sort).

In short, the class was designed to handle all of the common use cases for bisect but with a simpler API and support for key functions.

>>> from pprint import pprint
>>> from operator import itemgetter
>>> s = SortedCollection(key=itemgetter(2))
>>> for record in [
...         ('roger', 'young', 30),
...         ('angela', 'jones', 28),
...         ('bill', 'smith', 22),
...         ('david', 'thomas', 32)]:
...     s.insert(record)
>>> pprint(list(s))         # show records sorted by age
[('bill', 'smith', 22),
 ('angela', 'jones', 28),
 ('roger', 'young', 30),
 ('david', 'thomas', 32)]
>>> s.find_le(29)           # find oldest person aged 29 or younger
('angela', 'jones', 28)
>>> s.find_lt(28)           # find oldest person under 28
('bill', 'smith', 22)
>>> s.find_gt(28)           # find youngest person over 28
('roger', 'young', 30)
>>> r = s.find_ge(32)       # find youngest person aged 32 or older
>>> s.index(r)              # get the index of their record
3
>>> s[3]                    # fetch the record at that index
('david', 'thomas', 32)
>>> s.key = itemgetter(0)   # now sort by first name
>>> pprint(list(s))
[('angela', 'jones', 28),
 ('bill', 'smith', 22),
 ('david', 'thomas', 32),
 ('roger', 'young', 30)]
clear()
copy()
count(item)

Return number of occurrences of item

find(k)

Return first item with a key == k. Raise ValueError if not found.

find_ge(k)

Return first item with a key >= equal to k. Raise ValueError if not found

find_gt(k)

Return first item with a key > k. Raise ValueError if not found

find_le(k)

Return last item with a key <= k. Raise ValueError if not found.

find_lt(k)

Return last item with a key < k. Raise ValueError if not found.

index(item)

Find the position of an item. Raise ValueError if not found.

insert(item)

Insert a new item. If equal keys are found, add to the left

insert_right(item)

Insert a new item. If equal keys are found, add to the right

key

key function

pop(index=-1)
remove(item)

Remove first occurrence of item. Raise ValueError if not found

ulauncher.utils.Theme module

ulauncher.utils.date module

ulauncher.utils.date.iso_to_datetime(iso: str, zulu_time: bool = True) → datetime.datetime

ulauncher.utils.display module

ulauncher.utils.file_finder module

ulauncher.utils.file_finder.find_files(directory: str, pattern: str = None, filter_fn: Callable = None) → Generator[str, None, None]

Search files in directory filter_fn takes two arguments: directory, filename. If return value is False, file will be ignored

ulauncher.utils.fuzzy_search module

ulauncher.utils.image_loader module

ulauncher.utils.mypy_extensions module

mypy_extensions cannot be installed via apt or dnf so we need to make sure TypedDict exists at runtime

ulauncher.utils.mypy_extensions.TypedDict(*args, **kw)

ulauncher.utils.named_tuple_from_dict module

ulauncher.utils.named_tuple_from_dict.namedtuple_from_dict(obj)

ulauncher.utils.semver module

https://github.com/podhmo/python-semver/blob/master/semver/__init__.py

class ulauncher.utils.semver.Comparator(comp, loose)

Bases: object

parse(comp)
semver = None
test(version)
class ulauncher.utils.semver.Extendlist

Bases: list

exception ulauncher.utils.semver.InvalidTypeIncluded

Bases: ValueError

class ulauncher.utils.semver.Range(range_, loose, _split_rx=re.compile('\s*\|\|\s*'))

Bases: object

format()
parse_range(range_)
test(version, include_prerelease=False)
class ulauncher.utils.semver.SemVer(version, loose)

Bases: object

compare(other)
compare_main(other)
compare_pre(other)
format()
inc(release, identifier=None)
ulauncher.utils.semver.clean(version, loose)
ulauncher.utils.semver.cmp(a, op, b, loose)
ulauncher.utils.semver.comparator(comp, loose)
ulauncher.utils.semver.compare(a, b, loose)
ulauncher.utils.semver.compare_identifiers(a, b)
ulauncher.utils.semver.compare_loose(a, b)
ulauncher.utils.semver.eq(a, b, loose)
ulauncher.utils.semver.full_key_function(version)
ulauncher.utils.semver.gt(a, b, loose)
ulauncher.utils.semver.gte(a, b, loose)
ulauncher.utils.semver.hyphen_replace(mob)
ulauncher.utils.semver.inc(version, release, loose, identifier=None)
ulauncher.utils.semver.is_x(id)
ulauncher.utils.semver.list_get(xs, i)
ulauncher.utils.semver.loose_key_function(version)
ulauncher.utils.semver.lt(a, b, loose)
ulauncher.utils.semver.lte(a, b, loose)
ulauncher.utils.semver.ltr(version, range_, loose)
ulauncher.utils.semver.make_comparator(comp, loose)
ulauncher.utils.semver.make_range(range_, loose)
ulauncher.utils.semver.make_semver(version, loose)
ulauncher.utils.semver.max_satisfying(versions, range_, loose=False, include_prerelease=False)
ulauncher.utils.semver.neq(a, b, loose)
ulauncher.utils.semver.outside(version, range_, hilo, loose)
ulauncher.utils.semver.parse(version, loose)
ulauncher.utils.semver.parse_comparator(comp, loose)
ulauncher.utils.semver.rcompare(a, b, loose)
ulauncher.utils.semver.rcompare_identifiers(a, b)
ulauncher.utils.semver.replace_caret(comp, loose)
ulauncher.utils.semver.replace_carets(comp, loose)
ulauncher.utils.semver.replace_stars(comp, loose)
ulauncher.utils.semver.replace_tilde(comp, loose)
ulauncher.utils.semver.replace_tildes(comp, loose)
ulauncher.utils.semver.replace_xrange(comp, loose)
ulauncher.utils.semver.replace_xranges(comp, loose)
ulauncher.utils.semver.rsort(list, loose)
ulauncher.utils.semver.rtr(version, range_, loose)
ulauncher.utils.semver.satisfies(version, range_, loose=False, include_prerelease=False)
ulauncher.utils.semver.semver(version, loose)
ulauncher.utils.semver.sort(list, loose)
ulauncher.utils.semver.test_set(set_, version, include_prerelease=False)
ulauncher.utils.semver.to_comparators(range_, loose)
ulauncher.utils.semver.valid(version, loose)
ulauncher.utils.semver.valid_range(range_, loose)

ulauncher.utils.setup_logging module

ulauncher.utils.string module

ulauncher.utils.string.split_camel_case(text: str, sep: str = '_') → str

ulauncher.utils.text_highlighter module

ulauncher.utils.version_cmp module

Module contents