diff options
author | Guido van Rossum <guido@python.org> | 1993-05-24 14:16:22 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1993-05-24 14:16:22 (GMT) |
commit | d316607732aa70361d5793f6b301b70fab7ca367 (patch) | |
tree | d87376c3075042ebffdbf8bb13416f8055a5fd13 | |
parent | b3f7258f14cb2f3e52236a4087ed82541a173e7b (diff) | |
download | cpython-d316607732aa70361d5793f6b301b70fab7ca367.zip cpython-d316607732aa70361d5793f6b301b70fab7ca367.tar.gz cpython-d316607732aa70361d5793f6b301b70fab7ca367.tar.bz2 |
* ftplib.py: added abort() command (sends oob data).
* Several modules: change "class C(): ..." to "class C: ...".
* flp.py: support for frozen forms.
* Added string.find() which is like index but returns -1 if not found
-rw-r--r-- | Lib/aifc.py | 6 | ||||
-rw-r--r-- | Lib/ftplib.py | 20 | ||||
-rwxr-xr-x | Lib/irix5/cddb.py | 2 | ||||
-rwxr-xr-x | Lib/irix5/cdplayer.py | 2 | ||||
-rwxr-xr-x | Lib/irix5/flp.py | 45 | ||||
-rwxr-xr-x | Lib/irix5/readcd.py | 2 | ||||
-rwxr-xr-x | Lib/persist.py | 6 | ||||
-rwxr-xr-x | Lib/plat-irix5/cddb.py | 2 | ||||
-rwxr-xr-x | Lib/plat-irix5/cdplayer.py | 2 | ||||
-rwxr-xr-x | Lib/plat-irix5/flp.py | 45 | ||||
-rwxr-xr-x | Lib/plat-irix5/readcd.py | 2 | ||||
-rwxr-xr-x | Lib/profile.py | 4 | ||||
-rw-r--r-- | Lib/string.py | 11 | ||||
-rw-r--r-- | Lib/stringold.py | 11 | ||||
-rw-r--r-- | Lib/test/test_types.py | 2 |
15 files changed, 127 insertions, 35 deletions
diff --git a/Lib/aifc.py b/Lib/aifc.py index 4e919d4..bad5e43 100644 --- a/Lib/aifc.py +++ b/Lib/aifc.py @@ -281,7 +281,7 @@ def _write_float(f, x): _write_long(f, himant) _write_long(f, lomant) -class Chunk(): +class Chunk: def init(self, file): self.file = file self.chunkname = self.file.read(4) @@ -322,7 +322,7 @@ class Chunk(): if self.chunksize & 1: dummy = self.read(1) -class Aifc_read(): +class Aifc_read: # Variables used in this class: # # These variables are available to the user though appropriate @@ -568,7 +568,7 @@ class Aifc_read(): name = _read_string(chunk) self._markers.append((id, pos, name)) -class Aifc_write(): +class Aifc_write: # Variables used in this class: # # These variables are user settable through appropriate methods diff --git a/Lib/ftplib.py b/Lib/ftplib.py index 1b4705e..cc96a34 100644 --- a/Lib/ftplib.py +++ b/Lib/ftplib.py @@ -32,6 +32,10 @@ import socket import string +# Magic number from <socket.h> +MSG_OOB = 0x1 # Process data out of band + + # The standard FTP server control port FTP_PORT = 21 @@ -53,6 +57,10 @@ all_errors = (error_reply, error_temp, error_perm, error_proto, \ CRLF = '\r\n' +# Telnet special characters +DM = chr(242) # Data Mark +IP = chr(244) # Interrupt Process + # Next port to be used by makeport(), with PORT_OFFSET added # (This is now only used when the python interpreter doesn't support # the getsockname() method yet) @@ -152,6 +160,18 @@ class FTP: if resp[0] <> '2': raise error_reply, resp + # Abort a file transfer. Uses out-of-band data. + # This does not follow the procedure from the RFC to send Telnet + # IP and Synch; that doesn't seem to work with the servers I've + # tried. Instead, just send the ABOR command as OOB data. + def abort(self): + line = 'ABOR' + CRLF + if self.debugging > 1: print '*put urgent*', `line` + self.sock.send(line, MSG_OOB) + resp = self.getmultiline() + if resp[:3] not in ('426', '226'): + raise error_proto, resp + # Send a command and return the response def sendcmd(self, cmd): self.putcmd(cmd) diff --git a/Lib/irix5/cddb.py b/Lib/irix5/cddb.py index d07a63e..fa03ed3 100755 --- a/Lib/irix5/cddb.py +++ b/Lib/irix5/cddb.py @@ -25,7 +25,7 @@ def _dbid(v): else: return _dbid_map[v] -class Cddb(): +class Cddb: def init(self, tracklist): self.artist = '' self.title = '' diff --git a/Lib/irix5/cdplayer.py b/Lib/irix5/cdplayer.py index deec996..2685a42 100755 --- a/Lib/irix5/cdplayer.py +++ b/Lib/irix5/cdplayer.py @@ -16,7 +16,7 @@ cdplayerrc = '.cdplayerrc' -class Cdplayer(): +class Cdplayer: def init(self, tracklist): import string self.artist = '' diff --git a/Lib/irix5/flp.py b/Lib/irix5/flp.py index 0904efe..ced5598 100755 --- a/Lib/irix5/flp.py +++ b/Lib/irix5/flp.py @@ -59,7 +59,11 @@ def parse_forms(filename): # Internal: see if a cached version of the file exists # MAGIC = '.fdc' +_internal_cache = {} # Used by frozen scripts only def checkcache(filename): + if _internal_cache.has_key(filename): + altforms = _internal_cache[filename] + return _unpack_cache(altforms) import marshal fp, filename = _open_formfile2(filename) fp.close() @@ -80,6 +84,11 @@ def checkcache(filename): return None #print 'flp: valid cache file', cachename altforms = marshal.load(fp) + return _unpack_cache(altforms) + finally: + fp.close() + +def _unpack_cache(altforms): forms = {} for name in altforms.keys(): altobj, altlist = altforms[name] @@ -92,8 +101,6 @@ def checkcache(filename): list.append(nobj) forms[name] = obj, list return forms - finally: - fp.close() def rdlong(fp): s = fp.read(4) @@ -128,6 +135,32 @@ def writecache(filename, forms): return # Never mind fp.write('\0\0\0\0') # Seek back and write MAGIC when done wrlong(fp, getmtime(filename)) + altforms = _pack_cache(forms) + marshal.dump(altforms, fp) + fp.seek(0) + fp.write(MAGIC) + fp.close() + #print 'flp: wrote cache file', cachename + +# +# External: print some statements that set up the internal cache. +# This is for use with the "freeze" script. You should call +# flp.freeze(filename) for all forms used by the script, and collect +# the output on a file in a module file named "frozenforms.py". Then +# in the main program of the script import frozenforms. +# (Don't forget to take this out when using the unfrozen version of +# the script!) +# +def freeze(filename): + forms = parse_forms(filename) + altforms = _pack_cache(forms) + print 'import flp' + print 'flp._internal_cache[', `filename`, '] =', altforms + +# +# Internal: create the data structure to be placed in the cache +# +def _pack_cache(forms): altforms = {} for name in forms.keys(): obj, list = forms[name] @@ -135,12 +168,8 @@ def writecache(filename, forms): altlist = [] for obj in list: altlist.append(obj.__dict__) altforms[name] = altobj, altlist - marshal.dump(altforms, fp) - fp.seek(0) - fp.write(MAGIC) - fp.close() - #print 'flp: wrote cache file', cachename - + return altforms + # # Internal: Locate form file (using PYTHONPATH) and open file # diff --git a/Lib/irix5/readcd.py b/Lib/irix5/readcd.py index 6fe21a7..23c00ed 100755 --- a/Lib/irix5/readcd.py +++ b/Lib/irix5/readcd.py @@ -21,7 +21,7 @@ def _dopnum(self, cb_type, data): if func: func(arg, cb_type, data) -class Readcd(): +class Readcd: def init(self, *arg): if len(arg) == 0: self.player = cd.open() diff --git a/Lib/persist.py b/Lib/persist.py index ae7d58b..8f0f164 100755 --- a/Lib/persist.py +++ b/Lib/persist.py @@ -170,14 +170,14 @@ def dumptype(x, typedict, types, stack): print 'def some_function(): pass' print FN, '[', `uid`, '] = type(some_function)' elif x == type(some_class): - print 'class some_class(): pass' + print 'class some_class: pass' print FN, '[', `uid`, '] = type(some_class)' elif x == type(some_instance): - print 'class another_class(): pass' + 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 'class yet_another_class:' print ' def method(): pass' print 'another_instance = yet_another_class()' print FN, '[', `uid`, '] = type(another_instance.method)' diff --git a/Lib/plat-irix5/cddb.py b/Lib/plat-irix5/cddb.py index d07a63e..fa03ed3 100755 --- a/Lib/plat-irix5/cddb.py +++ b/Lib/plat-irix5/cddb.py @@ -25,7 +25,7 @@ def _dbid(v): else: return _dbid_map[v] -class Cddb(): +class Cddb: def init(self, tracklist): self.artist = '' self.title = '' diff --git a/Lib/plat-irix5/cdplayer.py b/Lib/plat-irix5/cdplayer.py index deec996..2685a42 100755 --- a/Lib/plat-irix5/cdplayer.py +++ b/Lib/plat-irix5/cdplayer.py @@ -16,7 +16,7 @@ cdplayerrc = '.cdplayerrc' -class Cdplayer(): +class Cdplayer: def init(self, tracklist): import string self.artist = '' diff --git a/Lib/plat-irix5/flp.py b/Lib/plat-irix5/flp.py index 0904efe..ced5598 100755 --- a/Lib/plat-irix5/flp.py +++ b/Lib/plat-irix5/flp.py @@ -59,7 +59,11 @@ def parse_forms(filename): # Internal: see if a cached version of the file exists # MAGIC = '.fdc' +_internal_cache = {} # Used by frozen scripts only def checkcache(filename): + if _internal_cache.has_key(filename): + altforms = _internal_cache[filename] + return _unpack_cache(altforms) import marshal fp, filename = _open_formfile2(filename) fp.close() @@ -80,6 +84,11 @@ def checkcache(filename): return None #print 'flp: valid cache file', cachename altforms = marshal.load(fp) + return _unpack_cache(altforms) + finally: + fp.close() + +def _unpack_cache(altforms): forms = {} for name in altforms.keys(): altobj, altlist = altforms[name] @@ -92,8 +101,6 @@ def checkcache(filename): list.append(nobj) forms[name] = obj, list return forms - finally: - fp.close() def rdlong(fp): s = fp.read(4) @@ -128,6 +135,32 @@ def writecache(filename, forms): return # Never mind fp.write('\0\0\0\0') # Seek back and write MAGIC when done wrlong(fp, getmtime(filename)) + altforms = _pack_cache(forms) + marshal.dump(altforms, fp) + fp.seek(0) + fp.write(MAGIC) + fp.close() + #print 'flp: wrote cache file', cachename + +# +# External: print some statements that set up the internal cache. +# This is for use with the "freeze" script. You should call +# flp.freeze(filename) for all forms used by the script, and collect +# the output on a file in a module file named "frozenforms.py". Then +# in the main program of the script import frozenforms. +# (Don't forget to take this out when using the unfrozen version of +# the script!) +# +def freeze(filename): + forms = parse_forms(filename) + altforms = _pack_cache(forms) + print 'import flp' + print 'flp._internal_cache[', `filename`, '] =', altforms + +# +# Internal: create the data structure to be placed in the cache +# +def _pack_cache(forms): altforms = {} for name in forms.keys(): obj, list = forms[name] @@ -135,12 +168,8 @@ def writecache(filename, forms): altlist = [] for obj in list: altlist.append(obj.__dict__) altforms[name] = altobj, altlist - marshal.dump(altforms, fp) - fp.seek(0) - fp.write(MAGIC) - fp.close() - #print 'flp: wrote cache file', cachename - + return altforms + # # Internal: Locate form file (using PYTHONPATH) and open file # diff --git a/Lib/plat-irix5/readcd.py b/Lib/plat-irix5/readcd.py index 6fe21a7..23c00ed 100755 --- a/Lib/plat-irix5/readcd.py +++ b/Lib/plat-irix5/readcd.py @@ -21,7 +21,7 @@ def _dopnum(self, cb_type, data): if func: func(arg, cb_type, data) -class Readcd(): +class Readcd: def init(self, *arg): if len(arg) == 0: self.player = cd.open() diff --git a/Lib/profile.py b/Lib/profile.py index 046b70b..a965f95 100755 --- a/Lib/profile.py +++ b/Lib/profile.py @@ -12,7 +12,7 @@ import string import fpformat import marshal -class Profile(): +class Profile: def init(self): self.timings = {} @@ -212,7 +212,7 @@ def depth(frame): frame = frame.f_back return d -class Stats(): +class Stats: def init(self, file): f = open(file, 'r') self.stats = marshal.load(f) diff --git a/Lib/string.py b/Lib/string.py index e5dc194..8c7d102 100644 --- a/Lib/string.py +++ b/Lib/string.py @@ -93,7 +93,7 @@ def joinfields(words, sep): res = res + (sep + w) return res[len(sep):] -# Find substring +# Find substring, raise exception if not found index_error = 'substring not found in string.index' def index(s, sub, *args): if args: @@ -107,7 +107,14 @@ def index(s, sub, *args): while i < m: if sub == s[i:i+n]: return i i = i+1 - raise index_error, (s, sub) + raise index_error, (s, sub) + args + +# Find substring, return -1 if not found +def find(*args): + try: + return apply(index, args) + except index_error: + return -1 # Convert string to integer atoi_error = 'non-numeric argument to string.atoi' diff --git a/Lib/stringold.py b/Lib/stringold.py index e5dc194..8c7d102 100644 --- a/Lib/stringold.py +++ b/Lib/stringold.py @@ -93,7 +93,7 @@ def joinfields(words, sep): res = res + (sep + w) return res[len(sep):] -# Find substring +# Find substring, raise exception if not found index_error = 'substring not found in string.index' def index(s, sub, *args): if args: @@ -107,7 +107,14 @@ def index(s, sub, *args): while i < m: if sub == s[i:i+n]: return i i = i+1 - raise index_error, (s, sub) + raise index_error, (s, sub) + args + +# Find substring, return -1 if not found +def find(*args): + try: + return apply(index, args) + except index_error: + return -1 # Convert string to integer atoi_error = 'non-numeric argument to string.atoi' diff --git a/Lib/test/test_types.py b/Lib/test/test_types.py index e14fa3a..ec0f841 100644 --- a/Lib/test/test_types.py +++ b/Lib/test/test_types.py @@ -21,7 +21,7 @@ if not (1, 1): raise TestFailed, '(1, 1) is false instead of true' if not [1]: raise TestFailed, '[1] is false instead of true' if not {'x': 1}: raise TestFailed, '{\'x\': 1} is false instead of true' def f(): pass -class C(): pass +class C: pass import sys x = C() if not f: raise TestFailed, 'f is false instead of true' |