‘filesysobjects.pprint’ - Module

The filesysobjects.pprint module provides pretty printer for paths.

Module

The filesysobjects.pprint module provides pretty printer for paths.

Classes

PPPathVar

Features

The class PPPathVar creates formatted printable strings for search path variables. The provided output formats comprise screen display formats and output strings of various data representation syntaxes such as JSON, XML, and YAML. The search path is therefore split into it’s entries and formatted in order to display and/or integrate the data into larger data structures.

The output string of the following input demonstrates the available output variants:

posix: path = "/path/entry/0:/path/entry/1"
win32: path = "\\path/entry\\0;\\path\\entry\\1"
  • format=console

    The conversion results by default in the output of ‘format=console’:

    |   MYPATH = [
    |       "/path/entry/0",
    |       "/path/entry/1",
    |   ]
    |
    ^ left paper border
    

    The settings of the output parameters were:

    |...MYPATH = [
    |...::::"/path/entry/0",
    |...::::"/path/entry/1",
    |...]
    |
    ^ left paper border
    

    with the parameters:

    <format>:         the output format, here 'format="console"'
    'MYPATH':         the prefix, here 'prefix=MYPATH'
    '=':              the assignchar, here 'assignchar="="'
    "/path/entry/0":  first path entry
    "/path/entry/1":  second path entry
    '.' * n:          'n' offset, here n=3 - 'offset=3'
    '.':              offsetchar, here 'offsetchar="."'
    ':' * m:          'm' indent, here m=4 - 'indent=4'
    ':':              indentchar, here 'indentchar=":"'
    
  • format=ini

    The same input results for the output ‘format=INI’ [multiconf] in:

    |   MYPATH = /path/entry/0 /path/entry/1
    |
    ^ left paper border
    
    offsetchar := ' '  # space
    indentchar := ' '  # space
    pathsep    := ' '  # space
    

    Does not require specific support of the parser.

  • format=inix0

    The same input results for the output ‘format=INIX’ [multiconf] in:

    |   MYPATH =
    |       :/path/entry/0
    |       :/path/entry/1
    |
    ^ left paper border
    
    offsetchar := ' '  # space
    indentchar := ' '  # space
    

    Requires the support of the INI file parser, e.g. see [multiconf].

  • format=inix1

    The same input results for the special output ‘format=INIX1’ [multiconf] in:

    |   MYPATH = /path/entry/0
    |   MYPATH = /path/entry/1
    |
    ^ left paper border
    
    offsetchar := ' '  # space
    indentchar := ' '  # space
    

    Requires the support of the INI file parser, e.g. see [multiconf].

  • format=inix2

    The same input results for the special output ‘format=INIX2’ [multiconf] in:

    |   MYPATH0 = /path/entry/0
    |   MYPATH1 = /path/entry/1
    |
    ^ left paper border
    
    offsetchar := ' '  # space
    indentchar := ' '  # space
    

    Does not require specific support of the parser.

  • format=json

    The same input for output ‘format=JSON’:

    |   "MYPATH": [
    |       "/path/entry/0",
    |       "/path/entry/1"
    |   ]
    |
    ^ left paper border
    
    offsetchar := ' '  # space
    indentchar := ' '  # space
    
  • format=python

    The same input for output ‘format=python’. This format is a synonym for ‘format=json’.

    |   "MYPATH": [
    |       "/path/entry/0",
    |       "/path/entry/1"
    |   ]
    |
    ^ left paper border
    
    offsetchar := ' '  # space
    indentchar := ' '  # space
    
  • format=xml

    The same input for output ‘format=XML’:

    |   <MYPATH>
    |       <entry idx=0>/path/entry/0</entry>
    |       <entry idx=1>/path/entry/1</entry>
    |   </MYPATH>
    |
    ^ left paper border
    
    offsetchar := ' '  # space
    indentchar := ' '  # space
    
  • format=yaml

    The same input for output ‘format=YAML’:

    |   MYPATH:
    |       - /path/entry/0
    |       - /path/entry/1
    |
    ^ left paper border
    
    offsetchar := ' '  # space
    indentchar := ' '  # space
    

