[PATCH v2] python: Encode query string as a utf-8 byte array

2011-07-11 Thread Sebastian Spaeth
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 at 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



[PATCH v2] python: Encode query string as a utf-8 byte array

2011-07-11 Thread Sebastian Spaeth
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 sebast...@sspaeth.de
---
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

___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch