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
gajim
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
203
Issues
203
List
Boards
Labels
Service Desk
Milestones
Merge Requests
22
Merge Requests
22
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
gajim
gajim
Commits
b99632ab
Commit
b99632ab
authored
Sep 12, 2018
by
Philipp Hörist
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix pylint errors
parent
691678b0
Changes
28
Hide whitespace changes
Inline
Side-by-side
Showing
28 changed files
with
183 additions
and
175 deletions
+183
-175
gajim/adhoc_commands.py
gajim/adhoc_commands.py
+1
-1
gajim/chat_control.py
gajim/chat_control.py
+1
-1
gajim/common/caps_cache.py
gajim/common/caps_cache.py
+1
-1
gajim/common/connection.py
gajim/common/connection.py
+3
-3
gajim/common/connection_handlers_events.py
gajim/common/connection_handlers_events.py
+1
-1
gajim/common/modules/adhoc_commands.py
gajim/common/modules/adhoc_commands.py
+55
-51
gajim/common/modules/atom.py
gajim/common/modules/atom.py
+2
-2
gajim/common/modules/dataforms.py
gajim/common/modules/dataforms.py
+69
-67
gajim/common/modules/muc.py
gajim/common/modules/muc.py
+1
-1
gajim/common/modules/pep.py
gajim/common/modules/pep.py
+2
-2
gajim/common/modules/presence.py
gajim/common/modules/presence.py
+3
-3
gajim/common/modules/pubsub.py
gajim/common/modules/pubsub.py
+1
-1
gajim/common/modules/roster.py
gajim/common/modules/roster.py
+16
-16
gajim/common/modules/user_activity.py
gajim/common/modules/user_activity.py
+2
-2
gajim/common/modules/user_avatar.py
gajim/common/modules/user_avatar.py
+2
-2
gajim/common/modules/user_location.py
gajim/common/modules/user_location.py
+3
-1
gajim/common/modules/user_mood.py
gajim/common/modules/user_mood.py
+4
-4
gajim/common/modules/user_nickname.py
gajim/common/modules/user_nickname.py
+2
-2
gajim/common/modules/user_tune.py
gajim/common/modules/user_tune.py
+2
-2
gajim/common/pep.py
gajim/common/pep.py
+1
-1
gajim/dialogs.py
gajim/dialogs.py
+1
-1
gajim/groupchat_control.py
gajim/groupchat_control.py
+1
-1
gajim/gtk/account_wizard.py
gajim/gtk/account_wizard.py
+1
-1
gajim/gtk/service_registration.py
gajim/gtk/service_registration.py
+1
-1
gajim/gtk/single_message.py
gajim/gtk/single_message.py
+1
-1
gajim/gtkgui_helpers.py
gajim/gtkgui_helpers.py
+2
-2
gajim/gui_interface.py
gajim/gui_interface.py
+2
-2
gajim/search_window.py
gajim/search_window.py
+2
-2
No files found.
gajim/adhoc_commands.py
View file @
b99632ab
...
...
@@ -404,7 +404,7 @@ def stage3_next_form(self, command):
self
.
commandnode
=
command
.
getAttr
(
'node'
)
if
command
.
getTag
(
'x'
):
self
.
dataform
=
dataforms
.
ExtendF
orm
(
node
=
command
.
getTag
(
'x'
))
self
.
dataform
=
dataforms
.
extend_f
orm
(
node
=
command
.
getTag
(
'x'
))
self
.
data_form_widget
.
set_sensitive
(
True
)
try
:
...
...
gajim/chat_control.py
View file @
b99632ab
...
...
@@ -588,7 +588,7 @@ def on_avatar_eventbox_button_press_event(self, widget, event):
def
on_location_eventbox_button_release_event
(
self
,
widget
,
event
):
if
'geoloc'
in
self
.
contact
.
pep
:
location
=
self
.
contact
.
pep
[
'geoloc'
].
_pep_specific_
data
location
=
self
.
contact
.
pep
[
'geoloc'
].
data
if
(
'lat'
in
location
)
and
(
'lon'
in
location
):
uri
=
'https://www.openstreetmap.org/?'
+
\
'mlat=%(lat)s&mlon=%(lon)s&zoom=16'
%
{
'lat'
:
location
[
'lat'
],
...
...
gajim/common/caps_cache.py
View file @
b99632ab
...
...
@@ -448,7 +448,7 @@ def append(self, stanza):
elif
child
.
getName
()
==
'x'
:
if
child
.
getNamespace
()
==
nbxmpp
.
NS_DATA
:
from
gajim.common.modules
import
dataforms
data
.
append
(
dataforms
.
ExtendF
orm
(
node
=
child
))
data
.
append
(
dataforms
.
extend_f
orm
(
node
=
child
))
if
nbxmpp
.
NS_MUC
not
in
features
:
# Not a MUC, don't cache info
...
...
gajim/common/connection.py
View file @
b99632ab
...
...
@@ -382,14 +382,14 @@ def unsubscribe_agent(self, agent):
def
update_contact
(
self
,
jid
,
name
,
groups
):
if
self
.
connection
:
self
.
getRoster
().
set
I
tem
(
jid
=
jid
,
name
=
name
,
groups
=
groups
)
self
.
getRoster
().
set
_i
tem
(
jid
=
jid
,
name
=
name
,
groups
=
groups
)
def
update_contacts
(
self
,
contacts
):
"""
Update multiple roster items
"""
if
self
.
connection
:
self
.
getRoster
().
set
ItemM
ulti
(
contacts
)
self
.
getRoster
().
set
_item_m
ulti
(
contacts
)
def
new_account
(
self
,
name
,
config
,
sync
=
False
):
"""
...
...
@@ -1578,7 +1578,7 @@ def unsubscribe_agent(self, agent):
iq
.
setID
(
id_
)
self
.
awaiting_answers
[
id_
]
=
(
AGENT_REMOVED
,
agent
)
self
.
connection
.
send
(
iq
)
self
.
getRoster
().
del
I
tem
(
agent
)
self
.
getRoster
().
del
_i
tem
(
agent
)
def
send_new_account_infos
(
self
,
form
,
is_form
):
if
is_form
:
...
...
gajim/common/connection_handlers_events.py
View file @
b99632ab
...
...
@@ -926,7 +926,7 @@ def generate(self):
form_tag
=
feature_tag
.
getTag
(
'x'
,
namespace
=
nbxmpp
.
NS_DATA
)
if
not
form_tag
:
return
self
.
dataform
=
dataforms
.
ExtendF
orm
(
node
=
form_tag
)
self
.
dataform
=
dataforms
.
extend_f
orm
(
node
=
form_tag
)
for
f
in
self
.
dataform
.
iter_fields
():
if
f
.
var
==
'stream-method'
and
f
.
type_
==
'list-single'
:
values
=
[
o
[
1
]
for
o
in
f
.
options
]
...
...
gajim/common/modules/adhoc_commands.py
View file @
b99632ab
...
...
@@ -39,7 +39,7 @@ class AdHocCommand:
commandfeatures
=
(
nbxmpp
.
NS_DATA
,)
@
staticmethod
def
is
VisibleFor
(
samejid
):
def
is
_visible_for
(
_
samejid
):
"""
This returns True if that command should be visible and invokable for
others
...
...
@@ -54,8 +54,8 @@ def __init__(self, conn, jid, sessionid):
self
.
jid
=
jid
self
.
sessionid
=
sessionid
def
build
R
esponse
(
self
,
request
,
status
=
'executing'
,
defaultaction
=
None
,
actions
=
None
):
def
build
_r
esponse
(
self
,
request
,
status
=
'executing'
,
defaultaction
=
None
,
actions
=
None
):
assert
status
in
(
'executing'
,
'completed'
,
'canceled'
)
response
=
request
.
buildReply
(
'result'
)
...
...
@@ -74,12 +74,12 @@ def buildResponse(self, request, status='executing', defaultaction=None,
cmd
.
addChild
(
'actions'
,
attrs
,
actions
)
return
response
,
cmd
def
bad
R
equest
(
self
,
stanza
):
def
bad
_r
equest
(
self
,
stanza
):
self
.
connection
.
connection
.
send
(
nbxmpp
.
Error
(
stanza
,
nbxmpp
.
NS_STANZAS
+
' bad-request'
))
def
cancel
(
self
,
request
):
response
=
self
.
build
R
esponse
(
request
,
status
=
'canceled'
)[
0
]
response
=
self
.
build
_r
esponse
(
request
,
status
=
'canceled'
)[
0
]
self
.
connection
.
connection
.
send
(
response
)
return
False
# finish the session
...
...
@@ -90,30 +90,30 @@ class ChangeStatusCommand(AdHocCommand):
def
__init__
(
self
,
conn
,
jid
,
sessionid
):
AdHocCommand
.
__init__
(
self
,
conn
,
jid
,
sessionid
)
self
.
cb
=
self
.
first_step
self
.
_callback
=
self
.
first_step
@
staticmethod
def
is
VisibleF
or
(
samejid
):
def
is
_visible_f
or
(
samejid
):
"""
Change status is visible only if the entity has the same bare jid
"""
return
samejid
def
execute
(
self
,
request
):
return
self
.
cb
(
request
)
return
self
.
_callback
(
request
)
def
first_step
(
self
,
request
):
# first query...
response
,
cmd
=
self
.
build
R
esponse
(
request
,
defaultaction
=
'execute'
,
actions
=
[
'execute'
])
response
,
cmd
=
self
.
build
_r
esponse
(
request
,
defaultaction
=
'execute'
,
actions
=
[
'execute'
])
cmd
.
addChild
(
node
=
dataforms
.
SimpleDataForm
(
title
=
_
(
'Change status'
),
instructions
=
_
(
'Set the presence type and description'
),
fields
=
[
dataforms
.
F
ield
(
dataforms
.
create_f
ield
(
'list-single'
,
var
=
'presence-type'
,
label
=
'Type of presence:'
,
...
...
@@ -126,7 +126,7 @@ def first_step(self, request):
(
'offline'
,
_
(
'Offline - disconnect'
))],
value
=
'online'
,
required
=
True
),
dataforms
.
F
ield
(
dataforms
.
create_f
ield
(
'text-multi'
,
var
=
'presence-desc'
,
label
=
_
(
'Presence description:'
))
...
...
@@ -137,7 +137,7 @@ def first_step(self, request):
self
.
connection
.
connection
.
send
(
response
)
# for next invocation
self
.
cb
=
self
.
second_step
self
.
_callback
=
self
.
second_step
return
True
# keep the session
...
...
@@ -147,19 +147,19 @@ def second_step(self, request):
form
=
dataforms
.
SimpleDataForm
(
extend
=
request
.
getTag
(
'command'
).
getTag
(
'x'
))
except
Exception
:
self
.
bad
R
equest
(
request
)
self
.
bad
_r
equest
(
request
)
return
False
try
:
presencetype
=
form
[
'presence-type'
].
value
if
presencetype
not
in
(
'chat'
,
'online'
,
'away'
,
'xa'
,
'dnd'
,
'offline'
):
self
.
bad
R
equest
(
request
)
self
.
bad
_r
equest
(
request
)
return
False
except
Exception
:
# KeyError if there's no presence-type field in form or
# AttributeError if that field is of wrong type
self
.
bad
R
equest
(
request
)
self
.
bad
_r
equest
(
request
)
return
False
try
:
...
...
@@ -167,7 +167,7 @@ def second_step(self, request):
except
Exception
:
# same exceptions as in last comment
presencedesc
=
''
response
,
cmd
=
self
.
build
R
esponse
(
request
,
status
=
'completed'
)
response
,
cmd
=
self
.
build
_r
esponse
(
request
,
status
=
'completed'
)
cmd
.
addChild
(
'note'
,
{},
_
(
'The status has been changed.'
))
# if going offline, we need to push response so it won't go into
...
...
@@ -206,23 +206,23 @@ class LeaveGroupchatsCommand(AdHocCommand):
def
__init__
(
self
,
conn
,
jid
,
sessionid
):
AdHocCommand
.
__init__
(
self
,
conn
,
jid
,
sessionid
)
self
.
cb
=
self
.
first_step
self
.
_callback
=
self
.
first_step
@
staticmethod
def
is
VisibleF
or
(
samejid
):
def
is
_visible_f
or
(
samejid
):
"""
Leave groupchats is visible only if the entity has the same bare jid
"""
return
samejid
def
execute
(
self
,
request
):
return
self
.
cb
(
request
)
return
self
.
_callback
(
request
)
def
first_step
(
self
,
request
):
# first query...
response
,
cmd
=
self
.
build
R
esponse
(
request
,
defaultaction
=
'execute'
,
actions
=
[
'execute'
])
response
,
cmd
=
self
.
build
_r
esponse
(
request
,
defaultaction
=
'execute'
,
actions
=
[
'execute'
])
options
=
[]
account
=
self
.
connection
.
name
for
gc
in
find_current_groupchats
(
account
):
...
...
@@ -230,8 +230,8 @@ def first_step(self, request):
(
'%s'
%
gc
[
0
],
_
(
'%(nickname)s on %(room_jid)s'
)
%
{
'nickname'
:
gc
[
1
],
'room_jid'
:
gc
[
0
]}))
if
not
len
(
options
)
:
response
,
cmd
=
self
.
build
R
esponse
(
request
,
status
=
'completed'
)
if
not
options
:
response
,
cmd
=
self
.
build
_r
esponse
(
request
,
status
=
'completed'
)
cmd
.
addChild
(
'note'
,
{},
_
(
'You have not joined a groupchat.'
))
self
.
connection
.
connection
.
send
(
response
)
...
...
@@ -242,7 +242,7 @@ def first_step(self, request):
title
=
_
(
'Leave Groupchats'
),
instructions
=
_
(
'Choose the groupchats you want to leave'
),
fields
=
[
dataforms
.
F
ield
(
dataforms
.
create_f
ield
(
'list-multi'
,
var
=
'groupchats'
,
label
=
_
(
'Groupchats'
),
...
...
@@ -255,7 +255,7 @@ def first_step(self, request):
self
.
connection
.
connection
.
send
(
response
)
# for next invocation
self
.
cb
=
self
.
second_step
self
.
_callback
=
self
.
second_step
return
True
# keep the session
...
...
@@ -265,13 +265,13 @@ def second_step(self, request):
form
=
dataforms
.
SimpleDataForm
(
extend
=
request
.
getTag
(
'command'
).
getTag
(
'x'
))
except
Exception
:
self
.
bad
R
equest
(
request
)
self
.
bad
_r
equest
(
request
)
return
False
try
:
gc
=
form
[
'groupchats'
].
values
except
Exception
:
# KeyError if there's no groupchats in form
self
.
bad
R
equest
(
request
)
self
.
bad
_r
equest
(
request
)
return
False
account
=
self
.
connection
.
name
try
:
...
...
@@ -279,15 +279,16 @@ def second_step(self, request):
gc_control
=
app
.
interface
.
msg_win_mgr
.
get_gc_control
(
room_jid
,
account
)
if
not
gc_control
:
gc_control
=
app
.
interface
.
minimized_controls
[
account
][
room_jid
]
minimized_controls
=
app
.
interface
.
minimized_controls
gc_control
=
minimized_controls
[
account
][
room_jid
]
gc_control
.
shutdown
()
app
.
interface
.
roster
.
remove_groupchat
(
room_jid
,
account
)
continue
gc_control
.
parent_win
.
remove_tab
(
gc_control
,
None
,
force
=
True
)
except
Exception
:
# KeyError if there's no such room opened
self
.
bad
R
equest
(
request
)
self
.
bad
_r
equest
(
request
)
return
False
response
,
cmd
=
self
.
build
R
esponse
(
request
,
status
=
'completed'
)
response
,
cmd
=
self
.
build
_r
esponse
(
request
,
status
=
'completed'
)
note
=
_
(
'You left the following groupchats:'
)
for
room_jid
in
gc
:
note
+=
'
\n\t
'
+
room_jid
...
...
@@ -327,13 +328,13 @@ def is_same_jid(self, jid):
def
command_list_query
(
self
,
stanza
):
iq
=
stanza
.
buildReply
(
'result'
)
jid
=
helpers
.
get_full_jid_from_iq
(
stanza
)
q
=
iq
.
getTag
(
'query'
)
q
uery
=
iq
.
getTag
(
'query'
)
# buildReply don't copy the node attribute. Re-add it
q
.
setAttr
(
'node'
,
nbxmpp
.
NS_COMMANDS
)
q
uery
.
setAttr
(
'node'
,
nbxmpp
.
NS_COMMANDS
)
for
node
,
cmd
in
self
.
_commands
.
items
():
if
cmd
.
is
VisibleF
or
(
self
.
is_same_jid
(
jid
)):
q
.
addChild
(
'item'
,
{
if
cmd
.
is
_visible_f
or
(
self
.
is_same_jid
(
jid
)):
q
uery
.
addChild
(
'item'
,
{
# TODO: find the jid
'jid'
:
str
(
self
.
_con
.
get_own_jid
()),
'node'
:
node
,
...
...
@@ -349,7 +350,7 @@ def command_info_query(self, stanza):
try
:
jid
=
helpers
.
get_full_jid_from_iq
(
stanza
)
except
helpers
.
InvalidFormat
:
log
.
warning
(
'Invalid JID: %s, ignoring it'
%
stanza
.
getFrom
())
log
.
warning
(
'Invalid JID: %s, ignoring it'
,
stanza
.
getFrom
())
return
node
=
stanza
.
getTagAttr
(
'query'
,
'node'
)
...
...
@@ -357,16 +358,16 @@ def command_info_query(self, stanza):
return
False
cmd
=
self
.
_commands
[
node
]
if
cmd
.
is
VisibleF
or
(
self
.
is_same_jid
(
jid
)):
if
cmd
.
is
_visible_f
or
(
self
.
is_same_jid
(
jid
)):
iq
=
stanza
.
buildReply
(
'result'
)
q
=
iq
.
getTag
(
'query'
)
q
.
addChild
(
'identity'
,
attrs
=
{
'type'
:
'command-node'
,
'category'
:
'automation'
,
'name'
:
cmd
.
commandname
})
q
.
addChild
(
'feature'
,
attrs
=
{
'var'
:
nbxmpp
.
NS_COMMANDS
})
q
uery
=
iq
.
getTag
(
'query'
)
q
uery
.
addChild
(
'identity'
,
attrs
=
{
'type'
:
'command-node'
,
'category'
:
'automation'
,
'name'
:
cmd
.
commandname
})
q
uery
.
addChild
(
'feature'
,
attrs
=
{
'var'
:
nbxmpp
.
NS_COMMANDS
})
for
feature
in
cmd
.
commandfeatures
:
q
.
addChild
(
'feature'
,
attrs
=
{
'var'
:
feature
})
q
uery
.
addChild
(
'feature'
,
attrs
=
{
'var'
:
feature
})
self
.
_con
.
connection
.
send
(
iq
)
return
True
...
...
@@ -385,14 +386,14 @@ def command_items_query(self, stanza):
return
False
cmd
=
self
.
_commands
[
node
]
if
cmd
.
is
VisibleF
or
(
self
.
is_same_jid
(
jid
)):
if
cmd
.
is
_visible_f
or
(
self
.
is_same_jid
(
jid
)):
iq
=
stanza
.
buildReply
(
'result'
)
self
.
_con
.
connection
.
send
(
iq
)
return
True
return
False
def
_execute_command_received
(
self
,
con
,
stanza
):
def
_execute_command_received
(
self
,
_
con
,
stanza
):
jid
=
helpers
.
get_full_jid_from_iq
(
stanza
)
cmd
=
stanza
.
getTag
(
'command'
)
...
...
@@ -417,7 +418,7 @@ def _execute_command_received(self, con, stanza):
raise
nbxmpp
.
NodeProcessed
newcmd
=
self
.
_commands
[
node
]
if
not
newcmd
.
is
VisibleF
or
(
self
.
is_same_jid
(
jid
)):
if
not
newcmd
.
is
_visible_f
or
(
self
.
is_same_jid
(
jid
)):
log
.
warning
(
'Command not visible for jid: %s'
,
jid
)
raise
nbxmpp
.
NodeProcessed
...
...
@@ -492,7 +493,9 @@ def _command_list_received(self, stanza):
items
=
stanza
.
getQueryPayload
()
commandlist
=
[]
if
items
:
commandlist
=
[(
t
.
getAttr
(
'node'
),
t
.
getAttr
(
'name'
))
for
t
in
items
]
commandlist
=
[
(
t
.
getAttr
(
'node'
),
t
.
getAttr
(
'name'
))
for
t
in
items
]
log
.
info
(
'Received: %s'
,
commandlist
)
app
.
nec
.
push_incoming_event
(
...
...
@@ -550,7 +553,8 @@ def send_cancel(self, jid, node, session_id):
self
.
_con
.
connection
.
SendAndCallForResponse
(
stanza
,
self
.
_cancel_result_received
)
def
_cancel_result_received
(
self
,
stanza
):
@
staticmethod
def
_cancel_result_received
(
stanza
):
if
not
nbxmpp
.
isResultNode
(
stanza
):
log
.
warning
(
'Error: %s'
,
stanza
.
getError
())
else
:
...
...
gajim/common/modules/atom.py
View file @
b99632ab
...
...
@@ -44,10 +44,10 @@ class AtomData(AbstractPEPData):
type_
=
PEPEventType
.
ATOM
def
__init__
(
self
,
atom
):
self
.
_pep_specific_
data
=
atom
self
.
data
=
atom
def
get_entry
(
self
):
return
self
.
_pep_specific_
data
return
self
.
data
class
Atom
(
AbstractPEPModule
):
...
...
gajim/common/modules/dataforms.py
View file @
b99632ab
...
...
@@ -39,22 +39,22 @@ class WrongFieldValue(Error):
# helper class to change class of already existing object
class
ExtendedNode
(
nbxmpp
.
Node
,
object
):
class
ExtendedNode
(
nbxmpp
.
Node
):
@
classmethod
def
__new__
(
cls
,
*
a
,
**
b
):
if
'extend'
not
in
b
.
keys
()
or
not
b
[
'extend'
]:
def
__new__
(
cls
,
*
a
rgs
,
**
kwargs
):
if
'extend'
not
in
kwargs
.
keys
()
or
not
kwargs
[
'extend'
]:
return
object
.
__new__
(
cls
)
extend
=
b
[
'extend'
]
extend
=
kwargs
[
'extend'
]
assert
issubclass
(
cls
,
extend
.
__class__
)
extend
.
__class__
=
cls
return
extend
# helper to create fields from scratch
def
F
ield
(
typ
,
**
attrs
):
def
create_f
ield
(
typ
,
**
attrs
):
''' Helper function to create a field of given type. '''
f
=
{
f
ield
=
{
'boolean'
:
BooleanField
,
'fixed'
:
StringField
,
'hidden'
:
StringField
,
...
...
@@ -66,18 +66,18 @@ def Field(typ, **attrs):
'list-single'
:
ListSingleField
,
'text-multi'
:
TextMultiField
,
}[
typ
](
typ
=
typ
,
**
attrs
)
return
f
return
f
ield
def
ExtendF
ield
(
node
):
def
extend_f
ield
(
node
):
"""
Helper function to extend a node to field of appropriate type
"""
# when validation (XEP-122) will go in, we could have another classes
# like DateTimeField - so that dicts in
Field() and ExtendField() will
# be different...
# like DateTimeField - so that dicts in
create_field() and
#
extend_field() will
be different...
typ
=
node
.
getAttr
(
'type'
)
f
=
{
f
ield
=
{
'boolean'
:
BooleanField
,
'fixed'
:
StringField
,
'hidden'
:
StringField
,
...
...
@@ -89,25 +89,24 @@ def ExtendField(node):
'list-single'
:
ListSingleField
,
'text-multi'
:
TextMultiField
,
}
if
typ
not
in
f
:
if
typ
not
in
f
ield
:
typ
=
'text-single'
return
f
[
typ
](
extend
=
node
)
return
f
ield
[
typ
](
extend
=
node
)
def
ExtendF
orm
(
node
):
def
extend_f
orm
(
node
):
"""
Helper function to extend a node to form of appropriate type
"""
if
node
.
getTag
(
'reported'
)
is
not
None
:
return
MultipleDataForm
(
extend
=
node
)
else
:
return
SimpleDataForm
(
extend
=
node
)
return
SimpleDataForm
(
extend
=
node
)
class
DataField
(
ExtendedNode
):
"""
Keeps data about one field - var, field type, labels, instructions... Base
class for different kinds of fields. Use
F
ield() function to construct one
class for different kinds of fields. Use
create_f
ield() function to construct one
of these
"""
...
...
@@ -136,10 +135,10 @@ def type_(self):
'text-private', 'text-single'. If you set this to something different,
DataField will store given name, but treat all data as text-single
"""
t
=
self
.
getAttr
(
'type'
)
if
t
is
None
:
t
ype_
=
self
.
getAttr
(
'type'
)
if
t
ype_
is
None
:
return
'text-single'
return
t
return
t
ype_
@
type_
.
setter
def
type_
(
self
,
value
):
...
...
@@ -199,9 +198,9 @@ def description(self, value):
@
description
.
deleter
def
description
(
self
):
t
=
self
.
getTag
(
'desc'
)
if
t
is
not
None
:
self
.
delChild
(
t
)
desc
=
self
.
getTag
(
'desc'
)
if
desc
is
not
None
:
self
.
delChild
(
desc
)
@
property
def
required
(
self
):
...
...
@@ -212,10 +211,10 @@ def required(self):
@
required
.
setter
def
required
(
self
,
value
):
t
=
self
.
getTag
(
'required'
)
if
t
and
not
value
:
self
.
delChild
(
t
)
elif
not
t
and
value
:
required
=
self
.
getTag
(
'required'
)
if
required
and
not
value
:
self
.
delChild
(
required
)
elif
not
required
and
value
:
self
.
addChild
(
'required'
)
@
property
...
...
@@ -234,11 +233,12 @@ def media(self, value):
@
media
.
deleter
def
media
(
self
):
t
=
self
.
getTag
(
'media'
)
if
t
is
not
None
:
self
.
delChild
(
t
)
media
=
self
.
getTag
(
'media'
)
if
media
is
not
None
:
self
.
delChild
(
media
)
def
is_valid
(
self
):
@
staticmethod
def
is_valid
():
return
True
...
...
@@ -306,12 +306,12 @@ def value(self):
"""
Value of field. May contain True, False or None
"""
v
=
self
.
getTagData
(
'value'
)
if
v
in
(
'0'
,
'false'
):
v
alue
=
self
.
getTagData
(
'value'
)
if
v
alue
in
(
'0'
,
'false'
):
return
False
if
v
in
(
'1'
,
'true'
):
if
v
alue
in
(
'1'
,
'true'
):
return
True
if
v
is
None
:
if
v
alue
is
None
:
return
False
# default value is False
raise
WrongFieldValue
...
...
@@ -321,9 +321,9 @@ def value(self, value):
@
value
.
deleter
def
value
(
self
):
t
=
self
.
getTag
(
'value'
)
if
t
is
not
None
:
self
.
delChild
(
t
)
value
=
self
.
getTag
(
'value'
)
if
value
is
not
None
:
self
.
delChild
(
value
)
class
StringField
(
DataField
):
...
...
@@ -366,13 +366,13 @@ def options(self):
"""
options
=
[]
for
element
in
self
.
getTags
(
'option'
):
v
=
element
.
getTagData
(
'value'
)
if
v
is
None
:
v
alue
=
element
.
getTagData
(
'value'
)
if
v
alue
is
None
:
raise
WrongFieldValue
label
=
element
.
getAttr
(
'label'
)
if
not
label
:
label
=
v
options
.
append
((
label
,
v
))
label
=
v
alue
options
.
append
((
label
,
v
alue
))
return
options
@
options
.
setter
...
...
@@ -389,13 +389,13 @@ def options(self):
def
iter_options
(
self
):
for
element
in
self
.
iterTags
(
'option'
):
v
=
element
.
getTagData
(
'value'
)
if
v
is
None
:
v
alue
=
element
.
getTagData
(
'value'
)
if
v
alue
is
None
:
raise
WrongFieldValue
label
=
element
.
getAttr
(
'label'
)
if
not
label
:
label
=
v
yield
(
v
,
label
)
label
=
v
alue
yield
(
v
alue
,
label
)
class
ListSingleField
(
ListField
,
StringField
):
...
...
@@ -469,7 +469,7 @@ class JidMultiField(ListMultiField):
Covers jid-multi fields
"""
def
is_valid
(
self
):
if
len
(
self
.
values
)
:
if
self
.
values
:
for
value
in
self
.
values
:
try
:
helpers
.
parse_jid
(
value
)
...
...
@@ -526,7 +526,7 @@ def __init__(self, fields=None, associated=None, extend=None):
if
fields
is
None
:
for
field
in
self
.
iterTags
(
'field'
):
if
not
isinstance
(
field
,
DataField
):
ExtendF
ield
(
field
)
extend_f
ield
(
field
)
self
.
vars
[
field
.
var
]
=
field
else
:
for
field
in
self
.
getTags
(
'field'
):
...
...
@@ -545,7 +545,7 @@ def fields(self, fields):
del
self
.
fields
for
field
in
fields
:
if
not
isinstance
(
field
,
DataField
):
ExtendF
ield
(
field
)
extend_f
ield
(
field
)
self
.
addChild
(
node
=
field
)
@
fields
.
deleter
...
...
@@ -572,8 +572,8 @@ def __getitem__(self, item):
return
self
.
vars
[
item
]
def
is_valid
(
self
):
for
f
in
self
.
iter_fields
():
if
not
f
.
is_valid
():
for
f
ield
in
self
.
iter_fields
():
if
not
f
ield
.
is_valid
():
return
False
return
True