From 35541a43e60316906aed91c1dd9ea9ce8ebdc881 Mon Sep 17 00:00:00 2001 From: Phyks Date: Sun, 3 Aug 2014 00:09:07 +0200 Subject: [PATCH] Fix imports + subparsers in python3 --- bmc.py | 3 ++- libbmc/fetcher.py | 12 ++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/bmc.py b/bmc.py index 90fe6a9..a3007a7 100755 --- a/bmc.py +++ b/bmc.py @@ -433,7 +433,8 @@ def update(entry): if __name__ == '__main__': parser = argparse.ArgumentParser(description="A bibliography " + "management tool.") - subparsers = parser.add_subparsers(help="sub-command help") + subparsers = parser.add_subparsers(help="sub-command help", dest='parser') + subparsers.required = True # Fix for Python 3.3.5 parser_download = subparsers.add_parser('download', help="download help") parser_download.add_argument('-t', '--type', default=None, diff --git a/libbmc/fetcher.py b/libbmc/fetcher.py index 19e2566..8228890 100644 --- a/libbmc/fetcher.py +++ b/libbmc/fetcher.py @@ -24,12 +24,13 @@ except ImportError: # Fall back to Python 2's urllib2 from urllib2 import urlopen, URLError import arxiv2bib as arxiv_metadata -import tools +import libbmc.tools from bibtexparser.bparser import BibTexParser -from config import Config +from libbmc.config import Config config = Config() +default_socket = socket.socket def download(url): @@ -51,13 +52,16 @@ def download(url): except ValueError: port = None socks.set_default_proxy(proxy_type, proxy, port) - else: # TODO : Reset if proxy is empty + socket.socket = socks.socksocket + elif proxy == '': + socket.socket = default_socket + else: try: proxy, port = proxy.split(':') except ValueError: port = None socks.set_default_proxy(socks.HTTP, proxy, port) - socket.socket = socks.socksocket + socket.socket = socks.socksocket try: r = urlopen(url) size = int(r.headers.getheader('content-length').strip())