Skip to content

Commit 243f0ba

Browse files
committed
merge changes
2 parents 0d46303 + a82e6ef commit 243f0ba

File tree

9 files changed

+95
-11
lines changed

9 files changed

+95
-11
lines changed

.hgignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ _trial_temp
77
build/*
88
env
99
.DS_Store
10+
.idea/

bpython/cli.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1909,7 +1909,8 @@ def main(args=None, locals_=None, banner=None):
19091909
# Fake stdout data so everything's still visible after exiting
19101910
if config.flush_output and not options.quiet:
19111911
sys.stdout.write(o)
1912-
sys.stdout.flush()
1912+
if hasattr(sys.stdout, 'flush'):
1913+
sys.stdout.flush()
19131914

19141915

19151916
if __name__ == '__main__':

bpython/inspection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ def is_eval_safe_name(string):
267267

268268
def is_callable(obj):
269269
if has_instance_type and isinstance(obj, types.InstanceType):
270-
# Work around a Python bug, see issue 7624
270+
# Work around a CPython bug, see CPython issue #7624
271271
return callable(obj)
272272
elif has_collections_callable:
273273
return isinstance(obj, collections.Callable)

bpython/repl.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,13 @@
4242
from urlparse import urlparse
4343
from xmlrpclib import ServerProxy, Error as XMLRPCError
4444

45-
from pygments.lexers import PythonLexer
45+
py3 = sys.version_info[0] == 3
46+
4647
from pygments.token import Token
48+
if py3:
49+
from pygments.lexers import Python3Lexer as PythonLexer
50+
else:
51+
from pygments.lexers import PythonLexer
4752

4853
from bpython import importcompletion, inspection
4954
from bpython.formatter import Parenthesis
@@ -61,8 +66,6 @@
6166
except (ImportError, AttributeError):
6267
has_abc = False
6368

64-
py3 = sys.version_info[0] == 3
65-
6669

6770
class Interpreter(code.InteractiveInterpreter):
6871

@@ -479,13 +482,17 @@ def get_args(self):
479482
stack[-1][1] += 1
480483
except TypeError:
481484
stack[-1][1] = ''
485+
stack[-1][0] = ''
482486
elif value == ':' and stack[-1][2] == 'lambda':
483487
stack.pop()
488+
else:
489+
stack[-1][0] = ''
484490
elif (token is Token.Name or token in Token.Name.subtypes or
485491
token is Token.Operator and value == '.'):
486492
stack[-1][0] += value
487493
elif token is Token.Operator and value == '=':
488494
stack[-1][1] = stack[-1][0]
495+
stack[-1][0] = ''
489496
elif token is Token.Keyword and value == 'lambda':
490497
stack.append(['', 0, value])
491498
else:

bpython/test/test_repl.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,7 @@ def test_lambda_position(self):
208208
# Argument position
209209
self.assertEqual(self.repl.argspec[3], 1)
210210

211-
def test_name_in_assignment_without_spaces(self):
212-
# Issue #127
211+
def test_issue127(self):
213212
self.setInputLine("x=range(")
214213
self.assertTrue(self.repl.get_args())
215214
self.assertEqual(self.repl.current_func.__name__, "range")
@@ -221,6 +220,9 @@ def test_name_in_assignment_without_spaces(self):
221220
self.setInputLine("foo(1, 2, x,range(")
222221
self.assertEqual(self.repl.current_func.__name__, "range")
223222

223+
self.setInputLine("(x,range(")
224+
self.assertEqual(self.repl.current_func.__name__, "range")
225+
224226
def test_nonexistent_name(self):
225227
self.setInputLine("spamspamspam(")
226228
self.assertFalse(self.repl.get_args())

bpython/urwid.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1103,8 +1103,11 @@ def main(args=None, locals_=None, banner=None):
11031103
# TODO: maybe support displays other than raw_display?
11041104
config, options, exec_args = bpargs.parse(args, (
11051105
'Urwid options', None, [
1106+
Option('--twisted', '-T', action='store_true',
1107+
help=_('Run twisted reactor.')),
11061108
Option('--reactor', '-r',
1107-
help=_('Run a reactor (see --help-reactors).')),
1109+
help=_('Select specific reactor (see --help-reactors). '
1110+
'Implies --twisted.')),
11081111
Option('--help-reactors', action='store_true',
11091112
help=_('List available reactors for -r.')),
11101113
Option('--plugin', '-p',
@@ -1133,8 +1136,8 @@ def main(args=None, locals_=None, banner=None):
11331136
('bold ' + name, color + ',bold', background, monochrome)
11341137
for name, color, background, monochrome in palette])
11351138

1136-
if (options.server or options.plugin) and not options.reactor:
1137-
options.reactor = 'select'
1139+
if options.server or options.plugin:
1140+
options.twisted = True
11381141

11391142
if options.reactor:
11401143
try:
@@ -1153,6 +1156,14 @@ def main(args=None, locals_=None, banner=None):
11531156
options.reactor,))
11541157
return
11551158
event_loop = TwistedEventLoop(reactor)
1159+
elif options.twisted:
1160+
try:
1161+
from twisted.internet import reactor
1162+
except ImportError:
1163+
sys.stderr.write('No reactors are available. Please install '
1164+
'twisted for reactor support.\n')
1165+
return
1166+
event_loop = TwistedEventLoop(reactor)
11561167
else:
11571168
# None, not urwid.SelectEventLoop(), to work with
11581169
# screens that do not support external event loops.

doc/sphinx/source/configuration.rst

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,47 @@ behalf. If set, this overrides `pastebin_url`. It also overrides `pastebin_show_
7777
as the helper is expected to return the full URL to the pastebin as the first word of
7878
its output. The data is supplied to the helper via STDIN.
7979

80-
An example helper program is ``pastebinit``, available for most systems.
80+
An example helper program is ``pastebinit``, available for most systems. The
81+
following helper program can be used to create `gists <http://gist.github.com>`_:
82+
83+
.. code-block:: python
84+
85+
#!/usr/bin/env python
86+
87+
import sys
88+
import urllib2
89+
import json
90+
91+
def do_gist_json(s):
92+
""" Use json to post to github. """
93+
gist_public = False
94+
gist_url = 'https://api.github.com/gists'
95+
96+
data = {'description': None,
97+
'public': None,
98+
'files' : {
99+
'sample': { 'content': None }
100+
}}
101+
data['description'] = 'Gist from BPython'
102+
data['public'] = gist_public
103+
data['files']['sample']['content'] = s
104+
105+
req = urllib2.Request(gist_url, json.dumps(data), {'Content-Type': 'application/json'})
106+
try:
107+
res = urllib2.urlopen(req)
108+
except HTTPError, e:
109+
return e
110+
111+
try:
112+
json_res = json.loads(res.read())
113+
return json_res['html_url']
114+
except HTTPError, e:
115+
return e
116+
117+
if __name__ == "__main__":
118+
s = sys.stdin.read()
119+
print do_gist_json(s)
120+
81121
82122
.. versionadded:: 0.12
83123

@@ -183,6 +223,12 @@ Default: C-l
183223

184224
Clears the screen to the top.
185225

226+
show_source
227+
^^^^^^^^^^^
228+
Default: F2
229+
230+
Shows the source of the currently being completed (python) function.
231+
186232
exit
187233
^^^^
188234
Default: C-d

doc/sphinx/source/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Contents:
2222
releases
2323
community
2424
django
25+
windows
2526
changelog
2627
sourcecode
2728
bpaste

doc/sphinx/source/windows.rst

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
.. _windows:
2+
3+
Windows
4+
=======
5+
When bpython was developed it only supported Linux and we grew support for
6+
other platforms as well.
7+
8+
There are no official binaries for bpython on Windows (though this is something
9+
we plan on providing in the future).
10+
11+
The easiest way to get `bpython.cli` (the curses frontend running) is to install
12+
an unofficial windows binary for pdcurses from:
13+
http://www.lfd.uci.edu/~gohlke/pythonlibs/#curses. After this you can just
14+
`pip install bpython` and run bpython like you would on a Linux system (e.g.
15+
by typing `bpython` on your prompt).

0 commit comments

Comments
 (0)