~ubuntu-branches/ubuntu/raring/wxwidgets2.8/raring

« back to all changes in this revision

Viewing changes to wxPython/wx/tools/Editra/src/ebmlib/searcheng.py

  • Committer: Package Import Robot
  • Author(s): Stéphane Graber
  • Date: 2012-01-07 13:59:25 UTC
  • mfrom: (1.1.9) (5.1.10 sid)
  • Revision ID: package-import@ubuntu.com-20120107135925-2601miy9ullcon9j
Tags: 2.8.12.1-6ubuntu1
* Resync from Debian, changes that were kept:
  - debian/rules: re-enable mediactrl. This allows libwx_gtk2u_media-2.8 to be
    built, as this is required by some applications (LP: #632984)
  - debian/control: Build-dep on libxt-dev for mediactrl.
  - Patches
    + fix-bashism-in-example
* Add conflict on python-wxgtk2.8 (<< 2.8.12.1-6ubuntu1~) to python-wxversion
  to guarantee upgrade ordering when moving from pycentral to dh_python2.

Show diffs side-by-side

added added

removed removed

Lines of Context:
7
7
###############################################################################
8
8
 
9
9
"""
10
 
Editra Buisness Model Library: SearchEngine
 
10
Editra Business Model Library: SearchEngine
11
11
 
12
12
Text Search Engine for finding text and grepping files
13
13
 
14
14
"""
15
15
 
16
16
__author__ = "Cody Precord <cprecord@editra.org>"
17
 
__cvsid__ = "$Id: searcheng.py 60680 2009-05-17 20:31:58Z CJP $"
18
 
__revision__ = "$Revision: 60680 $"
 
17
__cvsid__ = "$Id: searcheng.py 68232 2011-07-12 02:08:53Z CJP $"
 
18
__revision__ = "$Revision: 68232 $"
19
19
 
20
20
__all__ = [ 'SearchEngine', ]
21
21
 
25
25
import re
26
26
import fnmatch
27
27
import types
 
28
import unicodedata
28
29
from StringIO import StringIO
29
30
 
30
31
# Local imports
50
51
        @keyword wholeword: Match whole word
51
52
 
52
53
        """
53
 
        object.__init__(self)
 
54
        super(SearchEngine, self).__init__()
54
55
 
55
56
        # Attributes
56
57
        self._isregex = regex
57
58
        self._next = down
58
59
        self._matchcase = matchcase
59
60
        self._wholeword = wholeword
60
 
        self._unicode = False
61
61
        self._query = query
62
62
        self._regex = u''
63
63
        self._pool = u''
73
73
 
74
74
        """
75
75
        tmp = self._query
 
76
 
 
77
        uquery = type(tmp) is types.UnicodeType
 
78
        upool = type(self._pool) is types.UnicodeType
 
79
        if uquery and upool:
 
80
            tmp = unicodedata.normalize("NFD", tmp)
 
81
 
76
82
        if not self._isregex:
77
83
            tmp = re.escape(tmp)
78
84
 
79
85
        if self._wholeword:
80
 
            tmp = "\\b%s\\b" % tmp
 
86
            if uquery:
 
87
                tmp = u"\\b%s\\b" % tmp
 
88
            else:
 
89
                tmp = "\\b%s\\b" % tmp
81
90
 
82
91
        flags = re.MULTILINE
83
 
 
84
92
        if not self._matchcase:
85
93
            flags |= re.IGNORECASE
86
94
 
87
 
        if self._unicode:
 
95
        if upool:
88
96
            flags |= re.UNICODE
89
 
 
 
97
            # Normalize
 
98
            self._pool = unicodedata.normalize("NFD", self._pool)
 
99
        else:
 
100
            # If the pools is not Unicode also make sure that the
 
101
            # query is a string too.
 
102
            if uquery:
 
103
                try:
 
104
                    tmp = tmp.encode('utf-8')
 
105
                except UnicodeEncodeError:
 
106
                    # TODO: better error reporting about encoding issue
 
107
                    self._regex = None
 
108
                    return
90
109
        try:
91
110
            self._regex = re.compile(tmp, flags)
92
111
        except:
93
 
            self._regex = None
 
112
                self._regex = None
 
113
        self._data = (tmp, self._pool)
94
114
 
95
115
    def ClearPool(self):
96
116
        """Clear the search pool"""
378
398
        """
379
399
        del self._pool
380
400
        self._pool = pool
381
 
        if isinstance(self._pool, types.UnicodeType):
382
 
            self._unicode = True
383
 
            self._CompileRegex()
 
401
        self._CompileRegex()
384
402
 
385
403
    def SetQuery(self, query):
386
404
        """Set the search query