From bcb11ed38601f9c54eb20f131a043b2f48cf7235 Mon Sep 17 00:00:00 2001 From: moculus Date: Sun, 16 Mar 2008 20:08:37 +0000 Subject: [PATCH] changes to move toward python3 --HG-- branch : pmacs2 --- IDEAS | 5 +++++ aes.py | 13 ++++++++----- application.py | 13 ++++++++----- ispell.py | 14 ++++++++++++-- method/__init__.py | 43 +++++++++++++++++++++++++++++-------------- mode/c.py | 10 ++++++---- mode/python.py | 7 ++++--- mode/sh.py | 3 ++- 8 files changed, 74 insertions(+), 34 deletions(-) diff --git a/IDEAS b/IDEAS index d713221..e6837b2 100644 --- a/IDEAS +++ b/IDEAS @@ -1,3 +1,8 @@ +2008/03/16: + +pdb/gdb/perldb buffer integration +error/stack-trace buffer + 2007/10/20: Tags for matching should be allowed to be multi-character, and should be diff --git a/aes.py b/aes.py index 0065b59..8f46153 100755 --- a/aes.py +++ b/aes.py @@ -1,7 +1,8 @@ #!/usr/bin/python # # by Erik Osheim -import os, popen2 +import os +from subprocess import Popen, PIPE class Cipher(object): '''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'): '''Uses password to encrypt data''' _check_aespipe() - cmd = "aespipe -S '%s' -H '%s' -p 0" % (seed, hashtype) - (stdout, stdin, stderr) = popen2.popen3(cmd) + args = ["aespipe", "-S", seed, "-H", hashtype, "-p", "0"] + p = Popen(args, stdin=PIPE, stdout=PIPE, stderr=PIPE) + (stdout, stdin, stderr) = (p.stdout, p.stdin, p.stderr) stdin.write(password + '\n') stdin.write(data) 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'): '''Uses password to decrypt data''' _check_aespipe() - cmd = "aespipe -d -S '%s' -H '%s' -p 0" % (seed, hashtype) - (stdout, stdin, stderr) = popen2.popen3(cmd) + args = ["aespipe", "-d", "-S", seed, "-H", hashtype, "-p", "0"] + p = Popen(args, stdin=PIPE, stdout=PIPE, stderr=PIPE) + (stdout, stdin, stderr) = (p.stdout, p.stdin, p.stderr) stdin.write(password + '\n') stdin.write(encrypted) stdin.close() diff --git a/application.py b/application.py index 48210e9..7292d18 100755 --- a/application.py +++ b/application.py @@ -40,7 +40,7 @@ class Application(object): (self.y, self.x) = self.stdscr.getmaxyx() # 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.mini_active = False self.mini_buffer = None @@ -64,9 +64,9 @@ class Application(object): 'string.escaped': ('magenta', 'default'), 'string.end': ('green', 'default'), - 'char': ('green', 'default'), - 'integer': ('green', 'default'), - 'float': ('green', 'default'), + 'char': ('default', 'default'), + 'integer': ('default', 'default'), + 'float': ('default', 'default'), 'label': ('magenta', 'default'), 'keyword': ('cyan', 'default'), @@ -440,7 +440,10 @@ class Application(object): path = os.path.join(os.getenv('HOME'), '.pmc', 'conf') if os.path.exists(path): try: - execfile(path) + f = open(path, 'r') + #execfile(path) + exec(f) + f.close() except Exception, e: s = traceback.format_exc() self.rcerror = 'There was an error during startup:\n\n%s' % s diff --git a/ispell.py b/ispell.py index f6614c3..73a6d13 100644 --- a/ispell.py +++ b/ispell.py @@ -1,4 +1,5 @@ import os, popen2 +from subprocess import Popen, PIPE, STDOUT import cache _speller = None @@ -23,10 +24,14 @@ class Speller(object): self.pipe = popen2.Popen3('%s -a' % self.cmd, 'rw') self.pipe.childerr.close() self.pipe.fromchild.readline() + #self.pipe = Popen('%s -a' % self.cmd, stdin=PIPE, stdout=PIPE) + #self.pipe.stdout.readline() def stop(self): self.pipe.tochild.close() self.pipe.fromchild.close() + #self.pipe.stdin.close() + #self.pipe.stdout.close() self.pipe = None def restart(self): @@ -56,13 +61,17 @@ class Speller(object): if self.pipe.poll() >= 0: self.pipe = None self.start() - self.pipe.tochild.write("%s\n" % (word)) - self.pipe.tochild.flush() + #self.pipe.tochild.write("%s\n" % (word)) + #self.pipe.tochild.flush() + self.pipe.stdin.write("%s\n" % (word)) + self.pipe.stdin.flush() l = self.pipe.fromchild.readline() + #l = self.pipe.stdout.readline() if l.startswith("*") or l.startswith("+") or l.startswith("-"): result = True while True: l = self.pipe.fromchild.readline() + #l = self.pipe.stdout.readline() if l == "\n": break self.cache[word] = result @@ -73,6 +82,7 @@ class Speller(object): self.pipe = None self.start() self.pipe.tochild.write("*%s\n" % (word)) + #self.pipe.stdin.write("*%s\n" % (word)) self.pipe.tochild.flush() self.flush(word) diff --git a/method/__init__.py b/method/__init__.py index f68e5ec..16db776 100644 --- a/method/__init__.py +++ b/method/__init__.py @@ -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 from point import Point @@ -1085,15 +1087,20 @@ class FileDiff(Method): args = [Argument("path", type=type(""), prompt="Filename: ", datatype='path')] def _execute(self, w, **vargs): 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 indata = w.buffer.make_string() - pipe.tochild.write(indata) - pipe.tochild.close() + #pipe.tochild.write(indata) + #pipe.tochild.close() + pipe.stdin.write(indata) + pipe.stdin.close() - outdata = pipe.fromchild.read() - errdata = pipe.childerr.read() + #outdata = pipe.fromchild.read() + #errdata = pipe.childerr.read() + outdata = pipe.stdout.read() + errdata = pipe.stderr.read() status = pipe.wait() >> 8 if status == 0: @@ -1131,10 +1138,12 @@ class SvnBlame(Method): return 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 = [] - for line in pipe.fromchild: + #for line in pipe.fromchild: + for line in pipe.stdout: m = self.line_re.match(line) if not m: raise Exception, line @@ -1338,12 +1347,14 @@ class CvsBlame(Method): path = path[len(cwd):] cmd = ("/usr/bin/cvs", 'annotate', path) - pipe = popen2.Popen3(cmd, capturestderr=True) + #pipe = popen2.Popen3(cmd, capturestderr=True) + pipe = Popen(cmd, stdout=PIPE) tokens = [] max_rev = 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) if not m: raise Exception, line @@ -1653,14 +1664,18 @@ class Pipe(Method): if prog is None: return - pipe = popen2.Popen4(cmd) + #pipe = popen2.Popen4(cmd) + pipe = Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=STDOUT) pid = pipe.pid indata = w.buffer.make_string() - pipe.tochild.write(indata) - pipe.tochild.close() + #pipe.tochild.write(indata) + #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 bufname = '*%s*' % self.name.title() diff --git a/mode/c.py b/mode/c.py index 581b70b..b98d09f 100644 --- a/mode/c.py +++ b/mode/c.py @@ -1,4 +1,5 @@ -import os, popen2, re +import os, re +from subprocess import Popen, PIPE, STDOUT import color, default, method, mode, tab from lex import Grammar, PatternRule, RegionRule from mode.python import StringGrammar @@ -224,9 +225,10 @@ class CSetMake(method.Method): class CMake(method.Method): '''Check the syntax of the current python file''' def _execute(self, w, **vargs): - p = popen2.Popen4(w.mode.makecmd) - p.tochild.close() - output = p.fromchild.read() + #p = popen2.Popen4(w.mode.makecmd) + p = Popen(w.mode.makecmd, stdout=PIPE) + #output = p.fromchild.read() + output = p.stdout.read() result = p.wait() status = os.WEXITSTATUS(result) diff --git a/mode/python.py b/mode/python.py index 56644b1..9900587 100644 --- a/mode/python.py +++ b/mode/python.py @@ -39,11 +39,12 @@ class PythonGrammar(Grammar): PatternRule(r'identifier', r'[a-zA-Z_][a-zA-Z0-9_]*'), PatternRule(r'delimiter', r'\(|\)|\[|\]|{|}|@|,|:|\.|`|=|;|\+=|-=|\*=|/=|//=|%=|&=|\|=|\^=|>>=|<<=|\*\*='), - PatternRule(r"operator", r"\+|<>|<<|<=|<|-|>>|>=|>|\*\*|&|\*|\||/|\^|==|//|~|!=|%"), - PatternRule(r"integer", r"(?|<<|<=|<|-|>>|>=|>|\*\*|&|\*|\||/|\^|==|//|~|!=|%"), + OverridePatternRule(r'comment', r'#@@:(?P[.a-zA-Z0-9_]+):(?P[.a-zA-Z0-9_]+) *$'), PatternRule(r'comment', r'#.*$'), PatternRule(r'continuation', r'\\\n$'), diff --git a/mode/sh.py b/mode/sh.py index f7a8854..a12aac0 100644 --- a/mode/sh.py +++ b/mode/sh.py @@ -1,6 +1,6 @@ import commands import color, mode, tab -from lex import Grammar, PatternRule, RegionRule +from lex import Grammar, PatternRule, RegionRule, OverridePatternRule from method import Method class StringGrammar(Grammar): @@ -65,6 +65,7 @@ class ShGrammar(Grammar): PatternRule(r'variable', r"\$(?=\()"), RegionRule(r'string', "'", Grammar, "'"), RegionRule(r'string', '"', StringGrammar, '"'), + OverridePatternRule(r'comment', r'#@@:(?P[.a-zA-Z0-9_]+):(?P[.a-zA-Z0-9_]+) *$'), PatternRule(r'comment', r'#.*$'), PatternRule(r'bareword', r'[-a-zA-Z0-9_.]+'), PatternRule(r'continuation', r'\\\n$'),