Re: Some more Python 3: (was Re: rawhide report: 20100507 changes)

2010-05-07 Thread David Malcolm
On Fri, 2010-05-07 at 11:08 -0700, Kyle VanderBeek wrote:
> On Fri, May 7, 2010 at 9:05 AM, David Malcolm 
> wrote:
> On Fri, 2010-05-07 at 12:25 +, Rawhide Report wrote:
> 
> Three more python 3 subpackages in today's "rawhide" heading
> for F14 -
> I've gone ahead and added these to the wiki here:
> 
> https://fedoraproject.org/wiki/Features/Python3F13#Python_3_already_in_Fedora
> 
> Are we missing anything?
> 
> 
> 
> Crud, this probably means I need to either finish my pure-python MySQL
> driver, or work on making MySQLdb run with python3. :-)  If you want

:)

>  to update the upstream status for MySQLdb, we simply haven't started
> porting it.

You're probably in a better position to give accurate status on that
page (it's a wiki, feel free to edit)

I actually had a go at porting MySQLdb to py3k, I'll see if I can find
my source tree.

Dave


___
python-devel mailing list
[email protected]
https://admin.fedoraproject.org/mailman/listinfo/python-devel


Python 3 MySQLdb port (was Re: Some more Python 3: (was Re: rawhide report: 20100507 changes))

2010-05-07 Thread David Malcolm
On Fri, 2010-05-07 at 14:36 -0400, David Malcolm wrote:
> On Fri, 2010-05-07 at 11:08 -0700, Kyle VanderBeek wrote:
> > On Fri, May 7, 2010 at 9:05 AM, David Malcolm 
> > wrote:
> > On Fri, 2010-05-07 at 12:25 +, Rawhide Report wrote:
> > 
> > Three more python 3 subpackages in today's "rawhide" heading
> > for F14 -
> > I've gone ahead and added these to the wiki here:
> > 
> > https://fedoraproject.org/wiki/Features/Python3F13#Python_3_already_in_Fedora
> > 
> > Are we missing anything?
> > 
> > 
> > 
> > Crud, this probably means I need to either finish my pure-python MySQL
> > driver, or work on making MySQLdb run with python3. :-)  If you want
> 
> :)
> 
> >  to update the upstream status for MySQLdb, we simply haven't started
> > porting it.
> 
> You're probably in a better position to give accurate status on that
> page (it's a wiki, feel free to edit)
> 
> I actually had a go at porting MySQLdb to py3k, I'll see if I can find
> my source tree.

In the hope that's its helpful, attached is a messy, mostly-compiling
port of the code.

It's from SVN r633; this was an experiment I did back in November 2009.

The .py parts are from 2to3 and are python 3 only, but ought to be
regeneratable via 2to3.

The .c parts are from my 2to3c code and some manual hacking.  The aim is
that they're compilable against both 2 and 3 from the same sources.

(I may be misremembering all this)

It may well not fully compile, and I'm definitely playing fast-and-loose
with things like encodings.  IIRC I was able to get it to compile, and
to at least connect to MySQL from python3, but I'm definitely getting
things wrong with anything non-ASCII, I'm afraid.

(I'm assuming an invocation of 2to3 upon the .py code, and the use of
the "distribute" fork of setuptools; I'm using python 3.1.1 FWIW)

Hope this is helpful; I'd appreciate a shout-out to Red Hat if it does
help.

Dave
Index: MySQLdb/ez_setup.py
===
--- MySQLdb/ez_setup.py	(revision 633)
+++ MySQLdb/ez_setup.py	(working copy)
@@ -62,10 +62,10 @@
 if egg_name in md5_data:
 digest = md5(data).hexdigest()
 if digest != md5_data[egg_name]:
-print >>sys.stderr, (
+print((
 "md5 validation of %s failed!  (Possible download problem?)"
 % egg_name
-)
+), file=sys.stderr)
 sys.exit(2)
 return data
 
@@ -95,14 +95,14 @@
 return do_download()   
 try:
 pkg_resources.require("setuptools>="+version); return
-except pkg_resources.VersionConflict, e:
+except pkg_resources.VersionConflict as e:
 if was_imported:
-print >>sys.stderr, (
+print((
 "The required version of setuptools (>=%s) is not available, and\n"
 "can't be installed while this script is running. Please install\n"
 " a more recent version first, using 'easy_install -U setuptools'."
 "\n\n(Currently using %r)"
-) % (version, e.args[0])
+) % (version, e.args[0]), file=sys.stderr)
 sys.exit(2)
 else:
 del pkg_resources, sys.modules['pkg_resources']# reload ok
@@ -121,7 +121,7 @@
 with a '/'). `to_dir` is the directory where the egg will be downloaded.
 `delay` is the number of seconds to pause before an actual download attempt.
 """
-import urllib2, shutil
+import urllib.request, urllib.error, urllib.parse, shutil
 egg_name = "setuptools-%s-py%s.egg" % (version,sys.version[:3])
 url = download_base + egg_name
 saveto = os.path.join(to_dir, egg_name)
@@ -147,7 +147,7 @@
 version, download_base, delay, url
 ); from time import sleep; sleep(delay)
 log.warn("Downloading %s", url)
-src = urllib2.urlopen(url)
+src = urllib.request.urlopen(url)
 # Read/write all in one block, so we don't create a corrupt file
 # if the download is interrupted.
 data = _validate_md5(egg_name, src.read())
@@ -208,10 +208,10 @@
 os.unlink(egg)
 else:
 if setuptools.__version__ == '0.0.1':
-print >>sys.stderr, (
+print((
 "You have an obsolete version of setuptools installed.  Please\n"
 "remove it from your system entirely before rerunning this script."
-)
+), file=sys.stderr)
 sys.exit(2)
 
 req = "setuptools>="+version
@@ -230,8 +230,8 @@
 from setuptools.command.easy_install import main
 main(argv)
 else:
-print "Setuptools version",version,"or greater has been installed."
-print '(Run "ez_setup.py -U setuptools" to reinstall or upgrade.)'
+print("Setuptools version",version,"or greater has been installed.")
+