annotate MoinMoin/support/werkzeug/debug/console.py @ 6129:7f12cf241d5e

update werkzeug to 0.12.1, update CHANGES
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Tue, 11 Apr 2017 22:42:23 +0200
parents 9f12f41504fc
children
rev   line source
4301
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
2 """
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
3 werkzeug.debug.console
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
4 ~~~~~~~~~~~~~~~~~~~~~~
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
5
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
6 Interactive console support.
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
7
6094
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6010
diff changeset
8 :copyright: (c) 2014 by the Werkzeug Team, see AUTHORS for more details.
4301
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
9 :license: BSD.
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
10 """
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
11 import sys
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
12 import code
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
13 from types import CodeType
6094
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6010
diff changeset
14
4609
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4301
diff changeset
15 from werkzeug.utils import escape
4301
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
16 from werkzeug.local import Local
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
17 from werkzeug.debug.repr import debug_repr, dump, helper
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
18
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
19
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
20 _local = Local()
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
21
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
22
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
23 class HTMLStringO(object):
6094
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6010
diff changeset
24
4301
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
25 """A StringO version that HTML escapes on write."""
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
26
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
27 def __init__(self):
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
28 self._buffer = []
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
29
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
30 def isatty(self):
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
31 return False
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
32
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
33 def close(self):
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
34 pass
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
35
5801
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4609
diff changeset
36 def flush(self):
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4609
diff changeset
37 pass
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4609
diff changeset
38
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4609
diff changeset
39 def seek(self, n, mode=0):
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4609
diff changeset
40 pass
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4609
diff changeset
41
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4609
diff changeset
42 def readline(self):
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4609
diff changeset
43 if len(self._buffer) == 0:
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4609
diff changeset
44 return ''
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4609
diff changeset
45 ret = self._buffer[0]
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4609
diff changeset
46 del self._buffer[0]
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4609
diff changeset
47 return ret
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4609
diff changeset
48
4301
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
49 def reset(self):
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
50 val = ''.join(self._buffer)
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
51 del self._buffer[:]
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
52 return val
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
53
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
54 def _write(self, x):
6094
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6010
diff changeset
55 if isinstance(x, bytes):
4301
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
56 x = x.decode('utf-8', 'replace')
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
57 self._buffer.append(x)
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
58
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
59 def write(self, x):
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
60 self._write(escape(x))
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
61
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
62 def writelines(self, x):
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
63 self._write(escape(''.join(x)))
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
64
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
65
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
66 class ThreadedStream(object):
6094
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6010
diff changeset
67
4301
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
68 """Thread-local wrapper for sys.stdout for the interactive console."""
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
69
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
70 def push():
5801
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4609
diff changeset
71 if not isinstance(sys.stdout, ThreadedStream):
4301
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
72 sys.stdout = ThreadedStream()
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
73 _local.stream = HTMLStringO()
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
74 push = staticmethod(push)
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
75
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
76 def fetch():
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
77 try:
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
78 stream = _local.stream
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
79 except AttributeError:
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
80 return ''
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
81 return stream.reset()
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
82 fetch = staticmethod(fetch)
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
83
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
84 def displayhook(obj):
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
85 try:
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
86 stream = _local.stream
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
87 except AttributeError:
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
88 return _displayhook(obj)
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
89 # stream._write bypasses escaping as debug_repr is
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
90 # already generating HTML for us.
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
91 if obj is not None:
6094
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6010
diff changeset
92 _local._current_ipy.locals['_'] = obj
4301
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
93 stream._write(debug_repr(obj))
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
94 displayhook = staticmethod(displayhook)
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
95
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
96 def __setattr__(self, name, value):
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
97 raise AttributeError('read only attribute %s' % name)
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
98
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
99 def __dir__(self):
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
100 return dir(sys.__stdout__)
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
101
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
102 def __getattribute__(self, name):
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
103 if name == '__members__':
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
104 return dir(sys.__stdout__)
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
105 try:
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
106 stream = _local.stream
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
107 except AttributeError:
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
108 stream = sys.__stdout__
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
109 return getattr(stream, name)
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
110
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
111 def __repr__(self):
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
112 return repr(sys.__stdout__)
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
113
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
114
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
115 # add the threaded stream as display hook
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
116 _displayhook = sys.displayhook
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
117 sys.displayhook = ThreadedStream.displayhook
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
118
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
119
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
120 class _ConsoleLoader(object):
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
121
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
122 def __init__(self):
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
123 self._storage = {}
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
124
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
125 def register(self, code, source):
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
126 self._storage[id(code)] = source
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
127 # register code objects of wrapped functions too.
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
128 for var in code.co_consts:
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
129 if isinstance(var, CodeType):
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
130 self._storage[id(var)] = source
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
131
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
132 def get_source_by_code(self, code):
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
133 try:
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
134 return self._storage[id(code)]
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
135 except KeyError:
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
136 pass
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
137
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
138
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
139 def _wrap_compiler(console):
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
140 compile = console.compile
6094
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6010
diff changeset
141
4301
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
142 def func(source, filename, symbol):
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
143 code = compile(source, filename, symbol)
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
144 console.loader.register(code, source)
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
145 return code
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
146 console.compile = func
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
147
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
148
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
149 class _InteractiveConsole(code.InteractiveInterpreter):
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
150
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
151 def __init__(self, globals, locals):
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
152 code.InteractiveInterpreter.__init__(self, locals)
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
153 self.globals = dict(globals)
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
154 self.globals['dump'] = dump
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
155 self.globals['help'] = helper
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
156 self.globals['__loader__'] = self.loader = _ConsoleLoader()
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
157 self.more = False
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
158 self.buffer = []
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
159 _wrap_compiler(self)
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
160
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
161 def runsource(self, source):
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
162 source = source.rstrip() + '\n'
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
163 ThreadedStream.push()
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
164 prompt = self.more and '... ' or '>>> '
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
165 try:
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
166 source_to_eval = ''.join(self.buffer + [source])
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
167 if code.InteractiveInterpreter.runsource(self,
6094
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6010
diff changeset
168 source_to_eval, '<debugger>', 'single'):
4301
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
169 self.more = True
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
170 self.buffer.append(source)
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
171 else:
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
172 self.more = False
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
173 del self.buffer[:]
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
174 finally:
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
175 output = ThreadedStream.fetch()
6129
7f12cf241d5e update werkzeug to 0.12.1, update CHANGES
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6094
diff changeset
176 return prompt + escape(source) + output
4301
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
177
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
178 def runcode(self, code):
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
179 try:
6094
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6010
diff changeset
180 eval(code, self.globals, self.locals)
5801
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4609
diff changeset
181 except Exception:
4301
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
182 self.showtraceback()
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
183
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
184 def showtraceback(self):
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
185 from werkzeug.debug.tbtools import get_current_traceback
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
186 tb = get_current_traceback(skip=1)
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
187 sys.stdout._write(tb.render_summary())
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
188
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
189 def showsyntaxerror(self, filename=None):
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
190 from werkzeug.debug.tbtools import get_current_traceback
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
191 tb = get_current_traceback(skip=4)
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
192 sys.stdout._write(tb.render_summary())
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
193
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
194 def write(self, data):
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
195 sys.stdout.write(data)
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
196
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
197
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
198 class Console(object):
6094
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6010
diff changeset
199
4301
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
200 """An interactive console."""
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
201
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
202 def __init__(self, globals=None, locals=None):
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
203 if locals is None:
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
204 locals = {}
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
205 if globals is None:
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
206 globals = {}
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
207 self._ipy = _InteractiveConsole(globals, locals)
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
208
c689dfa55de1 Import werkzeug 0.3.1 package into MoinMoin.support (still need to insert CREDITS)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
209 def eval(self, code):
6094
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6010
diff changeset
210 _local._current_ipy = self._ipy
6010
fc1f97a47c7e upgrade bundled werkzeug to 0.8.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
211 old_sys_stdout = sys.stdout
fc1f97a47c7e upgrade bundled werkzeug to 0.8.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
212 try:
fc1f97a47c7e upgrade bundled werkzeug to 0.8.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
213 return self._ipy.runsource(code)
fc1f97a47c7e upgrade bundled werkzeug to 0.8.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
214 finally:
fc1f97a47c7e upgrade bundled werkzeug to 0.8.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
215 sys.stdout = old_sys_stdout