Package trac :: Package util

Package util

source code

Submodules

Classes
  WindowsError
Dummy exception replacing WindowsError on non-Windows platforms
  AtomicFile
A file that appears atomically with its full content.
  NaivePopen
This is a deadlock-safe version of popen that returns an object with errorlevel, out (a string) and err (a string).
  file_or_std
Context manager for opening a file or using a standard stream
  Ranges
Holds information about ranges parsed from a string
  lazy
A lazily-evaluated attribute.
Functions
 
get_reporter_id(req, arg_name=None)
Get most informative "reporter" identity out of a request.
source code
 
content_disposition(type=None, filename=None)
Generate a properly escaped Content-Disposition header.
source code
 
getuser()
Retrieve the identity of the process owner
source code
 
native_path(path)
Converts a Windows-style or POSIX-style path to the native style.
source code
 
normalize_filename(filepath) source code
 
read_file(path, mode='r')
Read a file and return its content.
source code
 
create_file(path, data='', mode='w')
Create a new file with the given data.
source code
 
create_unique_file(path)
Create a new file.
source code
 
touch_file(filename)
Update modified time of the given file.
source code
 
backup_config_file(env, suffix) source code
 
create_zipinfo(filename, mtime=None, dir=False, executable=False, symlink=False, comment=None)
Create a instance of ZipInfo.
source code
 
extract_zipfile(srcfile, destdir) source code
 
terminate(process)
Terminate the process.
source code
 
makedirs(path, overwrite=False)
Create as many directories as necessary to make path exist.
source code
 
copytree(src, dst, symlinks=False, skip=[], overwrite=False)
Recursively copy a directory tree using copy2() (from shutil.copytree.)
source code
 
is_path_below(path, parent)
Return True iff path is equal to parent or is located below parent at any level.
source code
 
fq_class_name(obj)
Return the fully qualified class name of given object.
source code
 
arity(f)
Return the number of arguments expected by the given function, unbound or bound method.
source code
 
get_last_traceback()
Retrieve the last traceback as an unicode string.
source code
 
get_lines_from_file(filename, lineno, context=0, globals=None)
Return content number of lines before and after the specified lineno from the (source code) file identified by filename.
source code
 
get_frame_info(tb)
Return frame information for a traceback.
source code
 
safe__import__(module_name)
Safe imports: rollback after a failed import.
source code
 
safe_repr(x)
`repr` replacement which "never" breaks.
source code
 
get_doc(obj)
Return the docstring of an object as a tuple (summary, description), where summary is the first paragraph and description is the remaining text.
source code
 
import_namespace(globals_dict, module_name)
Import the namespace of a module into a globals dict.
source code
 
get_module_path(module)
Return the base path the given module is imported from
source code
 
get_sources(path)
Return a dictionary mapping Python module source paths to the distributions that contain them.
source code
 
get_pkginfo(dist)
Get a dictionary containing package information for a package
source code
 
get_module_metadata(module)
Get a dictionary containing metadata for a module.
source code
 
warn_setuptools_issue(out=None) source code
 
hex_entropy(digits=32)
Generate digits number of hex digits of entropy.
source code
 
salt(length=2)
Returns a string of length random letters and numbers.
source code
 
md5crypt(password, salt, magic='$1$')
Based on FreeBSD src/lib/libcrypt/crypt.c 1.2
source code
 
to_ranges(revs)
Converts a list of revisions to a minimal set of ranges.
source code
 
embedded_numbers(s)
Comparison function for natural order sorting based on http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/214202.
source code
 
partition(iterable, order=None) source code
 
as_int(s, default=None, min=None, max=None)
Convert s to an int and limit it to the given range, or return default if unsuccessful.
source code
 
as_float(s, default=None, min=None, max=None)
Convert s to a float and limit it to the given range, or return default if unsuccessful.
source code
 
as_bool(value, default=False)
Convert the given value to a bool.
source code
 
pathjoin(*args)
Strip / from the arguments and join them with a single /.
source code
 
to_list(splittable, sep=',')
Split a string at sep and return a list without any empty items.
source code
 
sub_val(the_list, item_to_remove, item_to_add)
Substitute an item if the item is found in a list, otherwise leave the list unmodified.
source code
Variables
  MOVEFILE_REPLACE_EXISTING = 0x1
  MOVEFILE_WRITE_THROUGH = 0x8
  MoveFileEx = ctypes.windll.kernel32.MoveFileExW
  CreateTransaction = ctypes.windll.ktmw32.CreateTransaction
  CommitTransaction = ctypes.windll.ktmw32.CommitTransaction
  MoveFileTransacted = ctypes.windll.kernel32.MoveFileTransactedW
  CloseHandle = ctypes.windll.kernel32.CloseHandle
  can_rename_open_file = True
  DIGITS = re.compile(r'(\d+)')
  __no_apidoc__ = 'compat presentation translation'
  __package__ = 'trac.util'

Imports: csv, errno, functools, hashlib, importlib, inspect, io, izip, tee, locale, os, posixpath, find_distributions, random, re, shutil, sys, string, struct, tempfile, unicodedata, zipfile, quote, unquote, urlencode, time_now, to_datetime, to_timestamp, utc, exception_to_unicode, getpreferredencoding, stripws, to_unicode, pwd, ctypes, rename, urandom, TracError, reversed, escape, unescape, Markup, Deuglifier, CRLF, to_utf8, shorten_line, wrap, pretty_size, pretty_timedelta, format_datetime, format_date, format_time, get_date_format_hint, get_datetime_format_hint, http_date, parse_date, autoreload, compat, concurrency, daemon, datefmt, html, presentation, text, translation


Function Details

get_reporter_id(req, arg_name=None)

source code 

Get most informative "reporter" identity out of a request.

That's the Request's authname if not 'anonymous', or a Request argument, or the session name and e-mail, or only the name or only the e-mail, or 'anonymous' as last resort.

Parameters:
  • req - a trac.web.api.Request
  • arg_name - if given, a Request argument which may contain the id for non-authentified users

native_path(path)

source code 

Converts a Windows-style or POSIX-style path to the native style.

i.e. on Windows, convert POSIX path to Windows path, and in a POSIX system, convert Windows path to POSIX path.

Parameters:
  • path - the input path
Returns:
the path converted to native style

create_unique_file(path)

source code 
Create a new file. An index is added if the path exists

touch_file(filename)

source code 
Update modified time of the given file. The file is created if missing.

create_zipinfo(filename, mtime=None, dir=False, executable=False, symlink=False, comment=None)

source code 
Create a instance of ZipInfo.
Parameters:
  • filename - file name of the entry
  • mtime - modified time of the entry
  • dir - if True, the entry is a directory
  • executable - if True, the entry is a executable file
  • symlink - if True, the entry is a symbolic link
  • comment - comment of the entry

terminate(process)

source code 

Terminate the process.

If the process has already finished and has not been waited for, the function does not raise OSError and WindowsError exceptions unlike a terminate method of subprocess.Popen.

Parameters:
  • process - the integer id (pid) of the process.

makedirs(path, overwrite=False)

source code 

Create as many directories as necessary to make path exist.

If overwrite is True, don't raise an exception in case path already exists.

copytree(src, dst, symlinks=False, skip=[], overwrite=False)

source code 

Recursively copy a directory tree using copy2() (from shutil.copytree.)

Added a skip parameter consisting of absolute paths which we don't want to copy.

get_lines_from_file(filename, lineno, context=0, globals=None)

source code 

Return content number of lines before and after the specified lineno from the (source code) file identified by filename.

Returns a (lines_before, line, lines_after) tuple.

safe__import__(module_name)