|
|
dfd5875 |
Index: ipython-0.10/IPython/CrashHandler.py
|
|
|
dfd5875 |
===================================================================
|
|
|
dfd5875 |
--- ipython-0.10.orig/IPython/CrashHandler.py
|
|
|
dfd5875 |
+++ ipython-0.10/IPython/CrashHandler.py
|
|
|
dfd5875 |
@@ -27,7 +27,7 @@ from pprint import pprint,pformat
|
|
|
dfd5875 |
from IPython import Release
|
|
|
dfd5875 |
from IPython import ultraTB
|
|
|
dfd5875 |
from IPython.ColorANSI import ColorScheme,ColorSchemeTable # too long names
|
|
|
dfd5875 |
-from IPython.Itpl import Itpl,itpl,printpl
|
|
|
dfd5875 |
+from IPython.external.Itpl import Itpl, itpl, printpl
|
|
|
dfd5875 |
|
|
|
dfd5875 |
from IPython.genutils import *
|
|
|
dfd5875 |
|
|
|
dfd5875 |
Index: ipython-0.10/IPython/Extensions/ipy_editors.py
|
|
|
dfd5875 |
===================================================================
|
|
|
dfd5875 |
--- ipython-0.10.orig/IPython/Extensions/ipy_editors.py
|
|
|
dfd5875 |
+++ ipython-0.10/IPython/Extensions/ipy_editors.py
|
|
|
dfd5875 |
@@ -8,7 +8,7 @@ Contributions are *very* welcome.
|
|
|
dfd5875 |
import IPython.ipapi
|
|
|
dfd5875 |
ip = IPython.ipapi.get()
|
|
|
dfd5875 |
|
|
|
dfd5875 |
-from IPython.Itpl import itplns
|
|
|
dfd5875 |
+from IPython.external.Itpl import itplns
|
|
|
dfd5875 |
import os
|
|
|
dfd5875 |
|
|
|
dfd5875 |
def install_editor(run_template, wait = False):
|
|
|
dfd5875 |
Index: ipython-0.10/IPython/Extensions/ipy_profile_sh.py
|
|
|
dfd5875 |
===================================================================
|
|
|
dfd5875 |
--- ipython-0.10.orig/IPython/Extensions/ipy_profile_sh.py
|
|
|
dfd5875 |
+++ ipython-0.10/IPython/Extensions/ipy_profile_sh.py
|
|
|
dfd5875 |
@@ -173,7 +173,7 @@ def extend_shell_behavior(ip):
|
|
|
dfd5875 |
# mark the IPSHELL with this signature
|
|
|
dfd5875 |
ip.IP.user_ns['__builtins__'].__dict__['__sig__'] = ip.IP.__sig__
|
|
|
dfd5875 |
|
|
|
dfd5875 |
- from IPython.Itpl import ItplNS
|
|
|
dfd5875 |
+ from IPython.external.Itpl import ItplNS
|
|
|
dfd5875 |
from IPython.genutils import shell
|
|
|
dfd5875 |
# utility to expand user variables via Itpl
|
|
|
dfd5875 |
# xxx do something sensible with depth?
|
|
|
dfd5875 |
Index: ipython-0.10/IPython/Extensions/ipy_render.py
|
|
|
dfd5875 |
===================================================================
|
|
|
dfd5875 |
--- ipython-0.10.orig/IPython/Extensions/ipy_render.py
|
|
|
dfd5875 |
+++ ipython-0.10/IPython/Extensions/ipy_render.py
|
|
|
dfd5875 |
@@ -9,7 +9,7 @@ ip = IPython.ipapi.get()
|
|
|
dfd5875 |
from string import Template
|
|
|
dfd5875 |
import sys,os
|
|
|
dfd5875 |
|
|
|
dfd5875 |
-from IPython.Itpl import itplns
|
|
|
dfd5875 |
+from IPython.external.Itpl import itplns
|
|
|
dfd5875 |
|
|
|
dfd5875 |
def toclip_w32(s):
|
|
|
dfd5875 |
""" Places contents of s to clipboard
|
|
|
dfd5875 |
Index: ipython-0.10/IPython/genutils.py
|
|
|
dfd5875 |
===================================================================
|
|
|
dfd5875 |
--- ipython-0.10.orig/IPython/genutils.py
|
|
|
dfd5875 |
+++ ipython-0.10/IPython/genutils.py
|
|
|
dfd5875 |
@@ -46,7 +46,7 @@ else:
|
|
|
dfd5875 |
|
|
|
dfd5875 |
# Other IPython utilities
|
|
|
dfd5875 |
import IPython
|
|
|
dfd5875 |
-from IPython.Itpl import Itpl,itpl,printpl
|
|
|
dfd5875 |
+from IPython.external.Itpl import Itpl, itpl, printpl
|
|
|
dfd5875 |
from IPython import DPyGetOpt, platutils
|
|
|
dfd5875 |
from IPython.generics import result_display
|
|
|
dfd5875 |
import IPython.ipapi
|
|
|
dfd5875 |
Index: ipython-0.10/IPython/iplib.py
|
|
|
dfd5875 |
===================================================================
|
|
|
dfd5875 |
--- ipython-0.10.orig/IPython/iplib.py
|
|
|
dfd5875 |
+++ ipython-0.10/IPython/iplib.py
|
|
|
dfd5875 |
@@ -55,7 +55,7 @@ from IPython import Debugger,OInspect,Py
|
|
|
dfd5875 |
from IPython.ColorANSI import ColorScheme,ColorSchemeTable # too long names
|
|
|
dfd5875 |
from IPython.Extensions import pickleshare
|
|
|
dfd5875 |
from IPython.FakeModule import FakeModule, init_fakemod_dict
|
|
|
dfd5875 |
-from IPython.Itpl import Itpl,itpl,printpl,ItplNS,itplns
|
|
|
dfd5875 |
+from IPython.external.Itpl import Itpl, itpl, printpl, ItplNS, itplns
|
|
|
dfd5875 |
from IPython.Logger import Logger
|
|
|
dfd5875 |
from IPython.Magic import Magic
|
|
|
dfd5875 |
from IPython.Prompts import CachedOutput
|
|
|
dfd5875 |
Index: ipython-0.10/IPython/Magic.py
|
|
|
dfd5875 |
===================================================================
|
|
|
dfd5875 |
--- ipython-0.10.orig/IPython/Magic.py
|
|
|
dfd5875 |
+++ ipython-0.10/IPython/Magic.py
|
|
|
dfd5875 |
@@ -45,7 +45,7 @@ except ImportError:
|
|
|
dfd5875 |
import IPython
|
|
|
dfd5875 |
from IPython import Debugger, OInspect, wildcard
|
|
|
dfd5875 |
from IPython.FakeModule import FakeModule
|
|
|
dfd5875 |
-from IPython.Itpl import Itpl, itpl, printpl,itplns
|
|
|
dfd5875 |
+from IPython.external.Itpl import Itpl, itpl, printpl, itplns
|
|
|
dfd5875 |
from IPython.PyColorize import Parser
|
|
|
dfd5875 |
from IPython.ipstruct import Struct
|
|
|
dfd5875 |
from IPython.macro import Macro
|
|
|
dfd5875 |
Index: ipython-0.10/IPython/OInspect.py
|
|
|
dfd5875 |
===================================================================
|
|
|
dfd5875 |
--- ipython-0.10.orig/IPython/OInspect.py
|
|
|
dfd5875 |
+++ ipython-0.10/IPython/OInspect.py
|
|
|
dfd5875 |
@@ -29,7 +29,7 @@ import types
|
|
|
dfd5875 |
# IPython's own
|
|
|
dfd5875 |
from IPython import PyColorize
|
|
|
dfd5875 |
from IPython.genutils import page,indent,Term
|
|
|
dfd5875 |
-from IPython.Itpl import itpl
|
|
|
dfd5875 |
+from IPython.external.Itpl import itpl
|
|
|
dfd5875 |
from IPython.wildcard import list_namespace
|
|
|
dfd5875 |
from IPython.ColorANSI import *
|
|
|
dfd5875 |
|
|
|
dfd5875 |
Index: ipython-0.10/IPython/Itpl.py
|
|
|
dfd5875 |
===================================================================
|
|
|
dfd5875 |
--- ipython-0.10.orig/IPython/Itpl.py
|
|
|
dfd5875 |
+++ /dev/null
|
|
|
dfd5875 |
@@ -1,290 +0,0 @@
|
|
|
dfd5875 |
-# -*- coding: utf-8 -*-
|
|
|
dfd5875 |
-"""String interpolation for Python (by Ka-Ping Yee, 14 Feb 2000).
|
|
|
dfd5875 |
-
|
|
|
dfd5875 |
-This module lets you quickly and conveniently interpolate values into
|
|
|
dfd5875 |
-strings (in the flavour of Perl or Tcl, but with less extraneous
|
|
|
dfd5875 |
-punctuation). You get a bit more power than in the other languages,
|
|
|
dfd5875 |
-because this module allows subscripting, slicing, function calls,
|
|
|
dfd5875 |
-attribute lookup, or arbitrary expressions. Variables and expressions
|
|
|
dfd5875 |
-are evaluated in the namespace of the caller.
|
|
|
dfd5875 |
-
|
|
|
dfd5875 |
-The itpl() function returns the result of interpolating a string, and
|
|
|
dfd5875 |
-printpl() prints out an interpolated string. Here are some examples:
|
|
|
dfd5875 |
-
|
|
|
dfd5875 |
- from Itpl import printpl
|
|
|
dfd5875 |
- printpl("Here is a $string.")
|
|
|
dfd5875 |
- printpl("Here is a $module.member.")
|
|
|
dfd5875 |
- printpl("Here is an $object.member.")
|
|
|
dfd5875 |
- printpl("Here is a $functioncall(with, arguments).")
|
|
|
dfd5875 |
- printpl("Here is an ${arbitrary + expression}.")
|
|
|
dfd5875 |
- printpl("Here is an $array[3] member.")
|
|
|
dfd5875 |
- printpl("Here is a $dictionary['member'].")
|
|
|
dfd5875 |
-
|
|
|
dfd5875 |
-The filter() function filters a file object so that output through it
|
|
|
dfd5875 |
-is interpolated. This lets you produce the illusion that Python knows
|
|
|
dfd5875 |
-how to do interpolation:
|
|
|
dfd5875 |
-
|
|
|
dfd5875 |
- import Itpl
|
|
|
dfd5875 |
- sys.stdout = Itpl.filter()
|
|
|
dfd5875 |
- f = "fancy"
|
|
|
dfd5875 |
- print "Is this not $f?"
|
|
|
dfd5875 |
- print "Standard output has been replaced with a $sys.stdout object."
|
|
|
dfd5875 |
- sys.stdout = Itpl.unfilter()
|
|
|
dfd5875 |
- print "Okay, back $to $normal."
|
|
|
dfd5875 |
-
|
|
|
dfd5875 |
-Under the hood, the Itpl class represents a string that knows how to
|
|
|
dfd5875 |
-interpolate values. An instance of the class parses the string once
|
|
|
dfd5875 |
-upon initialization; the evaluation and substitution can then be done
|
|
|
dfd5875 |
-each time the instance is evaluated with str(instance). For example:
|
|
|
dfd5875 |
-
|
|
|
dfd5875 |
- from Itpl import Itpl
|
|
|
dfd5875 |
- s = Itpl("Here is $foo.")
|
|
|
dfd5875 |
- foo = 5
|
|
|
dfd5875 |
- print str(s)
|
|
|
dfd5875 |
- foo = "bar"
|
|
|
dfd5875 |
- print str(s)
|
|
|
dfd5875 |
-"""
|
|
|
dfd5875 |
-
|
|
|
dfd5875 |
-#*****************************************************************************
|
|
|
dfd5875 |
-#
|
|
|
dfd5875 |
-# Copyright (c) 2001 Ka-Ping Yee <ping@lfw.org>
|
|
|
dfd5875 |
-#
|
|
|
dfd5875 |
-#
|
|
|
dfd5875 |
-# Published under the terms of the MIT license, hereby reproduced:
|
|
|
dfd5875 |
-#
|
|
|
dfd5875 |
-# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
dfd5875 |
-# of this software and associated documentation files (the "Software"), to
|
|
|
dfd5875 |
-# deal in the Software without restriction, including without limitation the
|
|
|
dfd5875 |
-# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
|
|
dfd5875 |
-# sell copies of the Software, and to permit persons to whom the Software is
|
|
|
dfd5875 |
-# furnished to do so, subject to the following conditions:
|
|
|
dfd5875 |
-#
|
|
|
dfd5875 |
-# The above copyright notice and this permission notice shall be included in
|
|
|
dfd5875 |
-# all copies or substantial portions of the Software.
|
|
|
dfd5875 |
-#
|
|
|
dfd5875 |
-# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
dfd5875 |
-# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
dfd5875 |
-# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
dfd5875 |
-# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
dfd5875 |
-# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
dfd5875 |
-# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
|
|
dfd5875 |
-# IN THE SOFTWARE.
|
|
|
dfd5875 |
-#
|
|
|
dfd5875 |
-#*****************************************************************************
|
|
|
dfd5875 |
-
|
|
|
dfd5875 |
-__author__ = 'Ka-Ping Yee <ping@lfw.org>'
|
|
|
dfd5875 |
-__license__ = 'MIT'
|
|
|
dfd5875 |
-
|
|
|
dfd5875 |
-import string
|
|
|
dfd5875 |
-import sys
|
|
|
dfd5875 |
-from tokenize import tokenprog
|
|
|
dfd5875 |
-from types import StringType
|
|
|
dfd5875 |
-
|
|
|
dfd5875 |
-class ItplError(ValueError):
|
|
|
dfd5875 |
- def __init__(self, text, pos):
|
|
|
dfd5875 |
- self.text = text
|
|
|
dfd5875 |
- self.pos = pos
|
|
|
dfd5875 |
- def __str__(self):
|
|
|
dfd5875 |
- return "unfinished expression in %s at char %d" % (
|
|
|
dfd5875 |
- repr(self.text), self.pos)
|
|
|
dfd5875 |
-
|
|
|
dfd5875 |
-def matchorfail(text, pos):
|
|
|
dfd5875 |
- match = tokenprog.match(text, pos)
|
|
|
dfd5875 |
- if match is None:
|
|
|
dfd5875 |
- raise ItplError(text, pos)
|
|
|
dfd5875 |
-
|
|
|
dfd5875 |
- return match, match.end()
|
|
|
dfd5875 |
-
|
|
|
dfd5875 |
-try:
|
|
|
dfd5875 |
- itpl_encoding = sys.stdin.encoding or 'ascii'
|
|
|
dfd5875 |
-except AttributeError:
|
|
|
dfd5875 |
- itpl_encoding = 'ascii'
|
|
|
dfd5875 |
-
|
|
|
dfd5875 |
-
|
|
|
dfd5875 |
-
|
|
|
dfd5875 |
-class Itpl:
|
|
|
dfd5875 |
- """Class representing a string with interpolation abilities.
|
|
|
dfd5875 |
-
|
|
|
dfd5875 |
- Upon creation, an instance works out what parts of the format
|
|
|
dfd5875 |
- string are literal and what parts need to be evaluated. The
|
|
|
dfd5875 |
- evaluation and substitution happens in the namespace of the
|
|
|
dfd5875 |
- caller when str(instance) is called."""
|
|
|
dfd5875 |
-
|
|
|
dfd5875 |
- def __init__(self, format,codec=itpl_encoding,encoding_errors='backslashreplace'):
|
|
|
dfd5875 |
- """The single mandatory argument to this constructor is a format
|
|
|
dfd5875 |
- string.
|
|
|
dfd5875 |
-
|
|
|
dfd5875 |
- The format string is parsed according to the following rules:
|
|
|
dfd5875 |
-
|
|
|
dfd5875 |
- 1. A dollar sign and a name, possibly followed by any of:
|
|
|
dfd5875 |
- - an open-paren, and anything up to the matching paren
|
|
|
dfd5875 |
- - an open-bracket, and anything up to the matching bracket
|
|
|
dfd5875 |
- - a period and a name
|
|
|
dfd5875 |
- any number of times, is evaluated as a Python expression.
|
|
|
dfd5875 |
-
|
|
|
dfd5875 |
- 2. A dollar sign immediately followed by an open-brace, and
|
|
|
dfd5875 |
- anything up to the matching close-brace, is evaluated as
|
|
|
dfd5875 |
- a Python expression.
|
|
|
dfd5875 |
-
|
|
|
dfd5875 |
- 3. Outside of the expressions described in the above two rules,
|
|
|
dfd5875 |
- two dollar signs in a row give you one literal dollar sign.
|
|
|
dfd5875 |
-
|
|
|
dfd5875 |
- Optional arguments:
|
|
|
dfd5875 |
-
|
|
|
dfd5875 |
- - codec('utf_8'): a string containing the name of a valid Python
|
|
|
dfd5875 |
- codec.
|
|
|
dfd5875 |
-
|
|
|
dfd5875 |
- - encoding_errors('backslashreplace'): a string with a valid error handling
|
|
|
dfd5875 |
- policy. See the codecs module documentation for details.
|
|
|
dfd5875 |
-
|
|
|
dfd5875 |
- These are used to encode the format string if a call to str() fails on
|
|
|
dfd5875 |
- the expanded result."""
|
|
|
dfd5875 |
-
|
|
|
dfd5875 |
- if not isinstance(format,basestring):
|
|
|
dfd5875 |
- raise TypeError, "needs string initializer"
|
|
|
dfd5875 |
- self.format = format
|
|
|
dfd5875 |
- self.codec = codec
|
|
|
dfd5875 |
- self.encoding_errors = encoding_errors
|
|
|
dfd5875 |
-
|
|
|
dfd5875 |
- namechars = "abcdefghijklmnopqrstuvwxyz" \
|
|
|
dfd5875 |
- "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_";
|
|
|
dfd5875 |
- chunks = []
|
|
|
dfd5875 |
- pos = 0
|
|
|
dfd5875 |
-
|
|
|
dfd5875 |
- while 1:
|
|
|
dfd5875 |
- dollar = string.find(format, "$", pos)
|
|
|
dfd5875 |
- if dollar < 0: break
|
|
|
dfd5875 |
- nextchar = format[dollar+1]
|
|
|
dfd5875 |
-
|
|
|
dfd5875 |
- if nextchar == "{":
|
|
|
dfd5875 |
- chunks.append((0, format[pos:dollar]))
|
|
|
dfd5875 |
- pos, level = dollar+2, 1
|
|
|
dfd5875 |
- while level:
|
|
|
dfd5875 |
- match, pos = matchorfail(format, pos)
|
|
|
dfd5875 |
- tstart, tend = match.regs[3]
|
|
|
dfd5875 |
- token = format[tstart:tend]
|
|
|
dfd5875 |
- if token == "{": level = level+1
|
|
|
dfd5875 |
- elif token == "}": level = level-1
|
|
|
dfd5875 |
- chunks.append((1, format[dollar+2:pos-1]))
|
|
|
dfd5875 |
-
|
|
|
dfd5875 |
- elif nextchar in namechars:
|
|
|
dfd5875 |
- chunks.append((0, format[pos:dollar]))
|
|
|
dfd5875 |
- match, pos = matchorfail(format, dollar+1)
|
|
|
dfd5875 |
- while pos < len(format):
|
|
|
dfd5875 |
- if format[pos] == "." and \
|
|
|
dfd5875 |
- pos+1 < len(format) and format[pos+1] in namechars:
|
|
|
dfd5875 |
- match, pos = matchorfail(format, pos+1)
|
|
|
dfd5875 |
- elif format[pos] in "([":
|
|
|
dfd5875 |
- pos, level = pos+1, 1
|
|
|
dfd5875 |
- while level:
|
|
|
dfd5875 |
- match, pos = matchorfail(format, pos)
|
|
|
dfd5875 |
- tstart, tend = match.regs[3]
|
|
|
dfd5875 |
- token = format[tstart:tend]
|
|
|
dfd5875 |
- if token[0] in "([": level = level+1
|
|
|
dfd5875 |
- elif token[0] in ")]": level = level-1
|
|
|
dfd5875 |
- else: break
|
|
|
dfd5875 |
- chunks.append((1, format[dollar+1:pos]))
|
|
|
dfd5875 |
-
|
|
|
dfd5875 |
- else:
|
|
|
dfd5875 |
- chunks.append((0, format[pos:dollar+1]))
|
|
|
dfd5875 |
- pos = dollar + 1 + (nextchar == "$")
|
|
|
dfd5875 |
-
|
|
|
dfd5875 |
- if pos < len(format): chunks.append((0, format[pos:]))
|
|
|
dfd5875 |
- self.chunks = chunks
|
|
|
dfd5875 |
-
|
|
|
dfd5875 |
- def __repr__(self):
|
|
|
dfd5875 |
- return "<Itpl %s >" % repr(self.format)
|
|
|
dfd5875 |
-
|
|
|
dfd5875 |
- def _str(self,glob,loc):
|
|
|
dfd5875 |
- """Evaluate to a string in the given globals/locals.
|
|
|
dfd5875 |
-
|
|
|
dfd5875 |
- The final output is built by calling str(), but if this fails, the
|
|
|
dfd5875 |
- result is encoded with the instance's codec and error handling policy,
|
|
|
dfd5875 |
- via a call to out.encode(self.codec,self.encoding_errors)"""
|
|
|
dfd5875 |
- result = []
|
|
|
dfd5875 |
- app = result.append
|
|
|
dfd5875 |
- for live, chunk in self.chunks:
|
|
|
dfd5875 |
- if live:
|
|
|
dfd5875 |
- val = eval(chunk,glob,loc)
|
|
|
dfd5875 |
- try:
|
|
|
dfd5875 |
- app(str(val))
|
|
|
dfd5875 |
- except UnicodeEncodeError:
|
|
|
dfd5875 |
- app(unicode(val))
|
|
|
dfd5875 |
-
|
|
|
dfd5875 |
- else: app(chunk)
|
|
|
dfd5875 |
- out = ''.join(result)
|
|
|
dfd5875 |
- try:
|
|
|
dfd5875 |
- return str(out)
|
|
|
dfd5875 |
- except UnicodeError:
|
|
|
dfd5875 |
- return out.encode(self.codec,self.encoding_errors)
|
|
|
dfd5875 |
-
|
|
|
dfd5875 |
- def __str__(self):
|
|
|
dfd5875 |
- """Evaluate and substitute the appropriate parts of the string."""
|
|
|
dfd5875 |
-
|
|
|
dfd5875 |
- # We need to skip enough frames to get to the actual caller outside of
|
|
|
dfd5875 |
- # Itpl.
|
|
|
dfd5875 |
- frame = sys._getframe(1)
|
|
|
dfd5875 |
- while frame.f_globals["__name__"] == __name__: frame = frame.f_back
|
|
|
dfd5875 |
- loc, glob = frame.f_locals, frame.f_globals
|
|
|
dfd5875 |
-
|
|
|
dfd5875 |
- return self._str(glob,loc)
|
|
|
dfd5875 |
-
|
|
|
dfd5875 |
-class ItplNS(Itpl):
|
|
|
dfd5875 |
- """Class representing a string with interpolation abilities.
|
|
|
dfd5875 |
-
|
|
|
dfd5875 |
- This inherits from Itpl, but at creation time a namespace is provided
|
|
|
dfd5875 |
- where the evaluation will occur. The interpolation becomes a bit more
|
|
|
dfd5875 |
- efficient, as no traceback needs to be extracte. It also allows the
|
|
|
dfd5875 |
- caller to supply a different namespace for the interpolation to occur than
|
|
|
dfd5875 |
- its own."""
|
|
|
dfd5875 |
-
|
|
|
dfd5875 |
- def __init__(self, format,globals,locals=None,
|
|
|
dfd5875 |
- codec='utf_8',encoding_errors='backslashreplace'):
|
|
|
dfd5875 |
- """ItplNS(format,globals[,locals]) -> interpolating string instance.
|
|
|
dfd5875 |
-
|
|
|
dfd5875 |
- This constructor, besides a format string, takes a globals dictionary
|
|
|
dfd5875 |
- and optionally a locals (which defaults to globals if not provided).
|
|
|
dfd5875 |
-
|
|
|
dfd5875 |
- For further details, see the Itpl constructor."""
|
|
|
dfd5875 |
-
|
|
|
dfd5875 |
- if locals is None:
|
|
|
dfd5875 |
- locals = globals
|
|
|
dfd5875 |
- self.globals = globals
|
|
|
dfd5875 |
- self.locals = locals
|
|
|
dfd5875 |
- Itpl.__init__(self,format,codec,encoding_errors)
|
|
|
dfd5875 |
-
|
|
|
dfd5875 |
- def __str__(self):
|
|
|
dfd5875 |
- """Evaluate and substitute the appropriate parts of the string."""
|
|
|
dfd5875 |
- return self._str(self.globals,self.locals)
|
|
|
dfd5875 |
-
|
|
|
dfd5875 |
- def __repr__(self):
|
|
|
dfd5875 |
- return "<ItplNS %s >" % repr(self.format)
|
|
|
dfd5875 |
-
|
|
|
dfd5875 |
-# utilities for fast printing
|
|
|
dfd5875 |
-def itpl(text): return str(Itpl(text))
|
|
|
dfd5875 |
-def printpl(text): print itpl(text)
|
|
|
dfd5875 |
-# versions with namespace
|
|
|
dfd5875 |
-def itplns(text,globals,locals=None): return str(ItplNS(text,globals,locals))
|
|
|
dfd5875 |
-def printplns(text,globals,locals=None): print itplns(text,globals,locals)
|
|
|
dfd5875 |
-
|
|
|
dfd5875 |
-class ItplFile:
|
|
|
dfd5875 |
- """A file object that filters each write() through an interpolator."""
|
|
|
dfd5875 |
- def __init__(self, file): self.file = file
|
|
|
dfd5875 |
- def __repr__(self): return "<interpolated " + repr(self.file) + ">"
|
|
|
dfd5875 |
- def __getattr__(self, attr): return getattr(self.file, attr)
|
|
|
dfd5875 |
- def write(self, text): self.file.write(str(Itpl(text)))
|
|
|
dfd5875 |
-
|
|
|
dfd5875 |
-def filter(file=sys.stdout):
|
|
|
dfd5875 |
- """Return an ItplFile that filters writes to the given file object.
|
|
|
dfd5875 |
-
|
|
|
dfd5875 |
- 'file = filter(file)' replaces 'file' with a filtered object that
|
|
|
dfd5875 |
- has a write() method. When called with no argument, this creates
|
|
|
dfd5875 |
- a filter to sys.stdout."""
|
|
|
dfd5875 |
- return ItplFile(file)
|
|
|
dfd5875 |
-
|
|
|
dfd5875 |
-def unfilter(ifile=None):
|
|
|
dfd5875 |
- """Return the original file that corresponds to the given ItplFile.
|
|
|
dfd5875 |
-
|
|
|
dfd5875 |
- 'file = unfilter(file)' undoes the effect of 'file = filter(file)'.
|
|
|
dfd5875 |
- 'sys.stdout = unfilter()' undoes the effect of 'sys.stdout = filter()'."""
|
|
|
dfd5875 |
- return ifile and ifile.file or sys.stdout.file
|