Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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))
def add_channel (self, map = None):
return asyncore.dispatcher.add_channel (self, map)
def collect_incoming_data (self, data):
self.buffer = self.buffer + data
def found_terminator (self):
data, self.buffer = self.buffer, ''
if not data:
asyncore.close_all()
print("done")
return
n = string.atoi (string.split (data)[0])
tf = trigger_file (self)
self.count = self.count + 1
_thread.start_new_thread (thread_function, (tf, self.count, n))
class thread_server (asyncore.dispatcher):
def __init__ (self, family=socket.AF_INET, address=('', 9003)):
asyncore.dispatcher.__init__ (self)
self.create_socket (family, socket.SOCK_STREAM)
self.set_reuse_addr()
self.bind (address)
self.listen (5)
def handle_accept (self):
conn, addr = self.accept()
tp = thread_parent (conn, addr)
thread_server()
#asyncore.loop(1.0, use_poll=1)
try:
asyncore.loop ()
for thunk in self.thunks:
try:
thunk()
except:
if self.logger:
self.logger.trace ('the_trigger')
self.thunks = []
finally:
self.lock.release()
else:
# win32-safe version
class trigger (asyncore.dispatcher):
address = ('127.9.9.9', 19999)
def __init__ (self, logger = None):
self.logger = logger
sock_class = socket.socket
a = sock_class (socket.AF_INET, socket.SOCK_STREAM)
w = sock_class (socket.AF_INET, socket.SOCK_STREAM)
try:
a.setsockopt(
socket.SOL_SOCKET, socket.SO_REUSEADDR,
a.getsockopt(socket.SOL_SOCKET,
socket.SO_REUSEADDR) | 1
)
except socket.error:
pass
from rs4 import asyncore
from ..client.http import httprequest
from ..client.asynlib import asyncon
from . import asyncftp
from . import response
class asyncftp_download (asyncore.dispatcher):
def __init__ (self, handler, host, port):
asyncore.dispatcher.__init__ (self)
self.handler = handler
self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
self.connect((host, port))
def writable (self):
return 0
def handle_connect (self):
pass
def trace (self):
if self.handler:
self.handler.trace ()
#-------------------------------------------------------
# Asyn PostgresSQL Dispatcher
# Hans Roh (hansroh@gmail.com)
# 2015.6.9
#-------------------------------------------------------
from rs4 import asyncore
from . import dbconnect
import sys
DEBUG = False
REREY_TEST = False
class AsynConnect (dbconnect.AsynDBConnect, asyncore.dispatcher):
def __init__ (self, address, params = None, lock = None, logger = None):
dbconnect.AsynDBConnect.__init__ (self, address, params, lock, logger)
self.cur = None
self.retries = 0
asyncore.dispatcher.__init__ (self)
def retry (self):
if self.request is None:
return
self.retries += 1
self.logger ("[warn] closed psycopg2 connection, retrying...")
self.disconnect ()
request, self.request = self.request, None
self.execute (request)
return _STATE_RETRY
def conn(self):
import time
self.connect((self.ns,self.port))
self.time_start=time.time()
if 'start' in self.args and self.args['start']:
asyncore.dispatcher.go(self)