<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<grin/><br>
Not sure Jeremy! I'd never heard of it.<br></blockquote><div><br></div><div>Actually, it looks like 'rU' might be the way to go, not 'Urb'. I've never used it but probably should. :-) </div><div> </div>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
I'll let you know.... I'm assuming it is 2.x compatible?<br></blockquote><div><br></div><div>yes 2.7, not sure about earlier</div><div><br></div><div>--Jeremy</div><div><br></div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<br>
regards<br>
<div><div><br>
On 3 February 2014 12:40, Jeremy Gray <<a href="mailto:jrgray@gmail.com" target="_blank">jrgray@gmail.com</a>> wrote:<br>
> I may not understand the constraints of your situation, but wouldn't<br>
> python's "universal newlines" file-open mode achieve what you want? infile<br>
> = open(filename, 'Urb')<br>
><br>
> --Jeremy<br>
><br>
><br>
> On Mon, Feb 3, 2014 at 5:35 AM, Dave Pawson <<a href="mailto:dave.pawson@gmail.com" target="_blank">dave.pawson@gmail.com</a>> wrote:<br>
>><br>
>> Now resolved.<br>
>> Source plain text is created / modified in either DOS or Linux (np to add<br>
>> Mac)<br>
>><br>
>> read using<br>
>> chunk = unicode(infile.read(chunksize))<br>
>> # replace newline as appropriate<br>
>> chunk=replaceNL(chunk)<br>
>> # Convert to byte string<br>
>> chunk=safe_str(chunk)<br>
>> encrypt and write to disk<br>
>><br>
>><br>
>> # for decrypt<br>
>> #Iterate over file to read into string<br>
>> # replace the individual bytes of the Unicode character (u2022 in my case)<br>
>> # with \n for the local machine<br>
>> retval = replaceBullet(retval)<br>
>><br>
>> code below<br>
>><br>
>> #<br>
>> #Swap \n for \u2022<br>
>> #<br>
>> def replaceNL(str):<br>
>> # If DOS, replace \r\x0A<br>
>> # If Unix, replace \n<br>
>> lineEnd=u'\n'<br>
>> if string.find(str,'\r\x0a'):<br>
>> lineEnd=u'\r\x0A'<br>
>> return string.replace(str,lineEnd,u'\u2022')<br>
>><br>
>> #<br>
>> # Replace bullet by \n<br>
>> #<br>
>> def replaceBullet(bstr):<br>
>> return string.replace(bstr,u'\\u2022',u'\n')<br>
>><br>
>><br>
>><br>
>> def safe_str(obj):<br>
>> """ return the byte string representation of obj """<br>
>> try:<br>
>> return str(obj)<br>
>> except UnicodeEncodeError:<br>
>> # obj is unicode<br>
>> return unicode(obj).encode('unicode_escape')<br>
>><br>
>> HTH others, though it seems messy, it works.<br>
>><br>
>> Dave<br>
>><br>
>><br>
>> On 3 February 2014 09:39, Dave Pawson <<a href="mailto:dave.pawson@gmail.com" target="_blank">dave.pawson@gmail.com</a>> wrote:<br>
>> > I'm having a problem 'sharing' an encrypted file between<br>
>> > MSDOS and Linux.<br>
>> ><br>
>> > so I thought I'd replace \nl in the plain text with a non ASCII<br>
>> > character prior to encryption.<br>
>> ><br>
>> > encryptor = AES.new(key, AES.MODE_CBC, iv)<br>
>> > outfile.write(encryptor.encrypt(chunk))<br>
>> ><br>
>> > gives me<br>
>> ><br>
>> > File "/usr/lib64/python2.7/site-packages/Crypto/Cipher/blockalgo.py",<br>
>> > line 244, in encrypt<br>
>> > return self._cipher.encrypt(plaintext)<br>
>> > UnicodeEncodeError: 'ascii' codec can't encode character u'\u2022' in<br>
>> > position 34: ordinal not in range(128)<br>
>> ><br>
>> ><br>
>> > It would seem I can't use non-ASCII characters, at least with AES, is<br>
>> > this right ?<br>
>> ><br>
>> > If not, how to address it please?<br>
>> ><br>
>> ><br>
>> > regards<br>
>> ><br>
>> ><br>
>> > --<br>
>> > Dave Pawson<br>
>> > XSLT XSL-FO FAQ.<br>
>> > Docbook FAQ.<br>
>> > <a href="http://www.dpawson.co.uk" target="_blank">http://www.dpawson.co.uk</a><br>
>><br>
>><br>
>><br>
>> --<br>
>> Dave Pawson<br>
>> XSLT XSL-FO FAQ.<br>
>> Docbook FAQ.<br>
>> <a href="http://www.dpawson.co.uk" target="_blank">http://www.dpawson.co.uk</a><br>
>> _______________________________________________<br>
>> pycrypto mailing list<br>
>> <a href="mailto:pycrypto@lists.dlitz.net" target="_blank">pycrypto@lists.dlitz.net</a><br>
>> <a href="http://lists.dlitz.net/cgi-bin/mailman/listinfo/pycrypto" target="_blank">http://lists.dlitz.net/cgi-bin/mailman/listinfo/pycrypto</a><br>
><br>
><br>
><br>
> _______________________________________________<br>
> pycrypto mailing list<br>
> <a href="mailto:pycrypto@lists.dlitz.net" target="_blank">pycrypto@lists.dlitz.net</a><br>
> <a href="http://lists.dlitz.net/cgi-bin/mailman/listinfo/pycrypto" target="_blank">http://lists.dlitz.net/cgi-bin/mailman/listinfo/pycrypto</a><br>
><br>
<br>
<br>
<br>
--<br>
Dave Pawson<br>
XSLT XSL-FO FAQ.<br>
Docbook FAQ.<br>
<a href="http://www.dpawson.co.uk" target="_blank">http://www.dpawson.co.uk</a><br>
_______________________________________________<br>
pycrypto mailing list<br>
<a href="mailto:pycrypto@lists.dlitz.net" target="_blank">pycrypto@lists.dlitz.net</a><br>
<a href="http://lists.dlitz.net/cgi-bin/mailman/listinfo/pycrypto" target="_blank">http://lists.dlitz.net/cgi-bin/mailman/listinfo/pycrypto</a><br>
</div></div></blockquote></div><br></div></div>