How to use rs4 - 10 common examples

To help you get started, we’ve selected a few rs4 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github hansroh / aquests / aquests / athreads / socket_map.py View on Github external
with self.lock:
			v = dict.items (self)		
		return v
			
	def keys (self):
		with self.lock:
			v = dict.keys (self)
		return v
	
	def values (self):
		with self.lock:
			v = dict.values (self)		
		return v


if not hasattr (asyncore, "_socket_map"):
	asyncore._socket_map = asyncore.socket_map
	del asyncore.socket_map
	asyncore.socket_map = thread_safe_socket_map ()
github hansroh / aquests / aquests / athreads / trigger.py View on Github external
def wakeselect ():
	for fd, obj in list(asyncore.socket_map.items()):
		if hasattr(obj, "pull_trigger"):
			obj.pull_trigger()
github hansroh / aquests / aquests / protocols / dns / __init__.py View on Github external
map [client._fileno] = client
        fds = list (map.keys ())
        
        # maybe 2 is enough
        safeguard = count * 2
        while self.has_job () and safeguard:
            safeguard -= 1
            asyncore.loop (0.1, map, count = 1)
            if safeguard % 5 == 0:
                self.maintern (time.time ())        
        self.maintern (time.time ())
                            
        for fd in fds:
            if fd not in map:
                # resync 
                try: del asyncore.socket_map [fd]
                except KeyError: pass
github hansroh / aquests / aquests / __init__.py View on Github external
def mapsize ():
	return len (asyncore.socket_map)
github hansroh / aquests / aquests / protocols / ftp / asyncftp.py View on Github external
if code != "227":
			return # pasv failed
		match = pasv_pattern.search(response[-1])
		if not match:
			return # bad port
		p1, p2 = match.groups()
		try:
			port = (int(p1) & 255) * 256 + (int(p2) & 255)
		except ValueError:
			return # bad port
		
		# establish data connection
		self.handler.handle_establish_connection (self.host, port)
		

class asyncftp_download(asyncore.dispatcher):
	def __init__(self, host, port):
		asyncore.dispatcher.__init__(self)
		self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
		self.connect((host, port))

	def writable(self):
		return 0

	def handle_connect(self):
		pass

	def handle_expt(self):
		self.close()

	def handle_read(self):
		sys.stdout.write(self.recv(8192))
github hansroh / aquests / aquests / __init__.py View on Github external
_fetch_started = timeit.default_timer ()
	# IMP. mannually set
	lifetime._polling = 1

	# create initail workers
	#_logger ("creating connection pool", "info")
	target_socks = min (_workers, qsize ())
	for i in range (target_socks):
		_req ()

	select_timeout = 1.0
	if not _force_h1 and http2.MAX_HTTP2_CONCURRENT_STREAMS > 1:
		# wait all availabale
		while qsize ():
			lifetime.lifetime_loop (select_timeout, 1)
			target_socks = sum ([1 for conn in asyncore.socket_map.values () if hasattr (conn, "get_proto") and not isinstance (conn, (dns.UDPClient, dns.TCPClient)) and conn.get_proto () in H2_PROTOCOLS and conn.connected and not conn.isactive ()])
			if target_socks == _workers:
				#_logger ('%d connection(s) created' % target_socks, 'info')
				break

	# now starting
	if http2.MAX_HTTP2_CONCURRENT_STREAMS == 1:
		measurement = min
	else:
		measurement = max

	while qsize () or _currents:
		lifetime.lifetime_loop (select_timeout, 1)
		while _concurrent > measurement (len (_currents), mapsize ()) and qsize ():
			_req ()
			_max_conns = max (_max_conns, mapsize ())
		#print ('--', len (_currents), mapsize (), qsize ())
github hansroh / aquests / aquests / protocols / whois.py View on Github external
def abort(self):
        print(self.host, "=>", "failed")

    def close(self):
        print(self.host, "=>")
        print(self.text)

#
# try it out
for host in []:
    consumer = WhoisConsumer(host)
    request = WhoisRequest(consumer, host, "whois.internic.net")

# loop returns when all requests have been processed
asyncore.loop()
github hansroh / aquests / aquests / __init__.py View on Github external
meta ['req_id'] = _que.req_id
	meta ['req_method'] = method
	meta ['req_callback'] = callback
	_que.add ((method, url, params, auth, headers, meta, proxy))

	# DNS query for caching and massive
	if not lifetime._polling  and  _dns_reqs < _workers:
		host = urlparse (url) [1].split (":")[0]
		if host not in _dns_query_req:
			_dns_query_req [host] = None
			_dns_reqs += 1
			adns.query (host, "A", callback = lambda x: None)

		if dns.qsize ():
			dns.pop_all ()
			asyncore.loop (0.1, count = 2)
	#print ('~~~~~~~~~~~~~~~', asyndns.pool.connections)
github hansroh / aquests / aquests / athreads / select_trigger.py View on Github external
# tricky: get a pair of connected sockets
			a.bind (self.address)
			a.listen (1)
			w.setblocking (0)
			try:
				w.connect (self.address)
			except:
				pass
				
			r, addr = a.accept()
			a.close()
			w.setblocking (1)
			self.trigger = w

			asyncore.dispatcher.__init__ (self, r)
			self.lock = _thread.allocate_lock()
			self.thunks = []
			self._trigger_connected = 0
github hansroh / aquests / aquests / client / asynconnect.py View on Github external
def handshake (self):		
		if not self._handshaking:
			err = self.socket.getsockopt(socket.SOL_SOCKET, socket.SO_ERROR)
			if err != 0:
				raise OSError(err, asyncore._strerror(err))
				
			ssl_context = create_urllib3_context(ssl_version=resolve_ssl_version(None), cert_reqs=resolve_cert_reqs(None))
			if self.ac_negotiate_http2:								
				try: ssl_context.set_alpn_protocols (H2_PROTOCOLS)
				except AttributeError: ssl_context.set_npn_protocols (H2_PROTOCOLS)								
			self.socket = ssl_context.wrap_socket (self.socket, do_handshake_on_connect = False, server_hostname = self.address [0])			
			self._handshaking = True
			
		try:
			self.socket.do_handshake ()
		except ssl.SSLError as why:
			if why.args [0] in (ssl.SSL_ERROR_WANT_READ, ssl.SSL_ERROR_WANT_WRITE):
				return False
			raise ssl.SSLError(why)
			
		try: self._proto = self.socket.selected_alpn_protocol()