changeset 3:880904f1071f draft

Add python3 support.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Tue, 21 Aug 2012 21:21:47 +0200
parents 85cbd44f98b1
children c40f0eed70cd
files danboorufs.py
diffstat 1 files changed, 10 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/danboorufs.py
+++ b/danboorufs.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python2
+#!/usr/bin/env python
 # -*- encoding: utf-8 -*-
 #
 #
@@ -23,12 +23,13 @@
 # SOFTWARE.
 
 
-from __future__ import with_statement
+from __future__ import with_statement, unicode_literals
 
 from errno import ENOENT, ENOTDIR
 from sys import argv
 from threading import Lock
 from time import time
+from functools import reduce
 
 import os
 
@@ -61,8 +62,11 @@ class Danbooru(LoggingMixIn, Operations)
             with open(name, 'r') as tagfile:
                 for line in tagfile:
                     for tag in line.split():
-                        tag = tag.decode('UTF-8')
-                        tag = tag.replace('/', u'�') #XXX
+                        try:
+                            tag = tag.decode('UTF-8')
+                        except AttributeError:
+                            pass
+                        tag = tag.replace('/', '�') #XXX
                         tags.append(tag)
                         self.tags.setdefault(tag, []).append(basename)
 
@@ -117,7 +121,8 @@ class Danbooru(LoggingMixIn, Operations)
 
     def readdir(self, path, file_handle):
         if path == '/':
-            return ['.', '..'] + self.tags.keys() + self.files.keys()
+            return (['.', '..'] + list(self.tags.keys())
+                    + list(self.files.keys()))
 
         tags, filename = self._split_path(path)
         if filename: