Introduction to nis module














































Introduction to nis module



Nis - Interface to Sun's NIS(Yellow Pages):

Nis module provides an interface to NIS(yellow pages) services it is used to retrieve values from the database if its available.
Nis module is only for Unix 
we import the following module by using the following syntax:
import nis
The nis module defines the following function
nis.match(key, mapname, domain=default_domain):
Returns the match for key in map mapname, or raise an error (nis.error) if there is none. Both should be strings, key is 8-bit clean. Return value is an arbitrary array of bytes (may contain NULL and other joys).

Note that mapname is first checked if it is an alias to another name.

The domain argument allows overriding the NIS domain used for the lookup. If unspecified, lookup is in the default NIS domain.

nis.cat(mapname, domain=default_domain)
Return a dictionary mapping key to value such that match(key, mapname)==value. Note that both keys and values of the dictionary are arbitrary arrays of bytes.

Note that mapname is first checked if it is an alias to another name.

The domain argument allows overriding the NIS domain used for the lookup. If unspecified, lookup is in the default NIS domain.

nis.maps(domain=default_domain)
Return a list of all valid maps.

The domain argument allows overriding the NIS domain used for the lookup. If unspecified, lookup is in the default NIS domain.

nis.get_default_domain()
Return the system default NIS domain.
Heres is the following code example:
import nis
import string

print nis.cat("ypservers")
print string.split(nis.match("bacon", "hosts.byname"))



Comments