def lansar_no_se_encontro(self, p_mensaje): """ p_mensaje: representa una cadena de texto. Metodo que activa un mensaje de error de no encontrarse la palabra o frase de busqueda. """ Message(gtk.STOCK_DIALOG_ERROR, p_mensaje, "Sorry", self.__window2).run()
def on_button1_activate(self, p_widget): """ p_widget: representa una instancia de GtkButton. Metodo que se invoca tras hacer click sobre en el boton <save> en la ventana <shortcut editor>. En el se comprueba si la solicitud se refiere a adicionar un nuevo shortcut o editar uno existente. Tambien se muestran errores asociados a las anteriores acciones. """ label = self.__label.get_text() i, e = self.__text_v.get_buffer().get_bounds() callback = self.__text_v.get_buffer().get_text(i, e) ver = False if callback == "" or label == "": Message(gtk.STOCK_DIALOG_ERROR, "There are empty fields", "Sorry", self.__shortcut_editor).run() else: if not self.__shortcut_edit: ver = self.__container_shorcuts.verify_create_chortcut(label) if not ver: Message( gtk.STOCK_DIALOG_ERROR, "A Shortcut already \ exist with this label Please \nprovide a different label for this Shortcut", "Sorry", self.__shortcut_editor).run() else: self.__container_shorcuts.create_chortcut( label, callback, self.__combo_ico.get_active()) self.__shortcut_editor.destroy() self.__shortcut_editor = None else: self.__shortcut_edit = False ver = self.__container_shorcuts.modify_chortcut( self.__edit_shortcut, label, callback, self.__combo_ico.get_active()) if not ver: self.__shortcut_edit = True Message( gtk.STOCK_DIALOG_ERROR, "A Shortcut already \ exist with this label Please \nprovide a different label for this Shortcut", "Sorry", self.__shortcut_editor).run() else: self.__shortcut_editor.destroy() self.__shortcut_editor = None
def _pull_urfs(n, timeout=1): """ :param n: 每次取的条数 :param timeout: 取队列时,超时时间 :return: 一个Message列表 """ message_urfs = [] for i in range(0, n): if len(message_urfs) == 0: m = queue_todo.get(block=True) else: m = queue_todo.get(block=True, timeout=timeout) if m is None: return message_urfs m = Message(name='urf') m.parse_json(m) message_urfs.append(m) return message_urfs
def load(self): """ Retorna: True si se cargo el documento, False en caso contrario. Trata de cargar el documento. """ assert (not self.__used) self.__used = True doc = self.__doc path = doc.get_path() create = self.__create if not path: return True try: file_ = open(path, "r") doc.emit("loading", path) text = file_.read() file_.close() except IOError, error: title = ("Reverting Failed", "Opening Failed")[create] if not os.access(path, os.F_OK): if create: msg = "could not be find.\nPlease check that you typed " \ "the location correctly and try again." else: msg = "could not be revert.\nPerhaps it has recently " \ "been deleted." elif not os.access(path, os.R_OK): if create: msg = "could not be open.\nYou do not have the " \ "permissions necessary to open the file." else: msg = "could not be revert.\nPermission denied." else: if create: msg = "unexpected error.\n" + str(error) else: msg = "could not be revert.\n" + str(error) Message(gtk.STOCK_DIALOG_ERROR, "%s\n\n%s" %(path, msg), title, self.__window).run() return False
def execute(self, p_conn): """ p_conn: la 'Connection'. Carga las variables deseadas del fichero indicado. """ tail = p_conn.get_tail_with_priority() names = self.__names path = self.__path all_cmds = [names] for pos in xrange(len(tail) - 1, -1, -1): elem = tail[pos] if elem == self and elem.get_path() == path: all_cmds.append(elem.get_names()) tail.extract(pos) if [] in all_cmds: names = [] else: del all_cmds[0] for cmd in all_cmds: for name in cmd: if name not in names: names.append(name) # if (No existe el archivo): if not os.access(path, os.F_OK): msg = "could not be found." # elif (No se puede leeer): elif not os.access(path, os.R_OK): msg = "could not be readed." else: p_conn.get_terminal().feed_child("load '%s' %s;\n" % (path, " ".join(names))) p_conn.wait_until_ready() if p_conn.get_terminal().buff.get_all().split( "\n")[-2][0] != "e": # if (no_hubo_error) return else: msg = "could not be read matrix." Message(gtk.STOCK_DIALOG_WARNING, "%s\n\n%s" % (path, msg), "Loading Failed", p_conn.get_mwindow().get_window()).run(True)
def execute(self, p_conn): """ p_conn: la 'Connection'. Renombra la variable deseada con el nuevo nombre. """ tail = p_conn.get_tail_with_priority() found = False last = self for pos in xrange(tail.count(self) - 1, -1, -1): if tail[pos].get_old() == self.__old: if not found: last = tail[pos] found = True tail.extract(pos) new, old, attr = last.get_new(), last.get_old(), last.get_attr() if new != old: if re.search("^[_\$a-zA-Z][_\$a-zA-Z0-9]*\Z", new): cmd = "clear %s;" % new if "g" in attr: cmd += "global %s;" % new if "p" in attr: cmd += "persistent %s;" % new cmd += "%s=%s;clear %s;\n" % (new, old, old) p_conn.get_terminal().feed_child(cmd) p_conn.wait_until_ready() if p_conn.get_terminal().buff.get_all().rfind("^") == -1: return msg = 'Could not rename the variable.\n\n'\ '"%s" is not a valid OCTAVE variable name.\n'\ 'OCTAVE variable names must:\n'\ '- Begin with a letter, underscore or dollar\n'\ '- Contain only letters, underscores, dollars and digits\n'\ '- Not be a OCTAVE keyword' %new Message(gtk.STOCK_DIALOG_WARNING, msg, "Editing Failed", p_conn.get_mwindow().get_window()).run(True)
def save(self): """ Retorna: True si se salvo el documento, False en caso contrario. Trata de salvar el documento. """ assert (not self.__used) self.__used = True doc = self.__doc path = self.__path try: file_ = open(path, "w") doc.emit("saving", path) file_.write(doc.get_all_text()) file_.close() except IOError, error: if os.access(path, os.F_OK): msg = "could not be saved.\nYou do not have the permissions " \ "necessary to save the file.\nPlease check that you " \ "typed the location correctly and try again." elif not os.access(os.path.dirname(path), os.W_OK): msg = "could not be saved to this location.\nYou do not have "\ "the permissions necessary to create the file in that " \ "directory.\nPlease check that you typed the location " \ "correctly and try again." else: msg = str(error) + "\nPlease check that you typed the " \ "location correctly and try again." Message(gtk.STOCK_DIALOG_ERROR, "%s\n\n%s" % (path, msg), "Saving Failed", self.__window).run() return False
def lambda_handler(event, context): message_id = event['webhook_event']['message_id'] reply_account = event['webhook_event']['account_id'] keyword = event['webhook_event']['body'] if reply_account == MY_ACCOUNT: return print('No New Messages') es_client = EsClient() response = es_client.get_document_and(keyword) tickets = [] for ticket_record in response['hits']['hits']: ticket = Ticket(ticket_record) tickets.append(ticket) message = Message.get_message_body(message_id, reply_account, tickets, ROOM_ID) response = ChatWorkClient.post_messages(message, ROOM_ID) print(response)
def import_data(self): """ Es llamado cuando el usario desea importar variables hacia el 'Workspace'. Muestra un dialogo para que el usuario indique donde estan los datos a importar, una vez indicado esto, se muestra el 'ImportWizard'(Asistente de Importacion) en el cual se listan las variables presentes en el archivo seleccionado. """ if self.__import_wiz: self.__import_wiz.present() return path = WorkspaceImportDialog(self.__parent, self.__current_dir.get_path()).run() if not path: return # if (No existe el archivo): if not os.access(path, os.F_OK): msg = ( "could not be find.", "Please check that you typed the location correctly and try again." ) # elif (No se puede leer): elif not os.access(path, os.R_OK): msg = ( "could not be open.", "You do not have the permissions necessary to open the file.") else: self.__import_wiz = ImportWizard(path, self.__conn, self, self.__parent, self.__tree.get_model()) return Message(gtk.STOCK_DIALOG_WARNING, "%s\n\n%s" % (path, "\n".join(msg)), "Importing Failed", self.__parent).run()
def _parse_msg(self, msg): ''' Parses a message, makes a protocol independent message and sends it to the callback function. ''' if len(msg) == 0: logging.debug("IRC listener received empty message.") source = string.split(msg, "!")[0] if len(source) > 1: source = source[1:] if source == self._name: return parts = string.split(msg, " ") operation = None content = string.split(msg, ":") if len(content) > 2: content = string.join(content[2:], ":") else: content = "" content = string.strip(content) if len(parts) > 1: operation = parts[1] if operation == None: return elif operation == "PRIVMSG": if len(parts) < 3: return elif parts[2] == self._channel: message = Message(source, self._channel, content) self._function(message) else: message = PrivateMessage(source, parts[2], content) self._function(message) else: message = SystemMessage("SYSTEM", self._channel, content) self._function(message)
def __init__(self, source, target, body): Message.__init__(self, source, target, body)
def execute(self, p_conn): """ p_conn: la 'Connection'. Guarda las variables deseadas en el fichero indicado. """ tail = p_conn.get_tail_with_priority() names = self.__names path = self.__path for pos in xrange(len(tail) - 1, -1, -1): elem = tail[pos] if elem == self and len(elem.get_names()) == len(names) and\ elem.get_path() == path: flag = True for name in elem.get_names(): if name not in names: flag = False break if flag: tail.extract(pos) ########################## BEGIN ############################### main_win = p_conn.get_mwindow() parent = main_win.get_window() curdir = main_win.get_cdirectory().get_path() while True: save = True # if (Existe el archivo): if os.access(path, os.F_OK): # if (No se puede escribir): if not os.access(path, os.W_OK): save = False stock = gtk.STOCK_DIALOG_WARNING msg = ( "is read-only on disk.", "Do you want to save to a different name or location?") # elif (No puede crearse): elif not os.access(os.path.dirname(path), os.W_OK): save = False stock = gtk.STOCK_DIALOG_QUESTION msg = ("cannot be saved to this location.", "Do you want to save to a different location?") if save: break if not Confirm(stock, "%s\n\n%s" % (path, "\n".join(msg)), "Save to VAR-File:", parent).run(True): return path = WorkspaceSaveDialog(parent, curdir).run(True) if not path: return ########################## END ################################# p_conn.get_terminal().feed_child("save -binary '%s' %s;\n" % (path, " ".join(names))) p_conn.wait_until_ready() lines = p_conn.get_terminal().buff.get_all().split("\n") pos = -2 line = lines[pos] vars_ = [] while line[0] == "w": vars_.insert(0, line[line.rfind("`") + 1:-1]) pos -= 1 line = lines[pos] if vars_: if len(vars_) == 1: msg = 'A variable named "%s"' % vars_[0] elif len(vars_) == 2: msg = 'Variables named "%s" and "%s"' % (vars_[0], vars_[1]) else: msg = "Some variables" Message(gtk.STOCK_DIALOG_WARNING, "%s could not be saved." % msg, "Saving Failed", parent).run(True)
def get_latest_message(self): print("getting latest message...") return Message( self.driver.find_element( By.XPATH, '//div[@class="g5ia77u1 jwdofwj8 pby63qed"]'))
from util.sockets import ClientSocket from util.message import Message sock = ClientSocket('localhost', 5050) message = Message(sock) loginB = "l" in raw_input("(L)ogin or (R)egister?: ").lower() domain = None subdomain1 = None subdomain2 = None if loginB: # Do login stuff secret = raw_input("Enter your secret: ") message.send(10, 0, [secret]) response = message.get() if response["code"] == 2: print "INVALID SECRET" import sys sys.exit(1) message.send(21, 1) response = message.get() domain = response["param"][0] subdomain1 = response["param"][1] subdomain2 = response["param"][2] else: secret = raw_input("Enter a secret (like a password, but no security): ") domain = raw_input("Enter a domain: ") subdomain1 = raw_input("Enter a subdomain: ") subdomain2 = raw_input("Enter a second subdomain: ")