Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions README
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
===================
Installing PyHesiod
===================

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 Cython

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.

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).

.. _Cython: http://www.cython.org/
34 changes: 22 additions & 12 deletions _hesiod.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -59,22 +66,25 @@ def resolve(hes_name, hes_type):
cdef int i
cdef object py_result
py_result = list()
cdef char ** c_result

name_str, type_str = map(str, (hes_name, hes_type))
cdef int err = 0
cdef char ** c_result = NULL

if isinstance(hes_name, unicode):
hes_name = hes_name.encode('utf-8')
if isinstance(hes_type, unicode):
hes_type = hes_type.encode('utf-8')

__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, hes_name, hes_type)
err = errno

if c_result is NULL:
raise IOError(err, strerror(err))
i = 0
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)
Expand Down
4 changes: 2 additions & 2 deletions hesiod.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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',
Expand Down
12 changes: 5 additions & 7 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,22 @@

from setuptools import setup
from distutils.extension import Extension
from Pyrex.Distutils import build_ext
from Cython.Build import cythonize

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="[email protected]",
maintainer="Debathena Project",
maintainer_email="[email protected]",
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"]),
]),
)