Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id A5F5441434B for ; Sun, 8 Jan 2012 06:06:54 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: 0.001 X-Spam-Level: X-Spam-Status: No, score=0.001 tagged_above=-999 required=5 tests=[UNPARSEABLE_RELAY=0.001] autolearn=disabled Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id XCMf3xwDtIIl for ; Sun, 8 Jan 2012 06:06:51 -0800 (PST) Received: from mail.cryptobitch.de (cryptobitch.de [88.198.7.68]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id 2F35A414343 for ; Sun, 8 Jan 2012 06:06:51 -0800 (PST) Received: from mail.jade-hamburg.de (unknown [85.183.11.228]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.cryptobitch.de (Postfix) with ESMTPSA id A3768513C80 for ; Sun, 8 Jan 2012 15:06:49 +0100 (CET) Received: by mail.jade-hamburg.de (Postfix, from userid 401) id EA9DADF2A2; Sun, 8 Jan 2012 15:06:48 +0100 (CET) Received: from thinkbox.jade-hamburg.de (unknown [IPv6:fe80::216:d3ff:fe3e:5058%br0]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) (Authenticated sender: teythoon) by mail.jade-hamburg.de (Postfix) with ESMTPSA id 7A5BBDF2A0; Sun, 8 Jan 2012 15:06:47 +0100 (CET) Received: from teythoon by thinkbox.jade-hamburg.de with local (Exim 4.77) (envelope-from ) id 1RjtOY-0007wh-Ty; Sun, 08 Jan 2012 15:06:47 +0100 From: Justus Winter <4winter@informatik.uni-hamburg.de> To: notmuch@notmuchmail.org Subject: [PATCH] py3k: the basestring and unicode types are removed in python 3 Date: Sun, 8 Jan 2012 15:06:29 +0100 Message-Id: <1326031589-30506-1-git-send-email-4winter@informatik.uni-hamburg.de> X-Mailer: git-send-email 1.7.7.3 In-Reply-To: <20120108140444.26863.68188@thinkbox.jade-hamburg.de> References: <20120108140444.26863.68188@thinkbox.jade-hamburg.de> X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 08 Jan 2012 14:06:54 -0000 --- bindings/python/notmuch/globals.py | 34 ++++++++++++++++++++++------------ 1 files changed, 22 insertions(+), 12 deletions(-) diff --git a/bindings/python/notmuch/globals.py b/bindings/python/notmuch/globals.py index 32ed9ae..4138460 100644 --- a/bindings/python/notmuch/globals.py +++ b/bindings/python/notmuch/globals.py @@ -31,12 +31,34 @@ if sys.version_info[0] == 2: class Python3StringMixIn(object): def __str__(self): return unicode(self).encode('utf-8') + + + def _str(value): + """Ensure a nicely utf-8 encoded string to pass to libnotmuch + + C++ code expects strings to be well formatted and + unicode strings to have no null bytes.""" + if not isinstance(value, basestring): + raise TypeError("Expected str or unicode, got %s" % type(value)) + if isinstance(value, unicode): + return value.encode('UTF-8') + return value else: class Python3StringMixIn(object): def __str__(self): return self.__unicode__() + def _str(value): + """Ensure a nicely utf-8 encoded string to pass to libnotmuch + + C++ code expects strings to be well formatted and + unicode strings to have no null bytes.""" + if not isinstance(value, str): + raise TypeError("Expected str, got %s" % type(value)) + return value.encode('UTF-8') + + class Enum(object): """Provides ENUMS as "code=Enum(['a','b','c'])" where code.a=0 etc...""" def __init__(self, names): @@ -202,18 +224,6 @@ class NotInitializedError(NotmuchError): status = STATUS.NOT_INITIALIZED -def _str(value): - """Ensure a nicely utf-8 encoded string to pass to libnotmuch - - C++ code expects strings to be well formatted and - unicode strings to have no null bytes.""" - if not isinstance(value, basestring): - raise TypeError("Expected str or unicode, got %s" % str(type(value))) - if isinstance(value, unicode): - return value.encode('UTF-8') - return value - - class NotmuchDatabaseS(Structure): pass NotmuchDatabaseP = POINTER(NotmuchDatabaseS) -- 1.7.7.3