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
l-n-s
gajim
Commits
15b82539
Commit
15b82539
authored
14 years ago
by
roidelapluie
Browse files
Options
Downloads
Patches
Plain Diff
Splitting the function that process images
parent
29fbb7f7
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/htmltextview.py
+53
-48
53 additions, 48 deletions
src/htmltextview.py
with
53 additions
and
48 deletions
src/htmltextview.py
+
53
−
48
View file @
15b82539
...
...
@@ -484,6 +484,58 @@ class HtmlHandler(xml.sax.handler.ContentHandler):
tag
.
title
=
title
return
tag
def
_get_img
(
self
,
attrs
):
mem
=
''
# Wait maximum 1s for connection
socket
.
setdefaulttimeout
(
1
)
try
:
req
=
urllib2
.
Request
(
attrs
[
'
src
'
])
req
.
add_header
(
'
User-Agent
'
,
'
Gajim
'
+
gajim
.
version
)
f
=
urllib2
.
urlopen
(
req
)
except
Exception
,
ex
:
log
.
debug
(
'
Error loading image %s
'
%
attrs
[
'
src
'
]
+
str
(
ex
))
pixbuf
=
None
alt
=
attrs
.
get
(
'
alt
'
,
'
Broken image
'
)
else
:
# Wait 0.1s between each byte
try
:
f
.
fp
.
_sock
.
fp
.
_sock
.
settimeout
(
0.5
)
except
Exception
:
pass
# Max image size = 2 MB (to try to prevent DoS)
deadline
=
time
.
time
()
+
3
while
True
:
if
time
.
time
()
>
deadline
:
log
.
debug
(
str
(
'
Timeout loading image %s
'
%
\
attrs
[
'
src
'
]
+
ex
))
mem
=
''
alt
=
attrs
.
get
(
'
alt
'
,
''
)
if
alt
:
alt
+=
'
\n
'
alt
+=
_
(
'
Timeout loading image
'
)
break
try
:
temp
=
f
.
read
(
100
)
except
socket
.
timeout
,
ex
:
log
.
debug
(
'
Timeout loading image %s
'
%
\
attrs
[
'
src
'
]
+
str
(
ex
))
alt
=
attrs
.
get
(
'
alt
'
,
''
)
if
alt
:
alt
+=
'
\n
'
alt
+=
_
(
'
Timeout loading image
'
)
break
if
temp
:
mem
+=
temp
else
:
break
if
len
(
mem
)
>
2
*
1024
*
1024
:
alt
=
attrs
.
get
(
'
alt
'
,
''
)
if
alt
:
alt
+=
'
\n
'
alt
+=
_
(
'
Image is too big
'
)
break
return
mem
def
_process_img
(
self
,
attrs
):
'''
Process a img tag.
'''
...
...
@@ -495,54 +547,7 @@ class HtmlHandler(xml.sax.handler.ContentHandler):
img
=
attrs
[
'
src
'
].
split
(
'
,
'
)[
1
]
mem
=
base64
.
standard_b64decode
(
urllib2
.
unquote
(
img
))
else
:
# Wait maximum 1s for connection
socket
.
setdefaulttimeout
(
1
)
try
:
req
=
urllib2
.
Request
(
attrs
[
'
src
'
])
req
.
add_header
(
'
User-Agent
'
,
'
Gajim
'
+
gajim
.
version
)
f
=
urllib2
.
urlopen
(
req
)
except
Exception
,
ex
:
log
.
debug
(
'
Error loading image %s
'
%
attrs
[
'
src
'
]
+
str
(
ex
))
pixbuf
=
None
alt
=
attrs
.
get
(
'
alt
'
,
'
Broken image
'
)
else
:
# Wait 0.1s between each byte
try
:
f
.
fp
.
_sock
.
fp
.
_sock
.
settimeout
(
0.5
)
except
Exception
:
pass
# Max image size = 2 MB (to try to prevent DoS)
deadline
=
time
.
time
()
+
3
while
True
:
if
time
.
time
()
>
deadline
:
log
.
debug
(
str
(
'
Timeout loading image %s
'
%
\
attrs
[
'
src
'
]
+
ex
))
mem
=
''
alt
=
attrs
.
get
(
'
alt
'
,
''
)
if
alt
:
alt
+=
'
\n
'
alt
+=
_
(
'
Timeout loading image
'
)
break
try
:
temp
=
f
.
read
(
100
)
except
socket
.
timeout
,
ex
:
log
.
debug
(
'
Timeout loading image %s
'
%
\
attrs
[
'
src
'
]
+
str
(
ex
))
alt
=
attrs
.
get
(
'
alt
'
,
''
)
if
alt
:
alt
+=
'
\n
'
alt
+=
_
(
'
Timeout loading image
'
)
break
if
temp
:
mem
+=
temp
else
:
break
if
len
(
mem
)
>
2
*
1024
*
1024
:
alt
=
attrs
.
get
(
'
alt
'
,
''
)
if
alt
:
alt
+=
'
\n
'
alt
+=
_
(
'
Image is too big
'
)
break
mem
=
self
.
_get_img
(
attrs
)
pixbuf
=
None
if
mem
:
# Caveat: GdkPixbuf is known not to be safe to load
...
...
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