changes to move toward python3

--HG--
branch : pmacs2
This commit is contained in:
moculus 2008-03-16 20:08:37 +00:00
parent 867e38966f
commit bcb11ed386
8 changed files with 74 additions and 34 deletions

5
IDEAS
View File

@ -1,3 +1,8 @@
2008/03/16:
pdb/gdb/perldb buffer integration
error/stack-trace buffer
2007/10/20: 2007/10/20:
Tags for matching should be allowed to be multi-character, and should be Tags for matching should be allowed to be multi-character, and should be

13
aes.py
View File

@ -1,7 +1,8 @@
#!/usr/bin/python #!/usr/bin/python
# #
# by Erik Osheim # by Erik Osheim
import os, popen2 import os
from subprocess import Popen, PIPE
class Cipher(object): class Cipher(object):
'''Cipher represents a particular hashing strategy (password, seed, and type). Cipher can encrypt or decrypt data.''' '''Cipher represents a particular hashing strategy (password, seed, and type). Cipher can encrypt or decrypt data.'''
@ -23,8 +24,9 @@ def _check_aespipe():
def encrypt_data(data, password, seed='aes.py', hashtype='rmd160'): def encrypt_data(data, password, seed='aes.py', hashtype='rmd160'):
'''Uses password to encrypt data''' '''Uses password to encrypt data'''
_check_aespipe() _check_aespipe()
cmd = "aespipe -S '%s' -H '%s' -p 0" % (seed, hashtype) args = ["aespipe", "-S", seed, "-H", hashtype, "-p", "0"]
(stdout, stdin, stderr) = popen2.popen3(cmd) p = Popen(args, stdin=PIPE, stdout=PIPE, stderr=PIPE)
(stdout, stdin, stderr) = (p.stdout, p.stdin, p.stderr)
stdin.write(password + '\n') stdin.write(password + '\n')
stdin.write(data) stdin.write(data)
stdin.close() stdin.close()
@ -44,8 +46,9 @@ def encrypt_path(path, data, password, seed='aes.py', hashtype='rmd160'):
def decrypt_data(encrypted, password, seed='aes.py', hashtype='rmd160'): def decrypt_data(encrypted, password, seed='aes.py', hashtype='rmd160'):
'''Uses password to decrypt data''' '''Uses password to decrypt data'''
_check_aespipe() _check_aespipe()
cmd = "aespipe -d -S '%s' -H '%s' -p 0" % (seed, hashtype) args = ["aespipe", "-d", "-S", seed, "-H", hashtype, "-p", "0"]
(stdout, stdin, stderr) = popen2.popen3(cmd) p = Popen(args, stdin=PIPE, stdout=PIPE, stderr=PIPE)
(stdout, stdin, stderr) = (p.stdout, p.stdin, p.stderr)
stdin.write(password + '\n') stdin.write(password + '\n')
stdin.write(encrypted) stdin.write(encrypted)
stdin.close() stdin.close()

View File

@ -40,7 +40,7 @@ class Application(object):
(self.y, self.x) = self.stdscr.getmaxyx() (self.y, self.x) = self.stdscr.getmaxyx()
# initialize some basic stuff # initialize some basic stuff
# each highlighted_range contains three things: [window, start_p, end_p] # each highlighted_range contains three things: (window, start_p, end_p)
self.highlighted_ranges = [] self.highlighted_ranges = []
self.mini_active = False self.mini_active = False
self.mini_buffer = None self.mini_buffer = None
@ -64,9 +64,9 @@ class Application(object):
'string.escaped': ('magenta', 'default'), 'string.escaped': ('magenta', 'default'),
'string.end': ('green', 'default'), 'string.end': ('green', 'default'),
'char': ('green', 'default'), 'char': ('default', 'default'),
'integer': ('green', 'default'), 'integer': ('default', 'default'),
'float': ('green', 'default'), 'float': ('default', 'default'),
'label': ('magenta', 'default'), 'label': ('magenta', 'default'),
'keyword': ('cyan', 'default'), 'keyword': ('cyan', 'default'),
@ -440,7 +440,10 @@ class Application(object):
path = os.path.join(os.getenv('HOME'), '.pmc', 'conf') path = os.path.join(os.getenv('HOME'), '.pmc', 'conf')
if os.path.exists(path): if os.path.exists(path):
try: try:
execfile(path) f = open(path, 'r')
#execfile(path)
exec(f)
f.close()
except Exception, e: except Exception, e:
s = traceback.format_exc() s = traceback.format_exc()
self.rcerror = 'There was an error during startup:\n\n%s' % s self.rcerror = 'There was an error during startup:\n\n%s' % s

