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 1466D431FD0 for ; Mon, 11 Jul 2011 02:43:55 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -0.1 X-Spam-Level: X-Spam-Status: No, score=-0.1 tagged_above=-999 required=5 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, RCVD_IN_DNSWL_NONE=-0.0001] 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 zpXitqDt5i6r for ; Mon, 11 Jul 2011 02:43:53 -0700 (PDT) Received: from homiemail-a22.g.dreamhost.com (caiajhbdcbef.dreamhost.com [208.97.132.145]) by olra.theworths.org (Postfix) with ESMTP id 73870431FB6 for ; Mon, 11 Jul 2011 02:43:53 -0700 (PDT) Received: from homiemail-a22.g.dreamhost.com (localhost [127.0.0.1]) by homiemail-a22.g.dreamhost.com (Postfix) with ESMTP id AE0DC1A8069; Mon, 11 Jul 2011 02:43:52 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=SSpaeth.de; h=from:to:cc:subject :date:message-id:in-reply-to:references; q=dns; s=sspaeth.de; b= K/n2e98f+orXTCp0Kaom7QX5nvYvbgbkexESWwl6P7RTGbkndGhFG2Z+GFRETQtq FvvDW6cdFPuZKnyk8MeivPHPpgH4DF4WD1bPNDLWXSCZ8wvqe7njJTeYSKbvvqD3 e3vISGXiFfgzMEsnygcn7FJL0bNXuCVo04BUzLPDpa0= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=SSpaeth.de; h=from:to:cc :subject:date:message-id:in-reply-to:references; s=sspaeth.de; bh=gJRCICozrqH3qylzFf+5CpmhyVI=; b=jaeEt/ZbdKL9ZpwEQI6XwZxPkPKH FNGB94s1IMZmg4fszsEvBbYXmlICbv8f984yiQBf1n+OPbM0YL9/UHop4kiTSW7Z T3yMFRDWGGDonRhKAKAw+ALDd8XaIB/9rIq7QzY+oQU4SXJxQY1Sq8UFKLgbd4Zv 3ICNzSXym2/EKzA= Received: from spaetzbook.sspaeth.de (mtec-hg-docking-1-dhcp-253.ethz.ch [129.132.133.253]) (using TLSv1 with cipher DHE-RSA-AES128-SHA (128/128 bits)) (No client certificate requested) (Authenticated sender: fax@sspaeth.de) by homiemail-a22.g.dreamhost.com (Postfix) with ESMTPSA id 098541A8061; Mon, 11 Jul 2011 02:43:50 -0700 (PDT) Received: by spaetzbook.sspaeth.de (sSMTP sendmail emulation); Mon, 11 Jul 2011 11:43:49 +0200 From: Sebastian Spaeth To: notmuch@notmuchmail.org Subject: [PATCH] python: Encode query string as a utf-8 byte array Date: Mon, 11 Jul 2011 11:43:47 +0200 Message-Id: <1310377427-7656-1-git-send-email-Sebastian@SSpaeth.de> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <20110707113700.GA16347@megatron> References: <20110707113700.GA16347@megatron> Cc: Patrick Totzke 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: Mon, 11 Jul 2011 09:43:55 -0000 If we pass in an unicode instance as query string, we would probably get weird behavior (and indeed do so, see mail id:"20110707113700.GA16347@megatron"). If a unicode instance is passed in, make sure we encode it properly to an utf-8 encoded byte string. Signed-off-by: Sebastian Spaeth --- Patrick, can you test, if this fixes the inconsistent behavior in a good way? bindings/python/notmuch/database.py | 8 +++++--- 1 files changed, 5 insertions(+), 3 deletions(-) diff --git a/bindings/python/notmuch/database.py b/bindings/python/notmuch/database.py index 3770b13..859fb18 100644 --- a/bindings/python/notmuch/database.py +++ b/bindings/python/notmuch/database.py @@ -501,7 +501,7 @@ class Query(object): :param db: An open database which we derive the Query from. :type db: :class:`Database` :param querystr: The query string for the message. - :type querystr: str + :type querystr: utf-8 encoded str or unicode """ self._db = None self._query = None @@ -517,7 +517,7 @@ class Query(object): :param db: Database to create the query from. :type db: :class:`Database` :param querystr: The query string - :type querystr: str + :type querystr: utf-8 encoded str or unicode :returns: Nothing :exception: :exc:`NotmuchError` @@ -529,7 +529,9 @@ class Query(object): raise NotmuchError(STATUS.NOT_INITIALIZED) # create reference to parent db to keep it alive self._db = db - + if is_instance(querystr, unicode): + # xapian takes utf-8 encoded byte arrays + querystr = querystr.encode('utf-8') # create query, return None if too little mem available query_p = Query._create(db.db_p, querystr) if query_p is None: -- 1.7.4.1