rstgen.utils¶
Defines a series of utility classes and functions.
Functions
|
|
|
Ask for user confirmation from the console. |
|
|
|
Convert the given dict so that it's repr is the same for both Python 2 and 3. |
|
Convert an |
|
Convert int to time. |
|
Thanks to Chase Seibert, https://chase-seibert.github.io/blog/2014/04/23/python-imp-examples.html |
|
Examples: |
|
Convert the given list so that it's repr is the same for both Python 2 and 3. |
|
Return a tuple (url, txt) where url is the URL which links to the source code of the specified Python object and txt is the suggested short text to use in a hyperlink. |
|
Remove the 'u' prefix from unicode strings under Python 2 in order to produce Python 3 compatible output in a doctested code snippet. |
|
Like print, but simulating PY3 output under PY2. |
|
|
|
|
|
Convert the given tuple so that it's repr is the same for both Python 2 and 3. |
|
Reduces indentation of a docstring to the minimum. |
Classes
Base class for |
- rstgen.utils.confirm(prompt=None, default='y')¶
Ask for user confirmation from the console.
- rstgen.utils.i2d(i)¶
Convert an
int
orstr
to adatetime.date
.Examples:
>>> i2d("20121224") datetime.date(2012, 12, 24) >>> i2d(20121224) datetime.date(2012, 12, 24)
>>> i2d(123) Traceback (most recent call last): ... Exception: Invalid date specification 123.
- rstgen.utils.i2t(s)¶
Convert int to time. Examples:
>>> i2t(815) datetime.time(8, 15)
>>> i2t(1230) datetime.time(12, 30)
>>> i2t(12) datetime.time(12, 0)
>>> i2t(1) datetime.time(1, 0)
- rstgen.utils.indentation(s)¶
Examples:
>>> indentation("") 0 >>> indentation("foo") 0 >>> indentation(" foo") 1
- rstgen.utils.unindent(s)¶
Reduces indentation of a docstring to the minimum. Empty lines don’t count.
Examples:
>>> unindent('') '' >>> print(unindent(''' ... foo ... foo ... ''')) foo foo >>> print(unindent(''' ... foo ... foo ... ''')) foo foo
- class rstgen.utils.SubProcessParent¶
Bases:
object
Base class for
atelier.test.TestCase
. Also used standalone by lino.management.commands.makescreenshots.- build_environment()¶
Contructs and return a dict with the environment variables for the future subprocess.
- open_subprocess(args, **kw)¶
Additional keywords will be passed to the Popen constructor. They can be e.g. cwd : the working directory
- run_subprocess(args, **kw)¶
Run a subprocess, wait until it terminates, fail if the returncode is not 0.
- rstgen.utils.import_from_dotted_path(dotted_names, path=None)¶
Thanks to Chase Seibert, https://chase-seibert.github.io/blog/2014/04/23/python-imp-examples.html
- rstgen.utils.py2url_txt(s)¶
Return a tuple (url, txt) where url is the URL which links to the source code of the specified Python object and txt is the suggested short text to use in a hyperlink.
- rstgen.utils.dict_py2(old_dict)¶
Convert the given dict so that it’s repr is the same for both Python 2 and 3.
Deprecated. Use
rmu()
instead.
- rstgen.utils.list_py2(old_list)¶
Convert the given list so that it’s repr is the same for both Python 2 and 3.
Deprecated. Use
rmu()
instead.
- rstgen.utils.tuple_py2(old_tuple)¶
Convert the given tuple so that it’s repr is the same for both Python 2 and 3.
Deprecated. Use
rmu()
instead.
- rstgen.utils.rmu(x)¶
Remove the ‘u’ prefix from unicode strings under Python 2 in order to produce Python 3 compatible output in a doctested code snippet.
>>> lst = [123, "123", u"Äöü"] >>> print(rmu(lst)) [123, '123', '\xc4\xf6\xfc'] >>> print(rmu(tuple(lst))) (123, '123', '\xc4\xf6\xfc') >>> dct = {i: i for i in lst} >>> print(rmu(dct)) {...'\xc4\xf6\xfc': '\xc4\xf6\xfc'...}
- rstgen.utils.sixprint(*args)¶
Like print, but simulating PY3 output under PY2.