From 33295180a918fcd420428d9aa2fb737b864cacaf Mon Sep 17 00:00:00 2001 From: Tim Abbott Date: Sun, 1 Nov 2015 08:15:17 -0800 Subject: [PATCH] Apply Python 3 futurize transform libmodernize.fixes.fix_unicode_type. --- api/zulip/__init__.py | 4 +++- zerver/lib/ccache.py | 2 +- zerver/views/messages.py | 5 +++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/api/zulip/__init__.py b/api/zulip/__init__.py index 40bbc86092..f87117cc5b 100644 --- a/api/zulip/__init__.py +++ b/api/zulip/__init__.py @@ -21,6 +21,7 @@ # THE SOFTWARE. from __future__ import print_function +from __future__ import absolute_import import simplejson import requests import time @@ -36,6 +37,7 @@ from distutils.version import LooseVersion from six.moves.configparser import SafeConfigParser import logging +import six __version__ = "0.2.4" @@ -244,7 +246,7 @@ class Client(object): request = {} for (key, val) in orig_request.iteritems(): - if not (isinstance(val, str) or isinstance(val, unicode)): + if not (isinstance(val, str) or isinstance(val, six.text_type)): request[key] = simplejson.dumps(val) else: request[key] = val diff --git a/zerver/lib/ccache.py b/zerver/lib/ccache.py index 0ea50d135c..850e88a825 100644 --- a/zerver/lib/ccache.py +++ b/zerver/lib/ccache.py @@ -83,7 +83,7 @@ def der_encode_uint32(val): return der_encode_integer(val) def der_encode_string(val): - if not isinstance(val, unicode): + if not isinstance(val, six.text_type): raise TypeError("unicode") return der_encode_tlv(0x1b, val.encode("utf-8")) diff --git a/zerver/views/messages.py b/zerver/views/messages.py index 0b8b9e1c8f..d423ac2403 100644 --- a/zerver/views/messages.py +++ b/zerver/views/messages.py @@ -39,6 +39,7 @@ import ujson from zerver.lib.rest import rest_dispatch as _rest_dispatch from six.moves import map +import six rest_dispatch = csrf_exempt((lambda request, *args, **kwargs: _rest_dispatch(request, globals(), *args, **kwargs))) # This is a Pool that doesn't close connections. Therefore it can be used with @@ -292,7 +293,7 @@ class NarrowBuilder(object): return query.where(maybe_negate(cond)) def highlight_string(string, locs): - if isinstance(string, unicode): + if isinstance(string, six.text_type): string = string.encode('utf-8') highlight_start = '' @@ -326,7 +327,7 @@ def narrow_parameter(json): # We have to support a legacy tuple format. if isinstance(elem, list): if (len(elem) != 2 - or any(not isinstance(x, str) and not isinstance(x, unicode) + or any(not isinstance(x, str) and not isinstance(x, six.text_type) for x in elem)): raise ValueError("element is not a string pair") return dict(operator=elem[0], operand=elem[1])