Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
poezio
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
204
Issues
204
List
Boards
Labels
Service Desk
Milestones
Merge Requests
9
Merge Requests
9
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
poezio
poezio
Commits
8bdab491
Commit
8bdab491
authored
Nov 11, 2010
by
louiz@4325f9fc-e183-4c21-96ce-0ab188b42d13
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
roster search now uses difflib
parent
d502f4a5
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
3 deletions
+23
-3
src/tab.py
src/tab.py
+23
-3
No files found.
src/tab.py
View file @
8bdab491
...
...
@@ -31,6 +31,9 @@ log = logging.getLogger(__name__)
import
window
import
theme
import
curses
import
difflib
from
sleekxmpp.xmlstream.stanzabase
import
JID
from
config
import
config
from
roster
import
RosterGroup
,
roster
from
contact
import
Contact
,
Resource
...
...
@@ -481,7 +484,6 @@ class RosterInfoTab(Tab):
self
.
_color_state
=
theme
.
COLOR_TAB_NORMAL
def
on_gain_focus
(
self
):
log
.
debug
(
'on_gain_focus
\n
'
)
self
.
_color_state
=
theme
.
COLOR_TAB_CURRENT
curses
.
curs_set
(
0
)
...
...
@@ -617,12 +619,30 @@ class ConversationTab(Tab):
def
on_close
(
self
):
return
def
diffmatch
(
search
,
string
):
"""
Use difflib and a loop to check if search_pattern can
be 'almost' found INSIDE a string.
'almost' being defined by difflib
"""
l
=
len
(
search
)
ratio
=
0.7
for
i
in
range
(
len
(
string
)
-
l
+
1
):
if
difflib
.
SequenceMatcher
(
None
,
search
,
string
[
i
:
i
+
l
]).
ratio
()
>=
ratio
:
return
True
return
False
def
jid_and_name_match
(
contact
,
txt
):
"""
A function used to know if a contact in the roster should
be shown in the roster
"""
# TODO: search in nickname, and use libdiff
if
txt
in
contact
.
get_bare_jid
():
ratio
=
0.7
if
not
txt
:
return
True
# Everything matches when search is empty
user
=
JID
(
contact
.
get_bare_jid
()).
user
if
diffmatch
(
txt
,
user
):
return
True
if
contact
.
get_name
()
and
diffmatch
(
txt
,
contact
.
get_name
()):
return
True
return
False
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment