home *** CD-ROM | disk | FTP | other *** search
/ Chip 2011 November / CHIP_2011_11.iso / Programy / Narzedzia / Inkscape / Inkscape-0.48.2-1-win32.exe / python / Lib / site.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2011-03-27  |  17.9 KB  |  577 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. """Append module search paths for third-party packages to sys.path.
  5.  
  6. ****************************************************************
  7. * This module is automatically imported during initialization. *
  8. ****************************************************************
  9.  
  10. In earlier versions of Python (up to 1.5a3), scripts or modules that
  11. needed to use site-specific modules would place ``import site''
  12. somewhere near the top of their code.  Because of the automatic
  13. import, this is no longer necessary (but code that does it still
  14. works).
  15.  
  16. This will append site-specific paths to the module search path.  On
  17. Unix (including Mac OSX), it starts with sys.prefix and
  18. sys.exec_prefix (if different) and appends
  19. lib/python<version>/site-packages as well as lib/site-python.
  20. On other platforms (such as Windows), it tries each of the
  21. prefixes directly, as well as with lib/site-packages appended.  The
  22. resulting directories, if they exist, are appended to sys.path, and
  23. also inspected for path configuration files.
  24.  
  25. A path configuration file is a file whose name has the form
  26. <package>.pth; its contents are additional directories (one per line)
  27. to be added to sys.path.  Non-existing directories (or
  28. non-directories) are never added to sys.path; no directory is added to
  29. sys.path more than once.  Blank lines and lines beginning with
  30. '#' are skipped. Lines starting with 'import' are executed.
  31.  
  32. For example, suppose sys.prefix and sys.exec_prefix are set to
  33. /usr/local and there is a directory /usr/local/lib/python2.5/site-packages
  34. with three subdirectories, foo, bar and spam, and two path
  35. configuration files, foo.pth and bar.pth.  Assume foo.pth contains the
  36. following:
  37.  
  38.   # foo package configuration
  39.   foo
  40.   bar
  41.   bletch
  42.  
  43. and bar.pth contains:
  44.  
  45.   # bar package configuration
  46.   bar
  47.  
  48. Then the following directories are added to sys.path, in this order:
  49.  
  50.   /usr/local/lib/python2.5/site-packages/bar
  51.   /usr/local/lib/python2.5/site-packages/foo
  52.  
  53. Note that bletch is omitted because it doesn't exist; bar precedes foo
  54. because bar.pth comes alphabetically before foo.pth; and spam is
  55. omitted because it is not mentioned in either path configuration file.
  56.  
  57. After these path manipulations, an attempt is made to import a module
  58. named sitecustomize, which can perform arbitrary additional
  59. site-specific customizations.  If this import fails with an
  60. ImportError exception, it is silently ignored.
  61.  
  62. """
  63. import sys
  64. import os
  65. import __builtin__
  66. PREFIXES = [
  67.     sys.prefix,
  68.     sys.exec_prefix]
  69. ENABLE_USER_SITE = None
  70. USER_SITE = None
  71. USER_BASE = None
  72.  
  73. def makepath(*paths):
  74.     dir = os.path.abspath(os.path.join(*paths))
  75.     return (dir, os.path.normcase(dir))
  76.  
  77.  
  78. def abs__file__():
  79.     """Set all module' __file__ attribute to an absolute path"""
  80.     for m in sys.modules.values():
  81.         if hasattr(m, '__loader__'):
  82.             continue
  83.         
  84.         
  85.         try:
  86.             m.__file__ = os.path.abspath(m.__file__)
  87.         continue
  88.         except AttributeError:
  89.             continue
  90.             continue
  91.         
  92.  
  93.     
  94.  
  95.  
  96. def removeduppaths():
  97.     ''' Remove duplicate entries from sys.path along with making them
  98.     absolute'''
  99.     L = []
  100.     known_paths = set()
  101.     for dir in sys.path:
  102.         (dir, dircase) = makepath(dir)
  103.         if dircase not in known_paths:
  104.             L.append(dir)
  105.             known_paths.add(dircase)
  106.             continue
  107.     
  108.     sys.path[:] = L
  109.     return known_paths
  110.  
  111.  
  112. def addbuilddir():
  113.     """Append ./build/lib.<platform> in case we're running in the build dir
  114.     (especially for Guido :-)"""
  115.     get_platform = get_platform
  116.     import distutils.util
  117.     s = 'build/lib.%s-%.3s' % (get_platform(), sys.version)
  118.     if hasattr(sys, 'gettotalrefcount'):
  119.         s += '-pydebug'
  120.     
  121.     s = os.path.join(os.path.dirname(sys.path[-1]), s)
  122.     sys.path.append(s)
  123.  
  124.  
  125. def _init_pathinfo():
  126.     '''Return a set containing all existing directory entries from sys.path'''
  127.     d = set()
  128.     for dir in sys.path:
  129.         
  130.         try:
  131.             if os.path.isdir(dir):
  132.                 (dir, dircase) = makepath(dir)
  133.                 d.add(dircase)
  134.         continue
  135.         except TypeError:
  136.             continue
  137.             continue
  138.         
  139.  
  140.     
  141.     return d
  142.  
  143.  
  144. def addpackage(sitedir, name, known_paths):
  145.     """Process a .pth file within the site-packages directory:
  146.        For each line in the file, either combine it with sitedir to a path
  147.        and add that to known_paths, or execute it if it starts with 'import '.
  148.     """
  149.     if known_paths is None:
  150.         _init_pathinfo()
  151.         reset = 1
  152.     else:
  153.         reset = 0
  154.     fullname = os.path.join(sitedir, name)
  155.     
  156.     try:
  157.         f = open(fullname, 'rU')
  158.     except IOError:
  159.         return None
  160.  
  161.     f.__enter__()
  162.     
  163.     try:
  164.         for line in f:
  165.             if line.startswith(('import ', 'import\t')):
  166.                 exec line
  167.                 continue
  168.             
  169.             line = line.rstrip()
  170.             (dir, dircase) = makepath(sitedir, line)
  171.             if dircase not in known_paths and os.path.exists(dir):
  172.                 sys.path.append(dir)
  173.                 known_paths.add(dircase)
  174.                 continue
  175.     finally:
  176.         pass
  177.  
  178.     return known_paths
  179.  
  180.  
  181. def addsitedir(sitedir, known_paths = None):
  182.     """Add 'sitedir' argument to sys.path if missing and handle .pth files in
  183.     'sitedir'"""
  184.     if known_paths is None:
  185.         known_paths = _init_pathinfo()
  186.         reset = 1
  187.     else:
  188.         reset = 0
  189.     (sitedir, sitedircase) = makepath(sitedir)
  190.     if sitedircase not in known_paths:
  191.         sys.path.append(sitedir)
  192.     
  193.     
  194.     try:
  195.         names = os.listdir(sitedir)
  196.     except os.error:
  197.         return None
  198.  
  199.     dotpth = os.extsep + 'pth'
  200.     names = _[1]
  201.     for name in sorted(names):
  202.         addpackage(sitedir, name, known_paths)
  203.     
  204.     return known_paths
  205.  
  206.  
  207. def check_enableusersite():
  208.     '''Check if user site directory is safe for inclusion
  209.  
  210.     The function tests for the command line flag (including environment var),
  211.     process uid/gid equal to effective uid/gid.
  212.  
  213.     None: Disabled for security reasons
  214.     False: Disabled by user (command line option)
  215.     True: Safe and enabled
  216.     '''
  217.     if sys.flags.no_user_site:
  218.         return False
  219.     return True
  220.  
  221.  
  222. def addusersitepackages(known_paths):
  223.     '''Add a per user site-package to sys.path
  224.  
  225.     Each user has its own python directory with site-packages in the
  226.     home directory.
  227.  
  228.     USER_BASE is the root directory for all Python versions
  229.  
  230.     USER_SITE is the user specific site-packages directory
  231.  
  232.     USER_SITE/.. can be used for data.
  233.     '''
  234.     global USER_BASE, USER_SITE, USER_BASE, USER_SITE
  235.     env_base = os.environ.get('PYTHONUSERBASE', None)
  236.     
  237.     def joinuser(*args):
  238.         return os.path.expanduser(os.path.join(*args))
  239.  
  240.     if os.name == 'nt':
  241.         if not os.environ.get('APPDATA'):
  242.             pass
  243.         base = '~'
  244.         USER_BASE = None if env_base else joinuser(base, 'Python')
  245.         USER_SITE = os.path.join(USER_BASE, 'Python' + sys.version[0] + sys.version[2], 'site-packages')
  246.     elif env_base:
  247.         pass
  248.     
  249.     USER_BASE = joinuser('~', '.local')
  250.     USER_SITE = os.path.join(USER_BASE, 'lib', 'python' + sys.version[:3], 'site-packages')
  251.     if ENABLE_USER_SITE and os.path.isdir(USER_SITE):
  252.         addsitedir(USER_SITE, known_paths)
  253.     
  254.     return known_paths
  255.  
  256.  
  257. def addsitepackages(known_paths):
  258.     '''Add site-packages (and possibly site-python) to sys.path'''
  259.     sitedirs = []
  260.     seen = []
  261.     for prefix in PREFIXES:
  262.         if not prefix or prefix in seen:
  263.             continue
  264.         
  265.         seen.append(prefix)
  266.         if sys.platform in ('os2emx', 'riscos'):
  267.             sitedirs.append(os.path.join(prefix, 'Lib', 'site-packages'))
  268.         elif os.sep == '/':
  269.             sitedirs.append(os.path.join(prefix, 'lib', 'python' + sys.version[:3], 'site-packages'))
  270.             sitedirs.append(os.path.join(prefix, 'lib', 'site-python'))
  271.         else:
  272.             sitedirs.append(prefix)
  273.             sitedirs.append(os.path.join(prefix, 'lib', 'site-packages'))
  274.         if sys.platform == 'darwin':
  275.             if 'Python.framework' in prefix:
  276.                 sitedirs.append(os.path.expanduser(os.path.join('~', 'Library', 'Python', sys.version[:3], 'site-packages')))
  277.             
  278.         'Python.framework' in prefix
  279.     
  280.     for sitedir in sitedirs:
  281.         if os.path.isdir(sitedir):
  282.             addsitedir(sitedir, known_paths)
  283.             continue
  284.     
  285.     return known_paths
  286.  
  287.  
  288. def setBEGINLIBPATH():
  289.     '''The OS/2 EMX port has optional extension modules that do double duty
  290.     as DLLs (and must use the .DLL file extension) for other extensions.
  291.     The library search path needs to be amended so these will be found
  292.     during module import.  Use BEGINLIBPATH so that these are at the start
  293.     of the library search path.
  294.  
  295.     '''
  296.     dllpath = os.path.join(sys.prefix, 'Lib', 'lib-dynload')
  297.     libpath = os.environ['BEGINLIBPATH'].split(';')
  298.     if libpath[-1]:
  299.         libpath.append(dllpath)
  300.     else:
  301.         libpath[-1] = dllpath
  302.     os.environ['BEGINLIBPATH'] = ';'.join(libpath)
  303.  
  304.  
  305. def setquit():
  306.     """Define new built-ins 'quit' and 'exit'.
  307.     These are simply strings that display a hint on how to exit.
  308.  
  309.     """
  310.     if os.sep == ':':
  311.         eof = 'Cmd-Q'
  312.     elif os.sep == '\\':
  313.         eof = 'Ctrl-Z plus Return'
  314.     else:
  315.         eof = 'Ctrl-D (i.e. EOF)'
  316.     
  317.     class Quitter((object,)):
  318.         
  319.         def __init__(self, name):
  320.             self.name = name
  321.  
  322.         
  323.         def __repr__(self):
  324.             return 'Use %s() or %s to exit' % (self.name, eof)
  325.  
  326.         
  327.         def __call__(self, code = None):
  328.             
  329.             try:
  330.                 sys.stdin.close()
  331.             except:
  332.                 pass
  333.  
  334.             raise SystemExit(code)
  335.  
  336.  
  337.     __builtin__.quit = Quitter('quit')
  338.     __builtin__.exit = Quitter('exit')
  339.  
  340.  
  341. class _Printer(object):
  342.     '''interactive prompt objects for printing the license text, a list of
  343.     contributors and the copyright notice.'''
  344.     MAXLINES = 23
  345.     
  346.     def __init__(self, name, data, files = (), dirs = ()):
  347.         self._Printer__name = name
  348.         self._Printer__data = data
  349.         self._Printer__files = files
  350.         self._Printer__dirs = dirs
  351.         self._Printer__lines = None
  352.  
  353.     
  354.     def _Printer__setup(self):
  355.         if self._Printer__lines:
  356.             return None
  357.         data = None
  358.         for dir in self._Printer__dirs:
  359.             for filename in self._Printer__files:
  360.                 filename = os.path.join(dir, filename)
  361.                 
  362.                 try:
  363.                     fp = file(filename, 'rU')
  364.                     data = fp.read()
  365.                     fp.close()
  366.                 continue
  367.                 except IOError:
  368.                     self._Printer__lines
  369.                     self._Printer__lines
  370.                     continue
  371.                 
  372.  
  373.             
  374.             if data:
  375.                 break
  376.                 continue
  377.             self._Printer__lines<EXCEPTION MATCH>IOError
  378.         
  379.         self._Printer__lines = data.split('\n')
  380.         self._Printer__linecnt = len(self._Printer__lines)
  381.  
  382.     
  383.     def __repr__(self):
  384.         self._Printer__setup()
  385.         if len(self._Printer__lines) <= self.MAXLINES:
  386.             return '\n'.join(self._Printer__lines)
  387.         return 'Type %s() to see the full %s text' % (self._Printer__name,) * 2
  388.  
  389.     
  390.     def __call__(self):
  391.         self._Printer__setup()
  392.         prompt = 'Hit Return for more, or q (and Return) to quit: '
  393.         lineno = 0
  394.         while None:
  395.             
  396.             try:
  397.                 for i in range(lineno, lineno + self.MAXLINES):
  398.                     print self._Printer__lines[i]
  399.             except IndexError:
  400.                 break
  401.                 continue
  402.  
  403.             lineno += self.MAXLINES
  404.             key = None
  405.             while key is None:
  406.                 key = raw_input(prompt)
  407.                 if key not in ('', 'q'):
  408.                     key = None
  409.                     continue
  410.             if key == 'q':
  411.                 break
  412.                 continue
  413.             continue
  414.             return None
  415.  
  416.  
  417.  
  418. def setcopyright():
  419.     """Set 'copyright' and 'credits' in __builtin__"""
  420.     __builtin__.copyright = _Printer('copyright', sys.copyright)
  421.     if sys.platform[:4] == 'java':
  422.         __builtin__.credits = _Printer('credits', 'Jython is maintained by the Jython developers (www.jython.org).')
  423.     else:
  424.         __builtin__.credits = _Printer('credits', '    Thanks to CWI, CNRI, BeOpen.com, Zope Corporation and a cast of thousands\n    for supporting Python development.  See www.python.org for more information.')
  425.     here = os.path.dirname(os.__file__)
  426.     __builtin__.license = _Printer('license', 'See http://www.python.org/%.3s/license.html' % sys.version, [
  427.         'LICENSE.txt',
  428.         'LICENSE'], [
  429.         os.path.join(here, os.pardir),
  430.         here,
  431.         os.curdir])
  432.  
  433.  
  434. class _Helper(object):
  435.     """Define the built-in 'help'.
  436.     This is a wrapper around pydoc.help (with a twist).
  437.  
  438.     """
  439.     
  440.     def __repr__(self):
  441.         return 'Type help() for interactive help, or help(object) for help about object.'
  442.  
  443.     
  444.     def __call__(self, *args, **kwds):
  445.         import pydoc
  446.         return pydoc.help(*args, **kwds)
  447.  
  448.  
  449.  
  450. def sethelper():
  451.     __builtin__.help = _Helper()
  452.  
  453.  
  454. def aliasmbcs():
  455.     '''On Windows, some default encodings are not provided by Python,
  456.     while they are always available as "mbcs" in each locale. Make
  457.     them usable by aliasing to "mbcs" in such a case.'''
  458.     if sys.platform == 'win32':
  459.         import locale
  460.         import codecs
  461.         enc = locale.getdefaultlocale()[1]
  462.         if enc.startswith('cp'):
  463.             
  464.             try:
  465.                 codecs.lookup(enc)
  466.             except LookupError:
  467.                 import encodings
  468.                 encodings._cache[enc] = encodings._unknown
  469.                 encodings.aliases.aliases[enc] = 'mbcs'
  470.             except:
  471.                 None<EXCEPTION MATCH>LookupError
  472.             
  473.  
  474.         None<EXCEPTION MATCH>LookupError
  475.     
  476.  
  477.  
  478. def setencoding():
  479.     """Set the string encoding used by the Unicode implementation.  The
  480.     default is 'ascii', but if you're willing to experiment, you can
  481.     change this."""
  482.     encoding = 'ascii'
  483.     if encoding != 'ascii':
  484.         sys.setdefaultencoding(encoding)
  485.     
  486.  
  487.  
  488. def execsitecustomize():
  489.     '''Run custom site specific code, if available.'''
  490.     
  491.     try:
  492.         import sitecustomize
  493.     except ImportError:
  494.         pass
  495.  
  496.  
  497.  
  498. def execusercustomize():
  499.     '''Run custom user specific code, if available.'''
  500.     
  501.     try:
  502.         import usercustomize
  503.     except ImportError:
  504.         pass
  505.  
  506.  
  507.  
  508. def main():
  509.     global ENABLE_USER_SITE
  510.     abs__file__()
  511.     known_paths = removeduppaths()
  512.     if os.name == 'posix' and sys.path and os.path.basename(sys.path[-1]) == 'Modules':
  513.         addbuilddir()
  514.     
  515.     if ENABLE_USER_SITE is None:
  516.         ENABLE_USER_SITE = check_enableusersite()
  517.     
  518.     known_paths = addusersitepackages(known_paths)
  519.     known_paths = addsitepackages(known_paths)
  520.     if sys.platform == 'os2emx':
  521.         setBEGINLIBPATH()
  522.     
  523.     setquit()
  524.     setcopyright()
  525.     sethelper()
  526.     aliasmbcs()
  527.     setencoding()
  528.     execsitecustomize()
  529.     if ENABLE_USER_SITE:
  530.         execusercustomize()
  531.     
  532.     if hasattr(sys, 'setdefaultencoding'):
  533.         del sys.setdefaultencoding
  534.     
  535.  
  536. main()
  537.  
  538. def _script():
  539.     help = "    %s [--user-base] [--user-site]\n\n    Without arguments print some useful information\n    With arguments print the value of USER_BASE and/or USER_SITE separated\n    by '%s'.\n\n    Exit codes with --user-base or --user-site:\n      0 - user site directory is enabled\n      1 - user site directory is disabled by user\n      2 - uses site directory is disabled by super user\n          or for security reasons\n     >2 - unknown error\n    "
  540.     args = sys.argv[1:]
  541.     if not args:
  542.         print 'sys.path = ['
  543.         for dir in sys.path:
  544.             print '    %r,' % (dir,)
  545.         
  546.         print ']'
  547.         print None % ('USER_BASE: %r (%s)', USER_BASE if os.path.isdir(USER_BASE) else "doesn't exist")
  548.         print None % ('USER_SITE: %r (%s)', USER_SITE if os.path.isdir(USER_SITE) else "doesn't exist")
  549.         print 'ENABLE_USER_SITE: %r' % ENABLE_USER_SITE
  550.         sys.exit(0)
  551.     
  552.     buffer = []
  553.     if '--user-base' in args:
  554.         buffer.append(USER_BASE)
  555.     
  556.     if '--user-site' in args:
  557.         buffer.append(USER_SITE)
  558.     
  559.     if buffer:
  560.         print os.pathsep.join(buffer)
  561.         if ENABLE_USER_SITE:
  562.             sys.exit(0)
  563.         elif ENABLE_USER_SITE is False:
  564.             sys.exit(1)
  565.         elif ENABLE_USER_SITE is None:
  566.             sys.exit(2)
  567.         else:
  568.             sys.exit(3)
  569.     else:
  570.         import textwrap
  571.         print textwrap.dedent(help % (sys.argv[0], os.pathsep))
  572.         sys.exit(10)
  573.  
  574. if __name__ == '__main__':
  575.     _script()
  576.  
  577.