quixote upload.py,1.5,1.6

Anton Benard <abenard-fVcApmY9cLvQ3/1i3zOLAti2O/[email protected]>
Newsgroups gmane.comp.web.quixote.cvs
Message-ID <[email protected]>
Update of /home/cvs/quixote
In directory hewson:/tmp/cvs-serv1847

Modified Files:
	upload.py 
Log Message:
- Fixed .__str__() to not blow up if .orig_filename is None.
- Added .get_size() to Upload() class.
- Check for not filename rather than if filename is None to reduce the chance
  of getting an empty upload.


Index: upload.py
===================================================================
RCS file: /home/cvs/quixote/upload.py,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- upload.py	18 Oct 2002 18:21:55 -0000	1.5
+++ upload.py	7 Nov 2002 17:47:47 -0000	1.6
@@ -142,7 +142,7 @@
         self.tmp_filename = None
 
     def __str__ (self):
-        return self.orig_filename
+        return str(self.orig_filename)
 
     def __repr__ (self):
         return "<%s at %x: %s>" % (self.__class__.__name__, id(self), self)
@@ -159,6 +159,13 @@
         self.tmp_filename = filename
         return done
 
+    def get_size (self):
+        """get_size() : int
+        Return the size of the file, measured in bytes, or None if
+        the file doesn't exist.
+        """
+        stats = os.stat(self.tmp_filename)
+        return stats.st_size
 
 class CountingFile:
     """A file-like object that records the number of bytes read
@@ -292,8 +299,7 @@
                 raise RequestError("expected Content-Disposition header "
                                    "in body sub-part")
             (name, filename) = self.parse_content_disposition(cdisp)
-
-            if filename is not None:
+            if filename:
                 done = self.handle_upload(name, filename, file, boundary)
             else:
                 done = self.handle_regular_var(name, file, boundary)
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.