get a shell commands output, error message and return value and immediately return.
Warning
This returns with the first screen content for interctive commands.
Parameters: |
|
---|---|
Returns: | triple of stdout, error msg, return value of the shell command |
Return type: | str, str, int |
get a shell commands output, error message and return value as a deferred.
Parameters: | stdin (str) – string to pipe to the process |
---|---|
Returns: | deferred that calls back with triple of stdout, stderr and return value of the shell command |
Return type: | twisted.internet.defer.Deferred |
uses file magic to determine the encoding of the given data blob.
Parameters: | blob (data) – file content as read by file.read() |
---|---|
Returns: | encoding |
Return type: | str |
uses file magic to determine the mime-type of the given data blob.
Parameters: | blob (data) – file content as read by file.read() |
---|---|
Returns: | mime-type, falls back to ‘application/octet-stream’ |
Return type: | str |
>>> humanize_size(1)
'1'
>>> humanize_size(123)
'123'
>>> humanize_size(1234)
'1K'
>>> humanize_size(1234 * 1024)
'1.2M'
>>> humanize_size(1234 * 1024 * 1024)
'1234.0M'
this returns a prefix and suffix to be used in the tempfile module for a given mailcap nametemplate string
translates datetime d to a “sup-style” human readable string.
>>> now = datetime.now()
>>> now.strftime('%c')
'Sat 31 Mar 2012 14:47:26 '
>>> pretty_datetime(now)
u'just now'
>>> pretty_datetime(now - timedelta(minutes=1))
u'1min ago'
>>> pretty_datetime(now - timedelta(hours=5))
u'5h ago'
>>> pretty_datetime(now - timedelta(hours=12))
u'02:54am'
>>> pretty_datetime(now - timedelta(days=1))
u'yest 02pm'
>>> pretty_datetime(now - timedelta(days=2))
u'Thu 02pm'
>>> pretty_datetime(now - timedelta(days=7))
u'Mar 24'
>>> pretty_datetime(now - timedelta(days=356))
u'Apr 2011'
returns result of clb() and falls back to on_error in case exception E is raised.
Parameters: |
---|
>>> print(shell_quote("hello"))
'hello'
>>> print(shell_quote("hello'there"))
'hello'"'"'there'
shortens string if longer than maxlen, appending ellipsis
Parse a list of authors concatenated as a text string (comma separated) and smartly adjust them to maxlength.
1) If the complete list of sender names does not fit in maxlength, it tries to shorten names by using only the first part of each.
2) If the list is still too long, hide authors according to the following priority:
- First author is always shown (if too long is shorten with ellipsis)
- If possible, last author is also shown (if too long, uses ellipsis)
- If there are more than 2 authors in the thread, show the maximum of them. More recent senders have higher priority.
- If it is finally necessary to hide any author, an ellipsis between first and next authors is added.
>>> authors = u'King Kong, Mucho Muchacho, Jaime Huerta, Flash Gordon'
>>> print shorten_author_string(authors, 60)
King Kong, Mucho Muchacho, Jaime Huerta, Flash Gordon
>>> print shorten_author_string(authors, 40)
King, Mucho, Jaime, Flash
>>> print shorten_author_string(authors, 20)
King, …, Jai…, Flash
>>> print shorten_author_string(authors, 10)
King, …
>>> print shorten_author_string(authors, 2)
K…
>>> print shorten_author_string(authors, 1)
K
splits semi-colon separated commandlines
split command string into a list of strings to pass on to subprocess.Popen and the like. This simply calls shlex.split but works also with unicode bytestrings.
safely decodes string to unicode bytestring, respecting enc as a hint.
strips, and replaces non-printable characters
Parameters: | tab_width (int or None) – number of spaces to replace tabs with. Read from globals.tabwidth setting if None |
---|
>>> string_sanitize(' foo\rbar ', 8)
'foobar'
>>> string_sanitize('foo\tbar', 8)
'foo bar'
>>> string_sanitize('foo\t\tbar', 8)
'foo bar'
Sorting tags using this function puts all tags of length 1 at the beginning. This groups all tags mapped to unicode characters.