def __init__(self, segment='skynet'): config = Configuration() self.jobs = {} self.sched = MessageScheduler(self.message_handler) self.parser = Parser() self.aggregator = None self.failed_aggregator = False self.query_queue = [] conn = Connection('poller', 'roflcake') self.entity_prefix, entity_suffix = conn.get_entity_name() # self.entity_name = entity_prefix + entity_suffix conn.join_muc('pollers') self.segment = segment self.conn = conn.get_conn() self.log = Logging(conn) self.roster = self.conn.getRoster() self.conn.RegisterHandler('presence',self.presence_handler) self.conn.RegisterHandler('iq', self.result_handler, 'result') self.conn.RegisterHandler('iq', self.error_handler, 'error') self.conn.RegisterHandler('iq', self.get_handler, 'get') self.conn.RegisterHandler('iq', self.set_handler, 'set') self.go_on()
def get_event_connection(self): logging.debug('ex.get_event_connection') # any connections left ? if len(self.event_conn_queue): return self.event_conn_queue.pop(0) # No available connections, can we create # another one? if not self.event_connections < MAX_EVENT_CONNS: return None # create another one ep = EVENT_ENDPOINT.split(':') ep = (ep[0], int(ep[1])) self.event_connections += 1 conn = Connection( ep, self.loop, self.create_win_request, self.receive_win_response, self.remove_event_connection, None) state = conn.connect() if state == Connection.STATE_CONNECTING: logging.debug('event connecting with id %d' % conn.id) self.event_conns[conn.id] = conn return conn
def async_connect(self, endpoint): """ Asynchronously connect to an endpoint """ # create the connection logging.debug("launching async_connect to %s" % endpoint) ep = endpoint.split(":") ep = (ep[0], int(ep[1])) conn = Connection(ep, self.loop, self.create_request, self.receive_response, self.remove_connection, None) self.awaiting_conns[conn.id] = conn # create the entry if endpoint not in self.conns: self.conns[endpoint] = [] state = conn.connect() if state == Connection.STATE_CONNECTING: logging.debug("connecting!")
def async_connect(self, endpoint): ''' Asynchronously connect to an endpoint ''' # create the connection logging.debug('launching async_connect to %s' % endpoint) ep = endpoint.split(':') ep = (ep[0], int(ep[1])) conn = Connection(ep, self.loop, self.create_request, self.receive_response, self.remove_connection, None) self.awaiting_conns[conn.id] = conn # create the entry if endpoint not in self.conns: self.conns[endpoint] = [] state = conn.connect() if state == Connection.STATE_CONNECTING: logging.debug('connecting!')
def __init__(self): self.db = Database() entity_prefix = 'controller' conn = Connection(entity_prefix, static=True) self.entity_name, self.entity_suffix = conn.get_entity_name() # List of nodes known to the controller self.poller_map = {} self.poller_pool = {} self.job_map = {} self.job_pool = [] # Message scheduler self.sched = MessageScheduler(self.message_handler) self.log = Logging(conn) conn.join_muc('pollers') conn.join_muc('aggregators') self.parser = Parser() self.establish_jobs() self.conn = conn.get_conn() self.conn.RegisterHandler('iq',self.result_handler,'result') self.conn.RegisterHandler('iq',self.set_handler,'set') self.conn.RegisterHandler('presence',self.presence_handler) self.go_on()
def __init__(self, master_addr='localhost', master_port=9333, use_session=False): '''Creates WeedFS instance. Args: **master_addr**: Address of weed-fs master server (default: localhost) **master_port**: Weed-fs master server port (default: 9333) **use_session**: Use request.Session() for connections instead of requests themselves. (default: False) Returns: WeedFS instance. ''' self.master_addr = master_addr self.master_port = master_port self.conn = Connection(use_session)
def __init__(self): config = Configuration() self.db = Database() self.results = self.db.get_table('results') self.job_map = {} self.job_pool = [] self.failed_jobs = [] self.evals = {} self.notifier = Notifier() self.sched = MessageScheduler(self.message_handler) conn = Connection('aggregator', 'roflcake') entity_prefix, entity_suffix = conn.get_entity_name() self.entity_name = entity_prefix + entity_suffix self.log = Logging(conn) conn.join_muc('aggregators') self.conn = conn.get_conn() self.roster = self.conn.getRoster() self.conn.RegisterHandler('iq',self.set_handler,'set') self.conn.RegisterHandler('iq',self.get_handler,'get') self.conn.RegisterHandler('iq',self.result_handler,'result') self.conn.RegisterHandler('presence',self.presence_handler) self.temp_messages = [] self.parser = Parser() self.go_on()
def setConnectionInfo(): ''' :param: None :return: Connection object ''' parser = argparse.ArgumentParser(description='Ping over TCP/UDP network client') parser.add_argument('-p', '--port' , action="store", type=int, required=True, help="Network port (eg. 23, 80, 161, ...)") parser.add_argument('-n', '--protocol' , action="store", choices=['tcp', 'udp'], required=True, help="Network protocol (tcp or udp)") parser.add_argument('-i', '--ip' , action="store", required=True, help="IP or hostname of the server") parser.add_argument('-c', '--count' , action="store", type=int, help="Reply counts", default=4) parser.add_argument('-l', '--length' , action="store", type=int, help="Packet data length ", default=32) parser.add_argument('-t', '--timeout' , action="store", type=int, help="Replay max timout (sec) ", default=1) args=parser.parse_args() port = args.port if (not(port >= 0 and port <= 65535)): sys.exit("Invalid port rage %s" % port) protocol = args.protocol timeout = args.timeout count = args.count ip = args.ip packetSize = args.length connectionInfo = Connection(ip, port, protocol, timeout, packetSize, count) return connectionInfo
os.makedirs(folder) if not os.path.isfile(local_filename): r = requests.get(url, stream=True) with open(local_filename, 'wb') as f: for chunk in r.iter_content(chunk_size=1024): if chunk: # filter out keep-alive new chunks f.write(chunk) # f.flush() commented by recommendation from J.F.Sebastian return local_filename modules = ModuleLoader().load('modules') for clazz in modules: m = clazz() lst = m.getKarList(Connection()) n = 1 m = len(lst) for singer, urls in lst.iteritems(): print('singer ', n, '/', m) n += 1 a = 1 b = len(urls) for url in urls: print('song ', a, '/', b) download_file(singer, url) a += 1 print('*** END ***') """ page = requests.get('https://midi-karaoke-video.blogspot.it/2014/11/midi-karaoke-cantanti-italiani-ordine.html',headers={},proxies=proxyDict)
from __future__ import print_function # For Py2/3 compatibility import eel from utils import Connection if __name__ == '__main__': eel.init('gui') s = Connection("localhost", 8080) print("Iniciando conexion!") if not s.start(): print("Error al establecer conexion!") exit(code=1) @eel.expose # Decorador para eel (Exponemos la funcion a javascript) def sendCommand(message): data = s.sendMessage(message) # Enviamos el mensaje return str( data) # Regresamos a Javascript el resultado de la consulta! eel.start('index.html') # Start
class WeedFS(object): master_addr = "localhost" master_port = 9333 def __init__(self, master_addr='localhost', master_port=9333, use_session=False): '''Creates WeedFS instance. Args: **master_addr**: Address of weed-fs master server (default: localhost) **master_port**: Weed-fs master server port (default: 9333) **use_session**: Use request.Session() for connections instead of requests themselves. (default: False) Returns: WeedFS instance. ''' self.master_addr = master_addr self.master_port = master_port self.conn = Connection(use_session) def __repr__(self): return "<{0} {1}:{2}>".format(self.__class__.__name__, self.master_addr, self.master_port) def get_file(self, url): """Get file from WeedFS. Returns file content. May be problematic for large files as content is stored in memory. Args: **fid**: File identifier <volume_id>,<file_name_hash> Returns: Content of the file with provided fid or None if file doesn't exist on the server .. versionadded:: 0.3.1 """ # url = self.get_file_url(fid) return self.conn.get_raw_data(url) def get_file_location(self, volume_id): """ Get location for the file, WeedFS volume is choosed randomly :param integer volume_id: volume_id :rtype: namedtuple `FileLocation` `{"public_url":"", "url":""}` """ url = ("http://{master_addr}:{master_port}/" "dir/lookup?volumeId={volume_id}").format( master_addr=self.master_addr, master_port=self.master_port, volume_id=volume_id) data = json.loads(self.conn.get_data(url)) _file_location = random.choice(data['locations']) FileLocation = namedtuple('FileLocation', "public_url url") return FileLocation(_file_location['publicUrl'], _file_location['url']) def get_file_size(self, url): """ Gets size of uploaded file Or None if file doesn't exist. Args: **fid**: File identifier <volume_id>,<file_name_hash> Returns: Int or None """ # url = self.get_file_url(fid) res = self.conn.head(url) if res is not None: size = res.headers.get("content-length", None) if size is not None: return int(size) return None def file_exists(self, url): """Checks if file with provided fid exists Args: **fid**: File identifier <volume_id>,<file_name_hash> Returns: True if file exists. False if not. """ res = self.get_file_size(url) if res is not None: return True return False def delete_file(self, url): """ Delete file from WeedFS :param string fid: File ID """ # url = self.get_file_url(fid) return self.conn.delete_data(url) def upload_file(self, url, obj_name, obj_content): """ Uploads file to WeedFS I takes either path or stream and name and upload it to WeedFS server. Returns fid of the uploaded file. :param string path: :param string stream: :param string name: :rtype: string or None """ res = self.conn.post_file(url, obj_name, obj_content) response_data = json.loads(res) if "size" in response_data: return response_data.get('size') return None def vacuum(self, threshold=0.3): ''' Force garbage collection :param float threshold (optional): The threshold is optional, and will not change the default threshold. :rtype: boolean ''' url = ("http://{master_addr}:{master_port}/" "vol/vacuum?garbageThreshold={threshold}").format( master_addr=self.master_addr, master_port=self.master_port, threshold=threshold) res = self.conn.get_data(url) if res is not None: return True return False @property def version(self): ''' Returns Weed-FS master version :rtype: string ''' url = "http://{master_addr}:{master_port}/dir/status".format( master_addr=self.master_addr, master_port=self.master_port) data = self.conn.get_data(url) response_data = json.loads(data) return response_data.get("Version")
from __future__ import print_function # For Py2/3 compatibility import eel from utils import Connection if __name__ == '__main__': name = input("Nickname: ") port = int(input("PORT: ")) eel.init('gui') s = Connection("localhost",8080,"224.1.1.1",5007,name) print("Iniciando conexion!") if not s.start(): print("Error al establecer conexion!") exit(code=1) @eel.expose # Decorador para eel (Exponemos la funcion a javascript) def sendCommand(message,action): s.sendMessage(message,action) # Enviamos el mensaje return "ok" # Regresamos a Javascript el resultado de la consulta! @eel.expose def sendPhoto(message,data): s.sendPhoto(message) return "ok" eel.start('index.html', options={"port":port}) # Start