View File

@ -1,4 +1,5 @@
import os, popen2 import os, popen2
from subprocess import Popen, PIPE, STDOUT
import cache import cache
_speller = None _speller = None
@ -23,10 +24,14 @@ class Speller(object):
self.pipe = popen2.Popen3('%s -a' % self.cmd, 'rw') self.pipe = popen2.Popen3('%s -a' % self.cmd, 'rw')
self.pipe.childerr.close() self.pipe.childerr.close()
self.pipe.fromchild.readline() self.pipe.fromchild.readline()
#self.pipe = Popen('%s -a' % self.cmd, stdin=PIPE, stdout=PIPE)
#self.pipe.stdout.readline()
def stop(self): def stop(self):
self.pipe.tochild.close() self.pipe.tochild.close()
self.pipe.fromchild.close() self.pipe.fromchild.close()
#self.pipe.stdin.close()
#self.pipe.stdout.close()
self.pipe = None self.pipe = None
def restart(self): def restart(self):
@ -56,13 +61,17 @@ class Speller(object):
if self.pipe.poll() >= 0: if self.pipe.poll() >= 0:
self.pipe = None self.pipe = None
self.start() self.start()
self.pipe.tochild.write("%s\n" % (word)) #self.pipe.tochild.write("%s\n" % (word))
self.pipe.tochild.flush() #self.pipe.tochild.flush()
self.pipe.stdin.write("%s\n" % (word))
self.pipe.stdin.flush()
l = self.pipe.fromchild.readline() l = self.pipe.fromchild.readline()
#l = self.pipe.stdout.readline()
if l.startswith("*") or l.startswith("+") or l.startswith("-"): if l.startswith("*") or l.startswith("+") or l.startswith("-"):
result = True result = True
while True: while True:
l = self.pipe.fromchild.readline() l = self.pipe.fromchild.readline()
#l = self.pipe.stdout.readline()
if l == "\n": if l == "\n":
break break
self.cache[word] = result self.cache[word] = result
@ -73,6 +82,7 @@ class Speller(object):
self.pipe = None self.pipe = None
self.start() self.start()
self.pipe.tochild.write("*%s\n" % (word)) self.pipe.tochild.write("*%s\n" % (word))
#self.pipe.stdin.write("*%s\n" % (word))
self.pipe.tochild.flush() self.pipe.tochild.flush()
self.flush(word) self.flush(word)

View File

