home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyc (Python 2.6)
-
- import re
- import sys
- import codecs
- split_path_re = re.compile('[/\\\\ ]')
- doctype_lookup_re = re.compile('(?smx)\n (<\\?.*?\\?>)?\\s*\n <!DOCTYPE\\s+(\n [a-zA-Z_][a-zA-Z0-9]*\\s+\n [a-zA-Z_][a-zA-Z0-9]*\\s+\n "[^"]*")\n [^>]*>\n')
- tag_re = re.compile('<(.+?)(\\s.*?)?>.*?</.+?>(?uism)')
-
- class ClassNotFound(ValueError):
- pass
-
-
- class OptionError(Exception):
- pass
-
-
- def get_choice_opt(options, optname, allowed, default = None, normcase = False):
- string = options.get(optname, default)
- if normcase:
- string = string.lower()
-
- if string not in allowed:
- raise OptionError('Value for option %s must be one of %s' % (optname, ', '.join(map(str, allowed))))
- string not in allowed
- return string
-
-
- def get_bool_opt(options, optname, default = None):
- string = options.get(optname, default)
- if isinstance(string, bool):
- return string
- if isinstance(string, int):
- return bool(string)
- if not isinstance(string, basestring):
- raise OptionError('Invalid type %r for option %s; use 1/0, yes/no, true/false, on/off' % (string, optname))
- isinstance(string, basestring)
- if string.lower() in ('1', 'yes', 'true', 'on'):
- return True
- if string.lower() in ('0', 'no', 'false', 'off'):
- return False
- raise OptionError('Invalid value %r for option %s; use 1/0, yes/no, true/false, on/off' % (string, optname))
-
-
- def get_int_opt(options, optname, default = None):
- string = options.get(optname, default)
-
- try:
- return int(string)
- except TypeError:
- raise OptionError('Invalid type %r for option %s; you must give an integer value' % (string, optname))
- except ValueError:
- raise OptionError('Invalid value %r for option %s; you must give an integer value' % (string, optname))
-
-
-
- def get_list_opt(options, optname, default = None):
- val = options.get(optname, default)
- if isinstance(val, basestring):
- return val.split()
- if isinstance(val, (list, tuple)):
- return list(val)
- raise OptionError('Invalid type %r for option %s; you must give a list value' % (val, optname))
-
-
- def docstring_headline(obj):
- if not obj.__doc__:
- return ''
- res = []
- for line in obj.__doc__.strip().splitlines():
- if line.strip():
- res.append(' ' + line.strip())
- continue
- obj.__doc__
-
- return ''.join(res).lstrip()
-
-
- def make_analysator(f):
-
- def text_analyse(text):
- rv = f(text)
- if not rv:
- return 0
- return min(1, max(0, float(rv)))
-
- text_analyse.__doc__ = f.__doc__
- return staticmethod(text_analyse)
-
-
- def shebang_matches(text, regex):
- index = text.find('\n')
- if index >= 0:
- first_line = text[:index].lower()
- else:
- first_line = text.lower()
- if first_line.startswith('#!'):
-
- try:
- found = _[1][-1]
- except IndexError:
- return False
-
- regex = re.compile('^%s(\\.(exe|cmd|bat|bin))?$' % regex, re.IGNORECASE)
- if regex.search(found) is not None:
- return True
-
- return False
-
-
- def doctype_matches(text, regex):
- m = doctype_lookup_re.match(text)
- if m is None:
- return False
- doctype = m.group(2)
- return re.compile(regex).match(doctype.strip()) is not None
-
-
- def html_doctype_matches(text):
- return doctype_matches(text, 'html\\s+PUBLIC\\s+"-//W3C//DTD X?HTML.*')
-
- _looks_like_xml_cache = { }
-
- def looks_like_xml(text):
- key = hash(text)
-
- try:
- return _looks_like_xml_cache[key]
- except KeyError:
- m = doctype_lookup_re.match(text)
- if m is not None:
- return True
- rv = tag_re.search(text[:1000]) is not None
- _looks_like_xml_cache[key] = rv
- return rv
- m is not None
-
-
- if sys.version_info < (3, 0):
- b = bytes = str
- u_prefix = 'u'
- import StringIO
- import cStringIO
- BytesIO = cStringIO.StringIO
- StringIO = StringIO.StringIO
- uni_open = codecs.open
- else:
- import builtins
- bytes = builtins.bytes
- u_prefix = ''
-
- def b(s):
- if isinstance(s, str):
- return bytes(map(ord, s))
- if isinstance(s, bytes):
- return s
- raise TypeError('Invalid argument %r for b()' % (s,))
-
- import io
- BytesIO = io.BytesIO
- StringIO = io.StringIO
- uni_open = builtins.open
-