base64.decodestring or xmlrpc (in zope) is truncating strings
Craig Dunigan
faraway at mhtc.net
Wed Feb 21 16:42:12 EST 2001
More information about the Python-list mailing list
Wed Feb 21 16:42:12 EST 2001
- Previous message (by thread): base64.decodestring or xmlrpc (in zope) is truncating strings
- Next message (by thread): How does Subclassing Work?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
"Fredrik Lundh" <fredrik at pythonware.com> wrote in message news:hNVk6.14872$Qb7.2374586 at newsb.telia.net... > Craig Dunigan wrote: > > meta_type = fileObject.meta_type > > if meta_type == 'DTML Document': > > return ("OK", base64.encodestring(fileObject.document_src())) > > elif meta_type == 'File': > > return ("OK", base64.encodestring(fileObject.data)) > > elif meta_type == 'Image': > > return ("OK", base64.encodestring(fileObject.data)) > > else: > > return ("FAIL", 'Unsupported meta_type') > > xmlrpc usage note: instead of encoding and decoding yourself, > you can use the xmlrpclib.Binary wrapper: > if meta_type == 'DTML Document': > return ("OK", xmlrpclib.Binary(fileObject.document_src()) > elif meta_type in ('File', 'Image'): > return ("OK", xmlrpclib.Binary(fileObject.data)) > else: > return ("FAIL", 'Unsupported meta_type') > > the receiver gets a Binary object as well, and can pick out > the original string from the data attribute: > > if retval[0] == "OK": > return retval[1].data > I wasn't familiar with this, I'll look into it. It may resolve the problem. > > the calling object of "getFile" does a write to the local filesystem > > ...which usually means that you forgot to open the file in > binary mode: Often true, but not in this case. And, as I noted in my original post, I can verify that the decoded string isn't the right length before it even gets passed to the calling object. Anyway, the writing object code is: def addFile(self, pathSpec, fileName, contents, timeStamp, title, description): fullFileSpec = os.path.join(pathSpec, fileName) file = open(fullFileSpec, "wb") file.write(contents) file.close() os.utime(fullFileSpec, (int(timeStamp), int(timeStamp))) "contents" ultimately gets passed from the base64 decode, which is wrong before its object ever passes it anywhere. But, thanks for the xmlrpclib tip, I'll test that out.
- Previous message (by thread): base64.decodestring or xmlrpc (in zope) is truncating strings
- Next message (by thread): How does Subclassing Work?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list