Assorted utility functions that don’t fit in anywhere else.
A temporary directory for testing use.
Make sure you run cleanup() after you’re done using the directory.
Methods
cleanup() |
Invalid XML while parsing for a *.from_xml() method.
Parameters : | type : str
element : ElementTree.Element
error : str
|
---|
RFC 2822 [1] format string for time.strftime() and time.strptime().
[1] | See RFC 2822, sections 3.3 and A.1.1. |
Convert a time number into a useful localtime.
Where time_to_str() returns GMT +0000, handy_time returns a string in local time. This may be more accessible for the user.
Parameters : | time_val : float
|
---|
Require an iterable full of strings.
This is useful, for example, in validating *.extra_strings. See libbe.bugdir.BugDir.extra_strings
Parameters : | value : list or None
alternative :
|
---|
Examples
>>> iterable_full_of_strings([])
True
>>> iterable_full_of_strings(["abc", "def", u"hij"])
True
>>> iterable_full_of_strings(["abc", None, u"hij"])
False
>>> iterable_full_of_strings(None, alternative=None)
True
Find the file (or directory) named filename in path or in any of path’s parents. For example:
search_parent_directories("/a/b/c", ".be")
will return the path to the first existing file from:
/a/b/c/.be
/a/b/.be
/a/.be
/.be
or None if none of those files exist.
Convert an RFC 2822-fomatted string into a time value.
Parameters : | str_time : str
|
---|
See also
Examples
>>> str_to_time("Thu, 01 Jan 1970 00:00:00 +0000")
0
>>> q = time.time()
>>> str_to_time(time_to_str(q)) == int(q)
True
>>> str_to_time("Thu, 01 Jan 1970 00:00:00 -1000")
36000
Convert an RFC 2822-fomatted string to a GMT string.
Parameters : | str_time : str
|
---|
Examples
>>> time_to_gmtime("Thu, 01 Jan 1970 00:00:00 -1000")
'Thu, 01 Jan 1970 10:00:00 +0000'
Convert a time number into an RFC 2822-formatted string.
Parameters : | time_val : float
|
---|
See also
Examples
>>> time_to_str(0)
'Thu, 01 Jan 1970 00:00:00 +0000'
Produces a version of a string that is underlined.
Parameters : | string : str
char : str
|
---|
Examples
>>> underlined("Underlined String")
'Underlined String\n================='