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 DF25D431FD0 for ; Mon, 11 Jul 2011 02:49:50 -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 zNSDJ9xjeWRL for ; Mon, 11 Jul 2011 02:49:50 -0700 (PDT) Received: from homiemail-a75.g.dreamhost.com (caiajhbdcaid.dreamhost.com [208.97.132.83]) by olra.theworths.org (Postfix) with ESMTP id F1677431FB6 for ; Mon, 11 Jul 2011 02:49:49 -0700 (PDT) Received: from homiemail-a75.g.dreamhost.com (localhost [127.0.0.1]) by homiemail-a75.g.dreamhost.com (Postfix) with ESMTP id 779745EC080; Mon, 11 Jul 2011 02:49:49 -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= l3EUwu+SpWuPNHljU+Kxo227v/5f+Fp6PR1ruo0Ta3etLPaXQRBOr8MAXs6RzCE6 fErMVTe+0vEMqfPebgzjacx96pOwGRqLvoj9axW88VY37F6H+qXZKJ+Q27ge3/Bg Ly7J1cerhwGVHpBUtcuilzeb3Ed4nvDqmd0GuqP3lAg= 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=175vwMuKSmu9VyFuoDKEEZOxiyQ=; b=nFus8RoetO7Z4LYmo2x/0n2UtecM 7kPkYR5L7pKvO9QY3wpEZ4NK/zem5a+EwDQ5WZ4wn+LUKYGu9Wv+gHc3qCh4Kij/ DomE/GSTuwwAXeFCSvZKiQbO1131LmwqNxcAirv+reKSbPcCXetIebU2FZNBjrpN QwqfVjK3Vkh4BAA= 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-a75.g.dreamhost.com (Postfix) with ESMTPSA id C85945EC07E; Mon, 11 Jul 2011 02:49:47 -0700 (PDT) Received: by spaetzbook.sspaeth.de (sSMTP sendmail emulation); Mon, 11 Jul 2011 11:49:46 +0200 From: Sebastian Spaeth To: notmuch@notmuchmail.org Subject: [PATCH v2] python: Encode query string as a utf-8 byte array Date: Mon, 11 Jul 2011 11:49:45 +0200 Message-Id: <1310377785-7887-1-git-send-email-Sebastian@SSpaeth.de> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1310377427-7656-1-git-send-email-Sebastian@SSpaeth.de> References: <1310377427-7656-1-git-send-email-Sebastian@SSpaeth.de> 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:49:51 -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 --- DOH, I should test my patches for typos before actually sending them off. This one should be fine. 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..84cf79b 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 isinstance(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