From: Sebastian Spaeth <Sebastian@SSpaeth.de>
To: notmuch@notmuchmail.org
Cc: Patrick Totzke <patricktotzke@googlemail.com>
Subject: [PATCH] python: Encode query string as a utf-8 byte array
Date: Mon, 11 Jul 2011 11:43:47 +0200 [thread overview]
Message-ID: <1310377427-7656-1-git-send-email-Sebastian@SSpaeth.de> (raw)
In-Reply-To: <20110707113700.GA16347@megatron>
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 <Sebastian@SSpaeth.de>
---
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
next prev parent reply other threads:[~2011-07-11 9:43 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-07-07 11:37 [python] querystrings as unicode literals? Patrick Totzke
2011-07-11 9:32 ` Sebastian Spaeth
2011-07-11 9:43 ` Sebastian Spaeth [this message]
2011-07-11 9:49 ` [PATCH v2] python: Encode query string as a utf-8 byte array Sebastian Spaeth
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://notmuchmail.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1310377427-7656-1-git-send-email-Sebastian@SSpaeth.de \
--to=sebastian@sspaeth.de \
--cc=notmuch@notmuchmail.org \
--cc=patricktotzke@googlemail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://yhetil.org/notmuch.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).