@ -1,4 +1,6 @@
import os, commands, popen2, re, sets, tempfile import os, commands, re, sets, tempfile
from subprocess import Popen, PIPE, STDOUT
import buffer, default, dirutil, regex, util, window import buffer, default, dirutil, regex, util, window
from point import Point from point import Point
@ -1085,15 +1087,20 @@ class FileDiff(Method):
args = [Argument("path", type=type(""), prompt="Filename: ", datatype='path')] args = [Argument("path", type=type(""), prompt="Filename: ", datatype='path')]
def _execute(self, w, **vargs): def _execute(self, w, **vargs):
cmd = ("/usr/bin/diff", '-u', '-', vargs['path']) cmd = ("/usr/bin/diff", '-u', '-', vargs['path'])
pipe = popen2.Popen3(cmd, capturestderr=True) #pipe = popen2.Popen3(cmd, capturestderr=True)
pipe = Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE)
pid = pipe.pid pid = pipe.pid
indata = w.buffer.make_string() indata = w.buffer.make_string()
pipe.tochild.write(indata) #pipe.tochild.write(indata)
pipe.tochild.close() #pipe.tochild.close()
pipe.stdin.write(indata)
pipe.stdin.close()
outdata = pipe.fromchild.read() #outdata = pipe.fromchild.read()
errdata = pipe.childerr.read() #errdata = pipe.childerr.read()
outdata = pipe.stdout.read()
errdata = pipe.stderr.read()
status = pipe.wait() >> 8 status = pipe.wait() >> 8
if status == 0: if status == 0:
@ -1131,10 +1138,12 @@ class SvnBlame(Method):
return return
cmd = ("/usr/bin/svn", 'blame', '-v', w.buffer.path) cmd = ("/usr/bin/svn", 'blame', '-v', w.buffer.path)
pipe = popen2.Popen3(cmd) #pipe = popen2.Popen3(cmd)
pipe = Popen(cmd, stdin=PIPE, stdout=PIPE)
lines = [] lines = []
for line in pipe.fromchild: #for line in pipe.fromchild:
for line in pipe.stdout:
m = self.line_re.match(line) m = self.line_re.match(line)
if not m: if not m:
raise Exception, line raise Exception, line
@ -1338,12 +1347,14 @@ class CvsBlame(Method):
path = path[len(cwd):] path = path[len(cwd):]
cmd = ("/usr/bin/cvs", 'annotate', path) cmd = ("/usr/bin/cvs", 'annotate', path)
pipe = popen2.Popen3(cmd, capturestderr=True) #pipe = popen2.Popen3(cmd, capturestderr=True)
pipe = Popen(cmd, stdout=PIPE)
tokens = [] tokens = []
max_rev = 0 max_rev = 0
max_user = 0 max_user = 0
for line in pipe.fromchild: #for line in pipe.fromchild:
for line in pipe.stdout:
m = self.line_re.match(line) m = self.line_re.match(line)
if not m: if not m:
raise Exception, line raise Exception, line
@ -1653,14 +1664,18 @@ class Pipe(Method):
if prog is None: if prog is None:
return return
pipe = popen2.Popen4(cmd) #pipe = popen2.Popen4(cmd)
pipe = Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=STDOUT)
pid = pipe.pid pid = pipe.pid
indata = w.buffer.make_string() indata = w.buffer.make_string()
pipe.tochild.write(indata) #pipe.tochild.write(indata)
pipe.tochild.close() #pipe.tochild.close()
pipe.stdin.write(indata)
pipe.stdin.close()
outdata = pipe.fromchild.read() #outdata = pipe.fromchild.read()
outdata = pipe.stdout.read()
status = pipe.wait() >> 8 status = pipe.wait() >> 8
bufname = '*%s*' % self.name.title() bufname = '*%s*' % self.name.title()

View File

@ -1,4 +1,5 @@
import os, popen2, re import os, re
from subprocess import Popen, PIPE, STDOUT
import color, default, method, mode, tab import color, default, method, mode, tab
from lex import Grammar, PatternRule, RegionRule from lex import Grammar, PatternRule, RegionRule
from mode.python import StringGrammar from mode.python import StringGrammar
@ -224,9 +225,10 @@ class CSetMake(method.Method):
class CMake(method.Method): class CMake(method.Method):
'''Check the syntax of the current python file''' '''Check the syntax of the current python file'''
def _execute(self, w, **vargs): def _execute(self, w, **vargs):
p = popen2.Popen4(w.mode.makecmd) #p = popen2.Popen4(w.mode.makecmd)
p.tochild.close() p = Popen(w.mode.makecmd, stdout=PIPE)
output = p.fromchild.read() #output = p.fromchild.read()
output = p.stdout.read()
result = p.wait() result = p.wait()
status = os.WEXITSTATUS(result) status = os.WEXITSTATUS(result)

View File

