Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d316607

Browse files
committed
* 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
1 parent b3f7258 commit d316607

15 files changed

Lines changed: 127 additions & 35 deletions

File tree

Lib/aifc.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ def _write_float(f, x):
281281
_write_long(f, himant)
282282
_write_long(f, lomant)
283283

284-
class Chunk():
284+
class Chunk:
285285
def init(self, file):
286286
self.file = file
287287
self.chunkname = self.file.read(4)
@@ -322,7 +322,7 @@ def skip(self):
322322
if self.chunksize & 1:
323323
dummy = self.read(1)
324324

325-
class Aifc_read():
325+
class Aifc_read:
326326
# Variables used in this class:
327327
#
328328
# These variables are available to the user though appropriate
@@ -568,7 +568,7 @@ def _readmark(self, chunk):
568568
name = _read_string(chunk)
569569
self._markers.append((id, pos, name))
570570

571-
class Aifc_write():
571+
class Aifc_write:
572572
# Variables used in this class:
573573
#
574574
# These variables are user settable through appropriate methods

Lib/ftplib.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@
3232
import string
3333

3434

35+
# Magic number from <socket.h>
36+
MSG_OOB = 0x1 # Process data out of band
37+
38+
3539
# The standard FTP server control port
3640
FTP_PORT = 21
3741

@@ -53,6 +57,10 @@
5357
CRLF = '\r\n'
5458

5559

60+
# Telnet special characters
61+
DM = chr(242) # Data Mark
62+
IP = chr(244) # Interrupt Process
63+
5664
# Next port to be used by makeport(), with PORT_OFFSET added
5765
# (This is now only used when the python interpreter doesn't support
5866
# the getsockname() method yet)
@@ -152,6 +160,18 @@ def voidresp(self):
152160
if resp[0] <> '2':
153161
raise error_reply, resp
154162

163+
# Abort a file transfer. Uses out-of-band data.
164+
# This does not follow the procedure from the RFC to send Telnet
165+
# IP and Synch; that doesn't seem to work with the servers I've
166+
# tried. Instead, just send the ABOR command as OOB data.
167+
def abort(self):
168+
line = 'ABOR' + CRLF
169+
if self.debugging > 1: print '*put urgent*', `line`
170+
self.sock.send(line, MSG_OOB)
171+
resp = self.getmultiline()
172+
if resp[:3] not in ('426', '226'):
173+
raise error_proto, resp
174+
155175
# Send a command and return the response
156176
def sendcmd(self, cmd):
157177
self.putcmd(cmd)

Lib/irix5/cddb.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def _dbid(v):
2525
else:
2626
return _dbid_map[v]
2727

28-
class Cddb():
28+
class Cddb:
2929
def init(self, tracklist):
3030
self.artist = ''
3131
self.title = ''

Lib/irix5/cdplayer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
cdplayerrc = '.cdplayerrc'
1818

19-
class Cdplayer():
19+
class Cdplayer:
2020
def init(self, tracklist):
2121
import string
2222
self.artist = ''

Lib/irix5/flp.py

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,11 @@ def parse_forms(filename):
5959
# Internal: see if a cached version of the file exists
6060
#
6161
MAGIC = '.fdc'
62+
_internal_cache = {} # Used by frozen scripts only
6263
def checkcache(filename):
64+
if _internal_cache.has_key(filename):
65+
altforms = _internal_cache[filename]
66+
return _unpack_cache(altforms)
6367
import marshal
6468
fp, filename = _open_formfile2(filename)
6569
fp.close()
@@ -80,6 +84,11 @@ def checkcache(filename):
8084
return None
8185
#print 'flp: valid cache file', cachename
8286
altforms = marshal.load(fp)
87+
return _unpack_cache(altforms)
88+
finally:
89+
fp.close()
90+
91+
def _unpack_cache(altforms):
8392
forms = {}
8493
for name in altforms.keys():
8594
altobj, altlist = altforms[name]
@@ -92,8 +101,6 @@ def checkcache(filename):
92101
list.append(nobj)
93102
forms[name] = obj, list
94103
return forms
95-
finally:
96-
fp.close()
97104

98105
def rdlong(fp):
99106
s = fp.read(4)
@@ -128,19 +135,41 @@ def writecache(filename, forms):
128135
return # Never mind
129136
fp.write('\0\0\0\0') # Seek back and write MAGIC when done
130137
wrlong(fp, getmtime(filename))
138+
altforms = _pack_cache(forms)
139+
marshal.dump(altforms, fp)
140+
fp.seek(0)
141+
fp.write(MAGIC)
142+
fp.close()
143+
#print 'flp: wrote cache file', cachename
144+
145+
#
146+
# External: print some statements that set up the internal cache.
147+
# This is for use with the "freeze" script. You should call
148+
# flp.freeze(filename) for all forms used by the script, and collect
149+
# the output on a file in a module file named "frozenforms.py". Then
150+
# in the main program of the script import frozenforms.
151+
# (Don't forget to take this out when using the unfrozen version of
152+
# the script!)
153+
#
154+
def freeze(filename):
155+
forms = parse_forms(filename)
156+
altforms = _pack_cache(forms)
157+
print 'import flp'
158+
print 'flp._internal_cache[', `filename`, '] =', altforms
159+
160+
#
161+
# Internal: create the data structure to be placed in the cache
162+
#
163+
def _pack_cache(forms):
131164
altforms = {}
132165
for name in forms.keys():
133166
obj, list = forms[name]
134167
altobj = obj.__dict__
135168
altlist = []
136169
for obj in list: altlist.append(obj.__dict__)
137170
altforms[name] = altobj, altlist
138-
marshal.dump(altforms, fp)
139-
fp.seek(0)
140-
fp.write(MAGIC)
141-
fp.close()
142-
#print 'flp: wrote cache file', cachename
143-
171+
return altforms
172+
144173
#
145174
# Internal: Locate form file (using PYTHONPATH) and open file
146175
#

