From bb297adfc57723c2c3e208805419163cb1af4c7d Mon Sep 17 00:00:00 2001 From: Phyks Date: Sun, 3 Aug 2014 12:38:40 +0200 Subject: [PATCH] Further fixes for python3 --- libbmc/backend.py | 8 ++++---- libbmc/config.py | 1 + libbmc/tests/test_backend.py | 9 +++++---- libbmc/tests/test_config.py | 1 + libbmc/tests/test_tools.py | 1 + libbmc/tools.py | 5 ++--- 6 files changed, 14 insertions(+), 11 deletions(-) diff --git a/libbmc/backend.py b/libbmc/backend.py index 3a51b28..ec784ab 100644 --- a/libbmc/backend.py +++ b/libbmc/backend.py @@ -9,7 +9,7 @@ # Phyks # ----------------------------------------------------------------------------- - +from __future__ import unicode_literals import os import re import libbmc.tools as tools @@ -136,7 +136,7 @@ def deleteId(ident): try: with open(config.get("folder")+'index.bib', 'r', encoding='utf-8') \ as fh: - bibtex = BibTexParser(fh.read().decode('utf-8')) + bibtex = BibTexParser(fh.read()) bibtex = bibtex.get_entry_dict() except (IOError, TypeError): tools.warning("Unable to open index file.") @@ -172,7 +172,7 @@ def deleteFile(filename): try: with open(config.get("folder")+'index.bib', 'r', encoding='utf-8') \ as fh: - bibtex = BibTexParser(fh.read().decode('utf-8')) + bibtex = BibTexParser(fh.read()) bibtex = bibtex.get_entry_dict() except (TypeError, IOError): tools.warning("Unable to open index file.") @@ -315,7 +315,7 @@ def updateArXiv(entry): last_bibtex = BibTexParser(fetcher.arXiv2Bib(arxiv_id_no_v)) last_bibtex = last_bibtex.get_entry_dict() - last_bibtex = last_bibtex[last_bibtex.keys()[0]] + last_bibtex = last_bibtex[list(last_bibtex.keys())[0]] if last_bibtex['eprint'] not in ids: return last_bibtex diff --git a/libbmc/config.py b/libbmc/config.py index 8d7f4ce..4ac502c 100644 --- a/libbmc/config.py +++ b/libbmc/config.py @@ -1,3 +1,4 @@ +from __future__ import unicode_literals import os import errno import imp diff --git a/libbmc/tests/test_backend.py b/libbmc/tests/test_backend.py index 7e12074..b9e0635 100644 --- a/libbmc/tests/test_backend.py +++ b/libbmc/tests/test_backend.py @@ -8,6 +8,7 @@ # beer soda in return. # Phyks # ----------------------------------------------------------------------------- +from __future__ import unicode_literals import unittest from libbmc.backend import * from bibtexparser.bparser import BibTexParser @@ -43,7 +44,7 @@ Lattice}, 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]] + self.bibtex_article = self.bibtex_article[list(self.bibtex_article.keys())[0]] self.bibtex_book_string = """ @book{9780521846516, @@ -55,7 +56,7 @@ Lattice}, } """ self.bibtex_book = BibTexParser(self.bibtex_book_string).get_entry_dict() - self.bibtex_book = self.bibtex_book[self.bibtex_book.keys()[0]] + self.bibtex_book = self.bibtex_book[list(self.bibtex_book.keys())[0]] def test_getNewName_article(self): self.assertEqual(getNewName("test.pdf", self.bibtex_article), @@ -99,7 +100,7 @@ Lattice}, open(config.get("folder")+'test.pdf', 'w').close() deleteId(self.bibtex_article['id']) with open(config.get("folder")+'index.bib', 'r') as fh: - self.assertEquals(fh.read().strip(), "") + self.assertEqual(fh.read().strip(), "") self.assertFalse(os.path.isfile(config.get("folder")+'test.pdf')) def test_deleteFile(self): @@ -108,7 +109,7 @@ Lattice}, open(config.get("folder")+'test.pdf', 'w').close() deleteFile(self.bibtex_article['file']) with open(config.get("folder")+'index.bib', 'r') as fh: - self.assertEquals(fh.read().strip(), "") + self.assertEqual(fh.read().strip(), "") self.assertFalse(os.path.isfile(config.get("folder")+'test.pdf')) def test_diffFilesIndex(self): diff --git a/libbmc/tests/test_config.py b/libbmc/tests/test_config.py index dda96d2..b14386c 100644 --- a/libbmc/tests/test_config.py +++ b/libbmc/tests/test_config.py @@ -8,6 +8,7 @@ # beer soda in return. # Phyks # ----------------------------------------------------------------------------- +from __future__ import unicode_literals import unittest import json import os diff --git a/libbmc/tests/test_tools.py b/libbmc/tests/test_tools.py index 752ed39..20023cc 100644 --- a/libbmc/tests/test_tools.py +++ b/libbmc/tests/test_tools.py @@ -8,6 +8,7 @@ # beer soda in return. # Phyks # ----------------------------------------------------------------------------- +from __future__ import unicode_literals import unittest from libbmc.tools import * diff --git a/libbmc/tools.py b/libbmc/tools.py index e735c26..68cd012 100644 --- a/libbmc/tools.py +++ b/libbmc/tools.py @@ -10,7 +10,7 @@ # ----------------------------------------------------------------------------- -from __future__ import print_function +from __future__ import print_function, unicode_literals import os import re import sys @@ -72,8 +72,7 @@ def rawInput(string): def warning(*objs): """Write warnings to stderr""" - printed = [i.encode('utf-8') for i in objs] - print("WARNING: ", *printed, file=sys.stderr) + print("WARNING: ", *objs, file=sys.stderr) def listDir(path):