mirror of
https://github.com/kennethreitz-archive/bpython-gist.git
synced 2026-06-05 23:50:18 +00:00
PEP-8 compliance
This commit is contained in:
+4
-4
@@ -1,17 +1,17 @@
|
||||
# The MIT License
|
||||
#
|
||||
#
|
||||
# Copyright (c) 2008 Bob Farrell
|
||||
#
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
# of this software and associated documentation files (the "Software"), to deal
|
||||
# in the Software without restriction, including without limitation the rights
|
||||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
# copies of the Software, and to permit persons to whom the Software is
|
||||
# furnished to do so, subject to the following conditions:
|
||||
#
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be included in
|
||||
# all copies or substantial portions of the Software.
|
||||
#
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
|
||||
+25
-13
@@ -8,7 +8,8 @@ import cStringIO
|
||||
# actual user input, I couldn't think of another way of doing this.
|
||||
window = None
|
||||
|
||||
def _help( obj ):
|
||||
|
||||
def _help(obj):
|
||||
"""Wrapper for the regular help() function but with a ghetto
|
||||
PAGER since curses + less = :(
|
||||
As per the vanilla help(), this function special-cases for str,
|
||||
@@ -17,7 +18,7 @@ def _help( obj ):
|
||||
"""
|
||||
io = cStringIO.StringIO()
|
||||
doc = pydoc.TextDoc()
|
||||
helper = pydoc.Helper( None, io )
|
||||
helper = pydoc.Helper(None, io)
|
||||
|
||||
rows, columns = window.getmaxyx()
|
||||
rows -= 3
|
||||
@@ -29,19 +30,26 @@ def _help( obj ):
|
||||
# the bpython help is no compliant with the vanilla help.
|
||||
# Please let me know if you find this to be untrue.
|
||||
if type(obj) is type(''):
|
||||
if obj == 'help': helper.intro()
|
||||
elif obj == 'keywords': helper.listkeywords()
|
||||
elif obj == 'topics': helper.listtopics()
|
||||
elif obj == 'modules': helper.listmodules()
|
||||
if obj == 'help':
|
||||
helper.intro()
|
||||
elif obj == 'keywords':
|
||||
helper.listkeywords()
|
||||
elif obj == 'topics':
|
||||
helper.listtopics()
|
||||
elif obj == 'modules':
|
||||
helper.listmodules()
|
||||
elif obj[:8] == 'modules ':
|
||||
helper.listmodules(split(obj)[1])
|
||||
elif obj in helper.keywords: helper.showtopic(obj)
|
||||
elif obj in helper.topics: helper.showtopic(obj)
|
||||
elif obj: output = doc.document( eval(obj) )
|
||||
elif obj in helper.keywords:
|
||||
helper.showtopic(obj)
|
||||
elif obj in helper.topics:
|
||||
helper.showtopic(obj)
|
||||
elif obj:
|
||||
output = doc.document(eval(obj))
|
||||
#######################
|
||||
|
||||
else:
|
||||
output = doc.document( obj )
|
||||
output = doc.document(obj)
|
||||
if not output:
|
||||
output = "No help found for %s" % obj
|
||||
return
|
||||
@@ -63,12 +71,12 @@ def _help( obj ):
|
||||
|
||||
paragraphs = []
|
||||
for o in output:
|
||||
paragraphs.append( textwrap.wrap( o, columns ) )
|
||||
paragraphs.append(textwrap.wrap(o, columns))
|
||||
|
||||
i = 0
|
||||
for j, paragraph in enumerate( paragraphs ):
|
||||
for j, paragraph in enumerate(paragraphs):
|
||||
for line in paragraph:
|
||||
sys.stdout.write( line + '\n' )
|
||||
sys.stdout.write(line + '\n')
|
||||
i += 1
|
||||
# This is a little unclear, but it just waits for a
|
||||
# keypress when the a page worth of text has been
|
||||
@@ -76,6 +84,7 @@ def _help( obj ):
|
||||
if not i % rows and not wait_for_key():
|
||||
return
|
||||
|
||||
|
||||
def wait_for_key():
|
||||
"""Block until a key is pressed for the ghetto paging."""
|
||||
|
||||
@@ -90,7 +99,10 @@ def wait_for_key():
|
||||
clear_line()
|
||||
return q
|
||||
|
||||
|
||||
def clear_line():
|
||||
y = window.getyx()[0]
|
||||
window.move(y, 0)
|
||||
window.clrtoeol()
|
||||
|
||||
# vim: sw=4 ts=4 sts=4 ai et
|
||||
|
||||
+234
-190
File diff suppressed because it is too large
Load Diff
+58
-56
@@ -1,17 +1,17 @@
|
||||
# The MIT License
|
||||
#
|
||||
#
|
||||
# Copyright (c) 2008 Bob Farrell
|
||||
#
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
# of this software and associated documentation files (the "Software"), to deal
|
||||
# in the Software without restriction, including without limitation the rights
|
||||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
# copies of the Software, and to permit persons to whom the Software is
|
||||
# furnished to do so, subject to the following conditions:
|
||||
#
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be included in
|
||||
# all copies or substantial portions of the Software.
|
||||
#
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
@@ -22,7 +22,7 @@
|
||||
|
||||
# A simple formatter for bpython to work with Pygments.
|
||||
# Pygments really kicks ass, it made it really easy to
|
||||
# get the exact behaviour I wanted, thanks Pygments. :)
|
||||
# get the exact behaviour I wanted, thanks Pygments.:)
|
||||
|
||||
from pygments.formatter import Formatter
|
||||
from pygments.token import Keyword, Name, Comment, String, Error, \
|
||||
@@ -30,70 +30,72 @@ from pygments.token import Keyword, Name, Comment, String, Error, \
|
||||
|
||||
"""These format strings are pretty ugly.
|
||||
\x01 represents a colour marker, which
|
||||
can be proceded by one or two of
|
||||
the following letters:
|
||||
k, r, g, y, b, m, c, w, d
|
||||
Which represent:
|
||||
blacK, Red, Green, Yellow, Blue, Magenta,
|
||||
Cyan, White, Default
|
||||
e.g. \x01y for yellow,
|
||||
\x01gb for green on blue background
|
||||
can be proceded by one or two of
|
||||
the following letters:
|
||||
k, r, g, y, b, m, c, w, d
|
||||
Which represent:
|
||||
blacK, Red, Green, Yellow, Blue, Magenta,
|
||||
Cyan, White, Default
|
||||
e.g. \x01y for yellow,
|
||||
\x01gb for green on blue background
|
||||
|
||||
\x02 represents the bold attribute
|
||||
|
||||
\x03 represents the start of the actual
|
||||
text that is output (in this case it's
|
||||
a %s for substitution)
|
||||
text that is output (in this case it's
|
||||
a %s for substitution)
|
||||
|
||||
\x04 represents the end of the string; this is
|
||||
necessary because the strings are all joined
|
||||
together at the end so the parser needs them
|
||||
as delimeters
|
||||
necessary because the strings are all joined
|
||||
together at the end so the parser needs them
|
||||
as delimeters
|
||||
|
||||
"""
|
||||
|
||||
f_strings = {
|
||||
Keyword : "\x01y\x03%s\x04",
|
||||
Name : "\x01w\x02\x03%s\x04",
|
||||
Comment : "\x01b\x03%s\x04",
|
||||
String : "\x01m\x03%s\x04",
|
||||
Error : "\x01r\x03%s\x04",
|
||||
Literal : "\x01r\x03%s\x04",
|
||||
Literal.String : "\x01m\x03%s\x04",
|
||||
Token.Literal.Number.Float : "\x01g\x02\x03%s\x04",
|
||||
Number : "\x01g\x03%s\x04",
|
||||
Operator : "\x01c\x02\x03%s\x04",
|
||||
Operator.Word : "\x01c\x02\x03%s\x04",
|
||||
Punctuation : "\x01c\x02\x03%s\x04",
|
||||
Generic : "\x01d\x03%s\x04",
|
||||
Token : "\x01g\x03%s\x04",
|
||||
Whitespace : "\x02d\x03%s\x04"
|
||||
Keyword: "\x01y\x03%s\x04",
|
||||
Name: "\x01w\x02\x03%s\x04",
|
||||
Comment: "\x01b\x03%s\x04",
|
||||
String: "\x01m\x03%s\x04",
|
||||
Error: "\x01r\x03%s\x04",
|
||||
Literal: "\x01r\x03%s\x04",
|
||||
Literal.String: "\x01m\x03%s\x04",
|
||||
Token.Literal.Number.Float: "\x01g\x02\x03%s\x04",
|
||||
Number: "\x01g\x03%s\x04",
|
||||
Operator: "\x01c\x02\x03%s\x04",
|
||||
Operator.Word: "\x01c\x02\x03%s\x04",
|
||||
Punctuation: "\x01c\x02\x03%s\x04",
|
||||
Generic: "\x01d\x03%s\x04",
|
||||
Token: "\x01g\x03%s\x04",
|
||||
Whitespace: "\x02d\x03%s\x04",
|
||||
}
|
||||
|
||||
class BPythonFormatter( Formatter ):
|
||||
"""This is the custom formatter for bpython.
|
||||
Its format() method receives the tokensource
|
||||
and outfile params passed to it from the
|
||||
Pygments highlight() method and slops
|
||||
them into the appropriate format string
|
||||
as defined above, then writes to the outfile
|
||||
object the final formatted string.
|
||||
|
||||
See the Pygments source for more info; it's pretty
|
||||
straightforward."""
|
||||
class BPythonFormatter(Formatter):
|
||||
"""This is the custom formatter for bpython.
|
||||
Its format() method receives the tokensource
|
||||
and outfile params passed to it from the
|
||||
Pygments highlight() method and slops
|
||||
them into the appropriate format string
|
||||
as defined above, then writes to the outfile
|
||||
object the final formatted string.
|
||||
|
||||
def __init__(self, **options):
|
||||
Formatter.__init__(self, **options)
|
||||
|
||||
def format( self, tokensource, outfile ):
|
||||
o = ''
|
||||
for token, text in tokensource:
|
||||
if text == '\n':
|
||||
continue
|
||||
See the Pygments source for more info; it's pretty
|
||||
straightforward."""
|
||||
|
||||
if token in f_strings:
|
||||
o += f_strings[ token ] % text
|
||||
else:
|
||||
o += f_strings[ Token ] % text
|
||||
outfile.write( o.rstrip() )
|
||||
def __init__(self, **options):
|
||||
Formatter.__init__(self, **options)
|
||||
|
||||
def format(self, tokensource, outfile):
|
||||
o = ''
|
||||
for token, text in tokensource:
|
||||
if text == '\n':
|
||||
continue
|
||||
|
||||
if token in f_strings:
|
||||
o += f_strings[token] % text
|
||||
else:
|
||||
o += f_strings[Token] % text
|
||||
outfile.write(o.rstrip())
|
||||
|
||||
# vim: sw=4 ts=4 sts=4 ai et
|
||||
|
||||
Reference in New Issue
Block a user