def testQuoteUnquoteLatin1(self): "A latin-1 encoded string should be unmodified through quote and unquote" self.assertEqual("R\xe9sum\xe9", utils.unquote(utils.quote("R\xe9sum\xe9"))) self.assertEqual(utils.quote("R\xe9sum\xe9"), "R%E9sum%E9") self.assertEqual("R\xe9sum\xe9", utils.unquote("R%E9sum%E9")) self.assertEqual("R\xe9sum\xe9", utils.unquote(u"R%E9sum%E9"))
def stderr(username, root_wf_id, wf_id, job_id, job_instance_id): """ Get stderr contents for a specific job instance. """ dashboard = Dashboard(g.master_db_url, root_wf_id, wf_id) text = dashboard.get_stderr(wf_id, job_id, job_instance_id) if text.stderr_text is None: return "No Standard error for workflow " + wf_id + " job-id " + job_id else: return "<pre>%s</pre>" % utils.unquote(text.stderr_text)
def stderr(username, root_wf_id, wf_id, job_id, job_instance_id): """ Get stderr contents for a specific job instance. """ dashboard = Dashboard(g.master_db_url, root_wf_id, wf_id) text = dashboard.get_stderr(wf_id, job_id, job_instance_id) if text.stderr_text == None: return "No Standard error for workflow " + wf_id + " job-id " + job_id else: return "<pre>%s</pre>" % utils.unquote(text.stderr_text)
def stdout(username, root_wf_id, wf_id, job_id, job_instance_id): """ Get stdout contents for a specific job instance. """ dashboard = Dashboard(g.master_db_url, root_wf_id, wf_id) text = dashboard.get_stdout(wf_id, job_id, job_instance_id) if text.stdout_text == None: return 'No stdout for workflow ' + wf_id + ' job-id ' + job_id else: return '<pre>%s</pre>' % utils.unquote(text.stdout_text)
def stderr(root_wf_id, wf_id, job_id): ''' Get stderr contents for a specific job instance. ''' dashboard = Dashboard(g.master_db_url, root_wf_id, wf_id) text = dashboard.get_stderr(wf_id, job_id) if text.stderr_text == None: return 'No Standard error for workflow ' + wf_id + ' job-id ' + job_id; else: return '<pre>%s</pre>' % utils.unquote(text.stderr_text)
def testUnquote(self): "Unquoting should convert character entity references back to their Unicode equivalents" self.assertEqual(utils.unquote("hello%0D%0A%09"), b"hello\r\n\t") for i in range(0, 0x20): self.assertEqual( utils.unquote("%%%02X" % i), (i).to_bytes(1, byteorder="big") ) for i in range(0x20, 0x7F): if not chr(i) in "'\"%": self.assertEqual( utils.unquote(chr(i)), (i).to_bytes(1, byteorder="big") ) for i in range(0x7F, 0xFF): self.assertEqual( utils.unquote("%%%02X" % i), (i).to_bytes(1, byteorder="big") ) self.assertEqual(utils.unquote("%25"), b"%") self.assertEqual(utils.unquote("%27"), b"'") self.assertEqual(utils.unquote("%22"), b'"') self.assertEqual(utils.unquote("Hello%0AWorld!%0A"), b"Hello\nWorld!\n") self.assertEqual(utils.unquote("Zo%C3%AB"), b"Zo\xc3\xab") self.assertEqual( utils.unquote("warning: unused variable %E2%80%98Narr%E2%80%99"), b"warning: unused variable \xe2\x80\x98Narr\xe2\x80\x99", ) self.assertEqual( utils.unquote("warning: unused variable %E2%80%98Narr%E2%80%99").decode( "utf-8" ), "warning: unused variable ‘Narr’", ) self.assertEqual( utils.unquote("warning: unused variable %E2%80%98Narr%E2%80%99").decode( "utf-8" ), "warning: unused variable \u2018Narr\u2019", )
def testUnquoteUnicode(self): "Unicode strings should not be mangled when passed through unquote" # This is a unicode string with UTF-8 encoding, which is nonsense, but # should still work and return a UTF-8 encoded byte string self.assertEqual(utils.unquote("Zo%C3%AB"), b"Zo\xc3\xab")
def testUnquoteInvalidChars(self): "Invalid UTF-8 byte strings should not cause unquote to fail" self.assertEqual(utils.unquote("%80"), b"\x80") # Invalid 1 Octet Sequence self.assertEqual(utils.unquote("%C3("), b"\xc3\x28") # Invalid 2 Octet Sequence self.assertEqual( utils.unquote("%A0%A1"), b"\xa0\xa1" ) # Invalid Sequence Identifier self.assertEqual( utils.unquote("%E2%82%A1"), b"\xe2\x82\xa1" ) # Valid 3 Octet Sequence self.assertEqual( utils.unquote("%E2(%A1"), b"\xe2\x28\xa1" ) # Invalid 3 Octet Sequence (in 2nd Octet) self.assertEqual( utils.unquote("%E2%82("), b"\xe2\x82\x28" ) # Invalid 3 Octet Sequence (in 3rd Octet) self.assertEqual( utils.unquote("%F0%90%8C%BC"), b"\xf0\x90\x8c\xbc" ) # Valid 4 Octet Sequence self.assertEqual( utils.unquote("%F0(%8C%BC"), b"\xf0\x28\x8c\xbc" ) # Invalid 4 Octet Sequence (in 2nd Octet) self.assertEqual( utils.unquote("%F0%90(%BC"), b"\xf0\x90\x28\xbc" ) # Invalid 4 Octet Sequence (in 3rd Octet) self.assertEqual( utils.unquote("%F0(%8C("), b"\xf0\x28\x8c\x28" ) # Invalid 4 Octet Sequence (in 4th Octet) self.assertEqual( utils.unquote("%F8%A1%A1%A1%A1"), b"\xf8\xa1\xa1\xa1\xa1" ) # Valid 5 Octet Sequence (but not Unicode!) self.assertEqual( utils.unquote("%FC%A1%A1%A1%A1%A1"), b"\xfc\xa1\xa1\xa1\xa1\xa1" ) # Valid 6 Octet Sequence (but not Unicode!)
def testUnquote(self): "Unquoting should convert escape sequences back" self.assertEquals("hello\r\n\t", utils.unquote("hello%0D%0A%09"))
def testQuoteUnquoteLatin1(self): "A latin-1 encoded string should be unmodified through quote and unquote" self.assertEqual("R\xe9sum\xe9",utils.unquote(utils.quote("R\xe9sum\xe9"))) self.assertEqual(utils.quote("R\xe9sum\xe9"), "R%E9sum%E9") self.assertEqual("R\xe9sum\xe9",utils.unquote("R%E9sum%E9")) self.assertEqual("R\xe9sum\xe9",utils.unquote(u"R%E9sum%E9"))
def testUnquoteUnicode(self): "Unicode strings should not be mangled when passed through unquote" # This is a unicode string with UTF-8 encoding, which is nonsense, but # should still work and return a UTF-8 encoded byte string self.assertEqual(utils.unquote(u"Zo%C3%AB"), "Zo\xc3\xab")
def testUnquoteInvalidChars(self): "Invalid UTF-8 byte strings should not cause unquote to fail" self.assertEqual(utils.unquote("%80"), "\x80") # Invalid 1 Octet Sequence self.assertEqual(utils.unquote("%C3("), "\xc3\x28") # Invalid 2 Octet Sequence self.assertEqual(utils.unquote("%A0%A1"), "\xa0\xa1") # Invalid Sequence Identifier self.assertEqual(utils.unquote("%E2%82%A1"), "\xe2\x82\xa1") # Valid 3 Octet Sequence self.assertEqual(utils.unquote("%E2(%A1"), "\xe2\x28\xa1") # Invalid 3 Octet Sequence (in 2nd Octet) self.assertEqual(utils.unquote("%E2%82("), "\xe2\x82\x28") # Invalid 3 Octet Sequence (in 3rd Octet) self.assertEqual(utils.unquote("%F0%90%8C%BC"), "\xf0\x90\x8c\xbc") # Valid 4 Octet Sequence self.assertEqual(utils.unquote("%F0(%8C%BC"), "\xf0\x28\x8c\xbc") # Invalid 4 Octet Sequence (in 2nd Octet) self.assertEqual(utils.unquote("%F0%90(%BC"), "\xf0\x90\x28\xbc") # Invalid 4 Octet Sequence (in 3rd Octet) self.assertEqual(utils.unquote("%F0(%8C("), "\xf0\x28\x8c\x28") # Invalid 4 Octet Sequence (in 4th Octet) self.assertEqual(utils.unquote("%F8%A1%A1%A1%A1"), "\xf8\xa1\xa1\xa1\xa1") # Valid 5 Octet Sequence (but not Unicode!) self.assertEqual(utils.unquote("%FC%A1%A1%A1%A1%A1"), "\xfc\xa1\xa1\xa1\xa1\xa1") # Valid 6 Octet Sequence (but not Unicode!)
def testUnquote(self): "Unquoting should convert character entity references back to their Unicode equivalents" self.assertEqual(utils.unquote("hello%0D%0A%09"), "hello\r\n\t") for i in range(0, 0x20): self.assertEqual(utils.unquote("%%%02X" % i), chr(i)) for i in range(0x20, 0x7F): if not chr(i) in "'\"%": self.assertEqual(utils.unquote(chr(i)), chr(i)) for i in range(0x7F, 0xFF): self.assertEqual(utils.unquote("%%%02X" % i), chr(i)) self.assertEqual(utils.unquote("%25"), "%") self.assertEqual(utils.unquote("%27"), "'") self.assertEqual(utils.unquote("%22"), '"') self.assertEqual(utils.unquote("Hello%0AWorld!%0A"), "Hello\nWorld!\n") self.assertEqual(utils.unquote("Zo%C3%AB"), "Zoë") self.assertEqual(utils.unquote("warning: unused variable %E2%80%98Narr%E2%80%99"), "warning: unused variable ‘Narr’") self.assertEqual(utils.unquote("warning: unused variable %E2%80%98Narr%E2%80%99").decode('utf-8'), u"warning: unused variable ‘Narr’") self.assertEqual(utils.unquote("warning: unused variable %E2%80%98Narr%E2%80%99").decode('utf-8'), u"warning: unused variable \u2018Narr\u2019")
def testUnquote(self): "Unquoting should convert character entity references back to their Unicode equivalents" self.assertEqual(utils.unquote("hello%0D%0A%09"), "hello\r\n\t") for i in range(0, 0x20): self.assertEqual(utils.unquote("%%%02X" % i), chr(i)) for i in range(0x20, 0x7F): if not chr(i) in "'\"%": self.assertEqual(utils.unquote(chr(i)), chr(i)) for i in range(0x7F, 0xFF): self.assertEqual(utils.unquote("%%%02X" % i), chr(i)) self.assertEqual(utils.unquote("%25"), "%") self.assertEqual(utils.unquote("%27"), "'") self.assertEqual(utils.unquote("%22"), '"') self.assertEqual(utils.unquote("Hello%0AWorld!%0A"), "Hello\nWorld!\n") self.assertEqual(utils.unquote("Zo%C3%AB"), "Zoë") self.assertEqual( utils.unquote("warning: unused variable %E2%80%98Narr%E2%80%99"), "warning: unused variable ‘Narr’") self.assertEqual( utils.unquote("warning: unused variable %E2%80%98Narr%E2%80%99"). decode('utf-8'), u"warning: unused variable ‘Narr’") self.assertEqual( utils.unquote("warning: unused variable %E2%80%98Narr%E2%80%99"). decode('utf-8'), u"warning: unused variable \u2018Narr\u2019")