From 7fda1bd5fa208b3ac3ec37a601fc9892ee729e85 Mon Sep 17 00:00:00 2001 From: Phyks Date: Sun, 3 Aug 2014 00:17:01 +0200 Subject: [PATCH] Flake8 fixes --- libbmc/__init__.py | 2 -- libbmc/backend.py | 4 ++-- libbmc/config.py | 2 +- libbmc/fetcher.py | 15 ++++++++------- libbmc/tests/test_backend.py | 22 +++++++++++----------- 5 files changed, 22 insertions(+), 23 deletions(-) diff --git a/libbmc/__init__.py b/libbmc/__init__.py index 13c7609..aec8850 100644 --- a/libbmc/__init__.py +++ b/libbmc/__init__.py @@ -1,4 +1,2 @@ #!/usr/bin/env python2 # -*- coding: utf-8 -*- - - diff --git a/libbmc/backend.py b/libbmc/backend.py index e1587dd..3a51b28 100644 --- a/libbmc/backend.py +++ b/libbmc/backend.py @@ -12,8 +12,8 @@ import os import re -import libbmc.tools -import libbmc.fetcher +import libbmc.tools as tools +import libbmc.fetcher as fetcher from bibtexparser.bparser import BibTexParser from libbmc.config import Config from codecs import open diff --git a/libbmc/config.py b/libbmc/config.py index b12e8ed..8d7f4ce 100644 --- a/libbmc/config.py +++ b/libbmc/config.py @@ -4,7 +4,7 @@ import imp import inspect import json import sys -import libbmc.tools +import libbmc.tools as tools # List of available options (in ~/.config/bmc/bmc.json file): # * folder : folder in which papers are stored diff --git a/libbmc/fetcher.py b/libbmc/fetcher.py index 8228890..e7457d0 100644 --- a/libbmc/fetcher.py +++ b/libbmc/fetcher.py @@ -18,13 +18,13 @@ import subprocess import sys try: # For Python 3.0 and later - from urllib.request import urlopen + from urllib.request import urlopen, Request from urllib.error import URLError except ImportError: # Fall back to Python 2's urllib2 - from urllib2 import urlopen, URLError + from urllib2 import urlopen, Request, URLError import arxiv2bib as arxiv_metadata -import libbmc.tools +import libbmc.tools as tools from bibtexparser.bparser import BibTexParser from libbmc.config import Config @@ -230,14 +230,15 @@ def doi2Bib(doi): """ url = "http://dx.doi.org/" + doi headers = {"accept": "application/x-bibtex"} + req = Request(url, headers=headers) try: - r = requests.get(url, headers=headers) + r = urlopen(req) - if r.headers['content-type'] == 'application/x-bibtex': - return r.text + if r.headers.getheader('content-type') == 'application/x-bibtex': + return r.read() else: return '' - except requests.exceptions.ConnectionError: + except URLError: tools.warning('Unable to contact remote server to get the bibtex ' + 'entry for doi '+doi) return '' diff --git a/libbmc/tests/test_backend.py b/libbmc/tests/test_backend.py index 3ef98e5..7e12074 100644 --- a/libbmc/tests/test_backend.py +++ b/libbmc/tests/test_backend.py @@ -21,7 +21,7 @@ class TestFetcher(unittest.TestCase): config.set("folder", tempfile.mkdtemp()+"/") self.bibtex_article_string = """ @article{1303.3130v1, - abstract={We study the role of the dipolar interaction, correctly accounting for the + abstract={We study the role of the dipolar interaction, correctly accounting for the Dipolar-Induced Resonance (DIR), in a quasi-one-dimensional system of ultracold bosons. We first show how the DIR affects the lowest-energy states of two particles in a harmonic trap. Then, we consider a deep optical lattice loaded @@ -30,17 +30,17 @@ atom-dimer extended Bose-Hubbard model. We analyze the impact of the DIR on the phase diagram at T=0 by exact diagonalization of a small-sized system. In particular, the resonance strongly modifies the range of parameters for which a mass density wave should occur.}, - archiveprefix={arXiv}, - author={N. Bartolo and D. J. Papoular and L. Barbiero and C. Menotti and A. Recati}, - eprint={1303.3130v1}, - file={%sN_Bartolo_A_Recati-j-2013.pdf}, - link={http://arxiv.org/abs/1303.3130v1}, - month={Mar}, - primaryclass={cond-mat.quant-gas}, - tag={}, - title={Dipolar-Induced Resonance for Ultracold Bosons in a Quasi-1D Optical + archiveprefix={arXiv}, + author={N. Bartolo and D. J. Papoular and L. Barbiero and C. Menotti and A. Recati}, + eprint={1303.3130v1}, + file={%sN_Bartolo_A_Recati-j-2013.pdf}, + link={http://arxiv.org/abs/1303.3130v1}, + month={Mar}, + primaryclass={cond-mat.quant-gas}, + tag={}, + title={Dipolar-Induced Resonance for Ultracold Bosons in a Quasi-1D Optical Lattice}, - year={2013}, + year={2013}, }""" % config.get("folder") self.bibtex_article = BibTexParser(self.bibtex_article_string).get_entry_dict() self.bibtex_article = self.bibtex_article[self.bibtex_article.keys()[0]]