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
15 changes: 7 additions & 8 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -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::

Expand All @@ -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/
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 @@ -86,7 +86,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 @@ -106,7 +106,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,22 +2,20 @@

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.10",
version="0.2.11",
description="PyHesiod - Python bindings for the Heisod naming library",
author="Evan Broder",
author_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"]),
]),
)