See All Titles |
![]() ![]() UNIX SpecificThis group of modules exposes interfaces to features that are specific to the UNIX environment. posixThe posix module provides access to the most common POSIX system calls. Do not import this module directly; instead, I suggest that you import the os module. >>> uid = posix.getuid() # returns the user id pwdThe pwd module provides access to the UNIX passwd (password database) file routines. pwd.getpwnam() Returns the password of a given user. basic syntax: password = getpwnam(username)[1] >>> import pwd, getpass >>> pw = pwd.getpwnam(getpass.getuser())[1] grpThe grp module provides access to the UNIX group database. cryptThe crypt module offers an interface to the UNIX crypt routine. This module has a hash function based on a modified DES algorithm that is used to check UNIX passwords. newpwd = crypt.crypt(passwordstring, salt) salt consists of a two-random character seed used to initialize the algorithm. If newpwd == crypt.crypt(passwordstring, newpwd[:2]) import getpass import pwd import crypt uname = getpass.getuser() # get username from environment pw = getpass.getpass() # get entered password realpw = pwd.getpwnam(uname)[1] # get real password entrpw = crypt.crypt(pw, realpw[:2]) # returns an encrypted password if realpw == entrpw: # compare passwords print "Password Accepted" else: print "Get lost." dlmoduleThe dlmodule module exposes an interface to call C functions in shared objects that handle dynamically linked libraries. Note that this module is not needed for dynamic loading of Python modules. The documentation says that it is a highly experimental and dangerous device for calling arbitrary C functions in arbitrary shared libraries. dbmThe dbm module is a database interface that implements a simple UNIX (n)dbm library access method. dbm objects behave like dictionaries in which keys and values must contain string objects. This module allows strings, which might encode any python objects, to be archived in indexed files. See Chapter 8 for details. gdbmThe gdbm module is similar to the dbm module. However, their files are incompatible. This module provides a reinterpretation of the GNU dbm library. See Chapter 8 for details. termiosThe termios module provides an interface to the POSIX calls for managing the behavior of the POSIX tty. TERMIOSThe TERMIOS module stores constants required while using the termios module. ttyThe tty module implements terminal controlling functions for switching the tty into cbreak and raw modes. ptyThe pty module offers utilities to handle the pseudo-terminal concept. fcntlThe fcntl module performs file and I/O control on UNIX file descriptors. This module implements The fcntl() and ioctl() system calls, which can be used for file locking. pipesThe pipes module offers an interface to UNIX shell pipelines. By abstracting the pipeline concept, it enables you to create and use your own pipelines. posixfileThe posixfile module provides file-like objects with support for locking. It seems that this module will become obsolete soon. resourceThe resource module offers mechanisms for measuring and controlling system resources used by a program. nisThe nis module is a thin wrapper around Sun's NIS library. syslogThe syslog module implements an interface to the UNIX syslog library routines. This module allows you to trace the activity of your programs in a way similar to many daemons running on a typical GNU/Linux system. import syslog syslog.syslog('This script was activated') print "I am a lumberjack, and I am OK!" syslog.syslog('Shutting down script') Use the command tail -f /var/log/messages to read what your script is writing to the log. popen2The popen2 module allows you to create processes by running external commands and to connect their accessible streams (stdin, stdout, and stderr) using pipes. import os,popen2 str1 = os.popen('ls','r').read() print str1 out1,in1 = popen2.popen2('cat') in1.write(str1) in1.close() str2 = out1.read() out1.close() print str2 Note
Note that as of release 2.0, functions popen2, popen3, popen4 are supported on the Windows Platform. commandsThe commands module provides functions that execute external commands under UNIX by implementing wrapping functions for the os.popen() function. Those functions get a system command as a string argument and return any output generated by that command.
|
Index terms contained in this sectioncheckingUNIX passwords dlmodule module encrypting UNIX passwords functions popen2 popen3 popen4 gdbm module grp module libraries operating systems UNIX Specific 2nd modules dlmodule gdbm grp pwd passwords UNIX, encrypting UNIX, verifying popen2 function popen3 function popen4 function pwd module syntax functions pwd.getpwnam() UNIX Specific library 2nd verifying UNIX passwords |
© 2002, O'Reilly & Associates, Inc. |