[125609] users/g5pw/pypi2port/pypi2port.py
Lawrence Velázquez
larryv at macports.org
Mon Sep 22 13:11:48 PDT 2014
With this change, an failure importing either xmlrpclib or urllib2.urlopen will result in the fallback behavior for both. You should use two separate try blocks.
vq
On Sep 22, 2014, at 3:53 PM, g5pw at macports.org wrote:
> Revision
> 125609
> Author
> g5pw at macports.org
> Date
> 2014-09-22 12:53:16 -0700 (Mon, 22 Sep 2014)
> Log Message
>
> Conditionally import urllib
>
> This should work for python3, too, although it is untested because of a missing
> dependency.
> Modified Paths
>
> users/g5pw/pypi2port/pypi2port.py
> Diff
>
> Modified: users/g5pw/pypi2port/pypi2port.py (125608 => 125609)
>
> --- users/g5pw/pypi2port/pypi2port.py 2014-09-22 19:53:11 UTC (rev 125608)
> +++ users/g5pw/pypi2port/pypi2port.py 2014-09-22 19:53:16 UTC (rev 125609)
> @@ -11,14 +11,15 @@
> import argparse
> import sys
> import os
> -import urllib2
> import hashlib
> import zipfile
> import progressbar as pb
> try:
> import xmlrpclib
> + from urllib2 import urlopen
> except ImportError:
> import xmlrpc.client as xmlrpclib
> + from urllib.request import urlopen
> import textwrap
> import string
> import shutil
> @@ -77,7 +78,7 @@
> url = dict['url']
> file_name = src_dir + '/' + dict['filename']
>
> - u = urllib2.urlopen(url)
> + u = urlopen(url)
> with open(file_name, 'wb') as f:
> meta = u.info()
> file_size = int(meta.getheaders("Content-Length")[0])
> _______________________________________________
> macports-changes mailing list
> macports-changes at lists.macosforge.org
> https://lists.macosforge.org/mailman/listinfo/macports-changes
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/macports-dev/attachments/20140922/afafd39a/attachment.html>
More information about the macports-dev
mailing list