Permalink
Browse files

fix unicode encoding. bug spotted by jasondavies, thanks!

  • Loading branch information...
1 parent bdad46a commit 7664366c0167ddfeb0c9c16a6166d8944457bac4 @benoitc benoitc committed Mar 5, 2009
Showing with 17 additions and 8 deletions.
  1. +3 −3 python/couchapp/file_manager.py
  2. +13 −5 python/couchapp/utils/__init__.py
  3. +1 −0 setup.py
@@ -57,7 +57,7 @@ def _popen3(cmd, mode='t', bufsize=0):
import httplib2
from couchdb import Server, ResourceNotFound
-from couchapp.utils import _md5
+from couchapp.utils import _md5, to_bytestring
from couchapp.utils import *
from couchapp.utils.css_parser import CSSParser
@@ -404,7 +404,7 @@ def clone(cls, app_uri, app_dir, verbose=False):
break
if isinstance(content, basestring):
- _ref = _md5(content).hexdigest()
+ _ref = _md5(to_bytestring(content)).hexdigest()
if objects and _ref in objects:
content = objects[_ref]
@@ -702,7 +702,7 @@ def apply_lib(self, funcs, app_dir, verbose=False):
print >>sys.stderr, "Error running !code or !json on function \"%s\": %s" % (k, e)
sys.exit(-1)
if old_v != funcs[k]:
- self.objects[_md5(funcs[k].encode('utf-8')).hexdigest()] = old_v
+ self.objects[_md5(to_bytestring(funcs[k])).hexdigest()] = old_v
def run_code_macros(self, f_string, app_dir, verbose=False):
def rreq(mo):
@@ -26,7 +26,6 @@
import simplejson as json
-
def in_couchapp():
current_path = os.getcwd()
old_dirs = []
@@ -86,6 +85,15 @@ def parse_auth(string):
def get_appname(docid):
return docid.split('_design/')[1]
+
+def to_bytestring(s):
+ if not isinstance(s, basestring):
+ return s
+ if isinstance(s, unicode):
+ return s.encode('utf-8')
+ else:
+ return s
+
def read_file(fname):
f = codecs.open(fname, 'rb', "utf-8")
data = f.read()
@@ -100,10 +108,10 @@ def sign_file(file_path):
return _md5(content).hexdigest()
return ''
-def write_content(filename, content):
- f = open(filename, 'wb')
- f.write(content)
- f.close
+def write_content(fname, content):
+ f = open(fname, 'wb')
+ f.write(to_bytestring(content))
+ f.close()
def write_json(filename, content):
write_content(filename, json.dumps(content))
View
@@ -35,6 +35,7 @@ def process_distribution(self, *args, **kwargs):
""" overide process_distribution to add permissions"""
easy_install.real_process_distribution(self, *args, **kwargs)
import pkg_resources
+ external_path = '/pathto/couchapp/_external'
try:
pkg_resources.require('couchapp')
external_path = pkg_resources.resource_filename("couchapp", "_external")

0 comments on commit 7664366

Please sign in to comment.