summaryrefslogtreecommitdiffstats
path: root/Misc
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2003-01-28 17:55:05 (GMT)
committerGuido van Rossum <guido@python.org>2003-01-28 17:55:05 (GMT)
commit533dbcf250bf4e2310ab72d8d42f2efe3be6febf (patch)
tree49c338482d819fdd1f4027ef590529986b2070f9 /Misc
parent53b39d2e70768e34c3f01f0d6efbe76c9913d422 (diff)
downloadcpython-533dbcf250bf4e2310ab72d8d42f2efe3be6febf.zip
cpython-533dbcf250bf4e2310ab72d8d42f2efe3be6febf.tar.gz
cpython-533dbcf250bf4e2310ab72d8d42f2efe3be6febf.tar.bz2
Some experimental support for generating NEWOBJ with proto=2, and
fixed a bug in load_newobj().
Diffstat (limited to 'Misc')
0 files changed, 0 insertions, 0 deletions
>
-rwxr-xr-xLib/dos-8x3/bastion.py15
-rwxr-xr-xLib/dos-8x3/compilea.py2
-rwxr-xr-xLib/dos-8x3/formatte.py27
-rwxr-xr-xLib/dos-8x3/mimetool.py10
-rw-r--r--Lib/dos-8x3/mimewrit.py131
-rwxr-xr-xLib/dos-8x3/posixfil.py9
-rwxr-xr-xLib/dos-8x3/posixpat.py2
-rw-r--r--Lib/dos-8x3/test_mat.py153
-rwxr-xr-xLib/dos-8x3/tracebac.py72
10 files changed, 421 insertions, 31 deletions
diff --git a/Lib/dos-8x3/ast.py b/Lib/dos-8x3/ast.py
index 6f92bee..370cfe4 100755
--- a/Lib/dos-8x3/ast.py
+++ b/Lib/dos-8x3/ast.py
@@ -1,13 +1,13 @@
"""Object-oriented interface to the parser module.
-This module exports three classes which together provide an interface
+This module exports four classes which together provide an interface
to the parser module. Together, the three classes represent two ways
to create parsed representations of Python source and the two starting
data types (source text and tuple representations). Each class
provides interfaces which are identical other than the constructors.
The constructors are described in detail in the documentation for each
class and the remaining, shared portion of the interface is documented
-below. Briefly, the three classes provided are:
+below. Briefly, the classes provided are:
AST
Defines the primary interface to the AST objects and supports creation
@@ -23,6 +23,9 @@ FileSuiteAST
Convenience subclass of the `SuiteAST' class; loads source text of the
suite from an external file.
+Common Methods
+--------------
+
Aside from the constructors, several methods are provided to allow
access to the various interpretations of the parse tree and to check
conditions of the construct represented by the parse tree.
@@ -68,8 +71,8 @@ class AST:
This base class provides all of the query methods for subclass
objects defined in this module.
"""
- _p = __import__('parser') # import internally to avoid
- # namespace pollution at the
+ import parser # import internally to avoid
+ _p = parser # namespace pollution at the
# top level
_text = None
_code = None
@@ -84,7 +87,8 @@ class AST:
The tuple tree to convert.
The tuple-tree may represent either an expression or a suite; the
- type will be determined automatically.
+ type will be determined automatically. Line number information may
+ optionally be present for any subset of the terminal tokens.
"""
if type(tuple) is not type(()):
raise TypeError, 'Base AST class requires tuple parameter.'
@@ -93,11 +97,24 @@ class AST:
self._ast = self._p.tuple2ast(tuple)
self._type = (self._p.isexpr(self._ast) and 'expression') or 'suite'
- def tuple(self):
+ def list(self, line_info = 0):
+ """Returns a fresh list representing the parse tree.
+
+ line_info
+ If true, includes line number information for terminal tokens in
+ the output data structure,
+ """
+ return self._p.ast2list(self._ast, line_info)
+
+ def tuple(self, line_info = 0):
"""Returns the tuple representing the parse tree.
+
+ line_info
+ If true, includes line number information for terminal tokens in
+ the output data structure,
"""
if self._tupl is None:
- self._tupl = self._p.ast2tuple(self._ast)
+ self._tupl = self._p.ast2tuple(self._ast, line_info)
return self._tupl
def code(self):
diff --git a/Lib/dos-8x3/bastion.py b/Lib/dos-8x3/bastion.py
index 7ddd93e..cb54be9 100755
--- a/Lib/dos-8x3/bastion.py
+++ b/Lib/dos-8x3/bastion.py
@@ -141,6 +141,7 @@ def _test():
return self.sum
o = Original()
b = Bastion(o)
+ testcode = """if 1:
b.add(81)
b.add(18)
print "b.total() =", b.total()
@@ -156,6 +157,20 @@ def _test():
print "inaccessible"
else:
print "accessible"
+ try:
+ print "b._get_.func_defaults =", b._get_.func_defaults,
+ except:
+ print "inaccessible"
+ else:
+ print "accessible"
+ \n"""
+ exec testcode
+ print '='*20, "Using rexec:", '='*20
+ import rexec
+ r = rexec.RExec()
+ m = r.add_module('__main__')
+ m.b = b
+ r.r_exec(testcode)
if __name__ == '__main__':
diff --git a/Lib/dos-8x3/compilea.py b/Lib/dos-8x3/compilea.py
index 3120284..9947569 100755
--- a/Lib/dos-8x3/compilea.py
+++ b/Lib/dos-8x3/compilea.py
@@ -43,7 +43,7 @@ def compile_dir(dir, maxlevels = 10):
def compile_path(skip_curdir = 1):
for dir in sys.path:
- if dir == os.curdir and skip_curdir:
+ if (not dir or dir == os.curdir) and skip_curdir:
print 'Skipping current directory'
else:
compile_dir(dir, 0)
diff --git a/Lib/dos-8x3/formatte.py b/Lib/dos-8x3/formatte.py
index 0266379..c192e20 100755
--- a/Lib/dos-8x3/formatte.py
+++ b/Lib/dos-8x3/formatte.py
@@ -10,7 +10,7 @@ AS_IS = None
class NullFormatter:
- def __init__(self): pass
+ def __init__(self, writer): pass
def end_paragraph(self, blankline): pass
def add_line_break(self): pass
def add_hor_rule(self, abswidth=None, percentwidth=1.0,
@@ -33,6 +33,11 @@ class NullFormatter:
class AbstractFormatter:
+ # Space handling policy: blank spaces at the boundary between elements
+ # are handled by the outermost context. "Literal" data is not checked
+ # to determine context, so spaces in literal data are handled directly
+ # in all circumstances.
+
def __init__(self, writer):
self.writer = writer # Output device
self.align = None # Current alignment
@@ -162,7 +167,8 @@ class AbstractFormatter:
def add_literal_data(self, data):
if not data: return
- # Caller is expected to cause flush_softspace() if needed.
+ if self.softspace:
+ self.writer.send_flowing_data(" ")
self.hard_break = data[-1:] == '\n'
self.nospace = self.para_end = self.softspace = \
self.parskip = self.have_label = 0
@@ -170,8 +176,9 @@ class AbstractFormatter:
def flush_softspace(self):
if self.softspace:
- self.hard_break = self.nospace = self.para_end = self.parskip = \
+ self.hard_break = self.para_end = self.parskip = \
self.have_label = self.softspace = 0
+ self.nospace = 1
self.writer.send_flowing_data(' ')
def push_alignment(self, align):
@@ -194,7 +201,8 @@ class AbstractFormatter:
def push_font(self, (size, i, b, tt)):
if self.softspace:
- self.hard_break = self.nospace = self.para_end = self.softspace = 0
+ self.hard_break = self.para_end = self.softspace = 0
+ self.nospace = 1
self.writer.send_flowing_data(' ')
if self.font_stack:
csize, ci, cb, ctt = self.font_stack[-1]
@@ -207,9 +215,6 @@ class AbstractFormatter:
self.writer.new_font(font)
def pop_font(self):
- if self.softspace:
- self.hard_break = self.nospace = self.para_end = self.softspace = 0
- self.writer.send_flowing_data(' ')
if self.font_stack:
del self.font_stack[-1]
if self.font_stack:
@@ -241,22 +246,20 @@ class AbstractFormatter:
def push_style(self, *styles):
if self.softspace:
- self.hard_break = self.nospace = self.para_end = self.softspace = 0
+ self.hard_break = self.para_end = self.softspace = 0
+ self.nospace = 1
self.writer.send_flowing_data(' ')
for style in styles:
self.style_stack.append(style)
self.writer.new_styles(tuple(self.style_stack))
def pop_style(self, n=1):
- if self.softspace:
- self.hard_break = self.nospace = self.para_end = self.softspace = 0
- self.writer.send_flowing_data(' ')
del self.style_stack[-n:]
self.writer.new_styles(tuple(self.style_stack))
def assert_line_data(self, flag=1):
self.nospace = self.hard_break = not flag
- self.para_end = self.have_label = 0
+ self.para_end = self.parskip = self.have_label = 0
class NullWriter:
diff --git a/Lib/dos-8x3/mimetool.py b/Lib/dos-8x3/mimetool.py
index da33a77..baf9379 100755
--- a/Lib/dos-8x3/mimetool.py
+++ b/Lib/dos-8x3/mimetool.py
@@ -106,8 +106,14 @@ def choose_boundary():
import socket
import os
hostid = socket.gethostbyname(socket.gethostname())
- uid = `os.getuid()`
- pid = `os.getpid()`
+ try:
+ uid = `os.getuid()`
+ except:
+ uid = '1'
+ try:
+ pid = `os.getpid()`
+ except:
+ pid = '1'
seed = `rand.rand()`
_prefix = hostid + '.' + uid + '.' + pid
timestamp = `int(time.time())`
diff --git a/Lib/dos-8x3/mimewrit.py b/Lib/dos-8x3/mimewrit.py
new file mode 100644
index 0000000..6fbcb65
--- /dev/null
+++ b/Lib/dos-8x3/mimewrit.py
@@ -0,0 +1,131 @@
+"""Generic MIME writer.
+
+Classes:
+
+MimeWriter - the only thing here.
+
+"""
+
+__version__ = '$Revision$'
+# $Source$
+
+
+import string
+import mimetools
+
+
+class MimeWriter:
+
+ """Generic MIME writer.
+
+ Methods:
+
+ __init__()
+ addheader()
+ flushheaders()
+ startbody()
+ startmultipartbody()
+ nextpart()
+ lastpart()
+
+ A MIME writer is much more primitive than a MIME parser. It
+ doesn't seek around on the output file, and it doesn't use large
+ amounts of buffer space, so you have to write the parts in the
+ order they should occur on the output file. It does buffer the
+ headers you add, allowing you to rearrange their order.
+
+ General usage is:
+
+ f = <open the output file>
+ w = MimeWriter(f)
+ ...call w.addheader(key, value) 0 or more times...
+
+ followed by either:
+
+ f = w.startbody(content_type)
+ ...call f.write(data) for body data...
+
+ or:
+
+ w.startmultipartbody(subtype)
+ for each part:
+ subwriter = w.nextpart()
+ ...use the subwriter's methods to create the subpart...
+ w.lastpart()
+
+ The subwriter is another MimeWriter instance, and should be
+ treated in the same way as the toplevel MimeWriter. This way,
+ writing recursive body parts is easy.
+
+ Warning: don't forget to call lastpart()!
+
+ XXX There should be more state so calls made in the wrong order
+ are detected.
+
+ Some special cases:
+
+ - startbody() just returns the file passed to the constructor;
+ but don't use this knowledge, as it may be changed.
+
+ - startmultipartbody() actually returns a file as well;
+ this can be used to write the initial 'if you can read this your
+ mailer is not MIME-aware' message.
+
+ - If you call flushheaders(), the headers accumulated so far are
+ written out (and forgotten); this is useful if you don't need a
+ body part at all, e.g. for a subpart of type message/rfc822
+ that's (mis)used to store some header-like information.
+
+ - Passing a keyword argument 'prefix=<flag>' to addheader(),
+ start*body() affects where the header is inserted; 0 means
+ append at the end, 1 means insert at the start; default is
+ append for addheader(), but insert for start*body(), which use
+ it to determine where the Content-Type header goes.
+
+ """
+
+ def __init__(self, fp):
+ self._fp = fp
+ self._headers = []
+
+ def addheader(self, key, value, prefix=0):
+ lines = string.splitfields(value, "\n")
+ while lines and not lines[-1]: del lines[-1]
+ while lines and not lines[0]: del lines[0]
+ for i in range(1, len(lines)):
+ lines[i] = " " + string.strip(lines[i])
+ value = string.joinfields(lines, "\n") + "\n"
+ line = key + ": " + value
+ if prefix:
+ self._headers.insert(0, line)
+ else:
+ self._headers.append(line)
+
+ def flushheaders(self):
+ self._fp.writelines(self._headers)
+ self._headers = []
+
+ def startbody(self, ctype, plist=[], prefix=1):
+ for name, value in plist:
+ ctype = ctype + ';\n %s=\"%s\"' % (name, value)
+ self.addheader("Content-Type", ctype, prefix=prefix)
+ self.flushheaders()
+ self._fp.write("\n")
+ return self._fp
+
+ def startmultipartbody(self, subtype, boundary=None, plist=[], prefix=1):
+ self._boundary = boundary or mimetools.choose_boundary()
+ return self.startbody("multipart/" + subtype,
+ [("boundary", self._boundary)] + plist,
+ prefix=prefix)
+
+ def nextpart(self):
+ self._fp.write("\n--" + self._boundary + "\n")
+ return self.__class__(self._fp)
+
+ def lastpart(self):
+ self._fp.write("\n--" + self._boundary + "--\n")
+
+
+if __name__ == '__main__':
+ print "To test the MimeWriter module, run TestMimeWriter.py."
diff --git a/Lib/dos-8x3/posixfil.py b/Lib/dos-8x3/posixfil.py
index 64cda98..f0df543 100755
--- a/Lib/dos-8x3/posixfil.py
+++ b/Lib/dos-8x3/posixfil.py
@@ -174,11 +174,15 @@ class _posixfile_:
elif len(args) > 3:
raise TypeError, 'too many arguments'
- # Hack by davem@magnet.com to get locking to go on freebsd
+ # Hack by davem@magnet.com to get locking to go on freebsd;
+ # additions for AIX by Vladimir.Marangozov@imag.fr
import sys, os
if sys.platform == 'freebsd2':
flock = struct.pack('lxxxxlxxxxlhh', \
l_start, l_len, os.getpid(), l_type, l_whence)
+ elif sys.platform in ['aix3', 'aix4']:
+ flock = struct.pack('hhlllii', \
+ l_type, l_whence, l_start, l_len, 0, 0, 0)
else:
flock = struct.pack('hhllhh', \
l_type, l_whence, l_start, l_len, 0, 0)
@@ -189,6 +193,9 @@ class _posixfile_:
if sys.platform == 'freebsd2':
l_start, l_len, l_pid, l_type, l_whence = \
struct.unpack('lxxxxlxxxxlhh', flock)
+ elif sys.platform in ['aix3', 'aix4']:
+ l_type, l_whence, l_start, l_len, l_sysid, l_pid, l_vfs = \
+ struct.unpack('hhlllii', flock)
else:
l_type, l_whence, l_start, l_len, l_sysid, l_pid = \
struct.unpack('hhllhh', flock)
diff --git a/Lib/dos-8x3/posixpat.py b/Lib/dos-8x3/posixpat.py