Browse Source

Further changes for Python3.

Bentley James Oakes 7 years ago
parent
commit
14777e7c37
2 changed files with 15 additions and 10 deletions
  1. 13 1
      mt/httpd.py
  2. 2 9
      mt/ptcal/pytcore/core/himesis.py

+ 13 - 1
mt/httpd.py

@@ -62,7 +62,11 @@ class HTTPRequestHandler(BaseHTTPRequestHandler) :
 		#retrieve reqdata if any
 		reqData = None
 		if (self.command == 'PUT' or self.command == 'POST') :
-			dl = int(self.headers.getheader('Content-Length') or 0)
+			if sys.version_info < (3, 0):
+				header = self.headers.getheader('Content-Length')
+			else:
+				header = self.headers.get('Content-Length')
+			dl = int(header or 0)
 			if dl > 0 :
 				reqData = self.rfile.read(dl)
 
@@ -122,9 +126,17 @@ class HTTPRequestHandler(BaseHTTPRequestHandler) :
 
 		if round(statusCode/100.0) != 2 :
 			if reason != '' :
+				if sys.version_info < (3, 0):
+					reason = bytes(reason)
+				else:
+					reason = bytes(reason, 'utf8')
 				self.wfile.write(reason)
 		else :
 			if data != '' :
+				if sys.version_info < (3, 0):
+					data = bytes(data)
+				else:
+					data = bytes(data, 'utf8')
 				self.wfile.write(data)
 
 

+ 2 - 9
mt/ptcal/pytcore/core/himesis.py

@@ -479,15 +479,8 @@ class HimesisPostConditionPattern(HimesisPattern):
             RHS_labels = []
         else :
             RHS_labels = self.vs[Himesis.Constants.MT_LABEL]
-            def nonConnectorsFirst(l1,l2) :
-                c1 = self.vs[ self.get_node_with_label(l1) ][Himesis.Constants.CONNECTOR_TYPE]
-                c2 = self.vs[ self.get_node_with_label(l2) ][Himesis.Constants.CONNECTOR_TYPE]
-                if c1 and c2 :
-                    return 0
-                elif c1 :
-                    return 1
-                return -1
-            RHS_labels.sort(nonConnectorsFirst)
+            # sort non-connectors first
+            RHS_labels.sort(key=lambda x: self.vs[ self.get_node_with_label(x) ][Himesis.Constants.CONNECTOR_TYPE] or False)
             neighborhood = [graph.vs[labels[l]].attributes() for l in LHS_labels]
 
         new_labels = []