--- /dev/null
+import sys
+
+# Compatability definitions
+PY2 = sys.version_info[0] < 3
+if PY2:
+ # disable flake8 checks on python 3
+ string_type = basestring # noqa
+ unicode_type = unicode # noqa
+else:
+ string_type = str
+ unicode_type = str
from __future__ import print_function
import os
-from ConfigParser import RawConfigParser
+try:
+ from ConfigParser import RawConfigParser
+except ImportError: # py3
+ from configparser import RawConfigParser
__all__ = ['get_config']
from sqlobject import SQLObject, StringCol, UnicodeCol, IntCol, BoolCol, \
ForeignKey, DateCol, DatabaseIndex, RelatedJoin, \
connectionForURI, sqlhub, SQLObjectNotFound, dberrors
+from .compat import string_type
from .config import get_config
__all__ = ['Author', 'Book', 'Extension', 'Genre', 'Language',
if connection.dbName == 'sqlite':
def lower(s):
- if isinstance(s, basestring):
+ if isinstance(s, string_type):
return s.lower()
return s
Select(Book.q.file, Book.q.archive == archive))):
files.add(file)
for line in inp:
+ line = line.decode('utf-8')
parts = split_line(line)
file = parts[5]
if file not in files:
from sqlobject.sqlbuilder import CONCAT
from m_lib.defenc import default_encoding
+from m_librarian.compat import string_type
from m_librarian.config import get_config
from m_librarian.db import Author, Book, Extension, Genre, Language, open_db
from m_librarian.download import download
for column in columns:
value = getattr(args, column)
if value:
- if isinstance(value, basestring):
+ if isinstance(value, string_type):
value = unicode(value, default_encoding)
values[column] = value
return values
def _guess_case_sensitivity(values):
for value in values.values():
- if isinstance(value, basestring) and not value.islower():
+ if isinstance(value, string_type) and not value.islower():
return True
return False