[pygobject] Drop static IO_* constants



commit 0137a7af7bf69421e0c8e94120a1f8cff01fbeea
Author: Martin Pitt <martinpitt gnome org>
Date:   Wed Oct 24 13:59:31 2012 +0200

    Drop static IO_* constants
    
    Use the introspected constants instead, which are identical. Add backwards
    compatible aliases.
    
    These constants are covered by tests/test_iochannel.py.

 docs/reference/pyglib-constants.xml |   52 -----------------------------------
 gi/_glib/__init__.py                |   19 -------------
 gi/_glib/glibmodule.c               |   32 ---------------------
 gi/_gobject/__init__.py             |   18 ------------
 gi/overrides/GLib.py                |   18 +++++++++++-
 gi/overrides/GObject.py             |    8 +++++-
 tests/test_iochannel.py             |    1 +
 tests/test_source.py                |    2 +-
 8 files changed, 26 insertions(+), 124 deletions(-)
---
diff --git a/docs/reference/pyglib-constants.xml b/docs/reference/pyglib-constants.xml
index 2646232..333cfc6 100644
--- a/docs/reference/pyglib-constants.xml
+++ b/docs/reference/pyglib-constants.xml
@@ -12,10 +12,7 @@
     <title>Synopsis</title>
 
     <programlisting>
-<xref linkend="glib-io-condition-constants" endterm="glib-io-condition-constants-title"></xref>
-<xref linkend="glib-priority-constants" endterm="glib-priority-constants-title"></xref>
 <xref linkend="glib-spawn-flag-constants" endterm="glib-spawn-flag-constants-title"></xref>
-<xref linkend="glib-user-directory-constants" endterm="glib-user-directory-constants-title"></xref>
 <xref linkend="glib-version-constants" endterm="glib-version-constants-title"></xref>
 </programlisting>
 
@@ -24,55 +21,6 @@
   <refsect1 id="glib-constants-description">
     <title>Description</title>
 
-    <refsect2 id="glib-io-condition-constants">
-      <title id="glib-io-condition-constants-title">Glib IO Condition Constants</title>
-
-      <para>The IO Condition constants are a set of bit-flags that specify a
-condition to watch for on an event source.</para>
-
-      <variablelist>
-	<varlistentry>
-	  <term><literal>glib.IO_IN</literal></term>
-	  <listitem>
-	    <simpara>There is data to read</simpara>
-	  </listitem>
-	</varlistentry>
-	<varlistentry>
-	  <term><literal>glib.IO_OUT</literal></term>
-	  <listitem>
-	    <simpara>Data can be written (without blocking).</simpara>
-	  </listitem>
-	</varlistentry>
-	<varlistentry>
-	  <term><literal>glib.IO_PRI</literal></term>
-	  <listitem>
-	    <simpara>There is urgent data to read.</simpara>
-	  </listitem>
-	</varlistentry>
-	<varlistentry>
-	  <term><literal>glib.IO_ERR</literal></term>
-	  <listitem>
-	    <simpara>Error condition.</simpara>
-	  </listitem>
-	</varlistentry>
-	<varlistentry>
-	  <term><literal>glib.IO_HUP</literal></term>
-	  <listitem>
-	    <simpara>Hung up (the connection has been broken, usually for
-	    pipes and sockets).</simpara>
-	  </listitem>
-	</varlistentry>
-	<varlistentry>
-	  <term><literal>glib.IO_NVAL</literal></term>
-	  <listitem>
-	    <simpara>Invalid request. The file descriptor is not
-	    open.</simpara>
-	  </listitem>
-	</varlistentry>
-      </variablelist>
-
-    </refsect2>
-
     <refsect2 id="glib-spawn-flag-constants">
       <title id="glib-spawn-flag-constants-title">Glib Spawn Flag Constants</title>
 
