mirror of
https://github.com/AdaCore/cpython.git
synced 2026-02-12 12:57:15 -08:00
Whitespace normalization.
This commit is contained in:
14
Lib/shlex.py
14
Lib/shlex.py
@@ -1,14 +1,14 @@
|
||||
"""A lexical analyzer class for simple shell-like syntaxes."""
|
||||
|
||||
# Module and documentation by Eric S. Raymond, 21 Dec 1998
|
||||
# Module and documentation by Eric S. Raymond, 21 Dec 1998
|
||||
# Input stacking and error message cleanup added by ESR, March 2000
|
||||
# push_source() and pop_source() made explicit by ESR, January 2001.
|
||||
# push_source() and pop_source() made explicit by ESR, January 2001.
|
||||
|
||||
import os.path
|
||||
import sys
|
||||
|
||||
class shlex:
|
||||
"A lexical analyzer class for simple shell-like syntaxes."
|
||||
"A lexical analyzer class for simple shell-like syntaxes."
|
||||
def __init__(self, instream=None, infile=None):
|
||||
if instream:
|
||||
self.instream = instream
|
||||
@@ -101,7 +101,7 @@ class shlex:
|
||||
self.lineno = self.lineno + 1
|
||||
if self.debug >= 3:
|
||||
print "shlex: in state", repr(self.state), \
|
||||
"I see character:", repr(nextchar)
|
||||
"I see character:", repr(nextchar)
|
||||
if self.state is None:
|
||||
self.token = '' # past end of file
|
||||
break
|
||||
@@ -136,14 +136,14 @@ class shlex:
|
||||
if nextchar == self.state:
|
||||
self.state = ' '
|
||||
break
|
||||
elif not nextchar: # end of file
|
||||
elif not nextchar: # end of file
|
||||
if self.debug >= 2:
|
||||
print "shlex: I see EOF in quotes state"
|
||||
# XXX what error should be raised here?
|
||||
raise ValueError, "No closing quotation"
|
||||
elif self.state == 'a':
|
||||
if not nextchar:
|
||||
self.state = None # end of file
|
||||
self.state = None # end of file
|
||||
break
|
||||
elif nextchar in self.whitespace:
|
||||
if self.debug >= 2:
|
||||
@@ -194,7 +194,7 @@ class shlex:
|
||||
return "\"%s\", line %d: " % (infile, lineno)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == '__main__':
|
||||
if len(sys.argv) == 1:
|
||||
lexer = shlex()
|
||||
else:
|
||||
|
||||
@@ -28,7 +28,7 @@ class CallTip:
|
||||
background="#ffffe0", relief=SOLID, borderwidth=1,
|
||||
font = self.widget['font'])
|
||||
label.pack()
|
||||
|
||||
|
||||
def hidetip(self):
|
||||
tw = self.tipwindow
|
||||
self.tipwindow = None
|
||||
@@ -53,7 +53,7 @@ class container: # Conceptually an editor_window
|
||||
text.event_add("<<calltip-hide>>", ")")
|
||||
text.bind("<<calltip-show>>", self.calltip_show)
|
||||
text.bind("<<calltip-hide>>", self.calltip_hide)
|
||||
|
||||
|
||||
text.focus_set()
|
||||
# root.mainloop() # not in idle
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ class CallTips:
|
||||
if self.calltip:
|
||||
self.calltip.hidetip()
|
||||
self.calltip = None
|
||||
|
||||
|
||||
def paren_open_event(self, event):
|
||||
self._remove_calltip_window()
|
||||
arg_text = get_arg_text(self.get_object_at_cursor())
|
||||
@@ -91,9 +91,9 @@ class CallTips:
|
||||
namespace = sys.modules.copy()
|
||||
namespace.update(__main__.__dict__)
|
||||
try:
|
||||
return eval(word, namespace)
|
||||
return eval(word, namespace)
|
||||
except:
|
||||
pass
|
||||
pass
|
||||
return None # Can't find an object.
|
||||
|
||||
def _find_constructor(class_ob):
|
||||
|
||||
@@ -92,7 +92,7 @@ class ModuleBrowserTreeItem(TreeItem):
|
||||
|
||||
def IsExpandable(self):
|
||||
return os.path.normcase(self.file[-3:]) == ".py"
|
||||
|
||||
|
||||
def listclasses(self):
|
||||
dir, file = os.path.split(self.file)
|
||||
name, ext = os.path.splitext(file)
|
||||
|
||||
@@ -17,7 +17,7 @@ class Debugger(bdb.Bdb):
|
||||
bdb.Bdb.__init__(self)
|
||||
self.pyshell = pyshell
|
||||
self.make_gui()
|
||||
|
||||
|
||||
def canonic(self, filename):
|
||||
# Canonicalize filename -- called by Bdb
|
||||
return os.path.normcase(os.path.abspath(filename))
|
||||
@@ -299,10 +299,10 @@ class Debugger(bdb.Bdb):
|
||||
import linecache # Import as late as possible
|
||||
line = linecache.getline(filename, lineno)
|
||||
if not line:
|
||||
return 'That line does not exist!'
|
||||
return 'That line does not exist!'
|
||||
if not self.breaks.has_key(filename):
|
||||
self.breaks[filename] = []
|
||||
self.breaks[filename] = []
|
||||
list = self.breaks[filename]
|
||||
if not lineno in list:
|
||||
list.append(lineno)
|
||||
list.append(lineno)
|
||||
bp = bdb.Breakpoint(filename, lineno, temporary, cond)
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
class Delegator:
|
||||
|
||||
# The cache is only used to be able to change delegates!
|
||||
|
||||
@@ -26,12 +26,12 @@ class FileList:
|
||||
|
||||
|
||||
def goodname(self, filename):
|
||||
filename = self.canonize(filename)
|
||||
key = os.path.normcase(filename)
|
||||
if self.dict.has_key(key):
|
||||
edit = self.dict[key]
|
||||
filename = edit.io.filename or filename
|
||||
return filename
|
||||
filename = self.canonize(filename)
|
||||
key = os.path.normcase(filename)
|
||||
if self.dict.has_key(key):
|
||||
edit = self.dict[key]
|
||||
filename = edit.io.filename or filename
|
||||
return filename
|
||||
|
||||
def open(self, filename):
|
||||
assert filename
|
||||
|
||||
@@ -28,10 +28,10 @@ class FormatParagraph:
|
||||
keydefs = {
|
||||
'<<format-paragraph>>': ['<Alt-q>'],
|
||||
}
|
||||
|
||||
|
||||
unix_keydefs = {
|
||||
'<<format-paragraph>>': ['<Meta-q>'],
|
||||
}
|
||||
}
|
||||
|
||||
def __init__(self, editwin):
|
||||
self.editwin = editwin
|
||||
|
||||
@@ -10,24 +10,24 @@ class IdleConfParser(ConfigParser):
|
||||
builtin_sections = {}
|
||||
for section in ('EditorWindow', 'Colors'):
|
||||
builtin_sections[section] = section
|
||||
|
||||
|
||||
def getcolor(self, sec, name):
|
||||
"""Return a dictionary with foreground and background colors
|
||||
|
||||
The return value is appropriate for passing to Tkinter in, e.g.,
|
||||
a tag_config call.
|
||||
"""
|
||||
fore = self.getdef(sec, name + "-foreground")
|
||||
back = self.getdef(sec, name + "-background")
|
||||
fore = self.getdef(sec, name + "-foreground")
|
||||
back = self.getdef(sec, name + "-background")
|
||||
return {"foreground": fore,
|
||||
"background": back}
|
||||
|
||||
def getdef(self, sec, options, raw=0, vars=None, default=None):
|
||||
"""Get an option value for given section or return default"""
|
||||
try:
|
||||
try:
|
||||
return self.get(sec, options, raw, vars)
|
||||
except (NoSectionError, NoOptionError):
|
||||
return default
|
||||
except (NoSectionError, NoOptionError):
|
||||
return default
|
||||
|
||||
def getsection(self, section):
|
||||
"""Return a SectionConfigParser object"""
|
||||
@@ -37,10 +37,10 @@ class IdleConfParser(ConfigParser):
|
||||
exts = []
|
||||
for sec in self.sections():
|
||||
if self.builtin_sections.has_key(sec):
|
||||
continue
|
||||
# enable is a bool, but it may not be defined
|
||||
if self.getdef(sec, 'enable') != '0':
|
||||
exts.append(sec)
|
||||
continue
|
||||
# enable is a bool, but it may not be defined
|
||||
if self.getdef(sec, 'enable') != '0':
|
||||
exts.append(sec)
|
||||
return exts
|
||||
|
||||
def reload(self):
|
||||
@@ -69,10 +69,10 @@ class SectionConfigParser:
|
||||
|
||||
def getint(self, option):
|
||||
return self.config.getint(self.section, option)
|
||||
|
||||
|
||||
def getfloat(self, option):
|
||||
return self.config.getint(self.section, option)
|
||||
|
||||
|
||||
def getboolean(self, option):
|
||||
return self.config.getint(self.section, option)
|
||||
|
||||
@@ -98,7 +98,7 @@ def load(dir):
|
||||
genplatfile = os.path.join(dir, "config-mac.txt")
|
||||
else:
|
||||
genplatfile = os.path.join(dir, "config-unix.txt")
|
||||
|
||||
|
||||
platfile = os.path.join(dir, "config-%s.txt" % sys.platform)
|
||||
|
||||
try:
|
||||
@@ -110,4 +110,3 @@ def load(dir):
|
||||
os.path.join(homedir, ".idle")))
|
||||
|
||||
idleconf = IdleConfParser()
|
||||
|
||||
|
||||
@@ -86,4 +86,3 @@ class History:
|
||||
self.text.mark_set("insert", "end-1c")
|
||||
self.text.insert("insert", s)
|
||||
self.text.see("insert")
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ from Separator import HSeparator
|
||||
from ScrolledList import ScrolledList
|
||||
|
||||
class MultiScrolledLists:
|
||||
|
||||
|
||||
def __init__(self, root, nlists=2):
|
||||
assert nlists >= 1
|
||||
self.root = root
|
||||
@@ -51,17 +51,17 @@ class MultiScrolledLists:
|
||||
self.fill(0)
|
||||
# XXX one after_idle isn't enough; two are...
|
||||
top.after_idle(self.call_pack_propagate_1)
|
||||
|
||||
|
||||
def call_pack_propagate_1(self):
|
||||
self.top.after_idle(self.call_pack_propagate)
|
||||
|
||||
|
||||
def call_pack_propagate(self):
|
||||
for frame in self.frames:
|
||||
frame.pack_propagate(0)
|
||||
|
||||
|
||||
def close(self, event=None):
|
||||
self.top.destroy()
|
||||
|
||||
|
||||
def settitle(self):
|
||||
short = self.shorttitle()
|
||||
long = self.longtitle()
|
||||
@@ -80,23 +80,23 @@ class MultiScrolledLists:
|
||||
def longtitle(self):
|
||||
# override this
|
||||
return "Multi Scrolled Lists"
|
||||
|
||||
|
||||
def shorttitle(self):
|
||||
# override this
|
||||
return None
|
||||
|
||||
|
||||
def width(self, i):
|
||||
# override this
|
||||
return 20
|
||||
|
||||
|
||||
def height(self, i):
|
||||
# override this
|
||||
return 10
|
||||
|
||||
|
||||
def subtitle(self, i):
|
||||
# override this
|
||||
return "Column %d" % i
|
||||
|
||||
|
||||
def fill(self, i):
|
||||
for k in range(i, self.nlists):
|
||||
self.lists[k].clear()
|
||||
@@ -105,14 +105,14 @@ class MultiScrolledLists:
|
||||
l = self.items(i)
|
||||
for s in l:
|
||||
list.append(s)
|
||||
|
||||
|
||||
def on_select(self, index, i):
|
||||
item = self.lists[i].get(index)
|
||||
del self.path[i:]
|
||||
self.path.append(item)
|
||||
if i+1 < self.nlists:
|
||||
self.fill(i+1)
|
||||
|
||||
|
||||
def items(self, i):
|
||||
# override this
|
||||
l = []
|
||||
@@ -122,7 +122,7 @@ class MultiScrolledLists:
|
||||
s = self.path[i-1] + "." + s
|
||||
l.append(s)
|
||||
return l
|
||||
|
||||
|
||||
def on_double(self, index, i):
|
||||
pass
|
||||
|
||||
|
||||
@@ -1,32 +1,32 @@
|
||||
from Tkinter import *
|
||||
|
||||
class MultiStatusBar(Frame):
|
||||
|
||||
def __init__(self, master=None, **kw):
|
||||
if master is None:
|
||||
master = Tk()
|
||||
apply(Frame.__init__, (self, master), kw)
|
||||
self.labels = {}
|
||||
|
||||
def set_label(self, name, text='', side=LEFT):
|
||||
if not self.labels.has_key(name):
|
||||
label = Label(self, bd=1, relief=SUNKEN, anchor=W)
|
||||
label.pack(side=side)
|
||||
self.labels[name] = label
|
||||
else:
|
||||
label = self.labels[name]
|
||||
label.config(text=text)
|
||||
def __init__(self, master=None, **kw):
|
||||
if master is None:
|
||||
master = Tk()
|
||||
apply(Frame.__init__, (self, master), kw)
|
||||
self.labels = {}
|
||||
|
||||
def set_label(self, name, text='', side=LEFT):
|
||||
if not self.labels.has_key(name):
|
||||
label = Label(self, bd=1, relief=SUNKEN, anchor=W)
|
||||
label.pack(side=side)
|
||||
self.labels[name] = label
|
||||
else:
|
||||
label = self.labels[name]
|
||||
label.config(text=text)
|
||||
|
||||
def _test():
|
||||
b = Frame()
|
||||
c = Text(b)
|
||||
c.pack(side=TOP)
|
||||
a = MultiStatusBar(b)
|
||||
a.set_label("one", "hello")
|
||||
a.set_label("two", "world")
|
||||
a.pack(side=BOTTOM, fill=X)
|
||||
b.pack()
|
||||
b.mainloop()
|
||||
b = Frame()
|
||||
c = Text(b)
|
||||
c.pack(side=TOP)
|
||||
a = MultiStatusBar(b)
|
||||
a.set_label("one", "hello")
|
||||
a.set_label("two", "world")
|
||||
a.pack(side=BOTTOM, fill=X)
|
||||
b.pack()
|
||||
b.mainloop()
|
||||
|
||||
if __name__ == '__main__':
|
||||
_test()
|
||||
_test()
|
||||
|
||||
@@ -111,17 +111,17 @@ class OnDemandOutputWindow:
|
||||
# XXX Should use IdlePrefs.ColorPrefs
|
||||
"stdout": {"foreground": "blue"},
|
||||
"stderr": {"foreground": "#007700"},
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
def __init__(self, flist):
|
||||
self.flist = flist
|
||||
self.owin = None
|
||||
|
||||
|
||||
def write(self, s, tags, mark):
|
||||
if not self.owin:
|
||||
self.setup()
|
||||
self.owin.write(s, tags, mark)
|
||||
|
||||
|
||||
def setup(self):
|
||||
self.owin = owin = OutputWindow(self.flist)
|
||||
text = owin.text
|
||||
|
||||
@@ -20,7 +20,7 @@ class ParenMatch:
|
||||
"""Highlight matching parentheses
|
||||
|
||||
There are three supported style of paren matching, based loosely
|
||||
on the Emacs options. The style is select based on the
|
||||
on the Emacs options. The style is select based on the
|
||||
HILITE_STYLE attribute; it can be changed used the set_style
|
||||
method.
|
||||
|
||||
@@ -43,9 +43,9 @@ class ParenMatch:
|
||||
to the right of a right paren. I don't know how to do that in Tk,
|
||||
so I haven't bothered.
|
||||
"""
|
||||
|
||||
|
||||
menudefs = []
|
||||
|
||||
|
||||
keydefs = {
|
||||
'<<flash-open-paren>>' : ('<KeyRelease-parenright>',
|
||||
'<KeyRelease-bracketright>',
|
||||
@@ -146,7 +146,7 @@ class LastOpenBracketFinder:
|
||||
indentwidth = AutoIndent.indentwidth
|
||||
tabwidth = AutoIndent.tabwidth
|
||||
context_use_ps1 = AutoIndent.context_use_ps1
|
||||
|
||||
|
||||
def __init__(self, editwin):
|
||||
self.editwin = editwin
|
||||
self.text = editwin.text
|
||||
@@ -158,7 +158,7 @@ class LastOpenBracketFinder:
|
||||
startatindex = `startat` + ".0"
|
||||
# rawtext needs to contain everything up to the last
|
||||
# character, which was the close paren. the parser also
|
||||
# requires that the last line ends with "\n"
|
||||
# requires that the last line ends with "\n"
|
||||
rawtext = self.text.get(startatindex, "insert")[:-1] + "\n"
|
||||
y.set_str(rawtext)
|
||||
bod = y.find_good_parse_start(
|
||||
@@ -175,7 +175,7 @@ class LastOpenBracketFinder:
|
||||
lno = index2line(self.text.index("insert"))
|
||||
i, buf = self._find_offset_in_buf(lno)
|
||||
if i is None \
|
||||
or keysym_type(buf[i]) != right_keysym_type:
|
||||
or keysym_type(buf[i]) != right_keysym_type:
|
||||
return None
|
||||
lines_back = string.count(buf[i:], "\n") - 1
|
||||
# subtract one for the "\n" added to please the parser
|
||||
@@ -189,4 +189,3 @@ class LastOpenBracketFinder:
|
||||
icis=self.editwin.is_char_in_string):
|
||||
return icis(startindex + "%dc" % offset)
|
||||
return inner
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ from TreeWidget import TreeItem
|
||||
from ClassBrowser import ClassBrowser, ModuleBrowserTreeItem
|
||||
|
||||
class PathBrowser(ClassBrowser):
|
||||
|
||||
|
||||
def __init__(self, flist):
|
||||
self.init(flist)
|
||||
|
||||
|
||||
@@ -124,7 +124,7 @@ class ModifiedColorDelegator(ColorDelegator):
|
||||
"stderr": cconf.getcolor("stderr"),
|
||||
"console": cconf.getcolor("console"),
|
||||
"ERROR": cconf.getcolor("ERROR"),
|
||||
None: cconf.getcolor("normal"),
|
||||
None: cconf.getcolor("normal"),
|
||||
})
|
||||
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ VERBOSE = None
|
||||
class SocketProtocol:
|
||||
"""A simple protocol for sending strings across a socket"""
|
||||
BUF_SIZE = 8192
|
||||
|
||||
|
||||
def __init__(self, sock):
|
||||
self.sock = sock
|
||||
self._buffer = ''
|
||||
@@ -176,11 +176,11 @@ class CommandProtocol:
|
||||
|
||||
def decode_seqno(self, buf):
|
||||
return struct.unpack("I", buf)[0]
|
||||
|
||||
|
||||
|
||||
class StdioRedirector:
|
||||
"""Redirect sys.std{in,out,err} to a set of file-like objects"""
|
||||
|
||||
|
||||
def __init__(self, stdin, stdout, stderr):
|
||||
self.stdin = stdin
|
||||
self.stdout = stdout
|
||||
@@ -292,7 +292,7 @@ class RIClient:
|
||||
self._cmd.dispatch()
|
||||
except EOFError:
|
||||
pass
|
||||
|
||||
|
||||
def handle_stdout(self, buf):
|
||||
sys.stdout.write(buf)
|
||||
## sys.stdout.flush()
|
||||
@@ -339,5 +339,4 @@ if __name__ == "__main__":
|
||||
startRemoteInterp(id)
|
||||
else:
|
||||
file = args[1]
|
||||
riExec(id, file)
|
||||
|
||||
riExec(id, file)
|
||||
|
||||
@@ -34,13 +34,13 @@ To fix case 2, change all tabs to spaces by using Select All followed \
|
||||
by Untabify Region (both in the Edit menu)."""
|
||||
|
||||
class ScriptBinding:
|
||||
|
||||
|
||||
keydefs = {
|
||||
'<<check-module>>': ['<Alt-F5>', '<Meta-F5>'],
|
||||
'<<import-module>>': ['<F5>'],
|
||||
'<<run-script>>': ['<Control-F5>'],
|
||||
}
|
||||
|
||||
|
||||
menudefs = [
|
||||
('edit', [None,
|
||||
('Check module', '<<check-module>>'),
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
from Tkinter import *
|
||||
|
||||
class ScrolledList:
|
||||
|
||||
|
||||
default = "(None)"
|
||||
|
||||
def __init__(self, master, **options):
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
from Tkinter import *
|
||||
|
||||
class Separator:
|
||||
|
||||
|
||||
def __init__(self, master, orient, min=10, thickness=5, bg=None):
|
||||
self.min = max(1, min)
|
||||
self.thickness = max(1, thickness)
|
||||
@@ -10,14 +10,14 @@ class Separator:
|
||||
self.dim = "width"
|
||||
self.dir = "x"
|
||||
self.cursor = "sb_h_double_arrow"
|
||||
elif orient in ("v", "vertical"):
|
||||
self.side = "top"
|
||||
self.dim = "height"
|
||||
self.dir = "y"
|
||||
elif orient in ("v", "vertical"):
|
||||
self.side = "top"
|
||||
self.dim = "height"
|
||||
self.dir = "y"
|
||||
self.cursor = "sb_v_double_arrow"
|
||||
else:
|
||||
raise ValueError, "Separator: orient should be h or v"
|
||||
self.winfo_dim = "winfo_" + self.dim
|
||||
else:
|
||||
raise ValueError, "Separator: orient should be h or v"
|
||||
self.winfo_dim = "winfo_" + self.dim
|
||||
self.master = master = Frame(master)
|
||||
master.pack(expand=1, fill="both")
|
||||
self.f1 = Frame(master)
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user