summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2001-07-17 15:45:08 (GMT)
committerGuido van Rossum <guido@python.org>2001-07-17 15:45:08 (GMT)
commitb1a77dd248b6727113e86664ce0947cbee6cd156 (patch)
tree51d469d91d34c1beefa9d163752086532bf8f0f9 /Lib
parentf8a17b14c4179f9ae28d6329ba7c5a2cf9d7eb3e (diff)
downloadcpython-b1a77dd248b6727113e86664ce0947cbee6cd156.zip
cpython-b1a77dd248b6727113e86664ce0947cbee6cd156.tar.gz
cpython-b1a77dd248b6727113e86664ce0947cbee6cd156.tar.bz2
Deleting zombies
Diffstat (limited to 'Lib')
-rwxr-xr-xLib/builtin.py3
-rwxr-xr-xLib/macstat.py83
-rwxr-xr-xLib/persist.py297
3 files changed, 0 insertions, 383 deletions
diff --git a/Lib/builtin.py b/Lib/builtin.py
deleted file mode 100755
index 710d825..0000000
--- a/Lib/builtin.py
+++ /dev/null
@@ -1,3 +0,0 @@
-# B/W compat hack so code that says "import builtin" won't break after
-# name change from builtin to __builtin__.
-from __builtin__ import *
diff --git a/Lib/macstat.py b/Lib/macstat.py
deleted file mode 100755
index 4b53953..0000000
--- a/Lib/macstat.py
+++ /dev/null
@@ -1,83 +0,0 @@
-# Module 'stat'
-#
-# Defines constants and functions for interpreting stat/lstat struct
-# as returned by os.stat() and os.lstat() (if it exists).
-#
-# Suggested usage: from stat import *
-#
-# XXX Strictly spoken, this module may have to be adapted for each POSIX
-# implementation; in practice, however, the numeric constants used by
-# stat() are almost universal (even for stat() emulations on non-UNIX
-# systems like MS-DOS).
-
-# Indices for stat struct members in tuple returned by os.stat()
-
-ST_MODE = 0
-ST_INO = 1
-ST_DEV = 2
-ST_NLINK = 3
-ST_UID = 4
-ST_GID = 5
-ST_SIZE = 6
-ST_ATIME = 7
-ST_MTIME = 8
-ST_CTIME = 9
-
-# Extract bits from the mode
-
-def S_IMODE(mode):
- return 0
-
-def S_IFMT(mode):
- return mode & 0xFFFF
-
-# Constants used as S_IFMT() for various file types
-# (not all are implemented on all systems)
-
-S_IFDIR = 0x0000
-S_IFREG = 0x0003
-
-# Functions to test for each file type
-
-def S_ISDIR(mode):
- return S_IFMT(mode) == S_IFDIR
-
-def S_ISCHR(mode):
- return 0
-
-def S_ISBLK(mode):
- return 0
-
-def S_ISREG(mode):
- return S_IFMT(mode) == S_IFREG
-
-def S_ISFIFO(mode):
- return 0
-
-def S_ISLNK(mode):
- return 0
-
-def S_ISSOCK(mode):
- return 0
-
-# Names for permission bits
-
-S_ISUID = 04000
-S_ISGID = 02000
-S_ENFMT = S_ISGID
-S_ISVTX = 01000
-S_IREAD = 00400
-S_IWRITE = 00200
-S_IEXEC = 00100
-S_IRWXU = 00700
-S_IRUSR = 00400
-S_IWUSR = 00200
-S_IXUSR = 00100
-S_IRWXG = 00070
-S_IRGRP = 00040
-S_IWGRP = 00020
-S_IXGRP = 00010
-S_IRWXO = 00007
-S_IROTH = 00004
-S_IWOTH = 00002
-S_IXOTH = 00001
diff --git a/Lib/persist.py b/Lib/persist.py
deleted file mode 100755
index 8f0f164..0000000
--- a/Lib/persist.py
+++ /dev/null
@@ -1,297 +0,0 @@
-# persist.py
-#
-# Implement limited persistence.
-#
-# Simple interface:
-# persist.save() save __main__ module on file (overwrite)
-# persist.load() load __main__ module from file (merge)
-#
-# These use the filename persist.defaultfile, initialized to 'wsrestore.py'.
-#
-# A raw interface also exists:
-# persist.writedict(dict, fp) save dictionary to open file
-# persist.readdict(dict, fp) read (merge) dictionary from open file
-#
-# Internally, the function dump() and a whole bunch of support of functions
-# traverse a graph of objects and print them in a restorable form
-# (which happens to be a Python module).
-#
-# XXX Limitations:
-# - Volatile objects are dumped as strings:
-# - open files, windows etc.
-# - Other 'obscure' objects are dumped as strings:
-# - classes, instances and methods
-# - compiled regular expressions
-# - anything else reasonably obscure (e.g., capabilities)
-# - type objects for obscure objects
-# - It's slow when there are many of lists or dictionaries
-# (This could be fixed if there were a quick way to compute a hash
-# function of any object, even if recursive)
-
-defaultfile = 'wsrestore.py'
-
-def save():
- import __main__
- import os
- # XXX On SYSV, if len(defaultfile) >= 14, this is wrong!
- backup = defaultfile + '~'
- try:
- os.unlink(backup)
- except os.error:
- pass
- try:
- os.rename(defaultfile, backup)
- except os.error:
- pass
- fp = open(defaultfile, 'w')
- writedict(__main__.__dict__, fp)
- fp.close()
-
-def load():
- import __main__
- fp = open(defaultfile, 'r')
- readdict(__main__.__dict__, fp)
-
-def writedict(dict, fp):
- import sys
- savestdout = sys.stdout
- try:
- sys.stdout = fp
- dump(dict) # Writes to sys.stdout
- finally:
- sys.stdout = savestdout
-
-def readdict(dict, fp):
- contents = fp.read()
- globals = {}
- exec(contents, globals)
- top = globals['top']
- for key in top.keys():
- if dict.has_key(key):
- print 'warning:', key, 'not overwritten'
- else:
- dict[key] = top[key]
-
-
-# Function dump(x) prints (on sys.stdout!) a sequence of Python statements
-# that, when executed in an empty environment, will reconstruct the
-# contents of an arbitrary dictionary.
-
-import sys
-
-# Name used for objects dict on output.
-#
-FUNNYNAME = FN = 'A'
-
-# Top-level function. Call with the object you want to dump.
-#
-def dump(x):
- types = {}
- stack = [] # Used by test for recursive objects
- print FN, '= {}'
- topuid = dumpobject(x, types, stack)
- print 'top =', FN, '[', `topuid`, ']'
-
-# Generic function to dump any object.
-#
-dumpswitch = {}
-#
-def dumpobject(x, types, stack):
- typerepr = `type(x)`
- if not types.has_key(typerepr):
- types[typerepr] = {}
- typedict = types[typerepr]
- if dumpswitch.has_key(typerepr):
- return dumpswitch[typerepr](x, typedict, types, stack)
- else:
- return dumpbadvalue(x, typedict, types, stack)
-
-# Generic function to dump unknown values.
-# This assumes that the Python interpreter prints such values as
-# <foo object at xxxxxxxx>.
-# The object will be read back as a string: '<foo object at xxxxxxxx>'.
-# In some cases it may be possible to fix the dump manually;
-# to ease the editing, these cases are labeled with an XXX comment.
-#
-def dumpbadvalue(x, typedict, types, stack):
- xrepr = `x`
- if typedict.has_key(xrepr):
- return typedict[xrepr]
- uid = genuid()
- typedict[xrepr] = uid
- print FN, '[', `uid`, '] =', `xrepr`, '# XXX'
- return uid
-
-# Generic function to dump pure, simple values, except strings
-#
-def dumpvalue(x, typedict, types, stack):
- xrepr = `x`
- if typedict.has_key(xrepr):
- return typedict[xrepr]
- uid = genuid()
- typedict[xrepr] = uid
- print FN, '[', `uid`, '] =', `x`
- return uid
-
-# Functions to dump string objects
-#
-def dumpstring(x, typedict, types, stack):
- # XXX This can break if strings have embedded '\0' bytes
- # XXX because of a bug in the dictionary module
- if typedict.has_key(x):
- return typedict[x]
- uid = genuid()
- typedict[x] = uid
- print FN, '[', `uid`, '] =', `x`
- return uid
-
-# Function to dump type objects
-#
-typeswitch = {}
-class some_class:
- def method(self): pass
-some_instance = some_class()
-#
-def dumptype(x, typedict, types, stack):
- xrepr = `x`
- if typedict.has_key(xrepr):
- return typedict[xrepr]
- uid = genuid()
- typedict[xrepr] = uid
- if typeswitch.has_key(xrepr):
- print FN, '[', `uid`, '] =', typeswitch[xrepr]
- elif x == type(sys):
- print 'import sys'
- print FN, '[', `uid`, '] = type(sys)'
- elif x == type(sys.stderr):
- print 'import sys'
- print FN, '[', `uid`, '] = type(sys.stderr)'
- elif x == type(dumptype):
- print 'def some_function(): pass'
- print FN, '[', `uid`, '] = type(some_function)'
- elif x == type(some_class):
- print 'class some_class: pass'
- print FN, '[', `uid`, '] = type(some_class)'
- elif x == type(some_instance):
- print 'class another_class: pass'
- print 'some_instance = another_class()'
- print FN, '[', `uid`, '] = type(some_instance)'
- elif x == type(some_instance.method):
- print 'class yet_another_class:'
- print ' def method(): pass'
- print 'another_instance = yet_another_class()'
- print FN, '[', `uid`, '] = type(another_instance.method)'
- else:
- # Unknown type
- print FN, '[', `uid`, '] =', `xrepr`, '# XXX'
- return uid
-
-# Initialize the typeswitch
-#
-for x in None, 0, 0.0, '', (), [], {}:
- typeswitch[`type(x)`] = 'type(' + `x` + ')'
-for s in 'type(0)', 'abs', '[].append':
- typeswitch[`type(eval(s))`] = 'type(' + s + ')'
-
-# Dump a tuple object
-#
-def dumptuple(x, typedict, types, stack):
- item_uids = []
- xrepr = ''
- for item in x:
- item_uid = dumpobject(item, types, stack)
- item_uids.append(item_uid)
- xrepr = xrepr + ' ' + item_uid
- del stack[-1:]
- if typedict.has_key(xrepr):
- return typedict[xrepr]
- uid = genuid()
- typedict[xrepr] = uid
- print FN, '[', `uid`, '] = (',
- for item_uid in item_uids:
- print FN, '[', `item_uid`, '],',
- print ')'
- return uid
-
-# Dump a list object
-#
-def dumplist(x, typedict, types, stack):
- # Check for recursion
- for x1, uid1 in stack:
- if x is x1: return uid1
- # Check for occurrence elsewhere in the typedict
- for uid1 in typedict.keys():
- if x is typedict[uid1]: return uid1
- # This uses typedict differently!
- uid = genuid()
- typedict[uid] = x
- print FN, '[', `uid`, '] = []'
- stack.append(x, uid)
- item_uids = []
- for item in x:
- item_uid = dumpobject(item, types, stack)
- item_uids.append(item_uid)
- del stack[-1:]
- for item_uid in item_uids:
- print FN, '[', `uid`, '].append(', FN, '[', `item_uid`, '])'
- return uid
-
-# Dump a dictionary object
-#
-def dumpdict(x, typedict, types, stack):
- # Check for recursion
- for x1, uid1 in stack:
- if x is x1: return uid1
- # Check for occurrence elsewhere in the typedict
- for uid1 in typedict.keys():
- if x is typedict[uid1]: return uid1
- # This uses typedict differently!
- uid = genuid()
- typedict[uid] = x
- print FN, '[', `uid`, '] = {}'
- stack.append(x, uid)
- item_uids = []
- for key in x.keys():
- val_uid = dumpobject(x[key], types, stack)
- item_uids.append(key, val_uid)
- del stack[-1:]
- for key, val_uid in item_uids:
- print FN, '[', `uid`, '][', `key`, '] =',
- print FN, '[', `val_uid`, ']'
- return uid
-
-# Dump a module object
-#
-def dumpmodule(x, typedict, types, stack):
- xrepr = `x`
- if typedict.has_key(xrepr):
- return typedict[xrepr]
- from string import split
- # `x` has the form <module 'foo'>
- name = xrepr[9:-2]
- uid = genuid()
- typedict[xrepr] = uid
- print 'import', name
- print FN, '[', `uid`, '] =', name
- return uid
-
-
-# Initialize dumpswitch, a table of functions to dump various objects,
-# indexed by `type(x)`.
-#
-for x in None, 0, 0.0:
- dumpswitch[`type(x)`] = dumpvalue
-for x, f in ('', dumpstring), (type(0), dumptype), ((), dumptuple), \
- ([], dumplist), ({}, dumpdict), (sys, dumpmodule):
- dumpswitch[`type(x)`] = f
-
-
-# Generate the next unique id; a string consisting of digits.
-# The seed is stored as seed[0].
-#
-seed = [0]
-#
-def genuid():
- x = seed[0]
- seed[0] = seed[0] + 1
- return `x`