diff --git a/gi/_glib/__init__.py b/gi/_glib/__init__.py
index c65c20b..9f12f06 100644
--- a/gi/_glib/__init__.py
+++ b/gi/_glib/__init__.py
@@ -32,25 +32,6 @@ OptionGroup = _glib.OptionGroup
 Pid = _glib.Pid
 PollFD = _glib.PollFD
 
-# Constants
-IO_ERR = _glib.IO_ERR
-IO_FLAG_APPEND = _glib.IO_FLAG_APPEND
-IO_FLAG_GET_MASK = _glib.IO_FLAG_GET_MASK
-IO_FLAG_IS_READABLE = _glib.IO_FLAG_IS_READABLE
-IO_FLAG_IS_SEEKABLE = _glib.IO_FLAG_IS_SEEKABLE
-IO_FLAG_IS_WRITEABLE = _glib.IO_FLAG_IS_WRITEABLE
-IO_FLAG_MASK = _glib.IO_FLAG_MASK
-IO_FLAG_NONBLOCK = _glib.IO_FLAG_NONBLOCK
-IO_FLAG_SET_MASK = _glib.IO_FLAG_SET_MASK
-IO_HUP = _glib.IO_HUP
-IO_IN = _glib.IO_IN
-IO_NVAL = _glib.IO_NVAL
-IO_OUT = _glib.IO_OUT
-IO_PRI = _glib.IO_PRI
-IO_STATUS_AGAIN = _glib.IO_STATUS_AGAIN
-IO_STATUS_EOF = _glib.IO_STATUS_EOF
-IO_STATUS_ERROR = _glib.IO_STATUS_ERROR
-IO_STATUS_NORMAL = _glib.IO_STATUS_NORMAL
 OPTION_ERROR = _glib.OPTION_ERROR
 OPTION_ERROR_BAD_VALUE = _glib.OPTION_ERROR_BAD_VALUE
 OPTION_ERROR_FAILED = _glib.OPTION_ERROR_FAILED
diff --git a/gi/_glib/glibmodule.c b/gi/_glib/glibmodule.c
index a2b3e25..d57db13 100644
--- a/gi/_glib/glibmodule.c
+++ b/gi/_glib/glibmodule.c
@@ -403,38 +403,6 @@ pyglib_register_constants(PyObject *m)
     PyModule_AddIntConstant(m, "SPAWN_FILE_AND_ARGV_ZERO",
 			    G_SPAWN_FILE_AND_ARGV_ZERO);
 