Class

class filesysobjects.pprint.PPPathVar(path, **kargs)[source]

Pretty printer for PATH variables.

Methods

__init__
PPPathVar.__init__(path, **kargs)[source]

Pretty print search path variables. Splits and returns the formatted printable string for search path variables of type PATH.

The input:

posix: path = "/path/entry/0:/path/entry/1"
win32: path = "\path/entry\0;\path\entry\1" 

results in the output of ‘format=console’:

...MYPATH = [
...::::"/path/entry/0",
...::::"/path/entry/1",
...]

for the output parameters:

 <format>:        the output format, here format='console'
'MYPATH':         the prefix, here 'MYPATH'
'=':              the assignchar, here '='
"/path/entry/0":  first path entry
"/path/entry/1":  second path entry
'.' * n:          'n' offset, here n=3
'.':              offsetchar, here '.'
':' * m:          'm' indent, here m=4
':':              indentchar, here ':'

For further details and examples refer to the manual.

Args:
path:

The search path to be pretty printed.

path := (
<search-path-string>
<list-of-search-paths>
<tuple-of-search-paths>

)

search-path-string := “string of PATH syntax, see ‘tpf’ and ‘spf’” list-of-search-paths := [<path-entry-0>, <path-entry-1>, ...] tuple-of-search-paths := (<path-entry-0>, <path-entry-1>, ...)

kargs:
assignchar:
The character representing the assignment.
format:

The output format.:

format := (
      console    # formatted for console display
    | ini        # simple path print with normalized path
    | inix0      # multiline colon separated list
    | inix1      # multiple key repetition
    | json       # JSON syntax module
    | properties # 
    | python     # same as json
    | xml        # XML syntax module
    | yaml       # YAML syntax module
)

See manual for details.

indent:

Indention of each path item.

indent := <#int>

default := 4

indentchar:

The character used for padding of the indention. The use of ‘indentchar[0]’ only is forced.

offsetchar := <printable-character>

default := ‘ ‘ # space

indentclip:

Indention clipped overflows for of each individual path item.

indent := <#int>

default := 2

indentclipchar:

The character user for extra padding of clipped items. The use of ‘indentchar[0]’ only is forced.

offsetchar := <printable-character>

default := ‘ ‘ # space

keepentry:

Preserves path entries from overflow handling.

keepentry := (
     True    # ignore overflow for single path entries
   | False   # applies overflow processing within single
             # path entries
)
maxwidth:

The maximal line width.

default := 80

linesep:

The output line separator.

default := os.linesep

linesepfinal:

Controls the print of a line separator at the end of the string.

linesepfinal := (
     True   # prints a line separator as last character
   | False  # suppress the final line separator
)

default := True

offset:

The left side offset margin for all output strings.

offset := <#int>

default := 0

offsetchar:

The character used for padding of a general offset. The use of ‘offsetchar[0]’ only is forced.

offsetchar := <printable-character>

default := ‘ ‘ # space

overflow:

The behavior, when line is longer than maxwidth.

overflow := (
      'ignore'     # ignores overflow

    | 'cut'        # drops the overflow

    | 'clip'       # continues with the overflow  
                   # in next line, starts new for
                   # next item

    | 'clipmerge'  # continues with the overflow 
                   # in next line, concatenates
                   # next item 
)

default := ‘ignore’

pathsepin:

The input path separator.

default := os.pathsep

pathsepout:

The output path separator.

default := os.pathsep

prefix:

The prefix to be printed first.

prefix := "string without line breaks"

The output is:

<prefix> = [
   "<path-entry-0>",
   "<path-entry-1>",
]

default := ‘PATH’

spf:
Source platform.
tpf:
Target platform.
Returns:
Object/None
Raises:
pass-through
__str__
PPPathVar.__str__()[source]

Pretty prints as defined by the creation parameters.

__repr__
PPPathVar.__repr__()[source]

Exceptions

PathToolsError

exception filesysobjects.PrettyPrintError[source]

Generic exception for module pprint.