Kaydet (Commit) 705d517e authored tarafından Guido van Rossum's avatar Guido van Rossum

initial checkin

üst 3dc44aba
This directory contains a module (dnslib) that implements a DNS
(Domain Name Server) client, plus additional modules that define some
symbolic constants used by DNS (dnstype, dnsclass, dnsopcode).
Type "python dnslib.py -/" for a usage message.
You can also import dnslib and write your own, more sophisticated
client code; use the test program as an example (there is currently no
documentation :-).
--Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
URL: <http://www.cwi.nl/cwi/people/Guido.van.Rossum.html>
# CLASS values (section 3.2.4)
IN = 1 # the Internet
CS = 2 # the CSNET class (Obsolete - used only for examples in
# some obsolete RFCs)
CH = 3 # the CHAOS class
HS = 4 # Hesiod [Dyer 87]
# QCLASS values (section 3.2.5)
ANY = 255 # any class
# Construct reverse mapping dictionary
_names = dir()
classmap = {}
for _name in _names:
if _name[0] != '_': classmap[eval(_name)] = _name
def classstr(klass):
if classmap.has_key(klass): return classmap[klass]
else: return `klass`
This diff is collapsed.
# Opcode values in message header (section 4.1.1)
QUERY = 0
IQUERY = 1
STATUS = 2
# Construct reverse mapping dictionary
_names = dir()
opcodemap = {}
for _name in _names:
if _name[0] != '_': opcodemap[eval(_name)] = _name
def opcodestr(opcode):
if opcodemap.has_key(opcode): return opcodemap[opcode]
else: return `opcode`
# TYPE values (section 3.2.2)
A = 1 # a host address
NS = 2 # an authoritative name server
MD = 3 # a mail destination (Obsolete - use MX)
MF = 4 # a mail forwarder (Obsolete - use MX)
CNAME = 5 # the canonical name for an alias
SOA = 6 # marks the start of a zone of authority
MB = 7 # a mailbox domain name (EXPERIMENTAL)
MG = 8 # a mail group member (EXPERIMENTAL)
MR = 9 # a mail rename domain name (EXPERIMENTAL)
NULL = 10 # a null RR (EXPERIMENTAL)
WKS = 11 # a well known service description
PTR = 12 # a domain name pointer
HINFO = 13 # host information
MINFO = 14 # mailbox or mail list information
MX = 15 # mail exchange
TXT = 16 # text strings
# Additional TYPE values from host.c source
UNAME = 110
MP = 240
# QTYPE values (section 3.2.3)
AXFR = 252 # A request for a transfer of an entire zone
MAILB = 253 # A request for mailbox-related records (MB, MG or MR)
MAILA = 254 # A request for mail agent RRs (Obsolete - see MX)
ANY = 255 # A request for all records
# Construct reverse mapping dictionary
_names = dir()
typemap = {}
for _name in _names:
if _name[0] != '_': typemap[eval(_name)] = _name
def typestr(type):
if typemap.has_key(type): return typemap[type]
else: return `type`
# Makefile for embedded Python use demo
# Top of the build tree and source tree
blddir= ../..
srcdir= ../..
# Compiler flags
OPT= -g
INCLUDES= -I$(srcdir)/Include -I$(blddir)
DEFINES= -DHAVE_CONFIG_H
CFLAGS= $(OPT) $(DEFINES) $(INCLUDES)
# Libraries
# XXX edit MODLIBS, LIBS and SYSLIBS to match $(blddir)/Modules/Makefile
MYLIBS= $(blddir)/Modules/libModules.a \
$(blddir)/Python/libPython.a \
$(blddir)/Objects/libObjects.a \
$(blddir)/Parser/libParser.a
MODLIBS=
LIBS=
SYSLIBS= -lm
ALLLIBS= $(MYLIBS) $(MODLIBS) $(LIBS) $(SYSLIBS)
# Build the demo application
all: demo
demo: demo.o config.o
$(CC) demo.o config.o $(ALLLIBS) -o demo
# Build config.o, suppressing the main() function
config.o: $(blddir)/Modules/config.c
$(CC) $(CFLAGS) -DNO_MAIN -c $(blddir)/Modules/config.c
# Administrative targets
test: demo
./demo
clean:
-rm -f *.o core
clobber: clean
-rm -f *~ @* '#'* demo
This directory show how easy it is to embed the Python interpreter in
your own application. The file demo.c shows you all that is needed in
your C code.
To build it, you may have to edit the Makefile:
1) set blddir to the directory where you built Python, if it isn't in
the source directory (../..)
2) change the variables that together define the list of libraries
(MODLIBS, LIBS, SYSLIBS) to link with, to match their definitions in
$(blddir)/Modules/Makefile
/* Example of embedding Python in another program */
#include "allobjects.h"
static char *argv0;
main(argc, argv)
int argc;
char **argv;
{
/* Save a copy of argv0 */
argv0 = argv[0];
/* Initialize the Python interpreter. Required. */
initall();
/* Define sys.argv. It is up to the application if you
want this; you can also let it undefined (since the Python
code is generally not a main program it has no business
touching sys.argv...) */
setpythonargv(argc, argv);
/* Do some application specific code */
printf("Hello, brave new world\n\n");
/* Execute some Python statements (in module __main__) */
run_command("import sys\n");
run_command("print sys.builtin_module_names\n");
run_command("print sys.argv\n");
/* Note that you can call any public function of the Python
interpreter here, e.g. call_object(). */
/* Some more application specific code */
printf("\nGoodbye, cruel world\n");
/* Exit, cleaning up the interpreter */
goaway(0);
/*NOTREACHED*/
}
char *
getprogramname()
{
return argv0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment