[Python-Dev] Why doesn't the uu module give you the filename?
Daniel Berlin
dberlin@dberlin.org
Sun, 27 Apr 2003 11:49:02 -0400
While it's simple enough to get the uu module to uudecode a string
(using StringIO), it's impossible to get it to handle you the filename
the uuencoded thing specifies.
IE given
begin 644 a.ii.gz
<whatever>
end
Their is no way to get the decode function to tell you the thing is
named a.ii.gz.
Of course, it uses this filename itself in creating an output file if
you don't specify one. It just won't tell *you* what the filename is.
I could just give it no output file, and let it create it, then
determine the name of the file it created, but this seems like a very
large kludge.
Besides, I am decoding from/to a string, in memory. I don't want to
start have it write things to the disk for no reason.
The context of all of this is that I have a program that is converting
text that possibly contains uuencoded attachments into a bunch of SQL
statements to insert into a database (It's converting a GNATS bug
database to a Bugzilla one. It's a rewrite of an incredibly ugly, slow,
barely functional perl script that spews errors at random and leaks
memory for no reason :P).
I had to cut/paste the decode function from the uu module into a new
module and make it return the filename, just so that i could get access
to it.
This seems a bit silly.
The decode function has no return value right now, so giving it one
shouldn't break existing applications (since none of them should be
expecting it to return anything).
I believe it should return the filename specified in the begin line.
As an added bonus, it would be even nicer if it also returned the start
and end position of the decoded portion inside the input text. that
way if one wants to replace the entire uuencoded text with something
like, say, "See bug attachments for <filename>", you can do it easily.
:P
As i said, i've got a version of uu.decode that does all of this, i'll
happily submit it as a patch if people agree i'm right.
--Dan