]> jfr.im git - irc/quakenet/qwebirc.git/commitdiff
tidy up autobahn support -- now requires 0.17.2 319/head
authorChris Porter <redacted>
Fri, 28 Jul 2017 01:15:28 +0000 (02:15 +0100)
committerChris Porter <redacted>
Fri, 28 Jul 2017 01:15:28 +0000 (02:15 +0100)
bin/dependencies_b.py
qwebirc/engines/ajaxengine.py
qwebirc/util/autobahn_check.py [new file with mode: 0644]

index 61edb6602b73b4d4bfcbf9974f3cd3194bd6e558..753982d7dc4a4980bed83d2a2c21f87dd746fbfd 100644 (file)
@@ -126,20 +126,22 @@ def check_json():
   return 0
 
 def check_autobahn():
-  try:
-    import autobahn, autobahn.twisted.websocket
-    x = autobahn.version.split(".")
-    if len(x) != 3:
-      raise ImportError()
-    if (int(x[1]) < 8) or (int(x[1]) == 8 and int(x[2]) < 14):
-      raise ImportError()
+  import qwebirc.util.autobahn_check as autobahn_check
+  v = autobahn_check.check()
+  if v == True:
     return 0
-  except ImportError:
-    warn("autobahn 0.8.14 (minimum) not installed; websocket support will be disabled.",
+
+  if v == False:
+    warn("autobahn not installed; websocket support will be disabled.",
          "consider installing autobahn from:",
          "http://autobahn.ws/python/getstarted/")
     return 1
 
+  warn("error loading autobahn: %s; websocket support will be disabled." % v,
+       "consider installing/upgrading autobahn from:",
+       "http://autobahn.ws/python/getstarted/")
+  return 1
+
 if __name__ == "__main__":
   import dependencies
   dependencies.check_dependencies()
index 2d3769e3dbdd6ccd80400084c72cdaccf17903f9..33bc67bf8585601125ff3424e037535d9339de06 100644 (file)
@@ -9,23 +9,26 @@ from qwebirc.util import HitCounter
 import qwebirc.dns as qdns
 import qwebirc.util.qjson as json
 import urlparse
+import qwebirc.util.autobahn_check as autobahn_check
 
 TRANSPORTS = ["longpoll"]
 
-try:
+has_websocket = False
+autobahn_status = autobahn_check.check()
+if autobahn_status == True:
   import autobahn
-  x = autobahn.version.split(".")
-  if len(x) != 3:
-    raise ImportError("Unknown version: %s", autobahn.vesrion)
-  if (int(x[1]) < 8) or (int(x[1]) == 8 and int(x[2]) < 14):
-    raise ImportError()
-
   import autobahn.twisted.websocket
   import autobahn.twisted.resource
   has_websocket = True
   TRANSPORTS.append("websocket")
-except ImportError:
-  has_websocket = False
+elif autobahn_status == False:
+  # they've been warned already
+  pass
+else:
+  print >>sys.stderr, "WARNING:"
+  print >>sys.stderr, "  %s" % autobahn_status
+  print >>sys.stderr, "  as a result websocket support is disabled."
+  print >>sys.stderr, "  upgrade your version of autobahn from http://autobahn.ws/python/getstarted/"
 
 BAD_SESSION_MESSAGE = "Invalid session, this most likely means the server has restarted; close this dialog and then try refreshing the page."
 MAX_SEQNO = 9223372036854775807  # 2**63 - 1... yeah it doesn't wrap
@@ -366,6 +369,7 @@ if has_websocket:
     AWAITING_AUTH, AUTHED = 0, 1
 
     def __init__(self, *args, **kwargs):
+      super(WebSocketEngineProtocol, self).__init__(*args, **kwargs)
       self.__state = self.AWAITING_AUTH
       self.__session = None
       self.__channel = None
@@ -380,7 +384,7 @@ if has_websocket:
         self.__session.unsubscribe(self.__channel)
         self.__session = None
 
-    def onMessage(self, msg, binary):
+    def onMessage(self, msg, isBinary):
       # we don't bother checking the Origin header, as if you can auth then you've been able to pass the browser's
       # normal origin handling (POSTed the new connection request and managed to get the session id)
       state = self.__state
@@ -442,7 +446,7 @@ if has_websocket:
     def close(self, reason=None):
       self.__cancelTimeout()
       if reason:
-        self.sendClose(4999, reason)
+        self.sendClose(4999, unicode(reason))
       else:
         self.sendClose(4998)
 
@@ -465,3 +469,4 @@ if has_websocket:
     factory.setProtocolOptions(maxMessagePayloadSize=512, maxFramePayloadSize=512, tcpNoDelay=False)
     resource = WebSocketResource(factory)
     return resource
+
diff --git a/qwebirc/util/autobahn_check.py b/qwebirc/util/autobahn_check.py
new file mode 100644 (file)
index 0000000..d1b0468
--- /dev/null
@@ -0,0 +1,29 @@
+MINIMUM_VERSION = 0, 17, 2
+
+import config
+
+def check():
+  try:
+    import autobahn
+    import autobahn.twisted.websocket
+    import autobahn.twisted.resource
+  except ImportError:
+    return False
+
+  x = autobahn.version.split(".")
+  if len(x) != 3:
+    return "unable to parse autobahn version: %r" % autobahn.version
+
+  major, minor, veryminor = int(x[0]), int(x[1]), int(x[2])
+  if major > MINIMUM_VERSION[0]:
+    pass # ok
+  if minor > MINIMUM_VERSION[1]:
+    pass # ok
+  if veryminor >= MINIMUM_VERSION[2]:
+    pass # ok
+  elif hasattr(config, "FORCE_AUTOBAHN"):
+    pass # ok
+  else:
+    return "your version of autobahn (v%d.%d.%d) is too old, the minimum is v%d.%d.%d" % tuple([major, minor, veryminor] + list(MINIMUM_VERSION))
+
+  return True