Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
gajim
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Weblate
gajim
Commits
82b30c07
Commit
82b30c07
authored
16 years ago
by
Brendan Taylor
Browse files
Options
Downloads
Patches
Plain Diff
CapsCache: made docstring match the API, fixed minor bugs, added tests
parent
00b7e982
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/common/caps.py
+19
-24
19 additions, 24 deletions
src/common/caps.py
test/test_caps.py
+47
-0
47 additions, 0 deletions
test/test_caps.py
with
66 additions
and
24 deletions
src/common/caps.py
+
19
−
24
View file @
82b30c07
...
...
@@ -24,7 +24,7 @@ import helpers
class
CapsCache
(
object
):
'''
This object keeps the mapping between caps data and real disco
features they represent, and provides simple way to query that info.
features they represent, and provides simple way to query that info.
It is application-wide, that is there
'
s one object for all
connections.
Goals:
...
...
@@ -44,46 +44,39 @@ class CapsCache(object):
# object creation
>>>
cc
=
CapsCache
(
logger_object
)
>>>
caps
=
(
'
http://exodus.jabberstudio.org/caps
'
,
'
0.9
'
,
None
)
# node, ver, ext
>>>
muc
=
'
http://jabber.org/protocol/muc
'
>>>
chatstates
=
'
http://jabber.org/protocol/chatstates
'
>>>
caps
=
(
'
sha-1
'
,
'
66/0NaeaBKkwk85efJTGmU47vXI=
'
)
>>>
muc
=
'
http://jabber.org/protocol/muc
'
>>>
chatstates
=
'
http://jabber.org/protocol/chatstates
'
# setting data
>>>
cc
[
caps
].
identities
=
[{
'
category
'
:
'
client
'
,
'
type
'
:
'
pc
'
}]
>>>
cc
[
caps
].
features
=
[
muc
]
# retrieving data
>>>
muc
in
cc
[
caps
].
features
True
>>>
muc
in
cc
[
caps
]
True
>>>
chatstates
in
cc
[
caps
]
>>>
chatstates
in
cc
[
caps
].
features
False
>>>
cc
[
caps
].
identities
set
(
{
'
category
'
:
'
client
'
,
'
type
'
:
'
pc
'
}
)
>>>
x
=
cc
[
caps
]
# more efficient if making several queries for one set of caps
[
{
'
category
'
:
'
client
'
,
'
type
'
:
'
pc
'
}
]
>>>
x
=
cc
[
caps
]
# more efficient if making several queries for one set of caps
ATypicalBlackBoxObject
>>>
muc
in
x
>>>
muc
in
x
.
features
True
>>>
x
.
node
'
http://exodus.jabberstudio.org/caps
'
# retrieving data (multiple exts case)
>>>
caps
=
(
'
http://gajim.org/caps
'
,
'
0.9
'
,
(
'
csn
'
,
'
ft
'
))
>>>
muc
in
cc
[
caps
]
>>>
muc
in
cc
[
caps
]
.
features
True
# setting data
>>>
newcaps
=
(
'
http://exodus.jabberstudio.org/caps
'
,
'
0.9a
'
,
None
)
>>>
cc
[
newcaps
].
identities
.
add
({
'
category
'
:
'
client
'
,
'
type
'
:
'
pc
'
,
'
name
'
:
'
Gajim
'
})
>>>
cc
[
newcaps
].
features
+=
muc
# same as:
>>>
cc
[
newcaps
]
+=
muc
>>>
cc
[
newcaps
][
'
csn
'
]
+=
chatstates
# adding data as if ext was 'csn'
# warning: no feature removal!
'''
def
__init__
(
self
,
logger
=
None
):
'''
Create a cache for entity capabilities.
'''
# our containers:
# __cache is a dictionary mapping: pair of
n
od
e
and
version
maps
# __cache is a dictionary mapping: pair of
hash meth
od and
hash
maps
# to CapsCacheItem object
# __CacheItem is a class that stores data about particular
# client (
node/version
pair)
# client (
hash method/hash
pair)
self
.
__cache
=
{}
class
CacheItem
(
object
):
...
...
@@ -129,7 +122,7 @@ class CapsCache(object):
d
[
'
xml:lang
'
]
=
i
[
2
]
if
i
[
3
]:
d
[
'
name
'
]
=
i
[
3
]
list
.
append
(
d
)
list
_
.
append
(
d
)
return
list_
def
_set_identities
(
ciself
,
value
):
ciself
.
_identities
=
[]
...
...
@@ -172,7 +165,9 @@ class CapsCache(object):
def
__getitem__
(
self
,
caps
):
if
caps
in
self
.
__cache
:
return
self
.
__cache
[
caps
]
hash_method
,
hash
=
caps
[
0
],
caps
[
1
]
hash_method
,
hash
=
caps
x
=
self
.
__CacheItem
(
hash_method
,
hash
)
self
.
__cache
[(
hash_method
,
hash
)]
=
x
return
x
...
...
This diff is collapsed.
Click to expand it.
test/test_caps.py
0 → 100644
+
47
−
0
View file @
82b30c07
# tests for capabilities and the capabilities cache
import
unittest
import
testlib
testlib
.
setup_env
()
from
common
import
gajim
from
common
import
xmpp
from
common.caps
import
CapsCache
from
mock
import
Mock
class
MockLogger
(
Mock
):
def
__init__
(
self
,
*
args
):
Mock
.
__init__
(
self
,
*
args
)
class
TestCapsCache
(
unittest
.
TestCase
):
def
setUp
(
self
):
self
.
logger
=
MockLogger
()
self
.
cc
=
CapsCache
(
self
.
logger
)
def
test_examples
(
self
):
'''
tests the examples given in common/caps.py
'''
caps
=
(
'
sha-1
'
,
'
66/0NaeaBKkwk85efJTGmU47vXI=
'
)
identity
=
{
'
category
'
:
'
client
'
,
'
type
'
:
'
pc
'
}
muc
=
'
http://jabber.org/protocol/muc
'
chatstates
=
'
http://jabber.org/protocol/chatstates
'
self
.
cc
[
caps
].
identities
=
[
identity
]
self
.
cc
[
caps
].
features
=
[
muc
]
self
.
assert_
(
muc
in
self
.
cc
[
caps
].
features
)
self
.
assert_
(
chatstates
not
in
self
.
cc
[
caps
].
features
)
id
=
self
.
cc
[
caps
].
identities
self
.
assertEqual
(
1
,
len
(
id
))
id
=
id
[
0
]
self
.
assertEqual
(
'
client
'
,
id
[
'
category
'
])
self
.
assertEqual
(
'
pc
'
,
id
[
'
type
'
])
if
__name__
==
'
__main__
'
:
unittest
.
main
()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment