from base64 import b64encode
-from urllib.parse import urlsplit, urljoin
+from urllib.parse import urlsplit, parse_qsl, quote, quote_plus, urlencode, \
+ urljoin
import asyncio
import sys
import socket
bookmark.last_tested = str(start)
now = int(time.time())
bookmark.test_time = str(now - start)
+
+
+def encode_url(url, encoding='latin1'):
+ split_results = urlsplit(url)
+ protocol, netloc, path, query, tag = split_results
+ user = split_results.username
+ password = split_results.password
+ host = split_results.hostname
+ port = split_results.port
+
+ if query:
+ qlist = []
+ for name, value in parse_qsl(query):
+ if not isinstance(name, bytes):
+ name = name.encode(encoding)
+ value = value.encode(encoding)
+ qlist.append((name, value))
+
+ url = protocol + "://"
+ if user:
+ url += quote(user.encode(encoding))
+ if password:
+ url += ':' + quote(password.encode(encoding))
+ url += '@'
+ if host:
+ if isinstance(host, bytes):
+ host = host.decode(encoding)
+ url += host.encode('idna').decode('ascii')
+ if port:
+ url += ':%d' % port
+ if path:
+ if protocol == "file":
+ url += quote(path)
+ else:
+ url += quote(path.encode(encoding))
+ if query:
+ url += '?' + urlencode(qlist)
+ if tag:
+ url += '#' + quote_plus(tag.encode(encoding))
+
+ return url
from queue import Queue
from time import sleep
-from urllib.parse import urlsplit, parse_qsl, quote, quote_plus, urlencode
import concurrent.futures
import threading
import certifi
import pycurl
-from Robots.base import robot_base
+from Robots.base import robot_base, encode_url
from Robots.concurrent_futures import concurrent_futures
def body_callback(self, data):
self.body += data
-
-
-def encode_url(url, encoding='latin1'):
- split_results = urlsplit(url)
- protocol, netloc, path, query, tag = split_results
- user = split_results.username
- password = split_results.password
- host = split_results.hostname
- port = split_results.port
-
- if query:
- qlist = []
- for name, value in parse_qsl(query):
- if not isinstance(name, bytes):
- name = name.encode(encoding)
- value = value.encode(encoding)
- qlist.append((name, value))
-
- url = protocol + "://"
- if user:
- url += quote(user.encode(encoding))
- if password:
- url += ':' + quote(password.encode(encoding))
- url += '@'
- if host:
- if isinstance(host, bytes):
- host = host.decode(encoding)
- url += host.encode('idna').decode('ascii')
- if port:
- url += ':%d' % port
- if path:
- if protocol == "file":
- url += quote(path)
- else:
- url += quote(path.encode(encoding))
- if query:
- url += '?' + urlencode(qlist)
- if tag:
- url += '#' + quote_plus(tag.encode(encoding))
-
- return url