Skip to content
GitLab
Explore
Sign in
Register
Commits on Source (2)
Replace ustr() by str()
· 43e0a537
André
authored
Nov 26, 2018
43e0a537
Merge branch 'ustr' into 'master'
· 2c7a3e2c
Philipp Hörist
authored
Nov 27, 2018
Replace ustr() by str() See merge request
!22
2c7a3e2c
Hide whitespace changes
Inline
Side-by-side
nbxmpp/c14n.py
View file @
2c7a3e2c
...
...
@@ -22,8 +22,6 @@
XML canonicalisation methods (for XEP-0116)
"""
from
.simplexml
import
ustr
def
c14n
(
node
,
is_buggy
):
s
=
"
<
"
+
node
.
name
if
node
.
namespace
:
...
...
@@ -34,7 +32,7 @@ def c14n(node, is_buggy):
for
key
in
sorted_attrs
:
if
not
is_buggy
and
key
==
'
xmlns
'
:
continue
val
=
u
str
(
node
.
attrs
[
key
])
val
=
str
(
node
.
attrs
[
key
])
# like XMLescape() but with whitespace and without >
s
+=
'
%s=
"
%s
"'
%
(
key
,
normalise_attr
(
val
))
s
+=
"
>
"
...
...
nbxmpp/simplexml.py
View file @
2c7a3e2c
...
...
@@ -32,23 +32,6 @@ def XMLescape(txt):
# replace also FORM FEED and ESC, because they are not valid XML chars
return
txt
.
replace
(
"
&
"
,
"
&
"
).
replace
(
"
<
"
,
"
<
"
).
replace
(
"
>
"
,
"
>
"
).
replace
(
'"'
,
"
"
"
).
replace
(
'
\x0C
'
,
""
).
replace
(
'
\x1B
'
,
""
)
ENCODING
=
'
utf-8
'
def
ustr
(
what
):
"""
Converts object
"
what
"
to unicode string using it
'
s own __str__ method if
accessible or unicode method otherwise
"""
if
isinstance
(
what
,
str
):
return
what
try
:
r
=
what
.
__str__
()
except
AttributeError
:
r
=
str
(
what
)
if
not
isinstance
(
r
,
str
):
return
str
(
r
,
ENCODING
)
return
r
class
Node
(
object
):
"""
Node class describes syntax of separate XML Node. It have a constructor that
...
...
@@ -134,7 +117,7 @@ class Node(object):
if
isinstance
(
i
,
Node
):
self
.
addChild
(
node
=
i
)
else
:
self
.
data
.
append
(
u
str
(
i
))
self
.
data
.
append
(
str
(
i
))
def
lookup_nsp
(
self
,
pfx
=
''
):
ns
=
self
.
nsd
.
get
(
pfx
,
None
)
...
...
@@ -159,7 +142,7 @@ class Node(object):
if
'
xmlns
'
not
in
self
.
attrs
:
s
+=
'
xmlns=
"
%s
"'
%
self
.
namespace
for
key
in
self
.
attrs
.
keys
():
val
=
u
str
(
self
.
attrs
[
key
])
val
=
str
(
self
.
attrs
[
key
])
s
+=
'
%s=
"
%s
"'
%
(
key
,
XMLescape
(
val
))
s
+=
"
>
"
...
...
@@ -218,7 +201,7 @@ class Node(object):
"""
Add some CDATA to node
"""
self
.
data
.
append
(
u
str
(
data
))
self
.
data
.
append
(
str
(
data
))
def
clearData
(
self
):
"""
...
...
@@ -379,7 +362,7 @@ class Node(object):
"""
Set node
'
s CDATA to provided string. Resets all previous CDATA!
"""
self
.
data
=
[
u
str
(
data
)]
self
.
data
=
[
str
(
data
)]
def
setName
(
self
,
val
):
"""
...
...
@@ -441,9 +424,9 @@ class Node(object):
(optionally) attributes
"
attrs
"
and sets it
'
s CDATA to string
"
val
"
"""
try
:
self
.
getTag
(
tag
,
attrs
).
setData
(
u
str
(
val
))
self
.
getTag
(
tag
,
attrs
).
setData
(
str
(
val
))
except
Exception
:
self
.
addChild
(
tag
,
attrs
,
payload
=
[
u
str
(
val
)])
self
.
addChild
(
tag
,
attrs
,
payload
=
[
str
(
val
)])
def
has_attr
(
self
,
key
):
"""
...
...
nbxmpp/transports_nb.py
View file @
2c7a3e2c
...
...
@@ -38,7 +38,6 @@ try:
except
ImportError
:
from
urlparse
import
urlparse
from
.simplexml
import
ustr
from
.plugin
import
PlugIn
from
.idlequeue
import
IdleObject
from
.
import
proxy_connectors
...
...
@@ -544,7 +543,7 @@ class NonBlockingTCP(NonBlockingTransport, IdleObject):
if
isinstance
(
stanza
,
str
):
stanza
=
stanza
.
encode
(
'
utf-8
'
)
elif
not
isinstance
(
stanza
,
str
):
stanza
=
u
str
(
stanza
).
encode
(
'
utf-8
'
)
stanza
=
str
(
stanza
).
encode
(
'
utf-8
'
)
return
stanza
def
_plug_idle
(
self
,
writable
,
readable
):
...
...