Permalink
Browse files

Initial commit

  • Loading branch information...
0 parents commit df9d87ef883f632042e43ca0da4c88198751e6a1 @temoto committed Sep 1, 2009
Showing with 870 additions and 0 deletions.
  1. +32 −0 Makefile
  2. 0 README.rst
  3. +11 −0 config.mk
  4. +26 −0 setup.py
  5. +81 −0 test.py
  6. +1 −0 udns/__init__.py
  7. +676 −0 udns/mod_udns.c
  8. +43 −0 udns/mod_udns.h
@@ -0,0 +1,32 @@
+include config.mk
+
+
+ifdef DEBUG
+ CFLAGS += -UNDEBUG -g -O0
+else
+ CFLAGS += -DNDEBUG=1 -O3
+endif
+
+LDFLAGS += -ludns
+
+UDNS_OBJ := udns/mod_udns.o
+
+
+.PHONY: all clean test
+
+all: udns/_udns.so
+
+udns/mod_udns.o: udns/mod_udns.h
+ $(CC) -pthread -fPIC $(shell $(PYTHON)-config --cflags) $(CFLAGS) -c udns/mod_udns.c -o udns/mod_udns.o
+
+udns/_udns.so: $(UDNS_OBJ)
+ -#$(PYTHON) setup.py build_ext -fgb .
+ $(CC) -pthread -shared -Wl,-Bsymbolic-functions $(LDFLAGS) $(UDNS_OBJ) -ludns -o $@
+
+clean:
+ -rm -f udns/mod_udns.o
+ -rm -f udns/_udns.so
+ -rm -rf build
+
+test: udns/_udns.so
+ $(PYTHON) test.py
No changes.
@@ -0,0 +1,11 @@
+# Settings
+# ========
+
+CC := gcc
+MAKE := make
+PYTHON := python
+
+CFLAGS := -Wall -Wextra
+LDFLAGS :=
+
+#DEBUG := 1
@@ -0,0 +1,26 @@
+from distutils.core import setup, Extension
+import os
+
+
+PACKAGE = 'udns'
+SOURCES = [
+ 'udns/mod_udns.c',
+]
+
+README = open('README.rst').read().strip() if os.path.isfile('README.rst') else ''
+
+udns_module = Extension('udns._udns', SOURCES,
+ libraries=['udns'],
+ language='c')
+
+setup(name='pyudns',
+ version='0.1',
+ author='Sergey Shepelev',
+ author_email='temotor@gmail.com',
+ url='http://github.com/temoto/pyudns',
+ packages=[PACKAGE],
+ description="pyudns is python binding to udns library by Michael Tokarev.",
+ long_description=README,
+ ext_modules=[udns_module],
+ license='MIT License',
+ )
@@ -0,0 +1,81 @@
+import time
+import udns
+import unittest
+
+
+class InterfaceTestCase(unittest.TestCase):
+ def test_000(self):
+ pass # simply import work
+
+ def test_001(self):
+ udns.Resolver(False, True)
+
+ def test_002(self):
+ udns.Resolver(False)
+
+ def test_003(self):
+ udns.Resolver()
+
+ def test_011(self):
+ R = udns.Resolver()
+ R.active
+
+ def test_012(self):
+ R = udns.Resolver()
+ R.status
+
+ def test_013(self):
+ R = udns.Resolver()
+ R.sock
+
+ def test_021(self):
+ R = udns.Resolver()
+ R.submit_a4("localhost", lambda r, _data: None)
+
+ def test_022(self):
+ R = udns.Resolver()
+ q = R.submit_a4("localhost", lambda r, _data: None)
+ R.cancel(q)
+
+ def test_024(self):
+ R = udns.Resolver()
+ R.close()
+
+ def test_025(self):
+ R = udns.Resolver()
+ R.submit_a4("localhost", lambda r, _data: None)
+ R.close()
+
+ def test_031(self):
+ R = udns.Resolver()
+ q = R.submit_a4("localhost", lambda r, _data: None)
+ q.is_completed
+
+ def test_032(self):
+ R = udns.Resolver()
+ q = R.submit_a4("localhost", lambda r, _data: None)
+ q.cancel()
+
+
+class BasicTestCase(unittest.TestCase):
+ def setUp(self):
+ self.R = udns.Resolver()
+
+ def test_async_resolve_001(self):
+ TIMEOUT = 5 # sec
+ flags = []
+ def cb(r, _data):
+ flags.append(r)
+ self.R.submit_a4("localhost", cb)
+ # simulation of dumb event loop
+ for _ in xrange(TIMEOUT * 100):
+ self.R.ioevent()
+ self.R.timeouts(1)
+ time.sleep(0.01)
+ if not self.R.active:
+ break
+ self.assertTrue(flags)
+
+
+if __name__ == "__main__":
+ unittest.main()
@@ -0,0 +1 @@
+from _udns import *
Oops, something went wrong.

0 comments on commit df9d87e

Please sign in to comment.