sugar4.util

Various utility functions

Attributes

ACTIVITY_ID_LEN

units

AND

COMMA

NOW

ELAPSED

Classes

Node

LRU

Implementation of a length-limited O(1) LRU queue.

TempFilePath

str(object='') -> str

Functions

printable_hash(in_hash)

Convert binary hash data into printable characters.

sha_data(data)

sha1 hash some bytes.

unique_id([data])

Generate a likely-unique ID for whatever purpose

is_hex(s)

validate_activity_id(actid)

Validate an activity ID.

set_proc_title(title)

Sets the process title so ps and top show more

ngettext(singular, plural, n)

timestamp_to_elapsed_string(timestamp[, max_levels])

format_size(size)

Module Contents

sugar4.util.printable_hash(in_hash)[source]

Convert binary hash data into printable characters.

sugar4.util.sha_data(data)[source]

sha1 hash some bytes.

sugar4.util.unique_id(data='')[source]

Generate a likely-unique ID for whatever purpose

data – suffix appended to working data before hashing

Returns a 40-character string with hexidecimal digits representing an SHA hash of the time, a random digit within a constrained range and the data passed.

Note: these are not crypotographically secure or

globally unique identifiers. While they are likely to be unique-enough, no attempt is made to make perfectly unique values.

sugar4.util.ACTIVITY_ID_LEN = 40[source]
sugar4.util.is_hex(s)[source]
sugar4.util.validate_activity_id(actid)[source]

Validate an activity ID.

sugar4.util.set_proc_title(title)[source]

Sets the process title so ps and top show more descriptive names. This does not modify argv[0] and only the first 15 characters will be shown.

title – the title you wish to change the process

title to

Returns True on success. We don’t raise exceptions because if something goes wrong here it is not a big deal as this is intended as a nice thing to have for debugging

class sugar4.util.Node(prev, me)[source]

Bases: object

__slots__ = ['prev', 'next', 'me'][source]
prev[source]
me[source]
next = None[source]
class sugar4.util.LRU(count, pairs=[])[source]

Implementation of a length-limited O(1) LRU queue. Built for and used by PyPE: http://pype.sourceforge.net Copyright 2003 Josiah Carlson.

count[source]
d[source]
first = None[source]
last = None[source]
__contains__(obj)[source]
__getitem__(obj)[source]
__setitem__(obj, val)[source]
__delitem__(obj)[source]
__iter__()[source]
iteritems()[source]
iterkeys()[source]
itervalues()[source]
keys()[source]
sugar4.util.units[source]
sugar4.util.AND[source]
sugar4.util.COMMA[source]
sugar4.util.NOW[source]
sugar4.util.ELAPSED[source]
sugar4.util.ngettext(singular, plural, n)[source]
sugar4.util.timestamp_to_elapsed_string(timestamp, max_levels=2)[source]
class sugar4.util.TempFilePath[source]

Bases: str

str(object=’’) -> str str(bytes_or_buffer[, encoding[, errors]]) -> str

Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.__str__() (if defined) or repr(object). encoding defaults to sys.getdefaultencoding(). errors defaults to ‘strict’.

Initialize self. See help(type(self)) for accurate signature.

__del__()[source]
sugar4.util.format_size(size)[source]