| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -8,6 +8,7 @@ | |||
| 8 | 8 | ||
| 9 | 9 | ||
| 10 | 10 | class _Helper(object): | |
| 11 | + | ||
| 11 | 12 | def __init__(self): | |
| 12 | 13 | self.helper = pydoc.Helper(sys.stdin, sys.stdout) | |
| 13 | 14 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -412,11 +412,11 @@ def cw(self): | |||
| 412 | 412 | return | |
| 413 | 413 | ||
| 414 | 414 | i = 1 | |
| 415 | - while i < l+1: | ||
| 415 | + while i < l + 1: | ||
| 416 | 416 | if not self.s[-i].isalnum() and self.s[-i] not in ('.', '_'): | |
| 417 | 417 | break | |
| 418 | 418 | i += 1 | |
| 419 | - return self.s[-i +1:] | ||
| 419 | + return self.s[-i + 1:] | ||
| 420 | 420 | ||
| 421 | 421 | def delete(self): | |
| 422 | 422 | """Process a del""" | |
@@ -597,17 +597,17 @@ def mkargspec(self, topline, down): | |||
| 597 | 597 | y, x = self.list_win.getyx() | |
| 598 | 598 | ln = len(str(i)) | |
| 599 | 599 | kw = None | |
| 600 | - if kwargs and k+1 > len(args) - len(kwargs): | ||
| 600 | + if kwargs and k + 1 > len(args) - len(kwargs): | ||
| 601 | 601 | kw = str(kwargs[k - (len(args) - len(kwargs))]) | |
| 602 | 602 | ln += len(kw) + 1 | |
| 603 | 603 | ||
| 604 | 604 | if ln + x >= w: | |
| 605 | 605 | ty = self.list_win.getbegyx()[0] | |
| 606 | 606 | if not down and ty > 0: | |
| 607 | - h +=1 | ||
| 607 | + h += 1 | ||
| 608 | 608 | self.list_win.mvwin(ty-1, 1) | |
| 609 | 609 | self.list_win.resize(h, w) | |
| 610 | - elif down and h + r < maxh-ty: | ||
| 610 | + elif down and h + r < maxh - ty: | ||
| 611 | 611 | h += 1 | |
| 612 | 612 | self.list_win.resize(h, w) | |
| 613 | 613 | else: | |
@@ -985,7 +985,7 @@ def show_list(self, items, topline=None, current_item=None): | |||
| 985 | 985 | if down: | |
| 986 | 986 | max_h = h - y | |
| 987 | 987 | else: | |
| 988 | - max_h = y+1 | ||
| 988 | + max_h = y + 1 | ||
| 989 | 989 | max_w = int(w * 0.8) | |
| 990 | 990 | self.list_win.erase() | |
| 991 | 991 | if items: | |
@@ -1057,7 +1057,7 @@ def lsize(): | |||
| 1057 | 1057 | w = t | |
| 1058 | 1058 | ||
| 1059 | 1059 | ||
| 1060 | - if height_offset and display_rows+5 >= max_h: | ||
| 1060 | + if height_offset and display_rows + 5 >= max_h: | ||
| 1061 | 1061 | del v_items[-(cols * (height_offset)):] | |
| 1062 | 1062 | ||
| 1063 | 1063 | if self.docstring is None: | |
@@ -1087,7 +1087,7 @@ def lsize(): | |||
| 1087 | 1087 | if not py3: | |
| 1088 | 1088 | i = i.encode(getpreferredencoding()) | |
| 1089 | 1089 | self.list_win.addstr(i + padding, color) | |
| 1090 | - if ((cols == 1 or (ix and not (ix+1) % cols)) | ||
| 1090 | + if ((cols == 1 or (ix and not (ix + 1) % cols)) | ||
| 1091 | 1091 | and ix + 1 < len(v_items)): | |
| 1092 | 1092 | self.list_win.addstr('\n ') | |
| 1093 | 1093 | ||
@@ -1392,7 +1392,8 @@ def gethw(): | |||
| 1392 | 1392 | ||
| 1393 | 1393 | """ | |
| 1394 | 1394 | h, w = struct.unpack( | |
| 1395 | - "hhhh", fcntl.ioctl(sys.__stdout__, termios.TIOCGWINSZ, "\000"*8))[0:2] | ||
| 1395 | + "hhhh", | ||
| 1396 | + fcntl.ioctl(sys.__stdout__, termios.TIOCGWINSZ, "\000" * 8))[0:2] | ||
| 1396 | 1397 | return h, w | |
| 1397 | 1398 | ||
| 1398 | 1399 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5,10 +5,12 @@ | |||
| 5 | 5 | from bpython.keys import key_dispatch | |
| 6 | 6 | import errno | |
| 7 | 7 | ||
| 8 | + | ||
| 8 | 9 | class Struct(object): | |
| 9 | 10 | """Simple class for instantiating objects we can add arbitrary attributes | |
| 10 | 11 | to and use for various arbitrary things.""" | |
| 11 | 12 | ||
| 13 | + | ||
| 12 | 14 | def fill_config_with_default_values(config, default_values): | |
| 13 | 15 | for section in default_values.iterkeys(): | |
| 14 | 16 | if not config.has_section(section): | |
@@ -42,8 +44,7 @@ def loadini(struct, configfile): | |||
| 42 | 44 | 'paste_time': 0.02, | |
| 43 | 45 | 'syntax': True, | |
| 44 | 46 | 'tab_length': 4, | |
| 45 | - 'pastebin_url': 'http://bpaste.net' | ||
| 46 | - }, | ||
| 47 | + 'pastebin_url': 'http://bpaste.net'}, | ||
| 47 | 48 | 'keyboard': { | |
| 48 | 49 | 'clear_line': 'C-u', | |
| 49 | 50 | 'clear_screen': 'C-l', | |
@@ -57,9 +58,7 @@ def loadini(struct, configfile): | |||
| 57 | 58 | 'show_source': 'F2', | |
| 58 | 59 | 'undo': 'C-r', | |
| 59 | 60 | 'up_one_line': 'C-p', | |
| 60 | - 'yank_from_buffer': 'C-y' | ||
| 61 | - } | ||
| 62 | - }) | ||
| 61 | + 'yank_from_buffer': 'C-y'}}) | ||
| 63 | 62 | config.read(config_path) | |
| 64 | 63 | ||
| 65 | 64 | struct.tab_length = config.getint('general', 'tab_length') | |
@@ -118,6 +117,7 @@ def loadini(struct, configfile): | |||
| 118 | 117 | for key in (struct.pastebin_key, struct.save_key): | |
| 119 | 118 | key_dispatch[key] | |
| 120 | 119 | ||
| 120 | + | ||
| 121 | 121 | def load_theme(struct, path, inipath): | |
| 122 | 122 | theme = ConfigParser() | |
| 123 | 123 | try: | |
@@ -137,7 +137,8 @@ def load_theme(struct, path, inipath): | |||
| 137 | 137 | ||
| 138 | 138 | ||
| 139 | 139 | def migrate_rc(path): | |
| 140 | - """Use the shlex module to convert the old configuration file to the new format. | ||
| 140 | + """Use the shlex module to convert the old configuration file to the new | ||
| 141 | + format. | ||
| 141 | 142 | The old configuration file is renamed but not removed by now.""" | |
| 142 | 143 | import shlex | |
| 143 | 144 | f = open(path) | |
@@ -149,8 +150,7 @@ def migrate_rc(path): | |||
| 149 | 150 | 'on': True, | |
| 150 | 151 | 'false': False, | |
| 151 | 152 | 'no': False, | |
| 152 | - 'off': False | ||
| 153 | - } | ||
| 153 | + 'off': False} | ||
| 154 | 154 | ||
| 155 | 155 | config = ConfigParser() | |
| 156 | 156 | config.add_section('general') | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -68,8 +68,7 @@ | |||
| 68 | 68 | Token: 'token', | |
| 69 | 69 | Whitespace: 'background', | |
| 70 | 70 | Parenthesis: 'paren', | |
| 71 | - Parenthesis.UnderCursor: 'operator' | ||
| 72 | - } | ||
| 71 | + Parenthesis.UnderCursor: 'operator'} | ||
| 73 | 72 | ||
| 74 | 73 | ||
| 75 | 74 | class BPythonFormatter(Formatter): | |
@@ -104,7 +103,7 @@ def format(self, tokensource, outfile): | |||
| 104 | 103 | ||
| 105 | 104 | while token not in self.f_strings: | |
| 106 | 105 | token = token.parent | |
| 107 | - o += "%s\x03%s\x04" % (self.f_strings[token], text) | ||
| 106 | + o += "%s\x03%s\x04" % (self.f_strings[token], text) | ||
| 108 | 107 | outfile.write(o.rstrip()) | |
| 109 | 108 | ||
| 110 | 109 | # vim: sw=4 ts=4 sts=4 ai et | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -53,6 +53,7 @@ class ArgspecFormatter(object): | |||
| 53 | 53 | """ | |
| 54 | 54 | Format an argspec using Pango markup language. | |
| 55 | 55 | """ | |
| 56 | + | ||
| 56 | 57 | def format(self, args, varargs, varkw, defaults, in_arg): | |
| 57 | 58 | self.args_seen = 0 | |
| 58 | 59 | self.in_arg = in_arg | |
@@ -76,6 +77,7 @@ class Nested(object): | |||
| 76 | 77 | """ | |
| 77 | 78 | A helper class, inspired by a semaphore. | |
| 78 | 79 | """ | |
| 80 | + | ||
| 79 | 81 | def __init__(self): | |
| 80 | 82 | self.counter = 0 | |
| 81 | 83 | ||
@@ -97,6 +99,7 @@ class SuggestionWindow(gtk.Window): | |||
| 97 | 99 | __gsignals__ = dict(expose_event=None, | |
| 98 | 100 | selection_changed=(gobject.SIGNAL_RUN_LAST, None, | |
| 99 | 101 | (str, ))) | |
| 102 | + | ||
| 100 | 103 | def __init__(self): | |
| 101 | 104 | gtk.Window.__init__(self, gtk.WINDOW_POPUP) | |
| 102 | 105 | self.set_app_paintable(True) | |
@@ -213,6 +216,7 @@ class ReplWidget(gtk.TextView, repl.Repl): | |||
| 213 | 216 | focus_in_event=None, | |
| 214 | 217 | focus_out_event=None, | |
| 215 | 218 | realize=None) | |
| 219 | + | ||
| 216 | 220 | def __init__(self, interpreter): | |
| 217 | 221 | gtk.TextView.__init__(self) | |
| 218 | 222 | repl.Repl.__init__(self, interpreter) | |
@@ -569,14 +573,17 @@ def init_import_completion(): | |||
| 569 | 573 | def on_about(widget): | |
| 570 | 574 | pass | |
| 571 | 575 | ||
| 576 | + | ||
| 572 | 577 | def on_quit(widget): | |
| 573 | 578 | pass | |
| 574 | 579 | ||
| 580 | + | ||
| 575 | 581 | def on_button_press_event(widget, event, popup): | |
| 576 | 582 | if event.button == 3: | |
| 577 | 583 | popup.popup(None, None, None, event.button, event.time) | |
| 578 | 584 | return True | |
| 579 | 585 | ||
| 586 | + | ||
| 580 | 587 | def main(args=None): | |
| 581 | 588 | if args is None: | |
| 582 | 589 | args = sys.argv[1:] | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -30,6 +30,7 @@ | |||
| 30 | 30 | modules = set() | |
| 31 | 31 | fully_loaded = False | |
| 32 | 32 | ||
| 33 | + | ||
| 33 | 34 | def complete(line, cw): | |
| 34 | 35 | """Construct a full list of possibly completions for imports.""" | |
| 35 | 36 | if not cw: | |
@@ -102,6 +103,7 @@ def find_all_modules(path=None): | |||
| 102 | 103 | modules.add(module) | |
| 103 | 104 | yield | |
| 104 | 105 | ||
| 106 | + | ||
| 105 | 107 | def find_coroutine(): | |
| 106 | 108 | global fully_loaded | |
| 107 | 109 | ||
@@ -115,6 +117,7 @@ def find_coroutine(): | |||
| 115 | 117 | ||
| 116 | 118 | return True | |
| 117 | 119 | ||
| 120 | + | ||
| 118 | 121 | def reload(): | |
| 119 | 122 | """Refresh the list of known modules.""" | |
| 120 | 123 | modules.clear() | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -41,6 +41,7 @@ | |||
| 41 | 41 | class AttrCleaner(object): | |
| 42 | 42 | """A context manager that tries to make an object not exhibit side-effects | |
| 43 | 43 | on attribute lookup.""" | |
| 44 | + | ||
| 44 | 45 | def __init__(self, obj): | |
| 45 | 46 | self.obj = obj | |
| 46 | 47 | ||
@@ -128,6 +129,7 @@ def parsekeywordpairs(signature): | |||
| 128 | 129 | d[item[0]] = ''.join(item[2:]) | |
| 129 | 130 | return d | |
| 130 | 131 | ||
| 132 | + | ||
| 131 | 133 | def fixlongargs(f, argspec): | |
| 132 | 134 | """Functions taking default arguments that are references to other objects | |
| 133 | 135 | whose str() is too big will cause breakage, so we swap out the object | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -25,15 +25,18 @@ | |||
| 25 | 25 | ||
| 26 | 26 | import string | |
| 27 | 27 | ||
| 28 | + | ||
| 28 | 29 | class KeyMap: | |
| 30 | + | ||
| 29 | 31 | def __init__(self): | |
| 30 | 32 | self.map = {} | |
| 31 | 33 | ||
| 32 | 34 | def __getitem__(self, key): | |
| 33 | 35 | if key in self.map: | |
| 34 | 36 | return self.map[key] | |
| 35 | 37 | else: | |
| 36 | - raise Exception('Configured keymap (%s) does not exist in bpython.keys' % key) | ||
| 38 | + raise Exception('Configured keymap (%s)\ | ||
| 39 | + does not exist in bpython.keys' % key) | ||
| 37 | 40 | ||
| 38 | 41 | def __setitem__(self, key, value): | |
| 39 | 42 | self.map[key] = value | |
@@ -42,7 +45,7 @@ def __setitem__(self, key, value): | |||
| 42 | 45 | ||
| 43 | 46 | # fill dispatch with letters | |
| 44 | 47 | for c in string.ascii_lowercase: | |
| 45 | - key_dispatch['C-%s' % c] = (chr(string.ascii_lowercase.index(c)+1), | ||
| 48 | + key_dispatch['C-%s' % c] = (chr(string.ascii_lowercase.index(c) + 1), | ||
| 46 | 49 | '^%s' % c.upper()) | |
| 47 | 50 | ||
| 48 | 51 | # fill dispatch with cool characters | |
@@ -53,5 +56,5 @@ def __setitem__(self, key, value): | |||
| 53 | 56 | key_dispatch['C-_'] = (chr(31), '^_') | |
| 54 | 57 | ||
| 55 | 58 | # fill dispatch with function keys | |
| 56 | - for x in xrange(1,13): | ||
| 59 | + for x in xrange(1, 13): | ||
| 57 | 60 | key_dispatch['F%s' % str(x)] = ('KEY_F(%s)' % str(x),) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -64,6 +64,7 @@ def __init__(self, locals=None, encoding=sys.getdefaultencoding()): | |||
| 64 | 64 | code.InteractiveInterpreter.__init__(self, locals) | |
| 65 | 65 | ||
| 66 | 66 | if not py3: | |
| 67 | + | ||
| 67 | 68 | def runsource(self, source, filename='<input>', symbol='single'): | |
| 68 | 69 | source = '# coding: %s\n%s' % (self.encoding, | |
| 69 | 70 | source.encode(self.encoding)) | |
@@ -130,6 +131,7 @@ def writetb(self, lines): | |||
| 130 | 131 | ||
| 131 | 132 | ||
| 132 | 133 | class History(object): | |
| 134 | + | ||
| 133 | 135 | def __init__(self, entries=None): | |
| 134 | 136 | if entries is None: | |
| 135 | 137 | self.entries = [''] | |
@@ -189,6 +191,7 @@ def save(self, filename, encoding, lines=0): | |||
| 189 | 191 | ||
| 190 | 192 | ||
| 191 | 193 | class MatchesIterator(object): | |
| 194 | + | ||
| 192 | 195 | def __init__(self, current_word='', matches=[]): | |
| 193 | 196 | self.current_word = current_word | |
| 194 | 197 | self.matches = list(matches) | |
@@ -298,7 +301,6 @@ def __init__(self, interp, idle=None): | |||
| 298 | 301 | with open(filename, 'r') as f: | |
| 299 | 302 | self.interp.runsource(f.read(), filename, 'exec') | |
| 300 | 303 | ||
| 301 | - | ||
| 302 | 304 | def attr_matches(self, text): | |
| 303 | 305 | """Taken from rlcompleter.py and bent to my will.""" | |
| 304 | 306 | ||
@@ -586,7 +588,7 @@ def write2file(self): | |||
| 586 | 588 | def pastebin(self): | |
| 587 | 589 | """Upload to a pastebin and display the URL in the status bar.""" | |
| 588 | 590 | ||
| 589 | - pasteservice_url = OPTS.pastebin_url | ||
| 591 | + pasteservice_url = OPTS.pastebin_url | ||
| 590 | 592 | pasteservice = ServerProxy(urljoin(pasteservice_url, '/xmlrpc/')) | |
| 591 | 593 | ||
| 592 | 594 | s = self.getstdout() | |
@@ -595,7 +597,7 @@ def pastebin(self): | |||
| 595 | 597 | try: | |
| 596 | 598 | paste_id = pasteservice.pastes.newPaste('pycon', s) | |
| 597 | 599 | except XMLRPCError, e: | |
| 598 | - self.statusbar.message( 'Upload failed: %s' % (str(e), ) ) | ||
| 600 | + self.statusbar.message('Upload failed: %s' % (str(e), ) ) | ||
| 599 | 601 | return | |
| 600 | 602 | ||
| 601 | 603 | paste_url = urljoin(pasteservice_url, '/show/%s/' % (paste_id, )) | |
@@ -849,9 +851,11 @@ def split_lines(tokens): | |||
| 849 | 851 | if newline: | |
| 850 | 852 | yield (Token.Text, newline) | |
| 851 | 853 | ||
| 854 | + | ||
| 852 | 855 | def token_is(token_type): | |
| 853 | 856 | """Return a callable object that returns whether a token is of the | |
| 854 | 857 | given type `token_type`.""" | |
| 858 | + | ||
| 855 | 859 | def token_is_type(token): | |
| 856 | 860 | """Return whether a token is of a certain type or not.""" | |
| 857 | 861 | token = token[0] | |
@@ -861,6 +865,7 @@ def token_is_type(token): | |||
| 861 | 865 | ||
| 862 | 866 | return token_is_type | |
| 863 | 867 | ||
| 868 | + | ||
| 864 | 869 | def token_is_any_of(token_types): | |
| 865 | 870 | """Return a callable object that returns whether a token is any of the | |
| 866 | 871 | given types `token_types`.""" | |
| Back | FazBrowse Home | New Git URL |
0 commit comments