Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
D
dmlib
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
domotika
dmlib
Commits
ec745673
Commit
ec745673
authored
Nov 16, 2013
by
root
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix twisted.web.client._parse deprecation
parent
f0a07854
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
41 additions
and
2 deletions
+41
-2
webutils.py
dmlib/utils/webutils.py
+41
-2
No files found.
dmlib/utils/webutils.py
View file @
ec745673
...
...
@@ -21,7 +21,7 @@
#
##############################################################################
from
twisted.web
import
client
,
error
from
twisted.web
import
client
,
error
,
http
from
twisted.internet
import
reactor
,
defer
,
task
from
twisted.python
import
failure
import
gzip
...
...
@@ -29,6 +29,45 @@ import StringIO
import
time
import
base64
,
urlparse
def
_parse
(
url
,
defaultPort
=
None
):
"""
Split the given URL into the scheme, host, port, and path.
@type url: C{str}
@param url: An URL to parse.
@type defaultPort: C{int} or C{None}
@param defaultPort: An alternate value to use as the port if the URL does
not include one.
@return: A four-tuple of the scheme, host, port, and path of the URL. All
of these are C{str} instances except for port, which is an C{int}.
"""
url
=
url
.
strip
()
parsed
=
http
.
urlparse
(
url
)
scheme
=
parsed
[
0
]
path
=
urlunparse
((
''
,
''
)
+
parsed
[
2
:])
if
defaultPort
is
None
:
if
scheme
==
'https'
:
defaultPort
=
443
else
:
defaultPort
=
80
host
,
port
=
parsed
[
1
],
defaultPort
if
':'
in
host
:
host
,
port
=
host
.
split
(
':'
)
try
:
port
=
int
(
port
)
except
ValueError
:
port
=
defaultPort
if
path
==
''
:
path
=
'/'
return
scheme
,
host
,
port
,
path
class
HTTPPageGetter
(
client
.
HTTPPageGetter
):
rectimeout
=
15
...
...
@@ -273,7 +312,7 @@ def getPage(url, progress=False, stream=False, proxy_host = None, proxy_port = N
url
=
url
.
replace
(
parsed
.
scheme
+
"://"
+
parsed
.
username
+
"@"
,
parsed
.
scheme
+
"://"
)
else
:
url
=
url
.
replace
(
parsed
.
scheme
+
"://"
+
parsed
.
username
+
":"
+
parsed
.
password
+
"@"
,
parsed
.
scheme
+
"://"
)
scheme
,
host
,
port
,
path
=
client
.
_parse
(
url
)
scheme
,
host
,
port
,
path
=
_parse
(
url
)
if
not
progress
:
factory
=
HTTPClientFactory
(
url
,
proxy_host
=
proxy_host
,
proxy_port
=
proxy_port
,
headerscb
=
headerscb
,
headers
=
headers
,
*
args
,
**
kwargs
)
...
...
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