# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+import __builtin__
import inspect
import os
import re
if item == '__line__':
return self.frame.f_lineno
+ if self.formatter.locals and item in self.frame.f_locals:
+ return self.frame.f_locals[item]
+
if item in self.dict:
return self.dict[item]
- if self.formatter.locals or self.formatter.globals:
- if self.formatter.locals and item in self.frame.f_locals:
- return self.frame.f_locals[item]
-
- if self.formatter.globals and item in self.frame.f_globals:
- return self.frame.f_globals[item]
+ if self.formatter.globals and item in self.frame.f_globals:
+ return self.frame.f_globals[item]
- if item in __builtins__:
- return __builtins__[item]
+ if item in __builtin__.__dict__:
+ return __builtin__.__dict__[item]
try:
item = int(item)
self._dict = {}
self._indent_level = 0
self._indent_spaces = 4
- self.globals = kwargs.pop('globals',type(self).globals)
+ self.globals = kwargs.pop('globals', type(self).globals)
self.locals = kwargs.pop('locals', type(self).locals)
self._fix_newlines = \
kwargs.pop('fix_newlines', type(self).fix_newlines)
if args:
self.__call__(args)
- def indent(self):
- self._indent_level += self._indent_spaces
+ def indent(self, count=1):
+ self._indent_level += self._indent_spaces * count
- def dedent(self):
- assert self._indent_level >= self._indent_spaces
- self._indent_level -= self._indent_spaces
+ def dedent(self, count=1):
+ assert self._indent_level >= (self._indent_spaces * count)
+ self._indent_level -= self._indent_spaces * count
def fix(self, status):
previous = self._fix_newlines
initial_newline = False
- def insert_newline(self):
- self._data.append('\n')
+ def __call__(self, *args, **kwargs):
+ if not args:
+ self._data.append('\n')
+ return
+
+ format = args[0]
+ args = args[1:]
- def __call__(self, format, *args, **kwargs):
frame = inspect.currentframe().f_back
l = lookup(self, frame, *args, **kwargs)