From 7136568a32192acb0e2bfd57acfe2c5357773c24 Mon Sep 17 00:00:00 2001 From: hamada2029 <0000yt+github@gmail.com> Date: Sat, 21 Nov 2015 20:59:09 +0900 Subject: [PATCH] gdata-python3 for non ascii characters. --- src/atom/service.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/atom/service.py b/src/atom/service.py index 246dd1b..bd4bd9e 100755 --- a/src/atom/service.py +++ b/src/atom/service.py @@ -723,17 +723,18 @@ def CalculateDataLength(data): data: object If this is not a string or ElementTree element this funtion will return None. """ + #If non-ascii is in data, Content-Length will be too short. if isinstance(data, str): - return len(data) + return len( data.encode('utf-8') ) elif isinstance(data, list): return None elif ElementTree.iselement(data): - return len(ElementTree.tostring(data)) + return len( ElementTree.tostring(data).encode('utf-8') ) elif hasattr(data, 'read'): # If this is a file-like object, don't try to guess the length. return None else: - return len(str(data)) + return len( str(data).encode('utf-8') ) def deprecation(message):