/usr/share/pyshared/mx/Tools/NewBuiltins.py is in python-egenix-mxtools 3.2.1-1ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 | """ NewBuiltins - Installs (most of) the mx.Tools add-ons for Python
as Python builtins or in the sys module.
The installation is done upon import, so that you only need
to include the line 'import mx.Tools.NewBuiltins' at the top of your
script to have the add-ons available for use in the script.
Copyright (c) 2000, Marc-Andre Lemburg; mailto:mal@lemburg.com
Copyright (c) 2000-2011, eGenix.com Software GmbH; mailto:info@egenix.com
See the documentation for further information on copyrights,
or contact the author. All Rights Reserved.
"""
import sys,types,operator
import Tools
# Optional intra-package tools
try:
from mx.DateTime import DateTimeFrom
except ImportError:
DateTimeFrom = None
# Enable debugging output
_debug = 0
# Helper
def install_objects(namespace, objects,
DictType=types.DictType):
""" Install all the given objects in namespace.
Doesn't overwrite anything already defined in namespace.
"""
for obj in objects:
try:
name = obj.__name__
except AttributeError:
try:
name, obj = obj
except (TypeError, ValueError):
name = repr(obj)
if name[:2] != '__':
if namespace.has_key(name):
if _debug:
try:
import warnings
except ImportError:
pass
else:
warnings.warn('mxTools builtin %s would overwrite existing '
'builtin; not installed' % name,
RuntimeWarning)
else:
namespace[name] = obj
### Note that undocumented functions may well disappear in
### future releases !!!
# New APIs and objects that go into __builtins__
install_objects(__builtins__,
(Tools.NotGiven,
('True', Tools.True), # already defined in Python >= 2.2.x !
('False', Tools.False),# already defined in Python >= 2.2.x !
Tools.acquire,
Tools.attrlist,
Tools.count,
Tools.defined,
Tools.dict, # already defined in Python >= 2.2.x !
Tools.exists,
Tools.extract,
Tools.findattr,
Tools.forall,
Tools.frange, # undocumented
Tools.get,
Tools.ifilter,
Tools.index,
Tools.indices,
Tools.invdict,
Tools.irange,
Tools.iremove,
Tools.issequence, # undocumented
Tools.lists,
Tools.mapply,
Tools.method_mapply,
#Tools.mget, # old
#Tools.mgetattr, # old
Tools.napply,
#Tools.optimization, # moved to sys
Tools.projection, # undocumented
Tools.range_len,
Tools.reval,
Tools.reverse,
Tools.setdict,
Tools.sign,
Tools.sizeof,
Tools.sortedby, # undocumented
Tools.trange,
#Tools.trange_len, # old
Tools.truth,
('boolean', Tools.truth), # defined as bool() in Python >= 2.2.x !
Tools.tuples,
#Tools.verbosity, # moved to sys
#Tools.xmap, # no longer supported
('binary', buffer),
)
)
# Optional additional builtins
if DateTimeFrom is not None:
install_objects(__builtins__, (('datetime', DateTimeFrom),))
# New APIs for the sys module
install_objects(sys.__dict__,
(Tools.optimization,
Tools.verbosity,
Tools.debugging,
Tools.interactive,
Tools.cur_frame,
Tools.makeref,
)
)
# All other APIs are available through the Tools package, e.g
# Tools.docstring, etc.
|