def move_tmp(self, path, fail=False): """ Moves the tmp file to the specified path. :param path: directory to move the tmp file to :return: name of the file """ if self.__tmp: Event.print_events() Event.remove_event(key=self.__tmp) h = open(self.__tmp, 'rb') boundary = h.readline() filename = os.path.basename(Tools.get_item(h.readline(), 'filename')[1:-1]) content_type = h.readline().split(': ')[-1] blank_line = h.readline() if not filename or filename == '': return if os.path.exists(path + filename): if fail: return name, ext = Tools.split_extension(filename) filename = name + str(time.time()) + ext with open(path + filename, 'wb') as o: o.writelines(h.readlines()[:-1]) h.close() os.remove(self.__tmp) return filename
def __read_arguments(self, line): """ Read arguments for the current line. """ args = line.split('&') for arg in args: if '=' in arg: name, value = arg.split('=') self.req.arguments.update({Tools.strip_item(name.strip()): Tools.strip_item(value.strip())})
def update_clients(code=''): """ Pushes an update to connected clients. :param code: Message to send or code to imply. """ clients = [] for socket in socket_clients: try: socket.send(Tools.encode_socket(code)) except Exception: clients.append(socket) for client in clients: try: socket_clients.remove(client) except Exception: pass
__author__ = 'Sean Mead' class Static(type): """ Holds the servers as static variables """ web = Server() sock = WebSocketServer() def start(): """ Start the servers """ Static.sock.start() Static.web.start() print '\t**PyJax**\n' print '%s:%s' % (Settings.get('address'), Settings.get('port')) if __name__ == "__main__": Tools.clear_screen() var = '' try: start() while var != 'q': var = raw_input('Enter \'q\' to quit or \'r\' to restart: ') except Exception as e: print 'Error: %s' % e