def __user_input(self, prompt): try: input_val = "" if cross_version.get_python_version() == 3: input_val = input(prompt) elif cross_version.get_python_version() == 2: input_val = raw_input(prompt) return input_val.strip() except KeyboardInterrupt: return "exit"
def __base64_doc(self): doc_string = self.__doc_to_string() if doc_string.strip() == "": return "" else: if cross_version.get_python_version() == 2: output = base64.standard_b64encode(doc_string) elif cross_version.get_python_version() == 3: output = base64.standard_b64encode(bytes(doc_string,'UTF-8')) output = output.decode('utf-8') else: assert False return output
def __base64_doc(self): doc_string = self.__doc_to_string() if doc_string.strip() == "": return "" else: if cross_version.get_python_version() == 2: output = base64.standard_b64encode(doc_string) elif cross_version.get_python_version() == 3: output = base64.standard_b64encode(bytes(doc_string, "UTF-8")) output = output.decode("utf-8") else: assert False return output
def run(self, command_string, send_list=[]): PYTHON_VERSION = cross_version.get_python_version() if not cross_version.isstring(command_string): raise ValueError("Invalid command") proc = subprocess.Popen([command_string], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) if len(send_list) > 0: stdin_string = "" for value in send_list: stdin_string += value + "\n" if PYTHON_VERSION == 3: stdin_string = bytes(stdin_string, 'UTF-8') else: stdin_string = None try: if PYTHON_VERSION == 3: output, error = proc.communicate(stdin_string, timeout=60) output = output.decode('UTF-8') error = error.decode('UTF-8') elif PYTHON_VERSION == 2: output, error = proc.communicate(stdin_string) if not output.strip() == "": output_list = output.strip().split("\n") else: output_list = [] if not error.strip() == "": error_list = error.strip().split("\n") else: error_list = [] if '' in output_list: output_list.remove('') if '' in error_list: error_list.remove('') return (proc.returncode, output_list, error_list) except OSError as e: return ([], ["OSError", e.message])
def run(self, command_string, send_list=[]): PYTHON_VERSION = cross_version.get_python_version() if not cross_version.isstring(command_string): raise ValueError("Invalid command") proc = subprocess.Popen([command_string], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) if len(send_list) > 0: stdin_string = "" for value in send_list: stdin_string += value + "\n" if PYTHON_VERSION == 3: stdin_string = bytes(stdin_string, 'UTF-8') else: stdin_string = None try: if PYTHON_VERSION == 3: output, error = proc.communicate(stdin_string, timeout=60) output = output.decode('UTF-8') error = error.decode('UTF-8') elif PYTHON_VERSION == 2: output, error = proc.communicate(stdin_string) if not output.strip() == "": output_list = output.strip().split("\n") else: output_list = [] if not error.strip() == "": error_list = error.strip().split("\n") else: error_list = [] if '' in output_list: output_list.remove('') if '' in error_list: error_list.remove('') return (proc.returncode ,output_list, error_list) except OSError as e: return ([], ["OSError", e.message])
def get_python_version_tests(): assert cross_version.get_python_version( ) == 2 or cross_version.get_python_version() == 3
def get_python_version_tests(): assert cross_version.get_python_version() == 2 or cross_version.get_python_version() == 3