From 4fe2c069cca07aadf983f54e18dac4de492d5d69 Mon Sep 17 00:00:00 2001 From: Jim Shaver Date: Fri, 29 May 2015 23:17:48 -0400 Subject: [PATCH 1/3] Fixed print function to be inline with python 3 --- examples/flowbasic | 2 +- examples/har_extractor.py | 2 +- examples/mitmproxywrapper.py | 6 ++-- examples/nonblocking.py | 4 +-- examples/read_dumpfile | 4 +-- libmproxy/contrib/jsbeautifier/__init__.py | 2 +- libmproxy/contrib/pyparsing.py | 40 +++++++++++----------- libmproxy/platform/windows.py | 4 +-- libmproxy/tnetstring.py | 4 +-- libmproxy/web/app.py | 6 ++-- 10 files changed, 37 insertions(+), 37 deletions(-) diff --git a/examples/flowbasic b/examples/flowbasic index c71debc93..edd96b0d7 100755 --- a/examples/flowbasic +++ b/examples/flowbasic @@ -30,7 +30,7 @@ class MyMaster(flow.FlowMaster): f = flow.FlowMaster.handle_response(self, f) if f: f.reply() - print f + print(f) return f diff --git a/examples/har_extractor.py b/examples/har_extractor.py index 5c228ece6..489898a29 100644 --- a/examples/har_extractor.py +++ b/examples/har_extractor.py @@ -231,4 +231,4 @@ def print_attributes(obj, filter_string=None, hide_privates=False): if filter_string is not None and filter_string not in attr: continue value = getattr(obj, attr) - print "%s.%s" % ('obj', attr), value, type(value) \ No newline at end of file + print("%s.%s" % ('obj', attr), value, type(value)) diff --git a/examples/mitmproxywrapper.py b/examples/mitmproxywrapper.py index 2f3750e9f..29e3ac161 100755 --- a/examples/mitmproxywrapper.py +++ b/examples/mitmproxywrapper.py @@ -28,12 +28,12 @@ class Wrapper(object): return dict([re.findall(r'([^:]+): (.*)', line)[0] for line in state]) def enable_proxy_for_service(self, service): - print 'Enabling proxy on {}...'.format(service) + print('Enabling proxy on {}...'.format(service)) for subcommand in ['-setwebproxy', '-setsecurewebproxy']: self.run_networksetup_command(subcommand, service, '127.0.0.1', str(self.port)) def disable_proxy_for_service(self, service): - print 'Disabling proxy on {}...'.format(service) + print('Disabling proxy on {}...'.format(service)) for subcommand in ['-setwebproxystate', '-setsecurewebproxystate']: self.run_networksetup_command(subcommand, service, 'Off') @@ -112,7 +112,7 @@ class Wrapper(object): @classmethod def ensure_superuser(cls): if os.getuid() != 0: - print 'Relaunching with sudo...' + print('Relaunching with sudo...') os.execv('/usr/bin/sudo', ['/usr/bin/sudo'] + sys.argv) @classmethod diff --git a/examples/nonblocking.py b/examples/nonblocking.py index 481c0407f..7bc9c07b3 100644 --- a/examples/nonblocking.py +++ b/examples/nonblocking.py @@ -4,6 +4,6 @@ from libmproxy.script import concurrent @concurrent # Remove this and see what happens def request(context, flow): - print "handle request: %s%s" % (flow.request.host, flow.request.path) + print("handle request: %s%s" % (flow.request.host, flow.request.path)) time.sleep(5) - print "start request: %s%s" % (flow.request.host, flow.request.path) \ No newline at end of file + print("start request: %s%s" % (flow.request.host, flow.request.path)) diff --git a/examples/read_dumpfile b/examples/read_dumpfile index f58184835..82bf832df 100644 --- a/examples/read_dumpfile +++ b/examples/read_dumpfile @@ -13,6 +13,6 @@ with open("logfile", "rb") as logfile: print(f) print(f.request.host) json.dump(f.get_state(), sys.stdout, indent=4) - print "" + print("") except flow.FlowReadError, v: - print "Flow file corrupted. Stopped loading." + print("Flow file corrupted. Stopped loading.") diff --git a/libmproxy/contrib/jsbeautifier/__init__.py b/libmproxy/contrib/jsbeautifier/__init__.py index e319e8dd1..b43d41ce4 100644 --- a/libmproxy/contrib/jsbeautifier/__init__.py +++ b/libmproxy/contrib/jsbeautifier/__init__.py @@ -216,7 +216,7 @@ class Beautifier: parser_pos = 0 while True: token_text, token_type = self.get_next_token() - #print (token_text, token_type, self.flags.mode) + #print(token_text, token_type, self.flags.mode) if token_type == 'TK_EOF': break diff --git a/libmproxy/contrib/pyparsing.py b/libmproxy/contrib/pyparsing.py index 06b11d98f..4d26324cc 100644 --- a/libmproxy/contrib/pyparsing.py +++ b/libmproxy/contrib/pyparsing.py @@ -40,7 +40,7 @@ Here is a program to parse "Hello, World!" (or any greeting of the form "", greet.parseString( hello ) + print(hello, "->", greet.parseString( hello )) The program outputs the following:: @@ -651,13 +651,13 @@ def line( loc, strg ): return strg[lastCR+1:] def _defaultStartDebugAction( instring, loc, expr ): - print ("Match " + _ustr(expr) + " at loc " + _ustr(loc) + "(%d,%d)" % ( lineno(loc,instring), col(loc,instring) )) + print("Match " + _ustr(expr) + " at loc " + _ustr(loc) + "(%d,%d)" % ( lineno(loc,instring), col(loc,instring) )) def _defaultSuccessDebugAction( instring, startloc, endloc, expr, toks ): - print ("Matched " + _ustr(expr) + " -> " + str(toks.asList())) + print("Matched " + _ustr(expr) + " -> " + str(toks.asList())) def _defaultExceptionDebugAction( instring, loc, expr, exc ): - print ("Exception raised:" + _ustr(exc)) + print("Exception raised:" + _ustr(exc)) def nullDebugAction(*args): """'Do-nothing' debug action, to suppress debugging output during parsing.""" @@ -804,7 +804,7 @@ class ParserElement(object): numargs -= 1 - #~ print ("adding function %s with %d args" % (f.func_name,numargs)) + #~ print("adding function %s with %d args" % (f.func_name,numargs)) if numargs == 3: return f else: @@ -914,7 +914,7 @@ class ParserElement(object): debugging = ( self.debug ) #and doActions ) if debugging or self.failAction: - #~ print ("Match",self,"at loc",loc,"(%d,%d)" % ( lineno(loc,instring), col(loc,instring) )) + #~ print("Match",self,"at loc",loc,"(%d,%d)" % ( lineno(loc,instring), col(loc,instring) )) if (self.debugActions[0] ): self.debugActions[0]( instring, loc, self ) if callPreParse and self.callPreparse: @@ -928,7 +928,7 @@ class ParserElement(object): except IndexError: raise ParseException( instring, len(instring), self.errmsg, self ) except ParseBaseException, err: - #~ print ("Exception raised:", err) + #~ print("Exception raised:", err) if self.debugActions[2]: self.debugActions[2]( instring, tokensStart, self, err ) if self.failAction: @@ -962,7 +962,7 @@ class ParserElement(object): asList=self.saveAsList and isinstance(tokens,(ParseResults,list)), modal=self.modalResults ) except ParseBaseException, err: - #~ print "Exception raised in user parse action:", err + #~ print("Exception raised in user parse action:", err) if (self.debugActions[2] ): self.debugActions[2]( instring, tokensStart, self, err ) raise @@ -976,7 +976,7 @@ class ParserElement(object): modal=self.modalResults ) if debugging: - #~ print ("Matched",self,"->",retTokens.asList()) + #~ print("Matched",self,"->",retTokens.asList()) if (self.debugActions[1] ): self.debugActions[1]( instring, tokensStart, loc, self, retTokens ) @@ -2861,7 +2861,7 @@ class SkipTo(ParseElementEnhance): while 1: try: loc = self.ignoreExpr.tryParse(instring,loc) - print "found ignoreExpr, advance to", loc + print("found ignoreExpr, advance to", loc) except ParseBaseException: break expr._parse( instring, loc, doActions=False, callPreParse=False ) @@ -3239,7 +3239,7 @@ def oneOf( strs, caseless=False, useRegex=True ): i += 1 if not caseless and useRegex: - #~ print (strs,"->", "|".join( [ _escapeRegexChars(sym) for sym in symbols] )) + #~print(strs,"->", "|".join( [ _escapeRegexChars(sym) for sym in symbols] )) try: if len(symbols)==len("".join(symbols)): return Regex( "[%s]" % "".join( [ _escapeRegexRangeChars(sym) for sym in symbols] ) ) @@ -3669,16 +3669,16 @@ if __name__ == "__main__": try: tokens = simpleSQL.parseString( teststring ) tokenlist = tokens.asList() - print (teststring + "->" + str(tokenlist)) - print ("tokens = " + str(tokens)) - print ("tokens.columns = " + str(tokens.columns)) - print ("tokens.tables = " + str(tokens.tables)) - print (tokens.asXML("SQL",True)) + print(teststring + "->" + str(tokenlist)) + print("tokens = " + str(tokens)) + print("tokens.columns = " + str(tokens.columns)) + print("tokens.tables = " + str(tokens.tables)) + print(tokens.asXML("SQL",True)) except ParseBaseException,err: - print (teststring + "->") - print (err.line) - print (" "*(err.column-1) + "^") - print (err) + print(teststring + "->") + print(err.line) + print(" "*(err.column-1) + "^") + print(err) print() selectToken = CaselessLiteral( "select" ) diff --git a/libmproxy/platform/windows.py b/libmproxy/platform/windows.py index 066a377d9..98bfebcff 100644 --- a/libmproxy/platform/windows.py +++ b/libmproxy/platform/windows.py @@ -354,7 +354,7 @@ class TransparentProxy(object): if server: packet.src_addr, packet.src_port = server else: - print "Warning: Previously unseen connection from proxy to %s:%s." % client + print("Warning: Previously unseen connection from proxy to %s:%s." % client) packet = self.driver.update_packet_checksums(packet) self.response_handle.send((packet.raw, metadata)) @@ -391,4 +391,4 @@ if __name__ == "__main__": except KeyboardInterrupt: print(" * Shutting down...") proxy.shutdown() - print(" * Shut down.") \ No newline at end of file + print(" * Shut down.") diff --git a/libmproxy/tnetstring.py b/libmproxy/tnetstring.py index 585196754..91b3ba2aa 100644 --- a/libmproxy/tnetstring.py +++ b/libmproxy/tnetstring.py @@ -60,10 +60,10 @@ By default tnetstrings work only with byte strings, not unicode. If you want unicode strings then pass an optional encoding to the various functions, like so:: - >>> print repr(tnetstring.loads("2:\\xce\\xb1,")) + >>> print(repr(tnetstring.loads("2:\\xce\\xb1,"))) '\\xce\\xb1' >>> - >>> print repr(tnetstring.loads("2:\\xce\\xb1,","utf8")) + >>> print(repr(tnetstring.loads("2:\\xce\\xb1,","utf8"))) u'\u03b1' """ diff --git a/libmproxy/web/app.py b/libmproxy/web/app.py index 8598acf51..2fc849f98 100644 --- a/libmproxy/web/app.py +++ b/libmproxy/web/app.py @@ -180,7 +180,7 @@ class Settings(RequestHandler): update = {} for k, v in self.request.arguments.iteritems(): if len(v) != 1: - print "Warning: Unknown length for setting {}: {}".format(k, v) + print("Warning: Unknown length for setting {}: {}".format(k, v)) continue if k == "_xsrf": @@ -189,7 +189,7 @@ class Settings(RequestHandler): self.state.set_intercept(v[0]) update[k] = v[0] else: - print "Warning: Unknown setting {}: {}".format(k, v) + print("Warning: Unknown setting {}: {}".format(k, v)) ClientConnection.broadcast( type="settings", @@ -224,4 +224,4 @@ class Application(tornado.web.Application): cookie_secret=os.urandom(256), debug=debug, ) - super(Application, self).__init__(handlers, **settings) \ No newline at end of file + super(Application, self).__init__(handlers, **settings) From bd019a7124d96bbab6dc675e7295995ce9199903 Mon Sep 17 00:00:00 2001 From: Jim Shaver Date: Sun, 31 May 2015 07:59:00 -0400 Subject: [PATCH 2/3] revert changes in ncontrib --- libmproxy/contrib/jsbeautifier/__init__.py | 2 +- libmproxy/contrib/pyparsing.py | 40 +++++++++++----------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/libmproxy/contrib/jsbeautifier/__init__.py b/libmproxy/contrib/jsbeautifier/__init__.py index b43d41ce4..e319e8dd1 100644 --- a/libmproxy/contrib/jsbeautifier/__init__.py +++ b/libmproxy/contrib/jsbeautifier/__init__.py @@ -216,7 +216,7 @@ class Beautifier: parser_pos = 0 while True: token_text, token_type = self.get_next_token() - #print(token_text, token_type, self.flags.mode) + #print (token_text, token_type, self.flags.mode) if token_type == 'TK_EOF': break diff --git a/libmproxy/contrib/pyparsing.py b/libmproxy/contrib/pyparsing.py index 4d26324cc..b8c8e9375 100644 --- a/libmproxy/contrib/pyparsing.py +++ b/libmproxy/contrib/pyparsing.py @@ -40,7 +40,7 @@ Here is a program to parse "Hello, World!" (or any greeting of the form "", greet.parseString( hello )) + print hello, "->", greet.parseString( hello ) The program outputs the following:: @@ -651,13 +651,13 @@ def line( loc, strg ): return strg[lastCR+1:] def _defaultStartDebugAction( instring, loc, expr ): - print("Match " + _ustr(expr) + " at loc " + _ustr(loc) + "(%d,%d)" % ( lineno(loc,instring), col(loc,instring) )) + print ("Match " + _ustr(expr) + " at loc " + _ustr(loc) + "(%d,%d)" % ( lineno(loc,instring), col(loc,instring) )) def _defaultSuccessDebugAction( instring, startloc, endloc, expr, toks ): - print("Matched " + _ustr(expr) + " -> " + str(toks.asList())) + print ("Matched " + _ustr(expr) + " -> " + str(toks.asList())) def _defaultExceptionDebugAction( instring, loc, expr, exc ): - print("Exception raised:" + _ustr(exc)) + print ("Exception raised:" + _ustr(exc)) def nullDebugAction(*args): """'Do-nothing' debug action, to suppress debugging output during parsing.""" @@ -804,7 +804,7 @@ class ParserElement(object): numargs -= 1 - #~ print("adding function %s with %d args" % (f.func_name,numargs)) + #~ print ("adding function %s with %d args" % (f.func_name,numargs)) if numargs == 3: return f else: @@ -914,7 +914,7 @@ class ParserElement(object): debugging = ( self.debug ) #and doActions ) if debugging or self.failAction: - #~ print("Match",self,"at loc",loc,"(%d,%d)" % ( lineno(loc,instring), col(loc,instring) )) + #~ print ("Match",self,"at loc",loc,"(%d,%d)" % ( lineno(loc,instring), col(loc,instring) )) if (self.debugActions[0] ): self.debugActions[0]( instring, loc, self ) if callPreParse and self.callPreparse: @@ -928,7 +928,7 @@ class ParserElement(object): except IndexError: raise ParseException( instring, len(instring), self.errmsg, self ) except ParseBaseException, err: - #~ print("Exception raised:", err) + #~ print ("Exception raised:", err) if self.debugActions[2]: self.debugActions[2]( instring, tokensStart, self, err ) if self.failAction: @@ -962,7 +962,7 @@ class ParserElement(object): asList=self.saveAsList and isinstance(tokens,(ParseResults,list)), modal=self.modalResults ) except ParseBaseException, err: - #~ print("Exception raised in user parse action:", err) + #~ print ("Exception raised in user parse action:", err) if (self.debugActions[2] ): self.debugActions[2]( instring, tokensStart, self, err ) raise @@ -976,7 +976,7 @@ class ParserElement(object): modal=self.modalResults ) if debugging: - #~ print("Matched",self,"->",retTokens.asList()) + #~ print ("Matched",self,"->",retTokens.asList()) if (self.debugActions[1] ): self.debugActions[1]( instring, tokensStart, loc, self, retTokens ) @@ -2861,7 +2861,7 @@ class SkipTo(ParseElementEnhance): while 1: try: loc = self.ignoreExpr.tryParse(instring,loc) - print("found ignoreExpr, advance to", loc) + print "found ignoreExpr, advance to", loc except ParseBaseException: break expr._parse( instring, loc, doActions=False, callPreParse=False ) @@ -3239,7 +3239,7 @@ def oneOf( strs, caseless=False, useRegex=True ): i += 1 if not caseless and useRegex: - #~print(strs,"->", "|".join( [ _escapeRegexChars(sym) for sym in symbols] )) + #~ print (strs,"->", "|".join( [ _escapeRegexChars(sym) for sym in symbols] )) try: if len(symbols)==len("".join(symbols)): return Regex( "[%s]" % "".join( [ _escapeRegexRangeChars(sym) for sym in symbols] ) ) @@ -3669,16 +3669,16 @@ if __name__ == "__main__": try: tokens = simpleSQL.parseString( teststring ) tokenlist = tokens.asList() - print(teststring + "->" + str(tokenlist)) - print("tokens = " + str(tokens)) - print("tokens.columns = " + str(tokens.columns)) - print("tokens.tables = " + str(tokens.tables)) - print(tokens.asXML("SQL",True)) + print (teststring + "->" + str(tokenlist)) + print ("tokens = " + str(tokens)) + print ("tokens.columns = " + str(tokens.columns)) + print ("tokens.tables = " + str(tokens.tables)) + print (tokens.asXML("SQL",True)) except ParseBaseException,err: - print(teststring + "->") - print(err.line) - print(" "*(err.column-1) + "^") - print(err) + print (teststring + "->") + print (err.line) + print (" "*(err.column-1) + "^") + print (err) print() selectToken = CaselessLiteral( "select" ) From 07cc7f6f50074393d41d24ed2ed06e62507860c2 Mon Sep 17 00:00:00 2001 From: Jim Shaver Date: Sun, 31 May 2015 08:09:03 -0400 Subject: [PATCH 3/3] reverting change in libmproxy/contrib/pyparsing.py --- libmproxy/contrib/pyparsing.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libmproxy/contrib/pyparsing.py b/libmproxy/contrib/pyparsing.py index b8c8e9375..06b11d98f 100644 --- a/libmproxy/contrib/pyparsing.py +++ b/libmproxy/contrib/pyparsing.py @@ -962,7 +962,7 @@ class ParserElement(object): asList=self.saveAsList and isinstance(tokens,(ParseResults,list)), modal=self.modalResults ) except ParseBaseException, err: - #~ print ("Exception raised in user parse action:", err) + #~ print "Exception raised in user parse action:", err if (self.debugActions[2] ): self.debugActions[2]( instring, tokensStart, self, err ) raise