@ -39,11 +39,12 @@ class PythonGrammar(Grammar):
PatternRule(r'identifier', r'[a-zA-Z_][a-zA-Z0-9_]*'), PatternRule(r'identifier', r'[a-zA-Z_][a-zA-Z0-9_]*'),
PatternRule(r'delimiter', r'\(|\)|\[|\]|{|}|@|,|:|\.|`|=|;|\+=|-=|\*=|/=|//=|%=|&=|\|=|\^=|>>=|<<=|\*\*='), PatternRule(r'delimiter', r'\(|\)|\[|\]|{|}|@|,|:|\.|`|=|;|\+=|-=|\*=|/=|//=|%=|&=|\|=|\^=|>>=|<<=|\*\*='),
PatternRule(r"operator", r"\+|<>|<<|<=|<|-|>>|>=|>|\*\*|&|\*|\||/|\^|==|//|~|!=|%"), PatternRule(r"integer", r"(?<![\.0-9a-zA-Z_])(?:0|-?[1-9][0-9]*|0[0-7]+|0[xX][0-9a-fA-F]+)[lL]?(?![\.0-9a-zA-Z_])"),
PatternRule(r"integer", r"(?<![\.0-9a-zA-Z_])(?:0|[1-9][0-9]*|0[0-7]+|0[xX][0-9a-fA-F]+)[lL]?(?![\.0-9a-zA-Z_])"), PatternRule(r"float", r"(?<![\.0-9a-zA-Z_])(?:-?[0-9]+\.[0-9]*|-?\.[0-9]+|(?:[0-9]|[0-9]+\.[0-9]*|-?\.[0-9]+)[eE][\+-]?[0-9]+)(?![\.0-9a-zA-Z_])"),
PatternRule(r"float", r"(?<![\.0-9a-zA-Z_])(?:[0-9]+\.[0-9]*|\.[0-9]+|(?:[0-9]|[0-9]+\.[0-9]*|\.[0-9]+)[eE][\+-]?[0-9]+)(?![\.0-9a-zA-Z_])"),
PatternRule(r"imaginary", r"(?<![\.0-9a-zA-Z_])(?:[0-9]+|(?:[0-9]+\.[0-9]*|\.[0-9]+|(?:[0-9]|[0-9]+\.[0-9]*|\.[0-9]+)[eE][\+-]?[0-9]+)[jJ])(?![\.0-9a-zA-Z_])"), PatternRule(r"imaginary", r"(?<![\.0-9a-zA-Z_])(?:[0-9]+|(?:[0-9]+\.[0-9]*|\.[0-9]+|(?:[0-9]|[0-9]+\.[0-9]*|\.[0-9]+)[eE][\+-]?[0-9]+)[jJ])(?![\.0-9a-zA-Z_])"),
PatternRule(r"operator", r"\+|<>|<<|<=|<|-|>>|>=|>|\*\*|&|\*|\||/|\^|==|//|~|!=|%"),
OverridePatternRule(r'comment', r'#@@:(?P<token>[.a-zA-Z0-9_]+):(?P<mode>[.a-zA-Z0-9_]+) *$'), OverridePatternRule(r'comment', r'#@@:(?P<token>[.a-zA-Z0-9_]+):(?P<mode>[.a-zA-Z0-9_]+) *$'),
PatternRule(r'comment', r'#.*$'), PatternRule(r'comment', r'#.*$'),
PatternRule(r'continuation', r'\\\n$'), PatternRule(r'continuation', r'\\\n$'),

View File

@ -1,6 +1,6 @@
import commands import commands
import color, mode, tab import color, mode, tab
from lex import Grammar, PatternRule, RegionRule from lex import Grammar, PatternRule, RegionRule, OverridePatternRule
from method import Method from method import Method
class StringGrammar(Grammar): class StringGrammar(Grammar):
@ -65,6 +65,7 @@ class ShGrammar(Grammar):
PatternRule(r'variable', r"\$(?=\()"), PatternRule(r'variable', r"\$(?=\()"),
RegionRule(r'string', "'", Grammar, "'"), RegionRule(r'string', "'", Grammar, "'"),
RegionRule(r'string', '"', StringGrammar, '"'), RegionRule(r'string', '"', StringGrammar, '"'),
OverridePatternRule(r'comment', r'#@@:(?P<token>[.a-zA-Z0-9_]+):(?P<mode>[.a-zA-Z0-9_]+) *$'),
PatternRule(r'comment', r'#.*$'), PatternRule(r'comment', r'#.*$'),
PatternRule(r'bareword', r'[-a-zA-Z0-9_.]+'), PatternRule(r'bareword', r'[-a-zA-Z0-9_.]+'),
PatternRule(r'continuation', r'\\\n$'), PatternRule(r'continuation', r'\\\n$'),