Fix compilation error using python2.7
[python-purple] / connection_cbs.pxd
index b30016e..16576c2 100644 (file)
@@ -17,8 +17,6 @@
 #  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #
 
-cimport purple
-
 cdef extern from *:
     ctypedef char const_char "const char"
 
@@ -34,16 +32,17 @@ cdef void connect_progress(connection.PurpleConnection *gc, const_char *text, \
     of what is happening, as well as which a step out of step_count has been
     reached (which might be displayed as a progress bar).
     """
-    debug.c_purple_debug_info("connection", "%s", "connect-progress\n")
-    if connection_cbs.has_key("connect-progress"):
-        (<object> connection_cbs["connect-progress"])(<char *> text, step, step_count)
+    debug.purple_debug_info("connection", "%s", "connect-progress\n")
+    if "connect-progress" in connection_cbs:
+        (<object> connection_cbs["connect-progress"]) \
+            (<char *> text, step, step_count)
 
 cdef void connected(connection.PurpleConnection *gc):
     """
     Called when a connection is established (just before the signed-on signal).
     """
-    debug.c_purple_debug_info("connection", "%s", "connected\n")
-    if connection_cbs.has_key("connected"):
+    debug.purple_debug_info("connection", "%s", "connected\n")
+    if "connected" in connection_cbs:
         (<object> connection_cbs["connected"])("connected: TODO")
 
 cdef void disconnected(connection.PurpleConnection *gc):
@@ -51,8 +50,8 @@ cdef void disconnected(connection.PurpleConnection *gc):
     Called when a connection is ended (between the signing-off and signed-off
     signal).
     """
-    debug.c_purple_debug_info("connection", "%s", "disconnected\n")
-    if connection_cbs.has_key("disconnected"):
+    debug.purple_debug_info("connection", "%s", "disconnected\n")
+    if "disconnected" in connection_cbs:
         (<object> connection_cbs["disconnected"])("disconnected: TODO")
 
 cdef void notice(connection.PurpleConnection *gc, const_char *text):
@@ -61,8 +60,8 @@ cdef void notice(connection.PurpleConnection *gc, const_char *text):
     implements this as a no-op; purple_connection_notice(), which uses this
     operation, is not used by any of the protocols shipped with libpurple.)
     """
-    debug.c_purple_debug_info("connection", "%s", "notice\n")
-    if connection_cbs.has_key("notice"):
+    debug.purple_debug_info("connection", "%s", "notice\n")
+    if "notice" in connection_cbs:
         (<object> connection_cbs["notice"])("notice: TODO")
 
 cdef void report_disconnect(connection.PurpleConnection *gc, const_char *text):
@@ -74,8 +73,8 @@ cdef void report_disconnect(connection.PurpleConnection *gc, const_char *text):
     @deprecated in favour of
                 PurpleConnectionUiOps.report_disconnect_reason.
     """
-    debug.c_purple_debug_info("connection", "%s", "report-disconnect\n")
-    if connection_cbs.has_key("report-disconnect"):
+    debug.purple_debug_info("connection", "%s", "report-disconnect\n")
+    if "report-disconnect" in connection_cbs:
         (<object> connection_cbs["report-disconnect"])(<char *> text)
 
 cdef void network_connected():
@@ -84,8 +83,8 @@ cdef void network_connected():
     is active. On Linux, this uses Network Manager if available; on Windows,
     it uses Win32's network change notification infrastructure.
     """
-    debug.c_purple_debug_info("connection", "%s", "network-connected\n")
-    if connection_cbs.has_key("network-connected"):
+    debug.purple_debug_info("connection", "%s", "network-connected\n")
+    if "network-connected" in connection_cbs:
         (<object> connection_cbs["network-connected"])()
 
 cdef void network_disconnected():
@@ -93,12 +92,12 @@ cdef void network_disconnected():
     Called when libpurple discovers that the computer's network connection
     has gone away.
     """
-    debug.c_purple_debug_info("connection", "%s", "network-disconnected\n")
-    if connection_cbs.has_key("network-disconnected"):
+    debug.purple_debug_info("connection", "%s", "network-disconnected\n")
+    if "network-disconnected" in connection_cbs:
         (<object> connection_cbs["network-disconnected"])()
 
 cdef void report_disconnect_reason(connection.PurpleConnection *gc, \
-        connection.PurpleConnectionError reason, const_char *text):
+        connection.PurpleConnectionError reason, const_char *c_text):
     """
     Called when an error causes a connection to be disconnected. Called
     before disconnected. This op is intended to replace report_disconnect.
@@ -111,7 +110,7 @@ cdef void report_disconnect_reason(connection.PurpleConnection *gc, \
     @see purple_connection_error_reason
     @since 2.3.0
     """
-    debug.c_purple_debug_info("connection", "%s", "report-disconnect-reason\n")
+    debug.purple_debug_info("connection", "%s", "report-disconnect-reason\n")
 
     reason_string = {
         0: 'Network error',
@@ -132,5 +131,11 @@ cdef void report_disconnect_reason(connection.PurpleConnection *gc, \
         15: 'Certificate error (other)',
         16: 'Other error' }[reason]
 
-    if connection_cbs.has_key("report-disconnect-reason"):
-        (<object> connection_cbs["report-disconnect-reason"])(reason_string, <char *> text)
+    if c_text:
+        text = <char *> c_text
+    else:
+        text = None
+
+    if "report-disconnect-reason" in connection_cbs:
+        (<object> connection_cbs["report-disconnect-reason"]) \
+            (reason_string, <char *> text)