def _kw_name_match(self, item, expected): if isinstance(expected, basestring) or is_unicode(expected): return utils.eq(item, expected) or ( self._GIVEN_WHEN_THEN_MATCHER.match(item) and utils.eq( self._GIVEN_WHEN_THEN_MATCHER.sub('', item), expected)) return expected.match(item)
def _write_argfile(argfile, args): m_args = list() f = codecs.open(argfile, "wb") # , "utf-8") if PY2: # if IS_WINDOWS: # m_args = [unicode(item,"utf-8") for item in args] # else: # DEBUG # m_args = args for item in args: if is_unicode(item): m_args.append(item.encode("utf-8")) # .decode("utf-8")) else: m_args.append(bytes(item)) # DEBUG m_args = [item.decode("utf-8") for item in args] # print("DEBUG: write_args: %s\n" % m_args) else: m_args = [str(x) for x in args] # .encode("utf-8","surrogate") # print("DEBUG: write_args: %s\n" % m_args) # data = r"\n".join(m_args) if PY2: data = b"\n".join(m_args) f.write(bytes(data)) # DEBUG .decode("utf-8") .encode("utf-8") else: data = "\n".join(m_args) f.write(bytes(data.encode("utf-8", "surrogate"))) f.close()
def _write_argfile(argfile, args): if PY2 or IS_WINDOWS: f = codecs.open(argfile, "wb") #, encoding=encoding.OUTPUT_ENCODING) for item in args: if is_unicode(item): enc_arg = item.encode( 'utf-8' ) # encoding.OUTPUT_ENCODING) # DEBUG CONSOLE_ENCODING else: enc_arg = item try: f.write(enc_arg) #.encode(encoding.OUTPUT_ENCODING)) f.write("\n".encode(encoding.OUTPUT_ENCODING)) except UnicodeError: if PY2: f.write(bytes(item)) else: f.write(bytes(item, 'utf-8')) f.write(b"\n") # print("DEBUG: unicodedecodeerror when writting arg file") else: f = codecs.open(argfile, "w", "utf-8") f.write("\n".join(args)) f.close()
def _write_argfile(argfile, args): if PY2: f = codecs.open(argfile, "wb") for item in args: if is_unicode(item): enc_arg = item.encode(encoding.OUTPUT_ENCODING) else: enc_arg = item f.write(enc_arg+"\n") else: f = codecs.open(argfile, "w", "utf-8") f.write("\n".join(args)) f.close()
def _AppendText(self, textctrl, string, source="stdout", enc=True): if not self.panel or not textctrl: return textctrl.update_scroll_width(string) # we need this information to decide whether to autoscroll or not new_text_start = textctrl.GetLength() linecount = textctrl.GetLineCount() lastVisibleLine = textctrl.GetFirstVisibleLine() + \ textctrl.LinesOnScreen() - 1 textctrl.SetReadOnly(False) try: if enc: textctrl.AppendText(string.encode(encoding['SYSTEM'])) else: textctrl.AppendText(string) # print("DEBUG _AppendText Printed OK") except UnicodeDecodeError as e: # I'm not sure why I sometimes get this, and I don't know what I # can do other than to ignore it. if PY2: if is_unicode(string): textctrl.AppendTextRaw(bytes(string.encode('utf-8'))) else: textctrl.AppendTextRaw(string) else: textctrl.AppendTextRaw(bytes( string, encoding['SYSTEM'])) # DEBUG .encode('utf-8')) # print(r"DEBUG UnicodeDecodeError appendtext string=%s\n" % string) pass except UnicodeEncodeError as e: # I'm not sure why I sometimes get this, and I don't know what I # can do other than to ignore it. textctrl.AppendText( string.encode('utf-8')) # DEBUG .encode('utf-8')) # print(r"DEBUG UnicodeDecodeError appendtext string=%s\n" % string) pass # raise # DEBUG new_text_end = textctrl.GetLength() textctrl.StartStyling(new_text_start, 0x1f) if source == "stderr": textctrl.SetStyling(new_text_end - new_text_start, STYLE_STDERR) textctrl.SetReadOnly(True) if lastVisibleLine >= linecount - 4: linecount = textctrl.GetLineCount() textctrl.ScrollToLine(linecount)
def _AppendText(self, textctrl, string, source="stdout", enc=True): if not self.panel or not textctrl: return textctrl.update_scroll_width(string) # we need this information to decide whether to autoscroll or not new_text_start = textctrl.GetLength() linecount = textctrl.GetLineCount() lastVisibleLine = textctrl.GetFirstVisibleLine() + \ textctrl.LinesOnScreen() - 1 textctrl.SetReadOnly(False) try: if enc: textctrl.AppendText(string.encode(encoding['SYSTEM'])) else: textctrl.AppendText(string) # print("DEBUG _AppendText Printed OK") except UnicodeDecodeError as e: # I'm not sure why I sometimes get this, and I don't know what I # can do other than to ignore it. if PY2: if is_unicode(string): textctrl.AppendTextRaw(bytes(string.encode('utf-8'))) else: textctrl.AppendTextRaw(string) else: textctrl.AppendTextRaw(bytes(string, encoding['SYSTEM'])) # DEBUG .encode('utf-8')) # print(r"DEBUG UnicodeDecodeError appendtext string=%s\n" % string) pass except UnicodeEncodeError as e: # I'm not sure why I sometimes get this, and I don't know what I # can do other than to ignore it. textctrl.AppendText(string.encode('utf-8')) # DEBUG .encode('utf-8')) # print(r"DEBUG UnicodeDecodeError appendtext string=%s\n" % string) pass # raise # DEBUG new_text_end = textctrl.GetLength() textctrl.StartStyling(new_text_start, 0x1f) if source == "stderr": textctrl.SetStyling(new_text_end-new_text_start, STYLE_STDERR) textctrl.SetReadOnly(True) if lastVisibleLine >= linecount-4: linecount = textctrl.GetLineCount() textctrl.ScrollToLine(linecount)
def _format_command(self, argv): """Quote a list as if it were a command line command This isn't perfect but seems to work for the normal use cases. I'm not entirely sure what the perfect algorithm is since *nix and windows have different quoting behaviors. """ result = [] for arg in argv: if PY2 and is_unicode(arg): arg = arg.encode("utf-8") if "'" in arg or " " in arg or "&" in arg: # for windows, if there are spaces we need to use # double quotes. Single quotes cause problems result.append('"%s"' % arg) elif '"' in arg: result.append("'%s'" % arg) else: result.append(arg) return " ".join(result) # DEBUG added bytes
def _write_argfile(argfile, args): if PY2 or IS_WINDOWS: f = codecs.open(argfile, "wb") #, encoding=encoding.OUTPUT_ENCODING) for item in args: if is_unicode(item): enc_arg = item.encode('utf-8') # encoding.OUTPUT_ENCODING) # DEBUG CONSOLE_ENCODING else: enc_arg = item try: f.write(enc_arg) #.encode(encoding.OUTPUT_ENCODING)) f.write("\n".encode(encoding.OUTPUT_ENCODING)) except UnicodeError: if PY2: f.write(bytes(item)) else: f.write(bytes(item, 'utf-8')) f.write(b"\n") # print("DEBUG: unicodedecodeerror when writting arg file") else: f = codecs.open(argfile, "w", "utf-8") f.write("\n".join(args)) f.close()
def contains_keyword(self, name): if isinstance(name, basestring) or is_unicode(name): return self._item.name == name return name.match(self._item.name)