diff options
Diffstat (limited to 'pipermail/pycrypto/2010q4/000345.html')
-rw-r--r-- | pipermail/pycrypto/2010q4/000345.html | 144 |
1 files changed, 144 insertions, 0 deletions
diff --git a/pipermail/pycrypto/2010q4/000345.html b/pipermail/pycrypto/2010q4/000345.html new file mode 100644 index 0000000..d4e82d5 --- /dev/null +++ b/pipermail/pycrypto/2010q4/000345.html @@ -0,0 +1,144 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN"> +<HTML> + <HEAD> + <TITLE> [pycrypto] Python 3.x vs. Python 2.1 - prep the axe + </TITLE> + <LINK REL="Index" HREF="index.html" > + <LINK REL="made" HREF="mailto:pycrypto%40lists.dlitz.net?Subject=%5Bpycrypto%5D%20Python%203.x%20vs.%20Python%202.1%20-%20prep%20the%20axe&In-Reply-To=4D1972A2.4080305%40gmx.li"> + <META NAME="robots" CONTENT="index,nofollow"> + <META http-equiv="Content-Type" content="text/html; charset=us-ascii"> + <LINK REL="Previous" HREF="000332.html"> + <LINK REL="Next" HREF="000347.html"> + </HEAD> + <BODY BGCOLOR="#ffffff"> + <H1>[pycrypto] Python 3.x vs. Python 2.1 - prep the axe</H1> + <B>Dwayne C. Litzenberger</B> + <A HREF="mailto:pycrypto%40lists.dlitz.net?Subject=%5Bpycrypto%5D%20Python%203.x%20vs.%20Python%202.1%20-%20prep%20the%20axe&In-Reply-To=4D1972A2.4080305%40gmx.li" + TITLE="[pycrypto] Python 3.x vs. Python 2.1 - prep the axe">dlitz at dlitz.net + </A><BR> + <I>Wed Dec 29 00:39:12 CST 2010</I> + <P><UL> + <LI>Previous message: <A HREF="000332.html">[pycrypto] Python 3.x vs. Python 2.1 - stay of execution +</A></li> + <LI>Next message: <A HREF="000347.html">[pycrypto] Python 3.x vs. Python 2.1 - prep the axe +</A></li> + <LI> <B>Messages sorted by:</B> + <a href="date.html#345">[ date ]</a> + <a href="thread.html#345">[ thread ]</a> + <a href="subject.html#345">[ subject ]</a> + <a href="author.html#345">[ author ]</a> + </LI> + </UL> + <HR> +<!--beginarticle--> +<PRE>To do integer division a/b across Python 2.1 through 2.7 (including support for floatdiv), PyCrypto already uses divmod(a,b)[0] IIRC. + +"Thorsten Behrens" <<A HREF="http://lists.dlitz.net/cgi-bin/mailman/listinfo/pycrypto">sbehrens at gmx.li</A>> wrote: + +><i>On 12/23/2010 11:51 PM, Thorsten Behrens wrote: +</I>>><i> On 12/23/2010 9:18 PM, Dwayne C. Litzenberger wrote: +</I>>>><i> Also, down the road, I could be convinced to drop Python 2.1 +</I>><i>support, if I +</I>>>><i> had some concrete examples showing that the result would be +</I>><i>substantially +</I>>>><i> less error-prone, easier to maintain, etc. +</I>>><i> So far, it doesn't look like that's needed. dict.has_key() cannot be +</I>>><i> replaced with "in" for 2.1, but 2to3 seems to handle it fine. +</I>><i> +</I>><i>I've run into a bit of a snag. The / operator in 2.x returns an int, +</I>><i>and +</I>><i>in 3.x it can return a float. This causes an infinite loop in +</I>><i>numbers.py. I can solve it with //, which is supported from 2.2 on, but +</I>><i> +</I>><i>not in 2.1. +</I>><i> +</I>><i>I've pasted the offending code snippet from numbers.py below, in the +</I>><i>form that doesn't cause an infinite loop in 3.x. +</I>><i> +</I>><i>I'm at a bit of a loss here. int(math.floor(a/b)) is not an option due +</I>><i>to the size of the operands - it actually fails on 2.1, and gives +</I>><i>incorrect results on 3.x. That means I am stuck with //. +</I>><i> +</I>><i>I don't know how to "import something" and have "something" show up in +</I>><i>the namespace above. I don't think it works that way, unlike a C +</I>><i>#include. That means I can't just bring the right function in depending +</I>><i> +</I>><i>on version. And even if I could, 2.1 doesn't have the "as" keyword, so +</I>><i>it would never show up with the right numbers.getStrongPrime name +</I>><i>anyway, even _if_ such nested namespace manipulations were supported. +</I>><i>Which I don't think they are. +</I>><i> +</I>><i>I can't just "if sys.version" the offending code snippet, either: 2.1 +</I>><i>will still complain that // is a syntax error. +</I>><i> +</I>><i>We could duplicate the code and have setup.py bring in a special-cased +</I>><i>numbers.py for 2.1. I'm not sure how to do that with setup.py, but +</I>><i>there's got to be a way, even if it's just renaming files as needed. +</I>><i> +</I>><i>But that means duplicating an entire module, which is ugly. And I can't +</I>><i> +</I>><i>guarantee that this is the only occurrence of / that causes issues. In +</I>><i>fact, I'd wager some beer that it likely isn't. +</I>><i> +</I>><i>If you can think of a reasonably clean way of handling the "/" vs. "//" +</I>><i> +</I>><i>issue - or if anyone else can - please share. +</I>><i> +</I>><i>Barring that, I think my message is: If Python 3.x is to be supported +</I>><i>without code duplication, Python 2.1 support may have to go. +</I>><i> +</I>><i>Yours +</I>><i> +</I>><i>Thorsten +</I>><i> +</I>><i> # if e is given make sure that e and X-1 are coprime +</I>><i> # this is not necessarily a strong prime criterion but useful when +</I>><i> # creating them for RSA where the p-1 and q-1 should be coprime to +</I>><i> # the public exponent e +</I>><i> if e and is_possible_prime: +</I>><i> if e & 1: +</I>><i> if GCD (e, X-1) != 1: +</I>><i> is_possible_prime = 0 +</I>><i> else: +</I>><i> # Python 2.1 does not understand //, and 3.x returns a +</I>><i>float on / +</I>><i> # Infinite loop, wheee!!! +</I>><i> if GCD (e, (X-1)//2) != 1: +</I>><i> is_possible_prime = 0 +</I>><i>_______________________________________________ +</I>><i>pycrypto mailing list +</I>><i><A HREF="http://lists.dlitz.net/cgi-bin/mailman/listinfo/pycrypto">pycrypto at lists.dlitz.net</A> +</I>><i><A HREF="http://lists.dlitz.net/cgi-bin/mailman/listinfo/pycrypto">http://lists.dlitz.net/cgi-bin/mailman/listinfo/pycrypto</A> +</I> +-- +Sent from my Android phone with K-9 Mail. Please excuse my brevity. +</PRE> + + + + + + + + + +<!--endarticle--> + <HR> + <P><UL> + <!--threads--> + <LI>Previous message: <A HREF="000332.html">[pycrypto] Python 3.x vs. Python 2.1 - stay of execution +</A></li> + <LI>Next message: <A HREF="000347.html">[pycrypto] Python 3.x vs. Python 2.1 - prep the axe +</A></li> + <LI> <B>Messages sorted by:</B> + <a href="date.html#345">[ date ]</a> + <a href="thread.html#345">[ thread ]</a> + <a href="subject.html#345">[ subject ]</a> + <a href="author.html#345">[ author ]</a> + </LI> + </UL> + +<hr> +<a href="http://lists.dlitz.net/cgi-bin/mailman/listinfo/pycrypto">More information about the pycrypto +mailing list</a><br> +</body></html> |