File tree Expand file tree Collapse file tree 2 files changed +14
-5
lines changed Expand file tree Collapse file tree 2 files changed +14
-5
lines changed Original file line number Diff line number Diff line change @@ -36,7 +36,7 @@ def should_index(self):
3636 return True
3737
3838 def get_data (self ):
39- return ZimBlob (self .content . encode ( 'UTF-8' ) )
39+ return ZimBlob (self .content )
4040
4141# Create a ZimTestArticle article
4242
Original file line number Diff line number Diff line change @@ -18,9 +18,14 @@ from collections import defaultdict
1818cdef class ZimBlob:
1919 cdef Blob* c_blob
2020
21- def __init__ (self , bytes content ):
22- ref_content = content
23- self .c_blob = new Blob(< char * > ref_content, len (content))
21+ def __init__ (self , content ):
22+
23+ if isinstance (content, str ):
24+ ref_content = content.encode(' UTF-8' )
25+ else :
26+ ref_content = content
27+
28+ self .c_blob = new Blob(< char * > ref_content, len (ref_content))
2429
2530 def __dealloc__ (self ):
2631 if self .c_blob != NULL :
@@ -71,7 +76,11 @@ cdef class ZimArticle:
7176 @property
7277 def content (self ):
7378 blob = self .c_article.getData()
74- return blob.data()[:blob.size()]
79+ content = blob.data()[:blob.size()]
80+ try :
81+ return content.decode(' UTF-8' )
82+ except UnicodeDecodeError :
83+ return content
7584
7685 # This changes with implementation
7786 @property
You can’t perform that action at this time.
0 commit comments