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
199
Issues
199
List
Boards
Labels
Service Desk
Milestones
Merge Requests
8
Merge Requests
8
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
08f48b0c
Commit
08f48b0c
authored
Dec 12, 2020
by
mathieui
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move get_error_message to common
parent
e1720c8e
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
79 additions
and
77 deletions
+79
-77
poezio/common.py
poezio/common.py
+72
-0
poezio/core/core.py
poezio/core/core.py
+2
-39
poezio/core/handlers.py
poezio/core/handlers.py
+4
-4
poezio/core/structs.py
poezio/core/structs.py
+1
-34
No files found.
poezio/common.py
View file @
08f48b0c
...
...
@@ -505,3 +505,75 @@ def to_utc(time: datetime) -> datetime:
time
=
time
.
replace
(
tzinfo
=
tzone
).
astimezone
(
tz
=
timezone
.
utc
)
# Return an offset-naive datetime
return
time
.
replace
(
tzinfo
=
None
)
# http://xmpp.org/extensions/xep-0045.html#errorstatus
ERROR_AND_STATUS_CODES
=
{
'401'
:
'A password is required'
,
'403'
:
'Permission denied'
,
'404'
:
'The room doesn’t exist'
,
'405'
:
'Your are not allowed to create a new room'
,
'406'
:
'A reserved nick must be used'
,
'407'
:
'You are not in the member list'
,
'409'
:
'This nickname is already in use or has been reserved'
,
'503'
:
'The maximum number of users has been reached'
,
}
# http://xmpp.org/extensions/xep-0086.html
DEPRECATED_ERRORS
=
{
'302'
:
'Redirect'
,
'400'
:
'Bad request'
,
'401'
:
'Not authorized'
,
'402'
:
'Payment required'
,
'403'
:
'Forbidden'
,
'404'
:
'Not found'
,
'405'
:
'Not allowed'
,
'406'
:
'Not acceptable'
,
'407'
:
'Registration required'
,
'408'
:
'Request timeout'
,
'409'
:
'Conflict'
,
'500'
:
'Internal server error'
,
'501'
:
'Feature not implemented'
,
'502'
:
'Remote server error'
,
'503'
:
'Service unavailable'
,
'504'
:
'Remote server timeout'
,
'510'
:
'Disconnected'
,
}
def
get_error_message
(
stanza
:
Message
,
deprecated
:
bool
=
False
)
->
str
:
"""
Takes a stanza of the form <message type='error'><error/></message>
and return a well formed string containing error information
"""
sender
=
stanza
[
'from'
]
msg
=
stanza
[
'error'
][
'type'
]
condition
=
stanza
[
'error'
][
'condition'
]
code
=
stanza
[
'error'
][
'code'
]
body
=
stanza
[
'error'
][
'text'
]
if
not
body
:
if
deprecated
:
if
code
in
DEPRECATED_ERRORS
:
body
=
DEPRECATED_ERRORS
[
code
]
else
:
body
=
condition
or
'Unknown error'
else
:
if
code
in
ERROR_AND_STATUS_CODES
:
body
=
ERROR_AND_STATUS_CODES
[
code
]
else
:
body
=
condition
or
'Unknown error'
if
code
:
message
=
'%(from)s: %(code)s - %(msg)s: %(body)s'
%
{
'from'
:
sender
,
'msg'
:
msg
,
'body'
:
body
,
'code'
:
code
}
else
:
message
=
'%(from)s: %(msg)s: %(body)s'
%
{
'from'
:
sender
,
'msg'
:
msg
,
'body'
:
body
}
return
message
poezio/core/core.py
View file @
08f48b0c
...
...
@@ -45,6 +45,7 @@ from poezio import timed_events
from
poezio
import
windows
from
poezio.bookmarks
import
BookmarkList
from
poezio.common
import
get_error_message
from
poezio.config
import
config
,
firstrun
from
poezio.contact
import
Contact
,
Resource
from
poezio.daemon
import
Executor
...
...
@@ -66,8 +67,6 @@ from poezio.core.handlers import HandlerCore
from
poezio.core.structs
import
(
Command
,
Status
,
DEPRECATED_ERRORS
,
ERROR_AND_STATUS_CODES
,
POSSIBLE_SHOW
,
)
...
...
@@ -989,42 +988,6 @@ class Core:
for
jid
in
jids
:
self
.
invite
(
jid
,
room
)
def
get_error_message
(
self
,
stanza
,
deprecated
:
bool
=
False
):
"""
Takes a stanza of the form <message type='error'><error/></message>
and return a well formed string containing error information
"""
sender
=
stanza
[
'from'
]
msg
=
stanza
[
'error'
][
'type'
]
condition
=
stanza
[
'error'
][
'condition'
]
code
=
stanza
[
'error'
][
'code'
]
body
=
stanza
[
'error'
][
'text'
]
if
not
body
:
if
deprecated
:
if
code
in
DEPRECATED_ERRORS
:
body
=
DEPRECATED_ERRORS
[
code
]
else
:
body
=
condition
or
'Unknown error'
else
:
if
code
in
ERROR_AND_STATUS_CODES
:
body
=
ERROR_AND_STATUS_CODES
[
code
]
else
:
body
=
condition
or
'Unknown error'
if
code
:
message
=
'%(from)s: %(code)s - %(msg)s: %(body)s'
%
{
'from'
:
sender
,
'msg'
:
msg
,
'body'
:
body
,
'code'
:
code
}
else
:
message
=
'%(from)s: %(msg)s: %(body)s'
%
{
'from'
:
sender
,
'msg'
:
msg
,
'body'
:
body
}
return
message
####################### Tab logic-related things ##############################
### Tab getters ###
...
...
@@ -2125,7 +2088,7 @@ class Core:
tab
=
self
.
tabs
.
by_name_and_class
(
room_name
,
tabs
.
MucTab
)
if
not
tab
:
return
error_message
=
self
.
get_error_message
(
error
)
error_message
=
get_error_message
(
error
)
tab
.
add_message
(
Message
(
error_message
,
...
...
poezio/core/handlers.py
View file @
08f48b0c
...
...
@@ -31,7 +31,7 @@ from poezio import pep
from
poezio
import
tabs
from
poezio
import
xhtml
from
poezio
import
multiuserchat
as
muc
from
poezio.common
import
safeJID
from
poezio.common
import
safeJID
,
get_error_message
from
poezio.config
import
config
,
get_image_cache
from
poezio.core.structs
import
Status
from
poezio.contact
import
Resource
...
...
@@ -304,7 +304,7 @@ class HandlerCore:
if
jid_from
.
full
==
jid_from
.
bare
:
self
.
core
.
room_error
(
message
,
jid_from
.
bare
)
else
:
text
=
self
.
core
.
get_error_message
(
message
)
text
=
get_error_message
(
message
)
p_tab
=
self
.
core
.
tabs
.
by_name_and_class
(
jid_from
.
full
,
tabs
.
PrivateTab
)
if
p_tab
:
...
...
@@ -313,7 +313,7 @@ class HandlerCore:
self
.
core
.
information
(
text
,
'Error'
)
return
tab
=
self
.
core
.
get_conversation_by_jid
(
message
[
'from'
],
create
=
False
)
error_msg
=
self
.
core
.
get_error_message
(
message
,
deprecated
=
True
)
error_msg
=
get_error_message
(
message
,
deprecated
=
True
)
if
not
tab
:
self
.
core
.
information
(
error_msg
,
'Error'
)
return
...
...
@@ -1749,7 +1749,7 @@ class HandlerCore:
def
adhoc_error
(
self
,
iq
,
adhoc_session
):
self
.
core
.
xmpp
.
plugin
[
'xep_0050'
].
terminate_command
(
adhoc_session
)
error_message
=
self
.
core
.
get_error_message
(
iq
)
error_message
=
get_error_message
(
iq
)
self
.
core
.
information
(
"An error occurred while executing the command: %s"
%
(
error_message
),
'Error'
)
...
...
poezio/core/structs.py
View file @
08f48b0c
...
...
@@ -5,43 +5,10 @@ from dataclasses import dataclass
from
typing
import
Any
,
Callable
,
List
,
Dict
__all__
=
[
'
ERROR_AND_STATUS_CODES'
,
'DEPRECATED_ERRORS'
,
'
POSSIBLE_SHOW'
,
'Status'
,
'POSSIBLE_SHOW'
,
'Status'
,
'Command'
,
'Completion'
]
# http://xmpp.org/extensions/xep-0045.html#errorstatus
ERROR_AND_STATUS_CODES
=
{
'401'
:
'A password is required'
,
'403'
:
'Permission denied'
,
'404'
:
'The room doesn’t exist'
,
'405'
:
'Your are not allowed to create a new room'
,
'406'
:
'A reserved nick must be used'
,
'407'
:
'You are not in the member list'
,
'409'
:
'This nickname is already in use or has been reserved'
,
'503'
:
'The maximum number of users has been reached'
,
}
# http://xmpp.org/extensions/xep-0086.html
DEPRECATED_ERRORS
=
{
'302'
:
'Redirect'
,
'400'
:
'Bad request'
,
'401'
:
'Not authorized'
,
'402'
:
'Payment required'
,
'403'
:
'Forbidden'
,
'404'
:
'Not found'
,
'405'
:
'Not allowed'
,
'406'
:
'Not acceptable'
,
'407'
:
'Registration required'
,
'408'
:
'Request timeout'
,
'409'
:
'Conflict'
,
'500'
:
'Internal server error'
,
'501'
:
'Feature not implemented'
,
'502'
:
'Remote server error'
,
'503'
:
'Service unavailable'
,
'504'
:
'Remote server timeout'
,
'510'
:
'Disconnected'
,
}
POSSIBLE_SHOW
=
{
'available'
:
None
,
'chat'
:
'chat'
,
...
...
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