Package sourceinfo :: Module helper

Module helper

source code

pysourceinfo.helper - miscellaneous utilities - details see manuals

The provided interfaces are foreseen for the bottom layer of the software stack, thus provide basic handling only. This includes special cases of the file system parameters. For more advanced file system path processing refer to filesysobjects.


Version: 0.1.21

Author: Arno-Can Uestuensoez

Copyright: Copyright (C) 2010-2017 Arno-Can Uestuensoez @Ingenieurbuero Arno-Can Uestuensoez

License: Artistic-License-2.0 + Forced-Fairplay-Constraints

Functions
 
get_oid_filepathname(oid, spath=None)
File path name for OID.
source code
 
getfilepathname_type(fpath)
Type for stored module as defined by *imp*.
source code
 
getpythonpath(pname, plist=None, **kw)
Matches prefix from sys.path. Foreseen to be used for canonical base references in unit tests. This enables in particular for generic tests of file system positions where originally absolute pathnames were required.
source code
 
getpythonpath_rel(pname, plist=None, **kw)
Verifies an absolute or relative path name to be reachable as a relative path to one item of the search list plist.
source code
 
getpythonpath_rel_oid(pname, plist=None, **kw)
Calls getpythonpath_rel, returns the relative path as dotted OID relative to the search path.
source code
 
getstack_frame(spos=1, fromtop=False)
List of current mem-addresses on stack frames.
source code
 
getstack_len()
Length of current stack.
source code
 