Lib/irix5/readcd.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def _dopnum(self, cb_type, data):
2121
if func:
2222
func(arg, cb_type, data)
2323

24-
class Readcd():
24+
class Readcd:
2525
def init(self, *arg):
2626
if len(arg) == 0:
2727
self.player = cd.open()

Lib/persist.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,14 +170,14 @@ def dumptype(x, typedict, types, stack):
170170
print 'def some_function(): pass'
171171
print FN, '[', `uid`, '] = type(some_function)'
172172
elif x == type(some_class):
173-
print 'class some_class(): pass'
173+
print 'class some_class: pass'
174174
print FN, '[', `uid`, '] = type(some_class)'
175175
elif x == type(some_instance):
176-
print 'class another_class(): pass'
176+
print 'class another_class: pass'
177177
print 'some_instance = another_class()'
178178
print FN, '[', `uid`, '] = type(some_instance)'
179179
elif x == type(some_instance.method):
180-
print 'class yet_another_class():'
180+
print 'class yet_another_class:'
181181
print ' def method(): pass'
182182
print 'another_instance = yet_another_class()'
183183
print FN, '[', `uid`, '] = type(another_instance.method)'

Lib/plat-irix5/cddb.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def _dbid(v):
2525
else:
2626
return _dbid_map[v]
2727

28-
class Cddb():
28+
class Cddb:
2929
def init(self, tracklist):
3030
self.artist = ''
3131
self.title = ''

Lib/plat-irix5/cdplayer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
cdplayerrc = '.cdplayerrc'
1818

19-
class Cdplayer():
19+
class Cdplayer:
2020
def init(self, tracklist):
2121
import string
2222
self.artist = ''

Lib/plat-irix5/flp.py

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,11 @@ def parse_forms(filename):
5959
# Internal: see if a cached version of the file exists
6060
#
6161
MAGIC = '.fdc'
62+
_internal_cache = {} # Used by frozen scripts only
6263
def checkcache(filename):
64+
if _internal_cache.has_key(filename):
65+
altforms = _internal_cache[filename]
66+
return _unpack_cache(altforms)
6367
import marshal
6468
fp, filename = _open_formfile2(filename)
6569
fp.close()
@@ -80,6 +84,11 @@ def checkcache(filename):
8084
return None
8185
#print 'flp: valid cache file', cachename
8286
altforms = marshal.load(fp)
87+
return _unpack_cache(altforms)
88+
finally:
89+
fp.close()
90+
91+
def _unpack_cache(altforms):
8392
forms = {}
8493
for name in altforms.keys():
8594
altobj, altlist = altforms[name]
@@ -92,8 +101,6 @@ def checkcache(filename):
92101
list.append(nobj)
93102
forms[name] = obj, list
94103
return forms
95-
finally:
96-
fp.close()
97104

98105
def rdlong(fp):
99106
s = fp.read(4)
@@ -128,19 +135,41 @@ def writecache(filename, forms):
128135
return # Never mind
129136
fp.write('\0\0\0\0') # Seek back and write MAGIC when done
130137
wrlong(fp, getmtime(filename))
138+
altforms = _pack_cache(forms)
139+
marshal.dump(altforms, fp)
140+
fp.seek(0)
141+
fp.write(MAGIC)
142+
fp.close()
143+
#print 'flp: wrote cache file', cachename
144+
145+
#
146+
# External: print some statements that set up the internal cache.
147+
# This is for use with the "freeze" script. You should call
148+
# flp.freeze(filename) for all forms used by the script, and collect
149+
# the output on a file in a module file named "frozenforms.py". Then
150+
# in the main program of the script import frozenforms.
151+
# (Don't forget to take this out when using the unfrozen version of
152+
# the script!)
153+
#
154+
def freeze(filename):
155+
forms = parse_forms(filename)
156+
altforms = _pack_cache(forms)
157+
print 'import flp'
158+
print 'flp._internal_cache[', `filename`, '] =', altforms
159+
160+
#
161+
# Internal: create the data structure to be placed in the cache
162+
#
163+
def _pack_cache(forms):
131164
altforms = {}
132165
for name in forms.keys():
133166
obj, list = forms[name]
134167
altobj = obj.__dict__
135168
altlist = []
136169
for obj in list: altlist.append(obj.__dict__)
137170
altforms[name] = altobj, altlist
138-
marshal.dump(altforms, fp)
139-
fp.seek(0)
140-
fp.write(MAGIC)
141-
fp.close()
142-
#print 'flp: wrote cache file', cachename
143-
171+
return altforms
172+
144173
#
145174
# Internal: Locate form file (using PYTHONPATH) and open file
146175
#

0 commit comments

Comments
 (0)