]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
* ftplib.py: added abort() command (sends oob data).
authorGuido van Rossum <guido@python.org>
Mon, 24 May 1993 14:16:22 +0000 (14:16 +0000)
committerGuido van Rossum <guido@python.org>
Mon, 24 May 1993 14:16:22 +0000 (14:16 +0000)
* 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

15 files changed:
Lib/aifc.py
Lib/ftplib.py
Lib/irix5/cddb.py
Lib/irix5/cdplayer.py
Lib/irix5/flp.py
Lib/irix5/readcd.py
Lib/persist.py
Lib/plat-irix5/cddb.py
Lib/plat-irix5/cdplayer.py
Lib/plat-irix5/flp.py
Lib/plat-irix5/readcd.py
Lib/profile.py
Lib/string.py
Lib/stringold.py
Lib/test/test_types.py

index 4e919d44f93adfdda0cef7b08f40ba1d6e4150b8..bad5e43a4ae47ba7b6b02952e016108cc97c49a3 100644 (file)
@@ -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
index 1b4705e0c6d29c66d30112a418e723c43a363469..cc96a34bc3ebfd3ee7216e4a3bac36cd57f52e2f 100644 (file)
@@ -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)
index d07a63e2a5c00e156ef6721520abeb24682af234..fa03ed36da93b5804e394b7ccf5d455d6751282a 100755 (executable)
@@ -25,7 +25,7 @@ def _dbid(v):
        else:
                return _dbid_map[v]
 
-class Cddb():
+class Cddb:
        def init(self, tracklist):
                self.artist = ''
                self.title = ''
index deec99611937a738819ef55e1f34871b741c18b1..2685a423edd520ce869ffafffbae30d74a85df56 100755 (executable)
@@ -16,7 +16,7 @@
 
 cdplayerrc = '.cdplayerrc'
 
-class Cdplayer():
+class Cdplayer:
        def init(self, tracklist):
                import string
                self.artist = ''
index 0904efeb85fd9aca35cb0dc33c07102377fbfa5e..ced559836a7785692b0d4dc2fec22a99184acd0e 100755 (executable)
@@ -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
 #
index 6fe21a75472c59a67a1ccbf241669280e450d481..23c00ed074442dfbb251c1b584b7e82811e83935 100755 (executable)
@@ -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()
index ae7d58ba7e2b83fab2741aeb164c39f7c688343c..8f0f164bc696d30692990d817cb52af23c457846 100755 (executable)
@@ -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)'
index d07a63e2a5c00e156ef6721520abeb24682af234..fa03ed36da93b5804e394b7ccf5d455d6751282a 100755 (executable)
@@ -25,7 +25,7 @@ def _dbid(v):
        else:
                return _dbid_map[v]
 
-class Cddb():
+class Cddb:
        def init(self, tracklist):
                self.artist = ''
                self.title = ''
index deec99611937a738819ef55e1f34871b741c18b1..2685a423edd520ce869ffafffbae30d74a85df56 100755 (executable)
@@ -16,7 +16,7 @@
 
 cdplayerrc = '.cdplayerrc'
 
-class Cdplayer():
+class Cdplayer:
        def init(self, tracklist):
                import string
                self.artist = ''
index 0904efeb85fd9aca35cb0dc33c07102377fbfa5e..ced559836a7785692b0d4dc2fec22a99184acd0e 100755 (executable)
@@ -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
 #
index 6fe21a75472c59a67a1ccbf241669280e450d481..23c00ed074442dfbb251c1b584b7e82811e83935 100755 (executable)
@@ -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()
index 046b70b24abc40aa4e63f6788d674339627ed887..a965f952557781a5e56593f6888f766c14c771a5 100755 (executable)
@@ -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)
index e5dc1946bc05edd45d5f4ead13473d9744b44fa8..8c7d102b46409befa8dbade500889571c48d9aab 100644 (file)
@@ -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'
index e5dc1946bc05edd45d5f4ead13473d9744b44fa8..8c7d102b46409befa8dbade500889571c48d9aab 100644 (file)
@@ -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'
index e14fa3abfaedeb6fc39c1ddec1ade96e864fe3c2..ec0f84100f0715dc1fddccf26d24af71651714d9 100644 (file)
@@ -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'