Skip to content

Show the whole error for ERR lockers #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 25 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
8747d80
Initial checkin
ebroder Jul 12, 2008
e684013
Apparently Debian/Ubuntu's libhesiod doesn't have hesiod_free_string
ebroder Jul 12, 2008
3daccf2
Make lookups threadsafe by locking around the hesiod_resolve call
ebroder Jul 30, 2008
2686374
Changee exposed hesiod module to be pure Python
ebroder Jul 30, 2008
fa09890
Convert arguments to strings in resolve and bind
ebroder Jul 30, 2008
91c3507
Add object-oriented-style lookups for filsys, passwd, and uid lookups
ebroder Jul 30, 2008
caab8d1
Add support for group queries
ebroder Jul 30, 2008
98c8c47
Bump version number to 0.2.0
ebroder Jul 30, 2008
fbeb7b6
Add a quick note about a homepage
ebroder Jul 30, 2008
2eaec70
Add a MANIFEST.in file to include COPYING in the source dist
ebroder Jul 30, 2008
e3228e7
Fix dependency information
ebroder Jul 30, 2008
710b586
Fix invalid syntax in Python 2.4
ebroder Aug 1, 2008
776e34d
I put shebangs at the top of modules out of habit, but Debian doesn't…
ebroder Aug 1, 2008
b25635b
Raise IOError instances instead of tuples with a class
ebroder Aug 10, 2008
94ae59f
In passwd and group lookups, convert IDs to strings
ebroder Aug 11, 2008
934ad12
Actually set IOErrors correctly
ebroder Aug 12, 2008
ac653a0
Fix Linux bug where errno would get corrupted
ebroder Aug 20, 2008
ffa42bf
Undo a mistaken test commit
ebroder Aug 20, 2008
8fc04e6
Version 0.2.10: Sort filsys entries based on priority
ebroder Nov 20, 2008
4244859
Add my stock README, adapted from PyMoira.
ebroder Apr 23, 2009
ea3de19
Add instructions to the README for building on Debian.
ebroder Apr 23, 2009
2b11f72
Fix a typo in the README.
ebroder Apr 23, 2009
bd27880
Move python-hesiod into a subdirectory
dehnert Jun 19, 2013
9fb6598
Import Evan Broder's python-hesiod
dehnert Jun 19, 2013
6f283cf
Show the whole error for ERR lockers
dehnert Jun 18, 2013
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
22 changes: 22 additions & 0 deletions python/COPYING
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Copyright (C) 2008 Evan Broder

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
1 change: 1 addition & 0 deletions python/MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include COPYING
39 changes: 39 additions & 0 deletions python/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
===================
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.

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/
81 changes: 81 additions & 0 deletions python/_hesiod.pyx
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
cdef extern from "hesiod.h":
int hesiod_init(void **context)
void hesiod_end(void *context)
char *hesiod_to_bind(void *context, char *name, char *type)
char **hesiod_resolve(void *context, char *name, char *type)
void hesiod_free_list(void *context, char **list)
# This function isn't defined in 3.0.2, which is what Debian/Ubuntu use
#void hesiod_free_string(void *context, char *str)

cdef extern from "errno.h":
int errno

cdef extern from "string.h":
char * strerror(int errnum)

cdef extern from "stdlib.h":
void free(void *)

cdef void * __context

cdef class __ContextManager:
def __init__(self):
if hesiod_init(&__context) == -1:
raise IOError(errno, strerror(errno))

def __del__(self):
hesiod_end(__context)

cdef object __cm
__cm = __ContextManager()

import threading
__lookup_lock = threading.Lock()

def bind(hes_name, hes_type):
"""
Convert the provided arguments into a DNS name.

The DNS name derived from the name and type provided is used to
actually execute the Hesiod lookup.
"""
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)
if c_result is NULL:
raise IOError(errno, strerror(errno))
py_result = c_result

free(c_result)
return py_result

def resolve(hes_name, hes_type):
"""
Return a list of records matching the given name and 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))

__lookup_lock.acquire()
c_result = hesiod_resolve(__context, name_str, type_str)
err = errno
__lookup_lock.release()

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])
i = i + 1

hesiod_free_list(__context, c_result)
return py_result
114 changes: 114 additions & 0 deletions python/hesiod.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
"""
Present both functional and object-oriented interfaces for executing
lookups in Hesiod, Project Athena's service name resolution protocol.
"""

from _hesiod import bind, resolve

from pwd import struct_passwd
from grp import struct_group

class HesiodParseError(Exception):
pass

class Lookup(object):
"""
A Generic Hesiod lookup
"""
def __init__(self, hes_name, hes_type):
self.results = resolve(hes_name, hes_type)
self.parseRecords()

def parseRecords(self):
pass

class FilsysLookup(Lookup):
def __init__(self, name):
Lookup.__init__(self, name, 'filsys')

def parseRecords(self):
Lookup.parseRecords(self)

self.filsys = []
self.multiRecords = (len(self.results) > 1)

for result in self.results:
priority = 0
if self.multiRecords:
result, priority = result.rsplit(" ", 1)
priority = int(priority)

parts = result.split(" ")
type = parts[0]
if type == 'AFS':
self.filsys.append(dict(type=type,
location=parts[1],
mode=parts[2],
mountpoint=parts[3],
priority=priority))
elif type == 'NFS':
self.filsys.append(dict(type=type,
remote_location=parts[1],
server=parts[2],
mode=parts[3],
mountpoint=parts[4],
priority=priority))
elif type == 'ERR':
self.filsys.append(dict(type=type,
message=" ".join(parts[1:]),
priority=priority))
elif type == 'UFS':
self.filsys.append(dict(type=type,
device=parts[1],
mode=parts[2],
mountpoint=parts[3],
priority=priority))
elif type == 'LOC':
self.filsys.append(dict(type=type,
location=parts[1],
mode=parts[2],
mountpoint=parts[3],
priority=priority))
else:
raise HesiodParseError('Unknown filsys type: %s' % type)

self.filsys.sort(key=(lambda x: x['priority']))

class PasswdLookup(Lookup):
def __init__(self, name):
Lookup.__init__(self, name, 'passwd')

def parseRecords(self):
passwd_info = self.results[0].split(':')
passwd_info[2] = int(passwd_info[2])
passwd_info[3] = int(passwd_info[3])
self.passwd = struct_passwd(passwd_info)

class UidLookup(PasswdLookup):
def __init__(self, uid):
Lookup.__init__(self, uid, 'uid')

class GroupLookup(Lookup):
def __init__(self, group):
Lookup.__init__(self, group, 'group')

def parseRecords(self):
group_info = self.results[0].split(':')
group_info[2] = int(group_info[2])
members = group_info[3]
if members != '':
members = members.split(',')
else:
members = []
group_info[3] = members

self.group = struct_group(group_info)

class GidLookup(GroupLookup):
def __init__(self, gid):
Lookup.__init__(self, gid, 'gid')

__all__ = ['bind', 'resolve',
'Lookup', 'FilsysLookup', 'PasswdLookup', 'UidLookup',
'GroupLookup', 'GidLookup',
'HesiodParseError']
23 changes: 23 additions & 0 deletions python/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/python

from setuptools import setup
from distutils.extension import Extension
from Pyrex.Distutils import build_ext

setup(
name="PyHesiod",
version="0.2.10",
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=[
Extension("_hesiod",
["_hesiod.pyx"],
libraries=["hesiod"])
],
cmdclass= {"build_ext": build_ext}
)