[Python-checkins] CVS: python/dist/src/Lib uu.py,1.17,1.18

Barry Warsaw bwarsaw@users.sourceforge.net
2001年8月17日 12:59:37 -0700


Update of /cvsroot/python/python/dist/src/Lib
In directory usw-pr-cvs1:/tmp/cvs-serv14299
Modified Files:
	uu.py 
Log Message:
decode(): Raise a uu.Error if no out_file is given but the file
 specified in the uu header already exists. No additional
 workaround is provided since out_file=pathname is a deprecated
 interface, so it is better to simply pass a file-like object into
 out_file anyway. This closes SF bug #438083.
Use isinstance() tests instead of type comparisons.
Index: uu.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/uu.py,v
retrieving revision 1.17
retrieving revision 1.18
diff -C2 -d -r1.17 -r1.18
*** uu.py	2001年07月11日 04:08:49	1.17
--- uu.py	2001年08月17日 19:59:34	1.18
***************
*** 34,37 ****
--- 34,38 ----
 import os
 import sys
+ from types import StringType
 
 __all__ = ["Error", "encode", "decode"]
***************
*** 47,51 ****
 if in_file == '-':
 in_file = sys.stdin
! elif type(in_file) == type(''):
 if name is None:
 name = os.path.basename(in_file)
--- 48,52 ----
 if in_file == '-':
 in_file = sys.stdin
! elif isinstance(in_file, StringType):
 if name is None:
 name = os.path.basename(in_file)
***************
*** 61,65 ****
 if out_file == '-':
 out_file = sys.stdout
! elif type(out_file) == type(''):
 out_file = open(out_file, 'w')
 #
--- 62,66 ----
 if out_file == '-':
 out_file = sys.stdout
! elif isinstance(out_file, StringType):
 out_file = open(out_file, 'w')
 #
***************
*** 81,85 ****
 
 
! def decode(in_file, out_file=None, mode=None):
 """Decode uuencoded file"""
 #
--- 82,86 ----
 
 
! def decode(in_file, out_file=None, mode=None, quiet=0):
 """Decode uuencoded file"""
 #
***************
*** 88,92 ****
 if in_file == '-':
 in_file = sys.stdin
! elif type(in_file) == type(''):
 in_file = open(in_file)
 #
--- 89,93 ----
 if in_file == '-':
 in_file = sys.stdin
! elif isinstance(in_file, StringType):
 in_file = open(in_file)
 #
***************
*** 108,111 ****
--- 109,114 ----
 if out_file is None:
 out_file = hdrfields[2].rstrip()
+ if os.path.exists(out_file):
+ raise Error, 'Cannot overwrite existing file: %s' % out_file
 if mode is None:
 mode = int(hdrfields[1], 8)
***************
*** 115,119 ****
 if out_file == '-':
 out_file = sys.stdout
! elif type(out_file) == type(''):
 fp = open(out_file, 'wb')
 try:
--- 118,122 ----
 if out_file == '-':
 out_file = sys.stdout
! elif isinstance(out_file, StringType):
 fp = open(out_file, 'wb')
 try:
***************
*** 126,130 ****
 #
 s = in_file.readline()
! while s and s != 'end\n':
 try:
 data = binascii.a2b_uu(s)
--- 129,133 ----
 #
 s = in_file.readline()
! while s and s.strip() != 'end':
 try:
 data = binascii.a2b_uu(s)
***************
*** 133,137 ****
 nbytes = (((ord(s[0])-32) & 63) * 4 + 5) / 3
 data = binascii.a2b_uu(s[:nbytes])
! sys.stderr.write("Warning: %s\n" % str(v))
 out_file.write(data)
 s = in_file.readline()
--- 136,141 ----
 nbytes = (((ord(s[0])-32) & 63) * 4 + 5) / 3
 data = binascii.a2b_uu(s[:nbytes])
! if not quiet:
! sys.stderr.write("Warning: %s\n" % str(v))
 out_file.write(data)
 s = in_file.readline()
***************
*** 169,173 ****
 if dopt:
 if topt:
! if type(output) == type(''):
 output = open(output, 'w')
 else:
--- 173,177 ----
 if dopt:
 if topt:
! if isinstance(output, StringType):
 output = open(output, 'w')
 else:
***************
*** 177,181 ****
 else:
 if topt:
! if type(input) == type(''):
 input = open(input, 'r')
 else:
--- 181,185 ----
 else:
 if topt:
! if isinstance(input, StringType):
 input = open(input, 'r')
 else:

AltStyle によって変換されたページ (->オリジナル) /