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, g...@macports.org wrote:

> Revision
> 125609
> Author
> g...@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-chan...@lists.macosforge.org
> https://lists.macosforge.org/mailman/listinfo/macports-changes

_______________________________________________
macports-dev mailing list
macports-dev@lists.macosforge.org
https://lists.macosforge.org/mailman/listinfo/macports-dev

Reply via email to