home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyc (Python 2.6)
-
- from __future__ import generators
- import sys
- import imp
- import marshal
- from imp import PKG_DIRECTORY, PY_COMPILED, PY_SOURCE, PY_FROZEN
- from distutils.version import StrictVersion, LooseVersion
- __all__ = [
- 'Require',
- 'find_module',
- 'get_module_constant',
- 'extract_constant']
-
- class Require:
-
- def __init__(self, name, requested_version, module, homepage = '', attribute = None, format = None):
- if format is None and requested_version is not None:
- format = StrictVersion
-
- if format is not None:
- requested_version = format(requested_version)
- if attribute is None:
- attribute = '__version__'
-
-
- self.__dict__.update(locals())
- del self.self
-
-
- def full_name(self):
- if self.requested_version is not None:
- return '%s-%s' % (self.name, self.requested_version)
- return self.name
-
-
- def version_ok(self, version):
- if self.attribute is None and self.format is None and str(version) != 'unknown':
- pass
- return version >= self.requested_version
-
-
- def get_version(self, paths = None, default = 'unknown'):
- if self.attribute is None:
-
- try:
- (f, p, i) = find_module(self.module, paths)
- if f:
- f.close()
-
- return default
- except ImportError:
- return None
-
-
- None<EXCEPTION MATCH>ImportError
- v = get_module_constant(self.module, self.attribute, default, paths)
- if v is not None and v is not default and self.format is not None:
- return self.format(v)
- return v
-
-
- def is_present(self, paths = None):
- return self.get_version(paths) is not None
-
-
- def is_current(self, paths = None):
- version = self.get_version(paths)
- if version is None:
- return False
- return self.version_ok(version)
-
-
-
- def _iter_code(code):
- array = array
- import array
- HAVE_ARGUMENT = HAVE_ARGUMENT
- EXTENDED_ARG = EXTENDED_ARG
- import dis
- bytes = array('b', code.co_code)
- eof = len(code.co_code)
- ptr = 0
- extended_arg = 0
- while ptr < eof:
- op = bytes[ptr]
- if op >= HAVE_ARGUMENT:
- arg = bytes[ptr + 1] + bytes[ptr + 2] * 256 + extended_arg
- ptr += 3
- if op == EXTENDED_ARG:
- extended_arg = arg * 0x10000L
- continue
-
- else:
- arg = None
- ptr += 1
- yield (op, arg)
-
-
- def find_module(module, paths = None):
- parts = module.split('.')
- while parts:
- part = parts.pop(0)
- (suffix, mode, kind) = (f, path)
- if kind == PKG_DIRECTORY:
- if not parts:
- pass
- parts = [
- '__init__']
- paths = [
- path]
- continue
- info = imp.find_module(part, paths)
- if parts:
- raise ImportError("Can't find %r in %s" % (parts, module))
- parts
- continue
- imp.find_module(part, paths)
- return info
-
-
- def get_module_constant(module, symbol, default = -1, paths = None):
-
- try:
- (suffix, mode, kind) = (f, path)
- except ImportError:
- return None
-
-
- try:
- if kind == PY_COMPILED:
- f.read(8)
- code = marshal.load(f)
- elif kind == PY_FROZEN:
- code = imp.get_frozen_object(module)
- elif kind == PY_SOURCE:
- code = compile(f.read(), path, 'exec')
- elif module not in sys.modules:
- imp.load_module(module, f, path, (suffix, mode, kind))
-
- return getattr(sys.modules[module], symbol, None)
- finally:
- if f:
- f.close()
-
-
- return extract_constant(code, symbol, default)
-
-
- def extract_constant(code, symbol, default = -1):
- if symbol not in code.co_names:
- return None
- name_idx = list(code.co_names).index(symbol)
- STORE_NAME = 90
- STORE_GLOBAL = 97
- LOAD_CONST = 100
- const = default
- for op, arg in _iter_code(code):
- if op == LOAD_CONST:
- const = code.co_consts[arg]
- continue
- symbol not in code.co_names
- if arg == name_idx:
- if op == STORE_NAME or op == STORE_GLOBAL:
- return const
- const = default
-
- if sys.platform.startswith('java') or sys.platform == 'cli':
- del extract_constant
- del get_module_constant
- __all__.remove('extract_constant')
- __all__.remove('get_module_constant')
-
-