-    PyModule_AddIntConstant(m, "IO_IN",   G_IO_IN);
-    PyModule_AddIntConstant(m, "IO_OUT",  G_IO_OUT);
-    PyModule_AddIntConstant(m, "IO_PRI",  G_IO_PRI);
-    PyModule_AddIntConstant(m, "IO_ERR",  G_IO_ERR);
-    PyModule_AddIntConstant(m, "IO_HUP",  G_IO_HUP);
-    PyModule_AddIntConstant(m, "IO_NVAL", G_IO_NVAL);
-
-    PyModule_AddIntConstant(m, "IO_STATUS_ERROR",
-			    G_IO_STATUS_ERROR);
-    PyModule_AddIntConstant(m, "IO_STATUS_NORMAL",
-			    G_IO_STATUS_NORMAL);
-    PyModule_AddIntConstant(m, "IO_STATUS_EOF",
-			    G_IO_STATUS_EOF);
-    PyModule_AddIntConstant(m, "IO_STATUS_AGAIN",
-			    G_IO_STATUS_AGAIN);
-    PyModule_AddIntConstant(m, "IO_FLAG_APPEND",
-			    G_IO_FLAG_APPEND);
-    PyModule_AddIntConstant(m, "IO_FLAG_NONBLOCK",
-			    G_IO_FLAG_NONBLOCK);
-    PyModule_AddIntConstant(m, "IO_FLAG_IS_READABLE",
-			    G_IO_FLAG_IS_READABLE);
-    PyModule_AddIntConstant(m, "IO_FLAG_IS_WRITEABLE",
-			    G_IO_FLAG_IS_WRITEABLE);
-    PyModule_AddIntConstant(m, "IO_FLAG_IS_SEEKABLE",
-			    G_IO_FLAG_IS_SEEKABLE);
-    PyModule_AddIntConstant(m, "IO_FLAG_MASK",
-			    G_IO_FLAG_MASK);
-    PyModule_AddIntConstant(m, "IO_FLAG_GET_MASK",
-			    G_IO_FLAG_GET_MASK);
-    PyModule_AddIntConstant(m, "IO_FLAG_SET_MASK",
-			    G_IO_FLAG_SET_MASK);
-
     PyModule_AddIntConstant(m, "OPTION_FLAG_HIDDEN",
 			    G_OPTION_FLAG_HIDDEN);
     PyModule_AddIntConstant(m, "OPTION_FLAG_IN_MAIN",
diff --git a/gi/_gobject/__init__.py b/gi/_gobject/__init__.py
index 5e18246..91a229f 100644
--- a/gi/_gobject/__init__.py
+++ b/gi/_gobject/__init__.py
@@ -100,24 +100,6 @@ SPAWN_STDOUT_TO_DEV_NULL = _glib.SPAWN_STDOUT_TO_DEV_NULL
 SPAWN_STDERR_TO_DEV_NULL = _glib.SPAWN_STDERR_TO_DEV_NULL
 SPAWN_CHILD_INHERITS_STDIN = _glib.SPAWN_CHILD_INHERITS_STDIN
 SPAWN_FILE_AND_ARGV_ZERO = _glib.SPAWN_FILE_AND_ARGV_ZERO
-IO_IN = _glib.IO_IN
-IO_OUT = _glib.IO_OUT
-IO_PRI = _glib.IO_PRI
-IO_ERR = _glib.IO_ERR
-IO_HUP = _glib.IO_HUP
-IO_NVAL = _glib.IO_NVAL
-IO_STATUS_ERROR = _glib.IO_STATUS_ERROR
-IO_STATUS_NORMAL = _glib.IO_STATUS_NORMAL
-IO_STATUS_EOF = _glib.IO_STATUS_EOF
-IO_STATUS_AGAIN = _glib.IO_STATUS_AGAIN
-IO_FLAG_APPEND = _glib.IO_FLAG_APPEND
-IO_FLAG_NONBLOCK = _glib.IO_FLAG_NONBLOCK
-IO_FLAG_IS_READABLE = _glib.IO_FLAG_IS_READABLE
-IO_FLAG_IS_WRITEABLE = _glib.IO_FLAG_IS_WRITEABLE
-IO_FLAG_IS_SEEKABLE = _glib.IO_FLAG_IS_SEEKABLE
-IO_FLAG_MASK = _glib.IO_FLAG_MASK
-IO_FLAG_GET_MASK = _glib.IO_FLAG_GET_MASK
-IO_FLAG_SET_MASK = _glib.IO_FLAG_SET_MASK
 OPTION_FLAG_HIDDEN = _glib.OPTION_FLAG_HIDDEN
 OPTION_FLAG_IN_MAIN = _glib.OPTION_FLAG_IN_MAIN
 OPTION_FLAG_REVERSE = _glib.OPTION_FLAG_REVERSE
diff --git a/gi/overrides/GLib.py b/gi/overrides/GLib.py
index 2b704af..5902053 100644
--- a/gi/overrides/GLib.py
+++ b/gi/overrides/GLib.py
@@ -423,9 +423,25 @@ __all__.append('markup_escape_text')
 # backwards compatible names from old static bindings
 for n in ['DESKTOP', 'DOCUMENTS', 'DOWNLOAD', 'MUSIC', 'PICTURES',
           'PUBLIC_SHARE', 'TEMPLATES', 'VIDEOS']:
-    exec('USER_DIRECTORY_%s = GLib.UserDirectory.DIRECTORY_%s' % (n, n))
+    globals()['USER_DIRECTORY_' + n] = getattr(GLib.UserDirectory, 'DIRECTORY_' + n)
     __all__.append('USER_DIRECTORY_' + n)
 
+for n in ['ERR', 'HUP', 'IN', 'NVAL', 'OUT', 'PRI']:
+    globals()['IO_' + n] = getattr(GLib.IOCondition, n)
+    __all__.append('IO_' + n)
+
+for n in ['APPEND', 'GET_MASK', 'IS_READABLE', 'IS_SEEKABLE',
+          'MASK', 'NONBLOCK', 'SET_MASK']:
+    globals()['IO_FLAG_' + n] = getattr(GLib.IOFlags, n)
+    __all__.append('IO_FLAG_' + n)
+# spelling for the win
+IO_FLAG_IS_WRITEABLE = GLib.IOFlags.IS_WRITABLE
+__all__.append('IO_FLAG_IS_WRITEABLE')
+
+for n in ['AGAIN', 'EOF', 'ERROR', 'NORMAL']:
+    globals()['IO_STATUS_' + n] = getattr(GLib.IOStatus, n)
+    __all__.append('IO_STATUS_' + n)
+
 
 class MainLoop(GLib.MainLoop):
     # Backwards compatible constructor API
diff --git a/gi/overrides/GObject.py b/gi/overrides/GObject.py
index a2a8741..5c64b62 100644
--- a/gi/overrides/GObject.py
+++ b/gi/overrides/GObject.py
@@ -37,6 +37,12 @@ for name in ['markup_escape_text', 'get_application_name',
 
 # constants are also deprecated, but cannot mark them as such
 for name in ['PRIORITY_DEFAULT', 'PRIORITY_DEFAULT_IDLE', 'PRIORITY_HIGH',
-             'PRIORITY_HIGH_IDLE', 'PRIORITY_LOW']:
+             'PRIORITY_HIGH_IDLE', 'PRIORITY_LOW',
+             'IO_IN', 'IO_OUT', 'IO_PRI', 'IO_ERR', 'IO_HUP', 'IO_NVAL',
+             'IO_STATUS_ERROR', 'IO_STATUS_NORMAL', 'IO_STATUS_EOF',
+             'IO_STATUS_AGAIN', 'IO_FLAG_APPEND', 'IO_FLAG_NONBLOCK',
+             'IO_FLAG_IS_READABLE', 'IO_FLAG_IS_WRITEABLE',
+             'IO_FLAG_IS_SEEKABLE', 'IO_FLAG_MASK', 'IO_FLAG_GET_MASK',
+             'IO_FLAG_SET_MASK']:
     globals()[name] = getattr(GLib, name)
     __all__.append(name)
diff --git a/tests/test_iochannel.py b/tests/test_iochannel.py
index 0101751..868c6ba 100644
--- a/tests/test_iochannel.py
+++ b/tests/test_iochannel.py
@@ -257,6 +257,7 @@ second line
         self.assertEqual(GLib.IOCondition.IN, GLib.IO_IN)
         self.assertEqual(GLib.IOFlags.NONBLOCK, GLib.IO_FLAG_NONBLOCK)
         self.assertEqual(GLib.IOFlags.IS_SEEKABLE, GLib.IO_FLAG_IS_SEEKABLE)
+        self.assertEqual(GLib.IOStatus.NORMAL, GLib.IO_STATUS_NORMAL)
 
 if __name__ == '__main__':
     unittest.main()
diff --git a/tests/test_source.py b/tests/test_source.py
index 38d03ab..5f0b16c 100644
--- a/tests/test_source.py
+++ b/tests/test_source.py
@@ -171,7 +171,7 @@ class TestSource(unittest.TestCase):
 
     def test_add_remove_poll(self):
         # FIXME: very shallow test, only verifies the API signature
-        pollfd = GLib.PollFD(99, GLib.IO_IN | GLib.IO_HUP)
+        pollfd = GLib.PollFD(99, GLib.IOCondition.IN | GLib.IOCondition.HUP)
         self.assertEqual(pollfd.fd, 99)
         source = GLib.Source()
         source.add_poll(pollfd)



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]