pydocmaker.util

Attributes

UNDEFINED_PREFIX

log

colors_dc

Classes

bcolors

Create a collection of name/value pairs.

_raise_missing

MyJSONDecoder

Simple JSON <https://json.org> decoder

CommonJSONEncoder

Extensible JSON <https://json.org> encoder for Python data structures.

Functions

txtcolor(s, color)

split_camel_case(st)

flatten_list(lst)

generate_unique_id()

get_page_title(docname)

path2attachment(path, filename)

upload_report_to_redmine(doc, redmine, project_id[, ...])

Uploads a report generated from a Doc object to a Redmine wiki page.

filename2identifier(filename)

Converts a filename to a valid identifier by:

bytes_path_exists(→ bool)

Check if a bytes literal refers to an existing file/directory.

get_inp_context([default_name, context])

undefined_obj2str(obj)

undefined_name2str(name[, sep])

undefined_str2obj(s)

remove_undefined(params)

limit_len(k[, n_max, LR])

make_png_imageblob(→ str)

Prepends the data URI prefix for PNG images.

Module Contents

pydocmaker.util.UNDEFINED_PREFIX = '__jinja2.Undefined'
pydocmaker.util.log
class pydocmaker.util.bcolors(*args, **kwds)

Bases: enum.Enum

Create a collection of name/value pairs.

Example enumeration:

>>> class Color(Enum):
...     RED = 1
...     BLUE = 2
...     GREEN = 3

Access them by:

  • attribute access:

    >>> Color.RED
    <Color.RED: 1>
    
  • value lookup:

    >>> Color(1)
    <Color.RED: 1>
    
  • name lookup:

    >>> Color['RED']
    <Color.RED: 1>
    

Enumerations can be iterated over, and know how many members they have:

>>> len(Color)
3
>>> list(Color)
[<Color.RED: 1>, <Color.BLUE: 2>, <Color.GREEN: 3>]

Methods can be added to enumerations, and members can have their own attributes – see the documentation for details.

HEADER = '\x1b[95m'
OKBLUE = '\x1b[94m'
OKCYAN = '\x1b[96m'
OKGREEN = '\x1b[92m'
WARNING = '\x1b[93m'
FAIL = '\x1b[91m'
ENDC = '\x1b[0m'
BOLD = '\x1b[1m'
UNDERLINE = '\x1b[4m'
pydocmaker.util.colors_dc
pydocmaker.util.txtcolor(s: str, color: str)
pydocmaker.util.split_camel_case(st: str)
pydocmaker.util.flatten_list(lst)
pydocmaker.util.generate_unique_id()
pydocmaker.util.get_page_title(docname)
pydocmaker.util.path2attachment(path, filename)
pydocmaker.util.upload_report_to_redmine(doc, redmine, project_id, report_name=None, page_title=None, force_overwrite=False, verb=True)

Uploads a report generated from a Doc object to a Redmine wiki page.

Parameters:
  • doc (Doc) – The Doc object containing the report data.

  • redmine (redminelib.Redmine) – A Redmine connection object.

  • project_id (str) – The ID of the Redmine project where the report should be uploaded.

  • report_name (str, optional) – The name of the report. If not provided, the follwoing schema %Y%m%d_%H%M_exported_report will be used.

  • page_title (str, optional) – The title of the Redmine wiki page. If not provided, it will be derived from the report name.

  • force_overwrite (bool, optional) – Whether to overwrite an existing page with the same title. Defaults to False.

  • verb (bool, optional) – Whether to print verbose output during upload. Defaults to True.

Returns:

The uploaded Redmine wiki page object.

Return type:

redminelib.WikiPage

Raises:

AssertionError – If any of the doc, project_id or redmine arguments is None or empty.

pydocmaker.util.filename2identifier(filename)

Converts a filename to a valid identifier by: 1. Stripping the file extension 2. Replacing any non-alphanumeric character with an underscore 3. Ensuring it doesn’t start with a digit

class pydocmaker.util._raise_missing(*args, **kwargs)
classmethod __getattr__(name)
pydocmaker.util.bytes_path_exists(b: bytes, encoding: str = 'utf-8') bool

Check if a bytes literal refers to an existing file/directory.

pydocmaker.util.get_inp_context(default_name='main', context: dict = None, **kw)
pydocmaker.util.undefined_obj2str(obj: jinja2.Undefined)
pydocmaker.util.undefined_name2str(name, sep=',')
pydocmaker.util.undefined_str2obj(s: str)
pydocmaker.util.remove_undefined(params)
class pydocmaker.util.MyJSONDecoder(*args, **kwargs)

Bases: json.JSONDecoder

Simple JSON <https://json.org> decoder

Performs the following translations in decoding by default:

JSON

Python

object

dict

array

list

string

str

number (int)

int

number (real)

float

true

True

false

False

null

None

It also understands NaN, Infinity, and -Infinity as their corresponding float values, which is outside the JSON spec.

custom_object_hook(dct)

Custom hook to transform decoded objects.

class pydocmaker.util.CommonJSONEncoder(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None)

Bases: json.JSONEncoder

Extensible JSON <https://json.org> encoder for Python data structures.

Supports the following objects and types by default:

Python

JSON

dict

object

list, tuple

array

str

string

int, float

number

True

true

False

false

None

null

To extend this to recognize other objects, subclass and implement a .default() method with another method that returns a serializable object for o if possible, otherwise it should call the superclass implementation (to raise TypeError).

default(obj: Any) Any

Implement this method in a subclass such that it returns a serializable object for o, or calls the base implementation (to raise a TypeError).

For example, to support arbitrary iterators, you could implement default like this:

def default(self, o):
    try:
        iterable = iter(o)
    except TypeError:
        pass
    else:
        return list(iterable)
    # Let the base class default method raise the TypeError
    return super().default(o)
pydocmaker.util.limit_len(k, n_max=10, LR='L')
pydocmaker.util.make_png_imageblob(im_bytes: str) str

Prepends the data URI prefix for PNG images.

Parameters:

im_bytes – Base64-encoded PNG image data.

Returns:

The complete data URI string.

Return type:

str