From 8bf132976d49c38fdff02163993f2e3cf9c6ec88 Mon Sep 17 00:00:00 2001 From: Gregory Soutade Date: Sat, 19 Mar 2016 17:03:43 +0100 Subject: [PATCH] Read posts with unicode instead binary --- dynastie/generators/index.py | 16 ++++++++++------ dynastie/sites/blog.soutade.fr/_ljdc.xml | 18 ++++++++++++++++++ 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/dynastie/generators/index.py b/dynastie/generators/index.py index 5f342fa..cd87e62 100755 --- a/dynastie/generators/index.py +++ b/dynastie/generators/index.py @@ -25,6 +25,7 @@ import xml from xml.parsers.expat import * import xml.parsers.expat from xml.dom.minidom import parse, parseString +import codecs from dynastie.generators.generator import DynastieGenerator, StrictUTF8Writer from django.db import models from dynastie.generators import markdown2 @@ -202,7 +203,10 @@ class Index(DynastieGenerator): break try: - dom = parseString(code[start:end+11]) + try: + dom = parseString(code[start:end+11]) + except UnicodeEncodeError: + dom = parseString(code[start:end+11].encode('utf-8')) except xml.dom.DOMException as e: self.addError('Error parsing ' + self.filename) break @@ -210,7 +214,6 @@ class Index(DynastieGenerator): res = self.createCode(dom, dom.firstChild) if res: code = code.replace(code[start:end+11], res) - return code def _have_I_right(self, user, post_id): @@ -246,7 +249,8 @@ class Index(DynastieGenerator): if not post: continue new_content = self._loadPostContent(post) if new_content: - text = text.replace('[[' + str(post_id) + ']]', new_content) + p = '[[' + str(post_id) + ']]' + text = text.replace(p, new_content) if internal_posts: return text # HTML replace if not post or (post and post.content_format == Post.CONTENT_HTML): @@ -267,7 +271,7 @@ class Index(DynastieGenerator): if not post: break new_content = self._loadPostContent(post) if new_content: - text = text.replace(text[start:end+18], new_content.encode('utf-8')) + text = text.replace(text[start:end+18], new_content) return text def _loadPostContent(self, post): @@ -287,7 +291,7 @@ class Index(DynastieGenerator): filename = filename2 if not filename in self.hash_posts_content: - f = open(filename, 'rb') + f = codecs.open(filename, 'rb', 'utf-8') post_content = f.read() f.close() self.parent_posts.append(post.id) @@ -498,7 +502,7 @@ class Index(DynastieGenerator): # Remove
 after 
code = code[28:-13] - code = '
' + code + '
' + code = u'
' + unicode(code, 'utf-8') + u'
' return code diff --git a/dynastie/sites/blog.soutade.fr/_ljdc.xml b/dynastie/sites/blog.soutade.fr/_ljdc.xml index dc74c8b..9b09e92 100644 --- a/dynastie/sites/blog.soutade.fr/_ljdc.xml +++ b/dynastie/sites/blog.soutade.fr/_ljdc.xml @@ -1,5 +1,23 @@ + + 138932499327 +
http://thecodinglove.com/post/138932499327/seeing-my-own-code-after-years
+ Seeing my own code after years + http://tclhost.com/nDmdJau.gif +
+ + 137804239758 +
http://thecodinglove.com/post/137804239758/when-you-discover-a-serious-bug-during-a-client
+ When you discover a serious bug during a client... + http://tclhost.com/rzUXIEl.gif +
+ + 137344478111 +
http://thecodinglove.com/post/137344478111/arriving-late-to-an-important-meeting
+ Arriving late to an important meeting + http://tclhost.com/CXW1sJ4.gif +
132019829293
http://thecodinglove.com/post/132019829293/when-a-mad-boss-looking-for-me-enters-the-open