matchpath(path, pathlist=None, pmatch=1)
Match a file pathname of pathname on a pathlist.
source code
Variables
  BYTECODE_SUFFIXES = ['b'.pyc'']
  CUT_INIT_PY = re.compile('__init__.py')
  C_BUILTIN = 6
  C_EXTENSION = 3
  DEBUG_BYTECODE_SUFFIXES = ['b'.pyc'']
  EXTENSION_SUFFIXES = ['b'.cpython-38m-x86_64-linux-gnu.so'', '...
  ISSTR = (<class 'str'>, <class 'bytes'>)
  OID_LIST = 3
  OID_STR = 1
  OID_TUPLE = 2
  OPTIMIZED_BYTECODE_SUFFIXES = ['b'.pyc'']
  PKG_DIRECTORY = 5
  PYV35Plus = True
  PY_COMPILED = 2
  PY_FROZEN = 7
  PY_SOURCE = 1
  P_FIRST = 1
  P_IGNORE0 = 16
  P_LAST = 2
  P_LONGEST = 8
  P_SHORTEST = 4
  SOURCE_SUFFIXES = ['b'.py'']
  SourceInfoError = <class 'sourceinfo.SourceInfoError'>
  __cached__ = 'b'/local/hd1/home1/data/acue/rd/p-open-deploy/so...
  __loader__ = <_frozen_importlib_external.SourceFileLoader obje...
  __package__ = 'b'sourceinfo''
  __spec__ = ModuleSpec(name='sourceinfo.helper', loader=<_froze...
  __uuid__ = 'b'9de52399-7752-4633-9fdc-66c87a9200b8''
  presolve = 1
Function Details

getfilepathname_type(fpath)

source code 
Type for stored module as defined by *imp*.
Args:
    fpath:
        Module path.

Returns:
    Returns the type of the file. ::
    
        result := (
              C_BUILTIN
            | C_EXTENSION
            | PKG_DIRECTORY
            | PY_COMPILED
            | PY_FROZEN
            | PY_SOURCE
        )

Raises:
      pass-through

getpythonpath(pname, plist=None, **kw)

source code 

Matches prefix from sys.path. Foreseen to be used for canonical base references in unit tests. This enables in particular for generic tests of file system positions where originally absolute pathnames were required.

Args:
pname:
Path name to be searched an appropriate pythonpath prefix for, either absolute or relative to an item of plist.
plist:

List of possible python paths. Alternative to sys.path.

default := sys.path

kw:
ispre:
If True adds a postfix path separator.
presolve:

Defines the path resolution strategy:

presolve := (
      P_FIRST
    | P_LAST
    | P_LONGEST
    | P_SHORTEST
    )

The default is stored in:

sourceinfo.presolve = P_FIRST
verify:

Verify against the filesystem, else no checks are done.

default := True

Returns:

Returns the first matching path prefix from sys.path, as 'normpath'. Else:

ispre == True: returns empty str - ''
else:          returns None
Raises:

SourceInfoError

pass-through

getpythonpath_rel(pname, plist=None, **kw)

source code 

Verifies an absolute or relative path name to be reachable as a relative path to one item of the search list plist.

Args:
pname:
Path name of a path searched for relative to an item of plist. Absolute is cut, relative is searched literally.
plist:

Search path alternative to sys.path.

default := sys.path

kargs:
presolve:

The type of path resolution:

pname is relative:

    presolve := (
        P_FIRST
    )

pname is absolute:

   presolve := (
        P_FIRST
      | P_LAST
      | P_LONGEST
      | P_SHORTEST
   )

default := pysourceinfo.presolve(P_FIRST)

raw:

If True suppresses the call of 'os.path.normpath()':

raw := (
      True   # keep e.g. multiple and trailing *os.sep*
    | False  # apply os.path.normpath()
)
default := False
normpath:

The method to be called for the normalization of the provided input path. This is in particular required when cross-platform path strings are provided. These are by default processed internally with the os.sep of the current platform only.

The API is as defined by 'os.path.normpath':

normapth := (
      <custom-call>
    | <default-call>
)
custom-call := (
      ntpath
    | posixpath
    | <any-compatible-api>
)
default-call := os.path.normpath
verify:

Verify against the file system, else no checks are done.

default := True

Returns:

First matched path from sys.path as normalized path. Else:

if PYTHONPATH[i] == pname:   returns empty str - ''
else:
    if verify:               raise SourceInfoError
    else:                    returns None
Raises:

SourceInfoError

pass-through

getpythonpath_rel_oid(pname, plist=None, **kw)

source code 

Calls getpythonpath_rel, returns the relative path as dotted OID relative to the search path.

Args:

For interface parameters refer to:

sourceinfo.helper.getpythonpath_rel()
kargs:

For remaining parameters refer to getpythonpath_rel.

restype:

Result type:

restype = (
      OID_STR    # OID as dottedt string representation
    | OID_TUPLE  # OID as tuple
    | OID_LIST   # OID as list
)

default := OID_STR
sepin:

The path separator:

default := os.sep

The function internally checks the presence of the provided path. This is not cross-converted, thus requires native separator characters. While the NT file system supports multiple separators, the posix based file systems support regularly the slash '/' only. Thus these fail when other separator characters are provided. For advanced cross-capabilities refer to filesysobjects.

sepout:

The path separator:

default := '.'
Returns:
Returns the provided result by getpythonpath_rel in accordance to the requested result type - see restype.
Raises:

SourceInfoError

pass-through

getstack_frame(spos=1, fromtop=False)

source code 

List of current mem-addresses on stack frames.

Args:
spos:
Stack position.
fromtop:
Start on top, default from bottom.
Returns:
Returns the specified frame.
Raises:
passed through exceptions

getstack_len()

source code 

Length of current stack.

Args:
none.
Returns:
Returns the length of current stack.
Raises:
pass-through

matchpath(path, pathlist=None, pmatch=1)

source code 

Match a file pathname of pathname on a pathlist.

Args:
path:
Path to be searched in pathlist.
pathlist:

Search path for a given path.

default := sys.path

pmatch:

Match criteria for search.

pmatch := (
    P_FIRST, P_LAST, P_SHORTEST,
    P_LONGEST, P_IGNORE0
 )

default := P_FIRST

Returns:
Returns the matched pathname from pathlist.
Raises:
pass-through

Variables Details

EXTENSION_SUFFIXES

Value:
['b'.cpython-38m-x86_64-linux-gnu.so'', 'b'.abi3.so'', 'b'.so'']

__cached__

Value:
'b'/local/hd1/home1/data/acue/rd/p-open-deploy/sourceinfo/repos/source\
forge.net/pysourceinfo-code/sourceinfo/__pycache__/helper.cpython-38.p\
yc''

__loader__

Value:
<_frozen_importlib_external.SourceFileLoader object at 0x7f1b8822aaf0>

__spec__

Value:
ModuleSpec(name='sourceinfo.helper', loader=<_frozen_importlib_externa\
l.SourceFileLoader object at 0x7f1b8822aaf0>, origin='/local/hd1/home1\
/data/acue/rd/p-open-deploy/sourceinfo/repos/sourceforge.net/pysourcei\
nfo-code/sourceinfo/helper.py')