home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyc (Python 2.6)
-
- __docformat__ = 'restructuredtext en'
- import re
- import IPython.ipapi as IPython
-
- class LineInfo(object):
-
- def __init__(self, line, continue_prompt):
- self.line = line
- self.continue_prompt = continue_prompt
- (self.pre, self.iFun, self.theRest) = splitUserInput(line)
- self.preChar = self.pre.strip()
- if self.preChar:
- self.preWhitespace = ''
- else:
- self.preWhitespace = self.pre
- self._oinfo = None
-
-
- def ofind(self, ip):
- if not self._oinfo:
- self._oinfo = ip._ofind(self.iFun)
-
- return self._oinfo
-
-
- def __str__(self):
- return 'Lineinfo [%s|%s|%s]' % (self.pre, self.iFun, self.theRest)
-
-
-
- def splitUserInput(line, pattern = None):
- if not pattern:
- pattern = line_split
-
- match = pattern.match(line)
- if not match:
-
- try:
- (iFun, theRest) = line.split(None, 1)
- except ValueError:
- iFun = line
- theRest = ''
-
- pre = re.match('^(\\s*)(.*)', line).groups()[0]
- else:
- (pre, iFun, theRest) = match.groups()
-
- try:
- iFun = iFun.encode('ascii')
- except UnicodeEncodeError:
- theRest = iFun + u' ' + theRest
- iFun = u''
-
- return (pre, iFun.strip(), theRest.lstrip())
-
- line_split = re.compile('^([,;/%?]|!!?|\\s*)\\s*([\\w\\.]+)(\\s+.*$|$)')
- shell_line_split = re.compile('^(\\s*)(\\S*\\s*)(.*$)')
-
- def prefilter(line_info, ip):
- for check in [
- checkEmacs,
- checkShellEscape,
- checkIPyAutocall,
- checkMultiLineMagic,
- checkEscChars,
- checkAssignment,
- checkAutomagic,
- checkAlias,
- checkPythonOps,
- checkAutocall]:
- handler = check(line_info, ip)
- if handler:
- return handler(line_info)
-
- return ip.handle_normal(line_info)
-
-
- def checkShellEscape(l_info, ip):
- if l_info.line.lstrip().startswith(ip.ESC_SHELL):
- return ip.handle_shell_escape
-
-
- def checkEmacs(l_info, ip):
- if l_info.line.endswith('# PYTHON-MODE'):
- return ip.handle_emacs
- return None
-
-
- def checkIPyAutocall(l_info, ip):
- obj = ip.user_ns.get(l_info.iFun, None)
- if isinstance(obj, IPython.ipapi.IPyAutocall):
- obj.set_ip(ip.api)
- return ip.handle_auto
- return None
-
-
- def checkMultiLineMagic(l_info, ip):
- if l_info.continue_prompt and ip.rc.multi_line_specials:
- if l_info.iFun.startswith(ip.ESC_MAGIC):
- return ip.handle_magic
- else:
- return None
- return l_info.iFun.startswith(ip.ESC_MAGIC)
-
-
- def checkEscChars(l_info, ip):
- if l_info.line[-1] == ip.ESC_HELP and l_info.preChar != ip.ESC_SHELL and l_info.preChar != ip.ESC_SH_CAP:
- return ip.handle_help
- if l_info.preChar in ip.esc_handlers:
- return ip.esc_handlers[l_info.preChar]
- return None
-
-
- def checkAssignment(l_info, ip):
- if l_info.theRest and l_info.theRest[0] in '=,':
- return ip.handle_normal
- return None
-
-
- def checkAutomagic(l_info, ip):
- if not (ip.rc.automagic) or not hasattr(ip, 'magic_' + l_info.iFun):
- return None
- if l_info.continue_prompt and not (ip.rc.multi_line_specials):
- return None
- head = l_info.iFun.split('.', 1)[0]
- if isShadowed(head, ip):
- return None
- return ip.handle_magic
-
-
- def checkAlias(l_info, ip):
- head = l_info.iFun.split('.', 1)[0]
- if l_info.iFun not in ip.alias_table and head not in ip.alias_table or isShadowed(head, ip):
- return None
- return ip.handle_alias
-
-
- def checkPythonOps(l_info, ip):
- if l_info.theRest and l_info.theRest[0] in '!=()<>,+*/%^&|':
- return ip.handle_normal
- return None
-
-
- def checkAutocall(l_info, ip):
- if not ip.rc.autocall:
- return None
- oinfo = l_info.ofind(ip)
- if not oinfo['found']:
- return None
- if callable(oinfo['obj']) and not re_exclude_auto.match(l_info.theRest) and re_fun_name.match(l_info.iFun):
- return ip.handle_auto
- return None
-
- re_fun_name = re.compile('[a-zA-Z_]([a-zA-Z0-9_.]*) *$')
- re_exclude_auto = re.compile('^[,&^\\|\\*/\\+-]|^is |^not |^in |^and |^or ')
-
- def isShadowed(identifier, ip):
- if not identifier in ip.user_ns and identifier in ip.internal_ns:
- pass
- return identifier in ip.ns_table['builtin']
-
-