home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 November / maximum-cd-2010-11.iso / DiscContents / calibre-0.7.13.msi / file_1854 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-08-06  |  2.5 KB  |  92 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. __docformat__ = 'restructuredtext en'
  5. import os
  6. import __builtin__
  7. from util import Bunch
  8.  
  9. class Magic(object):
  10.     
  11.     def __init__(self, interpreter, config = None):
  12.         self.interpreter = interpreter
  13.         if config is None:
  14.             config = Bunch(ESC_MAGIC = '%')
  15.         
  16.         self.config = config
  17.  
  18.     
  19.     def has_magic(self, name):
  20.         return hasattr(self, 'magic_' + name)
  21.  
  22.     
  23.     def object_find(self, name):
  24.         name = name.strip()
  25.         user_ns = self.interpreter.user_ns
  26.         internal_ns = { }
  27.         builtin_ns = __builtin__.__dict__
  28.         alias_ns = { }
  29.         namespaces = [
  30.             ('Interactive', user_ns),
  31.             ('IPython internal', internal_ns),
  32.             ('Python builtin', builtin_ns),
  33.             ('Alias', alias_ns)]
  34.         found = False
  35.         obj = None
  36.         space = None
  37.         ds = None
  38.         ismagic = False
  39.         isalias = False
  40.         parts = name.split('.')
  41.         head = parts[0]
  42.         rest = parts[1:]
  43.         for nsname, ns in namespaces:
  44.             
  45.             try:
  46.                 obj = ns[head]
  47.             except KeyError:
  48.                 continue
  49.                 continue
  50.  
  51.             for part in rest:
  52.                 
  53.                 try:
  54.                     obj = getattr(obj, part)
  55.                 continue
  56.                 break
  57.                 continue
  58.  
  59.             else:
  60.                 found = True
  61.                 space = nsname
  62.                 isalias = ns == alias_ns
  63.                 break
  64.         
  65.         if not found:
  66.             if name.startswith(self.config.ESC_MAGIC):
  67.                 name = name[1:]
  68.             
  69.             obj = getattr(self, 'magic_' + name, None)
  70.             if obj is not None:
  71.                 found = True
  72.                 space = 'IPython internal'
  73.                 ismagic = True
  74.             
  75.         
  76.         if not found and head in ("''", '""', '[]', '{}', '()'):
  77.             obj = eval(head)
  78.             found = True
  79.             space = 'Interactive'
  80.         
  81.         return dict(found = found, obj = obj, namespace = space, ismagic = ismagic, isalias = isalias)
  82.  
  83.     
  84.     def magic_pwd(self, parameter_s = ''):
  85.         return os.getcwd()
  86.  
  87.     
  88.     def magic_env(self, parameter_s = ''):
  89.         return os.environ.data
  90.  
  91.  
  92.