Re: uuDecode problem
Alex Martelli wrote: I suggest a redesign...! What would you suggest? I have to encode/decode in chunks b/c of the 45 byte limitation. Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Re: uuDecode problem
py wrote: What would you suggest? I have to encode/decode in chunks b/c of the 45 byte limitation. so use 45-byte chunks, instead of one-byte chunks. but why are you using UU encoding in a nonstandard way ? why not just use the uu module to do the chunking for you? the third example on this page might be helpful: http://effbot.org/librarybook/uu.htm (if you don't want the standard begin/end lines, it's probably a better idea to use base64 encoding instead...) /F -- http://mail.python.org/mailman/listinfo/python-list
Re: uuDecode problem
py [EMAIL PROTECTED] wrote: Alex Martelli wrote: I suggest a redesign...! What would you suggest? I have to encode/decode in chunks b/c of the 45 byte limitation. Not quite: s=45*'v' a=binascii.b2a_uu(s) len(a) 62 b=binascii.a2b_uu(a) len(b) 45 b==s True I.e., you can pass to a2b_uu ANY string (and ONLY such a string, not, e.g., a slice or single char of it, as you're trying to do) that's a result of a b2a_uu call; the length limitation applies only the other way. I join /F in suggesting yo use binascii the standard way, but, at any rate, you should at least redesign your decoding strategy so it only calls a2b_uu on strings which are the results of b2a_uu calls. Alex -- http://mail.python.org/mailman/listinfo/python-list
Re: uuDecode problem
Thanks...I think base64 will work just fine...and doesnt seem to have 45 byte limitations, etc. Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Re: uuDecode problem
py [EMAIL PROTECTED] wrote: Thanks...I think base64 will work just fine...and doesnt seem to have 45 byte limitations, etc. Sure, base64 is a better encoding by all criteria, unless you specifically need to use uu encoding for compatibility with other old software. Alex -- http://mail.python.org/mailman/listinfo/python-list
Re: uuDecode problem
py [EMAIL PROTECTED] wrote: ... encoded.append(binascii.b2a_uu(stringToEncode)) binascii.b2a_uu only works for up to 45 bytes at once; but if you were feeding it more than 45 bytes, this should raise a binascii.Error itself. ..any idea why this is happening? Anyone successfully use the uu to encode/decode strings of varying length (even larger strings, more than a few hundred characters)? Definitely not, given the above limit. But I still don't quite understand the exact mechanics of the error you're getting. Alex -- http://mail.python.org/mailman/listinfo/python-list
Re: uuDecode problem
Alex Martelli wrote: binascii.b2a_uu only works for up to 45 bytes at once; but if you were feeding it more than 45 bytes, this should raise a binascii.Error itself. Definitely not, given the above limit. But I still don't quite understand the exact mechanics of the error you're getting. Alex here is an example. def doSomething(): data = aFile.readlines() result = [] for x in data: result.append(encode(x)) return result def printResult(encodedData): encodedData is a list of strings which are uu encoded print decode(encodedData) encode(data): data is a string if len(data) 45: tmp = [] for c in data: tmp.append(binascii.b2a_uu(c)) return ''.join(tmp) else: return binascii.b2a_uu(data) decode(data): data is a list of strings result = [] for val in data if len(val) 45: response = [] for x in val: response.append(binascii.a2b_uu(x)) result.append(response) else: result.append(binascii.a2b_uu(val)) return ''.join(result) ...i would use those functions like data = doSomething() printResult(data) Now i get this... response.append(binascii.a2b_uu(x)) java.lang.StringIndexOutOfBoundsException: java.lang.StringIndexOutOfBoundsExcep tion: String index out of range: 1 So the error is in the decode method .this is in Jython...perhaps Jython doesn't handle binascii.a2b_uu ? or perhaps since the actual data is being encoded in python, then read in and decoded in my jython script..that could be the problem? thanks. -- http://mail.python.org/mailman/listinfo/python-list
Re: uuDecode problem
Note that you can use the 'uu' encoding, which will handle arbitrary-length input and give multi-line uuencoded output, including the 'begin' and 'end' lines: print (\377 * 120).encode(uu) begin 666 data M M end Otherwise, you should use something like encoded = [binascii.b2a_uu(chunk) for chunk in iter(lambda: someFile.read(45), )] to send at most 45 bytes to each call to b2a_uu. Jeff pgpK0PRYLozaB.pgp Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list
Re: uuDecode problem
py [EMAIL PROTECTED] wrote: ... data is a string if len(data) 45: tmp = [] for c in data: tmp.append(binascii.b2a_uu(c)) You can't decode b2a-encoded data character by character, blindly, as you're trying to to here. Each character in the source string can be encoded into multiple characters in the target string, and the slicing, if slicing is needed, must be appropriate. I suggest a redesign...! Alex -- http://mail.python.org/mailman/listinfo/python-list