From 252a3ecbde1dcab8a292fb6aed4f2dd2ccb722e0 Mon Sep 17 00:00:00 2001 From: Evan Broder Date: Thu, 23 Apr 2009 17:05:09 -0400 Subject: [PATCH 1/8] Add my stock README, adapted from PyMoira. --- README | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 README diff --git a/README b/README new file mode 100644 index 0000000..5583b65 --- /dev/null +++ b/README @@ -0,0 +1,27 @@ +=================== +Installing PyHesiod +=================== + +To install PyHesiod, you will first need to install Pyrex_. It's +always a good idea to install Pyrex through your package manager, if +possible. Your system's Pyrex package may be named ``python-pyrex`` or +``pyrex-py25``. If your package manager doesn't have a package for +Pyrex, or if you wish to install Pyrex by hand anyway, you can do so +by running:: + + $ easy_install Pyrex + +Once you've done that, to install PyHesiod globally, run:: + + $ python setup.py install + +If you want to build PyHesiod without installing it globally, you may +want to run:: + + $ python setup.py build_ext --inplace + +which will build the C extensions in place next to their source, +allowing you to import the various modules, so long as your current +working directory is the root of the PyHesiod source tree. + +.. _Pyrex: http://www.cosc.canterbury.ac.nz/greg.ewing/python/Pyrex/ From ca9be4f18c55269e26b4a3bc9a181d35941284cc Mon Sep 17 00:00:00 2001 From: Evan Broder Date: Thu, 23 Apr 2009 17:21:54 -0400 Subject: [PATCH 2/8] Add instructions to the README for building on Debian. --- README | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/README b/README index 5583b65..bad6c02 100644 --- a/README +++ b/README @@ -24,4 +24,16 @@ which will build the C extensions in place next to their source, allowing you to import the various modules, so long as your current working directory is the root of the PyHesiod source tree. +Alternatively, PyHesiod has been packaged for Debian and Ubuntu. To +build the Debian package of the latest release, run:: + + $ git checkout debian + $ git buildpackage + $ sudo debi + +You will need the devscripts and git-buildpackage packages installed, +as well as this package's build dependencies (cdbs, debhelper, +python-all-dev, python-support, python-pyrex, python-setuptools, +libhesiod -dev). + .. _Pyrex: http://www.cosc.canterbury.ac.nz/greg.ewing/python/Pyrex/ From b4aafd1a5b295dd4925fc36df15b046ba2f49185 Mon Sep 17 00:00:00 2001 From: Evan Broder Date: Thu, 23 Apr 2009 17:27:31 -0400 Subject: [PATCH 3/8] Fix a typo in the README. --- README | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README b/README index bad6c02..93deb59 100644 --- a/README +++ b/README @@ -34,6 +34,6 @@ build the Debian package of the latest release, run:: You will need the devscripts and git-buildpackage packages installed, as well as this package's build dependencies (cdbs, debhelper, python-all-dev, python-support, python-pyrex, python-setuptools, -libhesiod -dev). +libhesiod-dev). .. _Pyrex: http://www.cosc.canterbury.ac.nz/greg.ewing/python/Pyrex/ From 974d6f93d4d0d0b8bb347627b00eb87376103741 Mon Sep 17 00:00:00 2001 From: Quentin Smith Date: Mon, 9 Dec 2019 20:03:43 -0500 Subject: [PATCH 4/8] Switch from Pyrex to Cython --- setup.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/setup.py b/setup.py index f15d7b9..a4be4f8 100755 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ from setuptools import setup from distutils.extension import Extension -from Pyrex.Distutils import build_ext +from Cython.Build import cythonize setup( name="PyHesiod", @@ -14,12 +14,10 @@ maintainer_email="debathena@mit.edu", url="http://ebroder.net/code/PyHesiod", license="MIT", - requires=['Pyrex'], py_modules=['hesiod'], - ext_modules=[ + ext_modules=cythonize([ Extension("_hesiod", ["_hesiod.pyx"], - libraries=["hesiod"]) - ], - cmdclass= {"build_ext": build_ext} + libraries=["hesiod"]), + ]), ) From b097d34e4557bd10fd36d0ba777540e84b9a12b7 Mon Sep 17 00:00:00 2001 From: Quentin Smith Date: Mon, 9 Dec 2019 20:16:39 -0500 Subject: [PATCH 5/8] Handle exceptions thrown by hesiod_resolve --- _hesiod.pyx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/_hesiod.pyx b/_hesiod.pyx index f0b41d9..8bb6b3d 100644 --- a/_hesiod.pyx +++ b/_hesiod.pyx @@ -59,14 +59,14 @@ def resolve(hes_name, hes_type): cdef int i cdef object py_result py_result = list() - cdef char ** c_result + cdef int err = 0 + cdef char ** c_result = NULL name_str, type_str = map(str, (hes_name, hes_type)) - __lookup_lock.acquire() - c_result = hesiod_resolve(__context, name_str, type_str) - err = errno - __lookup_lock.release() + with __lookup_lock: + c_result = hesiod_resolve(__context, name_str, type_str) + err = errno if c_result is NULL: raise IOError(err, strerror(err)) From 1f02e98bf6e46c6fe01f80c40f1d9c5b068faf73 Mon Sep 17 00:00:00 2001 From: Quentin Smith Date: Mon, 9 Dec 2019 20:43:35 -0500 Subject: [PATCH 6/8] Support Python 3. This uses str/unicode for Hesiod requests and replies. --- _hesiod.pyx | 26 ++++++++++++++++++-------- hesiod.py | 4 ++-- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/_hesiod.pyx b/_hesiod.pyx index 8bb6b3d..62e36fd 100644 --- a/_hesiod.pyx +++ b/_hesiod.pyx @@ -41,10 +41,17 @@ def bind(hes_name, hes_type): """ cdef object py_result cdef char * c_result - - name_str, type_str = map(str, (hes_name, hes_type)) - - c_result = hesiod_to_bind(__context, name_str, type_str) + + # N.B. libhesiod actually uses the locale, but + # locale.getpreferredencoding is not threadsafe so we have to + # assume utf-8. + + if isinstance(hes_name, unicode): + hes_name = hes_name.encode('utf-8') + if isinstance(hes_type, unicode): + hes_type = hes_type.encode('utf-8') + + c_result = hesiod_to_bind(__context, hes_name, hes_type) if c_result is NULL: raise IOError(errno, strerror(errno)) py_result = c_result @@ -61,11 +68,14 @@ def resolve(hes_name, hes_type): py_result = list() cdef int err = 0 cdef char ** c_result = NULL - - name_str, type_str = map(str, (hes_name, hes_type)) + + if isinstance(hes_name, unicode): + hes_name = hes_name.encode('utf-8') + if isinstance(hes_type, unicode): + hes_type = hes_type.encode('utf-8') with __lookup_lock: - c_result = hesiod_resolve(__context, name_str, type_str) + c_result = hesiod_resolve(__context, hes_name, hes_type) err = errno if c_result is NULL: @@ -74,7 +84,7 @@ def resolve(hes_name, hes_type): while True: if c_result[i] is NULL: break - py_result.append(c_result[i]) + py_result.append(c_result[i].decode('utf-8', 'replace')) i = i + 1 hesiod_free_list(__context, c_result) diff --git a/hesiod.py b/hesiod.py index 0e4475a..d277150 100755 --- a/hesiod.py +++ b/hesiod.py @@ -110,7 +110,7 @@ def parseRecords(self): class UidLookup(PasswdLookup): def __init__(self, uid): - Lookup.__init__(self, uid, 'uid') + Lookup.__init__(self, b'%d' % (uid,), 'uid') class GroupLookup(Lookup): def __init__(self, group): @@ -130,7 +130,7 @@ def parseRecords(self): class GidLookup(GroupLookup): def __init__(self, gid): - Lookup.__init__(self, gid, 'gid') + Lookup.__init__(self, b'%d' % (gid,), 'gid') __all__ = ['bind', 'resolve', 'Lookup', 'FilsysLookup', 'PasswdLookup', 'UidLookup', From 11d2a1a09611ad2ef9952f5948a44f6ee0571522 Mon Sep 17 00:00:00 2001 From: Quentin Smith Date: Thu, 12 Dec 2019 20:25:06 -0500 Subject: [PATCH 7/8] Update readme --- README | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/README b/README index 93deb59..31b3d83 100644 --- a/README +++ b/README @@ -2,14 +2,13 @@ Installing PyHesiod =================== -To install PyHesiod, you will first need to install Pyrex_. It's -always a good idea to install Pyrex through your package manager, if -possible. Your system's Pyrex package may be named ``python-pyrex`` or -``pyrex-py25``. If your package manager doesn't have a package for -Pyrex, or if you wish to install Pyrex by hand anyway, you can do so -by running:: +To install PyHesiod, you will first need to install Cython_. It's +always a good idea to install Cython through your package manager, if +possible. If your package manager doesn't have a package for Cython, +or if you wish to install Cython by hand anyway, you can do so by +running:: - $ easy_install Pyrex + $ easy_install Cython Once you've done that, to install PyHesiod globally, run:: @@ -36,4 +35,4 @@ as well as this package's build dependencies (cdbs, debhelper, python-all-dev, python-support, python-pyrex, python-setuptools, libhesiod-dev). -.. _Pyrex: http://www.cosc.canterbury.ac.nz/greg.ewing/python/Pyrex/ +.. _Cython: http://www.cython.org/ From e764d7cbe9ed013579af34f4b092ba7e68fc5ad3 Mon Sep 17 00:00:00 2001 From: Quentin Smith Date: Sun, 2 Aug 2020 22:32:20 -0400 Subject: [PATCH 8/8] Bump version number --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index a4be4f8..570798b 100755 --- a/setup.py +++ b/setup.py @@ -6,7 +6,7 @@ setup( name="PyHesiod", - version="0.2.12", + version="0.2.13", description="PyHesiod - Python bindings for the Heisod naming library", author="Evan Broder", author_email="broder@mit.edu",