mirror of https://github.com/python/cpython
Merged revisions 55225-55227,55229-55269 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/p3yk ................ r55238 | guido.van.rossum | 2007-05-10 16:46:05 -0700 (Thu, 10 May 2007) | 9 lines Merged revisions 55227 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r55227 | guido.van.rossum | 2007-05-10 10:20:15 -0700 (Thu, 10 May 2007) | 2 lines Fix a bug in test_c_api() that caused a negative refcount. ........ ................ r55246 | neal.norwitz | 2007-05-11 00:01:52 -0700 (Fri, 11 May 2007) | 1 line Remove commands.getstatus() it is obsolete. ................ r55248 | neal.norwitz | 2007-05-11 00:29:05 -0700 (Fri, 11 May 2007) | 2 lines Remove bsddb185 support. ................ r55249 | neal.norwitz | 2007-05-11 00:29:50 -0700 (Fri, 11 May 2007) | 1 line Remove bsddb185 module too ................ r55250 | neal.norwitz | 2007-05-11 00:32:13 -0700 (Fri, 11 May 2007) | 1 line bsddb185: Gotta remove from the file checked in, not Setup ................ r55251 | neal.norwitz | 2007-05-11 00:53:26 -0700 (Fri, 11 May 2007) | 1 line Remove obsolete IRIX modules (as much as I could find, there is probably more) ................ r55252 | neal.norwitz | 2007-05-11 00:55:35 -0700 (Fri, 11 May 2007) | 1 line Remove SGI turd. ................ r55254 | georg.brandl | 2007-05-11 03:11:01 -0700 (Fri, 11 May 2007) | 2 lines Add a case for set comprehensions to the "cannot assign to" switch. ................ r55255 | georg.brandl | 2007-05-11 03:11:25 -0700 (Fri, 11 May 2007) | 2 lines Fix wrong imports. ................ r55261 | georg.brandl | 2007-05-11 07:37:48 -0700 (Fri, 11 May 2007) | 2 lines Remove removed tex files. ................ r55262 | georg.brandl | 2007-05-11 08:28:41 -0700 (Fri, 11 May 2007) | 2 lines Commit PEP 3132 implementation. ................ r55264 | georg.brandl | 2007-05-11 08:50:19 -0700 (Fri, 11 May 2007) | 2 lines Check in the inevitable AST version number and format Py_ssize_t with %zd. ................ r55265 | neal.norwitz | 2007-05-11 09:12:22 -0700 (Fri, 11 May 2007) | 1 line Remove mention of os.popen* and popen2.* since these will be removed. ................ r55266 | neal.norwitz | 2007-05-11 09:19:57 -0700 (Fri, 11 May 2007) | 1 line Get doc to build again (almost, the doc is fine) ................ r55267 | neal.norwitz | 2007-05-11 09:21:02 -0700 (Fri, 11 May 2007) | 1 line Really get doc to build (remove use of string module) ................ r55269 | neal.norwitz | 2007-05-11 09:29:43 -0700 (Fri, 11 May 2007) | 1 line Add some notes to cleanup later ................
This commit is contained in:
parent
bdde01168f
commit
0368b726a1
|
@ -209,13 +209,6 @@ LIBFILES= $(MANSTYLES) $(INDEXSTYLES) $(COMMONTEX) \
|
|||
lib/libsha.tex \
|
||||
lib/libhmac.tex \
|
||||
lib/libstdwin.tex \
|
||||
lib/libsgi.tex \
|
||||
lib/libal.tex \
|
||||
lib/libcd.tex \
|
||||
lib/libfl.tex \
|
||||
lib/libfm.tex \
|
||||
lib/libgl.tex \
|
||||
lib/libimgfile.tex \
|
||||
lib/libsun.tex \
|
||||
lib/libxdrlib.tex \
|
||||
lib/libimghdr.tex \
|
||||
|
|
|
@ -429,22 +429,17 @@ and how to embed it in other applications.
|
|||
% OTHER PLATFORM-SPECIFIC STUFF
|
||||
% =============
|
||||
|
||||
% XXX(nnorwitz): all these modules (down to next comment) need to be (re)moved.
|
||||
%\input{libamoeba} % AMOEBA ONLY
|
||||
|
||||
%\input{libstdwin} % STDWIN ONLY
|
||||
|
||||
\input{libsgi} % SGI IRIX ONLY
|
||||
\input{libal}
|
||||
\input{libcd}
|
||||
\input{libfl}
|
||||
\input{libfm}
|
||||
\input{libgl}
|
||||
\input{libimgfile}
|
||||
\input{libjpeg}
|
||||
%\input{libpanel}
|
||||
|
||||
\input{libsun} % SUNOS ONLY
|
||||
\input{libsunaudio}
|
||||
% XXX(nnorwitz): the modules below this comment should be kept.
|
||||
|
||||
\input{windows} % MS Windows ONLY
|
||||
\input{libmsilib}
|
||||
|
|
|
@ -1,181 +0,0 @@
|
|||
\section{\module{al} ---
|
||||
Audio functions on the SGI}
|
||||
|
||||
\declaremodule{builtin}{al}
|
||||
\platform{IRIX}
|
||||
\modulesynopsis{Audio functions on the SGI.}
|
||||
|
||||
|
||||
This module provides access to the audio facilities of the SGI Indy
|
||||
and Indigo workstations. See section 3A of the IRIX man pages for
|
||||
details. You'll need to read those man pages to understand what these
|
||||
functions do! Some of the functions are not available in IRIX
|
||||
releases before 4.0.5. Again, see the manual to check whether a
|
||||
specific function is available on your platform.
|
||||
|
||||
All functions and methods defined in this module are equivalent to
|
||||
the C functions with \samp{AL} prefixed to their name.
|
||||
|
||||
Symbolic constants from the C header file \code{<audio.h>} are
|
||||
defined in the standard module
|
||||
\refmodule[al-constants]{AL}\refstmodindex{AL}, see below.
|
||||
|
||||
\warning{The current version of the audio library may dump core
|
||||
when bad argument values are passed rather than returning an error
|
||||
status. Unfortunately, since the precise circumstances under which
|
||||
this may happen are undocumented and hard to check, the Python
|
||||
interface can provide no protection against this kind of problems.
|
||||
(One example is specifying an excessive queue size --- there is no
|
||||
documented upper limit.)}
|
||||
|
||||
The module defines the following functions:
|
||||
|
||||
|
||||
\begin{funcdesc}{openport}{name, direction\optional{, config}}
|
||||
The name and direction arguments are strings. The optional
|
||||
\var{config} argument is a configuration object as returned by
|
||||
\function{newconfig()}. The return value is an \dfn{audio port
|
||||
object}; methods of audio port objects are described below.
|
||||
\end{funcdesc}
|
||||
|
||||
\begin{funcdesc}{newconfig}{}
|
||||
The return value is a new \dfn{audio configuration object}; methods of
|
||||
audio configuration objects are described below.
|
||||
\end{funcdesc}
|
||||
|
||||
\begin{funcdesc}{queryparams}{device}
|
||||
The device argument is an integer. The return value is a list of
|
||||
integers containing the data returned by \cfunction{ALqueryparams()}.
|
||||
\end{funcdesc}
|
||||
|
||||
\begin{funcdesc}{getparams}{device, list}
|
||||
The \var{device} argument is an integer. The list argument is a list
|
||||
such as returned by \function{queryparams()}; it is modified in place
|
||||
(!).
|
||||
\end{funcdesc}
|
||||
|
||||
\begin{funcdesc}{setparams}{device, list}
|
||||
The \var{device} argument is an integer. The \var{list} argument is a
|
||||
list such as returned by \function{queryparams()}.
|
||||
\end{funcdesc}
|
||||
|
||||
|
||||
\subsection{Configuration Objects \label{al-config-objects}}
|
||||
|
||||
Configuration objects returned by \function{newconfig()} have the
|
||||
following methods:
|
||||
|
||||
\begin{methoddesc}[audio configuration]{getqueuesize}{}
|
||||
Return the queue size.
|
||||
\end{methoddesc}
|
||||
|
||||
\begin{methoddesc}[audio configuration]{setqueuesize}{size}
|
||||
Set the queue size.
|
||||
\end{methoddesc}
|
||||
|
||||
\begin{methoddesc}[audio configuration]{getwidth}{}
|
||||
Get the sample width.
|
||||
\end{methoddesc}
|
||||
|
||||
\begin{methoddesc}[audio configuration]{setwidth}{width}
|
||||
Set the sample width.
|
||||
\end{methoddesc}
|
||||
|
||||
\begin{methoddesc}[audio configuration]{getchannels}{}
|
||||
Get the channel count.
|
||||
\end{methoddesc}
|
||||
|
||||
\begin{methoddesc}[audio configuration]{setchannels}{nchannels}
|
||||
Set the channel count.
|
||||
\end{methoddesc}
|
||||
|
||||
\begin{methoddesc}[audio configuration]{getsampfmt}{}
|
||||
Get the sample format.
|
||||
\end{methoddesc}
|
||||
|
||||
\begin{methoddesc}[audio configuration]{setsampfmt}{sampfmt}
|
||||
Set the sample format.
|
||||
\end{methoddesc}
|
||||
|
||||
\begin{methoddesc}[audio configuration]{getfloatmax}{}
|
||||
Get the maximum value for floating sample formats.
|
||||
\end{methoddesc}
|
||||
|
||||
\begin{methoddesc}[audio configuration]{setfloatmax}{floatmax}
|
||||
Set the maximum value for floating sample formats.
|
||||
\end{methoddesc}
|
||||
|
||||
|
||||
\subsection{Port Objects \label{al-port-objects}}
|
||||
|
||||
Port objects, as returned by \function{openport()}, have the following
|
||||
methods:
|
||||
|
||||
\begin{methoddesc}[audio port]{closeport}{}
|
||||
Close the port.
|
||||
\end{methoddesc}
|
||||
|
||||
\begin{methoddesc}[audio port]{getfd}{}
|
||||
Return the file descriptor as an int.
|
||||
\end{methoddesc}
|
||||
|
||||
\begin{methoddesc}[audio port]{getfilled}{}
|
||||
Return the number of filled samples.
|
||||
\end{methoddesc}
|
||||
|
||||
\begin{methoddesc}[audio port]{getfillable}{}
|
||||
Return the number of fillable samples.
|
||||
\end{methoddesc}
|
||||
|
||||
\begin{methoddesc}[audio port]{readsamps}{nsamples}
|
||||
Read a number of samples from the queue, blocking if necessary.
|
||||
Return the data as a string containing the raw data, (e.g., 2 bytes per
|
||||
sample in big-endian byte order (high byte, low byte) if you have set
|
||||
the sample width to 2 bytes).
|
||||
\end{methoddesc}
|
||||
|
||||
\begin{methoddesc}[audio port]{writesamps}{samples}
|
||||
Write samples into the queue, blocking if necessary. The samples are
|
||||
encoded as described for the \method{readsamps()} return value.
|
||||
\end{methoddesc}
|
||||
|
||||
\begin{methoddesc}[audio port]{getfillpoint}{}
|
||||
Return the `fill point'.
|
||||
\end{methoddesc}
|
||||
|
||||
\begin{methoddesc}[audio port]{setfillpoint}{fillpoint}
|
||||
Set the `fill point'.
|
||||
\end{methoddesc}
|
||||
|
||||
\begin{methoddesc}[audio port]{getconfig}{}
|
||||
Return a configuration object containing the current configuration of
|
||||
the port.
|
||||
\end{methoddesc}
|
||||
|
||||
\begin{methoddesc}[audio port]{setconfig}{config}
|
||||
Set the configuration from the argument, a configuration object.
|
||||
\end{methoddesc}
|
||||
|
||||
\begin{methoddesc}[audio port]{getstatus}{list}
|
||||
Get status information on last error.
|
||||
\end{methoddesc}
|
||||
|
||||
|
||||
\section{\module{AL} ---
|
||||
Constants used with the \module{al} module}
|
||||
|
||||
\declaremodule[al-constants]{standard}{AL}
|
||||
\platform{IRIX}
|
||||
\modulesynopsis{Constants used with the \module{al} module.}
|
||||
|
||||
|
||||
This module defines symbolic constants needed to use the built-in
|
||||
module \refmodule{al} (see above); they are equivalent to those defined
|
||||
in the C header file \code{<audio.h>} except that the name prefix
|
||||
\samp{AL_} is omitted. Read the module source for a complete list of
|
||||
the defined names. Suggested use:
|
||||
|
||||
\begin{verbatim}
|
||||
import al
|
||||
from AL import *
|
||||
\end{verbatim}
|
|
@ -94,14 +94,6 @@ interpretation.
|
|||
\end{funcdesc}
|
||||
|
||||
|
||||
\begin{notice}
|
||||
Beginning in 2.3 some \UNIX{} versions of Python may have a \module{bsddb185}
|
||||
module. This is present \emph{only} to allow backwards compatibility with
|
||||
systems which ship with the old Berkeley DB 1.85 database library. The
|
||||
\module{bsddb185} module should never be used directly in new code.
|
||||
\end{notice}
|
||||
|
||||
|
||||
\begin{seealso}
|
||||
\seemodule{dbhash}{DBM-style interface to the \module{bsddb}}
|
||||
\end{seealso}
|
||||
|
|
|
@ -1,304 +0,0 @@
|
|||
\section{\module{cd} ---
|
||||
CD-ROM access on SGI systems}
|
||||
|
||||
\declaremodule{builtin}{cd}
|
||||
\platform{IRIX}
|
||||
\modulesynopsis{Interface to the CD-ROM on Silicon Graphics systems.}
|
||||
|
||||
|
||||
This module provides an interface to the Silicon Graphics CD library.
|
||||
It is available only on Silicon Graphics systems.
|
||||
|
||||
The way the library works is as follows. A program opens the CD-ROM
|
||||
device with \function{open()} and creates a parser to parse the data
|
||||
from the CD with \function{createparser()}. The object returned by
|
||||
\function{open()} can be used to read data from the CD, but also to get
|
||||
status information for the CD-ROM device, and to get information about
|
||||
the CD, such as the table of contents. Data from the CD is passed to
|
||||
the parser, which parses the frames, and calls any callback
|
||||
functions that have previously been added.
|
||||
|
||||
An audio CD is divided into \dfn{tracks} or \dfn{programs} (the terms
|
||||
are used interchangeably). Tracks can be subdivided into
|
||||
\dfn{indices}. An audio CD contains a \dfn{table of contents} which
|
||||
gives the starts of the tracks on the CD. Index 0 is usually the
|
||||
pause before the start of a track. The start of the track as given by
|
||||
the table of contents is normally the start of index 1.
|
||||
|
||||
Positions on a CD can be represented in two ways. Either a frame
|
||||
number or a tuple of three values, minutes, seconds and frames. Most
|
||||
functions use the latter representation. Positions can be both
|
||||
relative to the beginning of the CD, and to the beginning of the
|
||||
track.
|
||||
|
||||
Module \module{cd} defines the following functions and constants:
|
||||
|
||||
|
||||
\begin{funcdesc}{createparser}{}
|
||||
Create and return an opaque parser object. The methods of the parser
|
||||
object are described below.
|
||||
\end{funcdesc}
|
||||
|
||||
\begin{funcdesc}{msftoframe}{minutes, seconds, frames}
|
||||
Converts a \code{(\var{minutes}, \var{seconds}, \var{frames})} triple
|
||||
representing time in absolute time code into the corresponding CD
|
||||
frame number.
|
||||
\end{funcdesc}
|
||||
|
||||
\begin{funcdesc}{open}{\optional{device\optional{, mode}}}
|
||||
Open the CD-ROM device. The return value is an opaque player object;
|
||||
methods of the player object are described below. The device is the
|
||||
name of the SCSI device file, e.g. \code{'/dev/scsi/sc0d4l0'}, or
|
||||
\code{None}. If omitted or \code{None}, the hardware inventory is
|
||||
consulted to locate a CD-ROM drive. The \var{mode}, if not omitted,
|
||||
should be the string \code{'r'}.
|
||||
\end{funcdesc}
|
||||
|
||||
The module defines the following variables:
|
||||
|
||||
\begin{excdesc}{error}
|
||||
Exception raised on various errors.
|
||||
\end{excdesc}
|
||||
|
||||
\begin{datadesc}{DATASIZE}
|
||||
The size of one frame's worth of audio data. This is the size of the
|
||||
audio data as passed to the callback of type \code{audio}.
|
||||
\end{datadesc}
|
||||
|
||||
\begin{datadesc}{BLOCKSIZE}
|
||||
The size of one uninterpreted frame of audio data.
|
||||
\end{datadesc}
|
||||
|
||||
The following variables are states as returned by
|
||||
\function{getstatus()}:
|
||||
|
||||
\begin{datadesc}{READY}
|
||||
The drive is ready for operation loaded with an audio CD.
|
||||
\end{datadesc}
|
||||
|
||||
\begin{datadesc}{NODISC}
|
||||
The drive does not have a CD loaded.
|
||||
\end{datadesc}
|
||||
|
||||
\begin{datadesc}{CDROM}
|
||||
The drive is loaded with a CD-ROM. Subsequent play or read operations
|
||||
will return I/O errors.
|
||||
\end{datadesc}
|
||||
|
||||
\begin{datadesc}{ERROR}
|
||||
An error occurred while trying to read the disc or its table of
|
||||
contents.
|
||||
\end{datadesc}
|
||||
|
||||
\begin{datadesc}{PLAYING}
|
||||
The drive is in CD player mode playing an audio CD through its audio
|
||||
jacks.
|
||||
\end{datadesc}
|
||||
|
||||
\begin{datadesc}{PAUSED}
|
||||
The drive is in CD layer mode with play paused.
|
||||
\end{datadesc}
|
||||
|
||||
\begin{datadesc}{STILL}
|
||||
The equivalent of \constant{PAUSED} on older (non 3301) model Toshiba
|
||||
CD-ROM drives. Such drives have never been shipped by SGI.
|
||||
\end{datadesc}
|
||||
|
||||
\begin{datadesc}{audio}
|
||||
\dataline{pnum}
|
||||
\dataline{index}
|
||||
\dataline{ptime}
|
||||
\dataline{atime}
|
||||
\dataline{catalog}
|
||||
\dataline{ident}
|
||||
\dataline{control}
|
||||
Integer constants describing the various types of parser callbacks
|
||||
that can be set by the \method{addcallback()} method of CD parser
|
||||
objects (see below).
|
||||
\end{datadesc}
|
||||
|
||||
|
||||
\subsection{Player Objects}
|
||||
\label{player-objects}
|
||||
|
||||
Player objects (returned by \function{open()}) have the following
|
||||
methods:
|
||||
|
||||
\begin{methoddesc}[CD player]{allowremoval}{}
|
||||
Unlocks the eject button on the CD-ROM drive permitting the user to
|
||||
eject the caddy if desired.
|
||||
\end{methoddesc}
|
||||
|
||||
\begin{methoddesc}[CD player]{bestreadsize}{}
|
||||
Returns the best value to use for the \var{num_frames} parameter of
|
||||
the \method{readda()} method. Best is defined as the value that
|
||||
permits a continuous flow of data from the CD-ROM drive.
|
||||
\end{methoddesc}
|
||||
|
||||
\begin{methoddesc}[CD player]{close}{}
|
||||
Frees the resources associated with the player object. After calling
|
||||
\method{close()}, the methods of the object should no longer be used.
|
||||
\end{methoddesc}
|
||||
|
||||
\begin{methoddesc}[CD player]{eject}{}
|
||||
Ejects the caddy from the CD-ROM drive.
|
||||
\end{methoddesc}
|
||||
|
||||
\begin{methoddesc}[CD player]{getstatus}{}
|
||||
Returns information pertaining to the current state of the CD-ROM
|
||||
drive. The returned information is a tuple with the following values:
|
||||
\var{state}, \var{track}, \var{rtime}, \var{atime}, \var{ttime},
|
||||
\var{first}, \var{last}, \var{scsi_audio}, \var{cur_block}.
|
||||
\var{rtime} is the time relative to the start of the current track;
|
||||
\var{atime} is the time relative to the beginning of the disc;
|
||||
\var{ttime} is the total time on the disc. For more information on
|
||||
the meaning of the values, see the man page \manpage{CDgetstatus}{3dm}.
|
||||
The value of \var{state} is one of the following: \constant{ERROR},
|
||||
\constant{NODISC}, \constant{READY}, \constant{PLAYING},
|
||||
\constant{PAUSED}, \constant{STILL}, or \constant{CDROM}.
|
||||
\end{methoddesc}
|
||||
|
||||
\begin{methoddesc}[CD player]{gettrackinfo}{track}
|
||||
Returns information about the specified track. The returned
|
||||
information is a tuple consisting of two elements, the start time of
|
||||
the track and the duration of the track.
|
||||
\end{methoddesc}
|
||||
|
||||
\begin{methoddesc}[CD player]{msftoblock}{min, sec, frame}
|
||||
Converts a minutes, seconds, frames triple representing a time in
|
||||
absolute time code into the corresponding logical block number for the
|
||||
given CD-ROM drive. You should use \function{msftoframe()} rather than
|
||||
\method{msftoblock()} for comparing times. The logical block number
|
||||
differs from the frame number by an offset required by certain CD-ROM
|
||||
drives.
|
||||
\end{methoddesc}
|
||||
|
||||
\begin{methoddesc}[CD player]{play}{start, play}
|
||||
Starts playback of an audio CD in the CD-ROM drive at the specified
|
||||
track. The audio output appears on the CD-ROM drive's headphone and
|
||||
audio jacks (if fitted). Play stops at the end of the disc.
|
||||
\var{start} is the number of the track at which to start playing the
|
||||
CD; if \var{play} is 0, the CD will be set to an initial paused
|
||||
state. The method \method{togglepause()} can then be used to commence
|
||||
play.
|
||||
\end{methoddesc}
|
||||
|
||||
\begin{methoddesc}[CD player]{playabs}{minutes, seconds, frames, play}
|
||||
Like \method{play()}, except that the start is given in minutes,
|
||||
seconds, and frames instead of a track number.
|
||||
\end{methoddesc}
|
||||
|
||||
\begin{methoddesc}[CD player]{playtrack}{start, play}
|
||||
Like \method{play()}, except that playing stops at the end of the
|
||||
track.
|
||||
\end{methoddesc}
|
||||
|
||||
\begin{methoddesc}[CD player]{playtrackabs}{track, minutes, seconds, frames, play}
|
||||
Like \method{play()}, except that playing begins at the specified
|
||||
absolute time and ends at the end of the specified track.
|
||||
\end{methoddesc}
|
||||
|
||||
\begin{methoddesc}[CD player]{preventremoval}{}
|
||||
Locks the eject button on the CD-ROM drive thus preventing the user
|
||||
from arbitrarily ejecting the caddy.
|
||||
\end{methoddesc}
|
||||
|
||||
\begin{methoddesc}[CD player]{readda}{num_frames}
|
||||
Reads the specified number of frames from an audio CD mounted in the
|
||||
CD-ROM drive. The return value is a string representing the audio
|
||||
frames. This string can be passed unaltered to the
|
||||
\method{parseframe()} method of the parser object.
|
||||
\end{methoddesc}
|
||||
|
||||
\begin{methoddesc}[CD player]{seek}{minutes, seconds, frames}
|
||||
Sets the pointer that indicates the starting point of the next read of
|
||||
digital audio data from a CD-ROM. The pointer is set to an absolute
|
||||
time code location specified in \var{minutes}, \var{seconds}, and
|
||||
\var{frames}. The return value is the logical block number to which
|
||||
the pointer has been set.
|
||||
\end{methoddesc}
|
||||
|
||||
\begin{methoddesc}[CD player]{seekblock}{block}
|
||||
Sets the pointer that indicates the starting point of the next read of
|
||||
digital audio data from a CD-ROM. The pointer is set to the specified
|
||||
logical block number. The return value is the logical block number to
|
||||
which the pointer has been set.
|
||||
\end{methoddesc}
|
||||
|
||||
\begin{methoddesc}[CD player]{seektrack}{track}
|
||||
Sets the pointer that indicates the starting point of the next read of
|
||||
digital audio data from a CD-ROM. The pointer is set to the specified
|
||||
track. The return value is the logical block number to which the
|
||||
pointer has been set.
|
||||
\end{methoddesc}
|
||||
|
||||
\begin{methoddesc}[CD player]{stop}{}
|
||||
Stops the current playing operation.
|
||||
\end{methoddesc}
|
||||
|
||||
\begin{methoddesc}[CD player]{togglepause}{}
|
||||
Pauses the CD if it is playing, and makes it play if it is paused.
|
||||
\end{methoddesc}
|
||||
|
||||
|
||||
\subsection{Parser Objects}
|
||||
\label{cd-parser-objects}
|
||||
|
||||
Parser objects (returned by \function{createparser()}) have the
|
||||
following methods:
|
||||
|
||||
\begin{methoddesc}[CD parser]{addcallback}{type, func, arg}
|
||||
Adds a callback for the parser. The parser has callbacks for eight
|
||||
different types of data in the digital audio data stream. Constants
|
||||
for these types are defined at the \module{cd} module level (see above).
|
||||
The callback is called as follows: \code{\var{func}(\var{arg}, type,
|
||||
data)}, where \var{arg} is the user supplied argument, \var{type} is
|
||||
the particular type of callback, and \var{data} is the data returned
|
||||
for this \var{type} of callback. The type of the data depends on the
|
||||
\var{type} of callback as follows:
|
||||
|
||||
\begin{tableii}{l|p{4in}}{code}{Type}{Value}
|
||||
\lineii{audio}{String which can be passed unmodified to
|
||||
\function{al.writesamps()}.}
|
||||
\lineii{pnum}{Integer giving the program (track) number.}
|
||||
\lineii{index}{Integer giving the index number.}
|
||||
\lineii{ptime}{Tuple consisting of the program time in minutes,
|
||||
seconds, and frames.}
|
||||
\lineii{atime}{Tuple consisting of the absolute time in minutes,
|
||||
seconds, and frames.}
|
||||
\lineii{catalog}{String of 13 characters, giving the catalog number
|
||||
of the CD.}
|
||||
\lineii{ident}{String of 12 characters, giving the ISRC
|
||||
identification number of the recording. The string consists of two
|
||||
characters country code, three characters owner code, two characters
|
||||
giving the year, and five characters giving a serial number.}
|
||||
\lineii{control}{Integer giving the control bits from the CD
|
||||
subcode data}
|
||||
\end{tableii}
|
||||
\end{methoddesc}
|
||||
|
||||
\begin{methoddesc}[CD parser]{deleteparser}{}
|
||||
Deletes the parser and frees the memory it was using. The object
|
||||
should not be used after this call. This call is done automatically
|
||||
when the last reference to the object is removed.
|
||||
\end{methoddesc}
|
||||
|
||||
\begin{methoddesc}[CD parser]{parseframe}{frame}
|
||||
Parses one or more frames of digital audio data from a CD such as
|
||||
returned by \method{readda()}. It determines which subcodes are
|
||||
present in the data. If these subcodes have changed since the last
|
||||
frame, then \method{parseframe()} executes a callback of the
|
||||
appropriate type passing to it the subcode data found in the frame.
|
||||
Unlike the \C{} function, more than one frame of digital audio data
|
||||
can be passed to this method.
|
||||
\end{methoddesc}
|
||||
|
||||
\begin{methoddesc}[CD parser]{removecallback}{type}
|
||||
Removes the callback for the given \var{type}.
|
||||
\end{methoddesc}
|
||||
|
||||
\begin{methoddesc}[CD parser]{resetparser}{}
|
||||
Resets the fields of the parser used for tracking subcodes to an
|
||||
initial state. \method{resetparser()} should be called after the disc
|
||||
has been changed.
|
||||
\end{methoddesc}
|
|
@ -35,16 +35,6 @@ Like \function{getstatusoutput()}, except the exit status is ignored
|
|||
and the return value is a string containing the command's output.
|
||||
\end{funcdesc}
|
||||
|
||||
\begin{funcdesc}{getstatus}{file}
|
||||
Return the output of \samp{ls -ld \var{file}} as a string. This
|
||||
function uses the \function{getoutput()} function, and properly
|
||||
escapes backslashes and dollar signs in the argument.
|
||||
|
||||
\deprecated{2.6}{This function is nonobvious and useless,
|
||||
also the name is misleading in the presence of
|
||||
\function{getstatusoutput()}.}
|
||||
\end{funcdesc}
|
||||
|
||||
Example:
|
||||
|
||||
\begin{verbatim}
|
||||
|
@ -57,8 +47,6 @@ Example:
|
|||
(256, 'sh: /bin/junk: not found')
|
||||
>>> commands.getoutput('ls /bin/ls')
|
||||
'/bin/ls'
|
||||
>>> commands.getstatus('/bin/ls')
|
||||
'-rwxr-xr-x 1 root 13352 Oct 14 1994 /bin/ls'
|
||||
\end{verbatim}
|
||||
|
||||
\begin{seealso}
|
||||
|
|
|
@ -1,507 +0,0 @@
|
|||
\section{\module{fl} ---
|
||||
FORMS library for graphical user interfaces}
|
||||
|
||||
\declaremodule{builtin}{fl}
|
||||
\platform{IRIX}
|
||||
\modulesynopsis{FORMS library for applications with graphical user
|
||||
interfaces.}
|
||||
|
||||
|
||||
This module provides an interface to the FORMS Library\index{FORMS
|
||||
Library} by Mark Overmars\index{Overmars, Mark}. The source for the
|
||||
library can be retrieved by anonymous ftp from host
|
||||
\samp{ftp.cs.ruu.nl}, directory \file{SGI/FORMS}. It was last tested
|
||||
with version 2.0b.
|
||||
|
||||
Most functions are literal translations of their C equivalents,
|
||||
dropping the initial \samp{fl_} from their name. Constants used by
|
||||
the library are defined in module \refmodule[fl-constants]{FL}
|
||||
described below.
|
||||
|
||||
The creation of objects is a little different in Python than in C:
|
||||
instead of the `current form' maintained by the library to which new
|
||||
FORMS objects are added, all functions that add a FORMS object to a
|
||||
form are methods of the Python object representing the form.
|
||||
Consequently, there are no Python equivalents for the C functions
|
||||
\cfunction{fl_addto_form()} and \cfunction{fl_end_form()}, and the
|
||||
equivalent of \cfunction{fl_bgn_form()} is called
|
||||
\function{fl.make_form()}.
|
||||
|
||||
Watch out for the somewhat confusing terminology: FORMS uses the word
|
||||
\dfn{object} for the buttons, sliders etc. that you can place in a form.
|
||||
In Python, `object' means any value. The Python interface to FORMS
|
||||
introduces two new Python object types: form objects (representing an
|
||||
entire form) and FORMS objects (representing one button, slider etc.).
|
||||
Hopefully this isn't too confusing.
|
||||
|
||||
There are no `free objects' in the Python interface to FORMS, nor is
|
||||
there an easy way to add object classes written in Python. The FORMS
|
||||
interface to GL event handling is available, though, so you can mix
|
||||
FORMS with pure GL windows.
|
||||
|
||||
\strong{Please note:} importing \module{fl} implies a call to the GL
|
||||
function \cfunction{foreground()} and to the FORMS routine
|
||||
\cfunction{fl_init()}.
|
||||
|
||||
\subsection{Functions Defined in Module \module{fl}}
|
||||
\nodename{FL Functions}
|
||||
|
||||
Module \module{fl} defines the following functions. For more
|
||||
information about what they do, see the description of the equivalent
|
||||
C function in the FORMS documentation:
|
||||
|
||||
\begin{funcdesc}{make_form}{type, width, height}
|
||||
Create a form with given type, width and height. This returns a
|
||||
\dfn{form} object, whose methods are described below.
|
||||
\end{funcdesc}
|
||||
|
||||
\begin{funcdesc}{do_forms}{}
|
||||
The standard FORMS main loop. Returns a Python object representing
|
||||
the FORMS object needing interaction, or the special value
|
||||
\constant{FL.EVENT}.
|
||||
\end{funcdesc}
|
||||
|
||||
\begin{funcdesc}{check_forms}{}
|
||||
Check for FORMS events. Returns what \function{do_forms()} above
|
||||
returns, or \code{None} if there is no event that immediately needs
|
||||
interaction.
|
||||
\end{funcdesc}
|
||||
|
||||
\begin{funcdesc}{set_event_call_back}{function}
|
||||
Set the event callback function.
|
||||
\end{funcdesc}
|
||||
|
||||
\begin{funcdesc}{set_graphics_mode}{rgbmode, doublebuffering}
|
||||
Set the graphics modes.
|
||||
\end{funcdesc}
|
||||
|
||||
\begin{funcdesc}{get_rgbmode}{}
|
||||
Return the current rgb mode. This is the value of the C global
|
||||
variable \cdata{fl_rgbmode}.
|
||||
\end{funcdesc}
|
||||
|
||||
\begin{funcdesc}{show_message}{str1, str2, str3}
|
||||
Show a dialog box with a three-line message and an OK button.
|
||||
\end{funcdesc}
|
||||
|
||||
\begin{funcdesc}{show_question}{str1, str2, str3}
|
||||
Show a dialog box with a three-line message and YES and NO buttons.
|
||||
It returns \code{1} if the user pressed YES, \code{0} if NO.
|
||||
\end{funcdesc}
|
||||
|
||||
\begin{funcdesc}{show_choice}{str1, str2, str3, but1\optional{,
|
||||
but2\optional{, but3}}}
|
||||
Show a dialog box with a three-line message and up to three buttons.
|
||||
It returns the number of the button clicked by the user
|
||||
(\code{1}, \code{2} or \code{3}).
|
||||
\end{funcdesc}
|
||||
|
||||
\begin{funcdesc}{show_input}{prompt, default}
|
||||
Show a dialog box with a one-line prompt message and text field in
|
||||
which the user can enter a string. The second argument is the default
|
||||
input string. It returns the string value as edited by the user.
|
||||
\end{funcdesc}
|
||||
|
||||
\begin{funcdesc}{show_file_selector}{message, directory, pattern, default}
|
||||
Show a dialog box in which the user can select a file. It returns
|
||||
the absolute filename selected by the user, or \code{None} if the user
|
||||
presses Cancel.
|
||||
\end{funcdesc}
|
||||
|
||||
\begin{funcdesc}{get_directory}{}
|
||||
\funcline{get_pattern}{}
|
||||
\funcline{get_filename}{}
|
||||
These functions return the directory, pattern and filename (the tail
|
||||
part only) selected by the user in the last
|
||||
\function{show_file_selector()} call.
|
||||
\end{funcdesc}
|
||||
|
||||
\begin{funcdesc}{qdevice}{dev}
|
||||
\funcline{unqdevice}{dev}
|
||||
\funcline{isqueued}{dev}
|
||||
\funcline{qtest}{}
|
||||
\funcline{qread}{}
|
||||
%\funcline{blkqread}{?}
|
||||
\funcline{qreset}{}
|
||||
\funcline{qenter}{dev, val}
|
||||
\funcline{get_mouse}{}
|
||||
\funcline{tie}{button, valuator1, valuator2}
|
||||
These functions are the FORMS interfaces to the corresponding GL
|
||||
functions. Use these if you want to handle some GL events yourself
|
||||
when using \function{fl.do_events()}. When a GL event is detected that
|
||||
FORMS cannot handle, \function{fl.do_forms()} returns the special value
|
||||
\constant{FL.EVENT} and you should call \function{fl.qread()} to read
|
||||
the event from the queue. Don't use the equivalent GL functions!
|
||||
\end{funcdesc}
|
||||
|
||||
\begin{funcdesc}{color}{}
|
||||
\funcline{mapcolor}{}
|
||||
\funcline{getmcolor}{}
|
||||
See the description in the FORMS documentation of
|
||||
\cfunction{fl_color()}, \cfunction{fl_mapcolor()} and
|
||||
\cfunction{fl_getmcolor()}.
|
||||
\end{funcdesc}
|
||||
|
||||
\subsection{Form Objects}
|
||||
\label{form-objects}
|
||||
|
||||
Form objects (returned by \function{make_form()} above) have the
|
||||
following methods. Each method corresponds to a C function whose
|
||||
name is prefixed with \samp{fl_}; and whose first argument is a form
|
||||
pointer; please refer to the official FORMS documentation for
|
||||
descriptions.
|
||||
|
||||
All the \method{add_*()} methods return a Python object representing
|
||||
the FORMS object. Methods of FORMS objects are described below. Most
|
||||
kinds of FORMS object also have some methods specific to that kind;
|
||||
these methods are listed here.
|
||||
|
||||
\begin{flushleft}
|
||||
|
||||
\begin{methoddesc}[form]{show_form}{placement, bordertype, name}
|
||||
Show the form.
|
||||
\end{methoddesc}
|
||||
|
||||
\begin{methoddesc}[form]{hide_form}{}
|
||||
Hide the form.
|
||||
\end{methoddesc}
|
||||
|
||||
\begin{methoddesc}[form]{redraw_form}{}
|
||||
Redraw the form.
|
||||
\end{methoddesc}
|
||||
|
||||
\begin{methoddesc}[form]{set_form_position}{x, y}
|
||||
Set the form's position.
|
||||
\end{methoddesc}
|
||||
|
||||
\begin{methoddesc}[form]{freeze_form}{}
|
||||
Freeze the form.
|
||||
\end{methoddesc}
|
||||
|
||||
\begin{methoddesc}[form]{unfreeze_form}{}
|
||||
Unfreeze the form.
|
||||
\end{methoddesc}
|
||||
|
||||
\begin{methoddesc}[form]{activate_form}{}
|
||||
Activate the form.
|
||||
\end{methoddesc}
|
||||
|
||||
\begin{methoddesc}[form]{deactivate_form}{}
|
||||
Deactivate the form.
|
||||
\end{methoddesc}
|
||||
|
||||
\begin{methoddesc}[form]{bgn_group}{}
|
||||
Begin a new group of objects; return a group object.
|
||||
\end{methoddesc}
|
||||
|
||||
\begin{methoddesc}[form]{end_group}{}
|
||||
End the current group of objects.
|
||||
\end{methoddesc}
|
||||
|
||||
\begin{methoddesc}[form]{find_first}{}
|
||||
Find the first object in the form.
|
||||
\end{methoddesc}
|
||||
|
||||
\begin{methoddesc}[form]{find_last}{}
|
||||
Find the last object in the form.
|
||||
\end{methoddesc}
|
||||
|
||||
%---
|
||||
|
||||
\begin{methoddesc}[form]{add_box}{type, x, y, w, h, name}
|
||||
Add a box object to the form.
|
||||
No extra methods.
|
||||
\end{methoddesc}
|
||||
|
||||
\begin{methoddesc}[form]{add_text}{type, x, y, w, h, name}
|
||||
Add a text object to the form.
|
||||
No extra methods.
|
||||
\end{methoddesc}
|
||||
|
||||
%\begin{methoddesc}[form]{add_bitmap}{type, x, y, w, h, name}
|
||||
%Add a bitmap object to the form.
|
||||
%\end{methoddesc}
|
||||
|
||||
\begin{methoddesc}[form]{add_clock}{type, x, y, w, h, name}
|
||||
Add a clock object to the form. \\
|
||||
Method:
|
||||
\method{get_clock()}.
|
||||
\end{methoddesc}
|
||||
|
||||
%---
|
||||
|
||||
\begin{methoddesc}[form]{add_button}{type, x, y, w, h, name}
|
||||
Add a button object to the form. \\
|
||||
Methods:
|
||||
\method{get_button()},
|
||||
\method{set_button()}.
|
||||
\end{methoddesc}
|
||||
|
||||
\begin{methoddesc}[form]{add_lightbutton}{type, x, y, w, h, name}
|
||||
Add a lightbutton object to the form. \\
|
||||
Methods:
|
||||
\method{get_button()},
|
||||
\method{set_button()}.
|
||||
\end{methoddesc}
|
||||
|
||||
\begin{methoddesc}[form]{add_roundbutton}{type, x, y, w, h, name}
|
||||
Add a roundbutton object to the form. \\
|
||||
Methods:
|
||||
\method{get_button()},
|
||||
\method{set_button()}.
|
||||
\end{methoddesc}
|
||||
|
||||
%---
|
||||
|
||||
\begin{methoddesc}[form]{add_slider}{type, x, y, w, h, name}
|
||||
Add a slider object to the form. \\
|
||||
Methods:
|
||||
\method{set_slider_value()},
|
||||
\method{get_slider_value()},
|
||||
\method{set_slider_bounds()},
|
||||
\method{get_slider_bounds()},
|
||||
\method{set_slider_return()},
|
||||
\method{set_slider_size()},
|
||||
\method{set_slider_precision()},
|
||||
\method{set_slider_step()}.
|
||||
\end{methoddesc}
|
||||
|
||||
\begin{methoddesc}[form]{add_valslider}{type, x, y, w, h, name}
|
||||
Add a valslider object to the form. \\
|
||||
Methods:
|
||||
\method{set_slider_value()},
|
||||
\method{get_slider_value()},
|
||||
\method{set_slider_bounds()},
|
||||
\method{get_slider_bounds()},
|
||||
\method{set_slider_return()},
|
||||
\method{set_slider_size()},
|
||||
\method{set_slider_precision()},
|
||||
\method{set_slider_step()}.
|
||||
\end{methoddesc}
|
||||
|
||||
\begin{methoddesc}[form]{add_dial}{type, x, y, w, h, name}
|
||||
Add a dial object to the form. \\
|
||||
Methods:
|
||||
\method{set_dial_value()},
|
||||
\method{get_dial_value()},
|
||||
\method{set_dial_bounds()},
|
||||
\method{get_dial_bounds()}.
|
||||
\end{methoddesc}
|
||||
|
||||
\begin{methoddesc}[form]{add_positioner}{type, x, y, w, h, name}
|
||||
Add a positioner object to the form. \\
|
||||
Methods:
|
||||
\method{set_positioner_xvalue()},
|
||||
\method{set_positioner_yvalue()},
|
||||
\method{set_positioner_xbounds()},
|
||||
\method{set_positioner_ybounds()},
|
||||
\method{get_positioner_xvalue()},
|
||||
\method{get_positioner_yvalue()},
|
||||
\method{get_positioner_xbounds()},
|
||||
\method{get_positioner_ybounds()}.
|
||||
\end{methoddesc}
|
||||
|
||||
\begin{methoddesc}[form]{add_counter}{type, x, y, w, h, name}
|
||||
Add a counter object to the form. \\
|
||||
Methods:
|
||||
\method{set_counter_value()},
|
||||
\method{get_counter_value()},
|
||||
\method{set_counter_bounds()},
|
||||
\method{set_counter_step()},
|
||||
\method{set_counter_precision()},
|
||||
\method{set_counter_return()}.
|
||||
\end{methoddesc}
|
||||
|
||||
%---
|
||||
|
||||
\begin{methoddesc}[form]{add_input}{type, x, y, w, h, name}
|
||||
Add a input object to the form. \\
|
||||
Methods:
|
||||
\method{set_input()},
|
||||
\method{get_input()},
|
||||
\method{set_input_color()},
|
||||
\method{set_input_return()}.
|
||||
\end{methoddesc}
|
||||
|
||||
%---
|
||||
|
||||
\begin{methoddesc}[form]{add_menu}{type, x, y, w, h, name}
|
||||
Add a menu object to the form. \\
|
||||
Methods:
|
||||
\method{set_menu()},
|
||||
\method{get_menu()},
|
||||
\method{addto_menu()}.
|
||||
\end{methoddesc}
|
||||
|
||||
\begin{methoddesc}[form]{add_choice}{type, x, y, w, h, name}
|
||||
Add a choice object to the form. \\
|
||||
Methods:
|
||||
\method{set_choice()},
|
||||
\method{get_choice()},
|
||||
\method{clear_choice()},
|
||||
\method{addto_choice()},
|
||||
\method{replace_choice()},
|
||||
\method{delete_choice()},
|
||||
\method{get_choice_text()},
|
||||
\method{set_choice_fontsize()},
|
||||
\method{set_choice_fontstyle()}.
|
||||
\end{methoddesc}
|
||||
|
||||
\begin{methoddesc}[form]{add_browser}{type, x, y, w, h, name}
|
||||
Add a browser object to the form. \\
|
||||
Methods:
|
||||
\method{set_browser_topline()},
|
||||
\method{clear_browser()},
|
||||
\method{add_browser_line()},
|
||||
\method{addto_browser()},
|
||||
\method{insert_browser_line()},
|
||||
\method{delete_browser_line()},
|
||||
\method{replace_browser_line()},
|
||||
\method{get_browser_line()},
|
||||
\method{load_browser()},
|
||||
\method{get_browser_maxline()},
|
||||
\method{select_browser_line()},
|
||||
\method{deselect_browser_line()},
|
||||
\method{deselect_browser()},
|
||||
\method{isselected_browser_line()},
|
||||
\method{get_browser()},
|
||||
\method{set_browser_fontsize()},
|
||||
\method{set_browser_fontstyle()},
|
||||
\method{set_browser_specialkey()}.
|
||||
\end{methoddesc}
|
||||
|
||||
%---
|
||||
|
||||
\begin{methoddesc}[form]{add_timer}{type, x, y, w, h, name}
|
||||
Add a timer object to the form. \\
|
||||
Methods:
|
||||
\method{set_timer()},
|
||||
\method{get_timer()}.
|
||||
\end{methoddesc}
|
||||
\end{flushleft}
|
||||
|
||||
Form objects have the following data attributes; see the FORMS
|
||||
documentation:
|
||||
|
||||
\begin{tableiii}{l|l|l}{member}{Name}{C Type}{Meaning}
|
||||
\lineiii{window}{int (read-only)}{GL window id}
|
||||
\lineiii{w}{float}{form width}
|
||||
\lineiii{h}{float}{form height}
|
||||
\lineiii{x}{float}{form x origin}
|
||||
\lineiii{y}{float}{form y origin}
|
||||
\lineiii{deactivated}{int}{nonzero if form is deactivated}
|
||||
\lineiii{visible}{int}{nonzero if form is visible}
|
||||
\lineiii{frozen}{int}{nonzero if form is frozen}
|
||||
\lineiii{doublebuf}{int}{nonzero if double buffering on}
|
||||
\end{tableiii}
|
||||
|
||||
\subsection{FORMS Objects}
|
||||
\label{forms-objects}
|
||||
|
||||
Besides methods specific to particular kinds of FORMS objects, all
|
||||
FORMS objects also have the following methods:
|
||||
|
||||
\begin{methoddesc}[FORMS object]{set_call_back}{function, argument}
|
||||
Set the object's callback function and argument. When the object
|
||||
needs interaction, the callback function will be called with two
|
||||
arguments: the object, and the callback argument. (FORMS objects
|
||||
without a callback function are returned by \function{fl.do_forms()}
|
||||
or \function{fl.check_forms()} when they need interaction.) Call this
|
||||
method without arguments to remove the callback function.
|
||||
\end{methoddesc}
|
||||
|
||||
\begin{methoddesc}[FORMS object]{delete_object}{}
|
||||
Delete the object.
|
||||
\end{methoddesc}
|
||||
|
||||
\begin{methoddesc}[FORMS object]{show_object}{}
|
||||
Show the object.
|
||||
\end{methoddesc}
|
||||
|
||||
\begin{methoddesc}[FORMS object]{hide_object}{}
|
||||
Hide the object.
|
||||
\end{methoddesc}
|
||||
|
||||
\begin{methoddesc}[FORMS object]{redraw_object}{}
|
||||
Redraw the object.
|
||||
\end{methoddesc}
|
||||
|
||||
\begin{methoddesc}[FORMS object]{freeze_object}{}
|
||||
Freeze the object.
|
||||
\end{methoddesc}
|
||||
|
||||
\begin{methoddesc}[FORMS object]{unfreeze_object}{}
|
||||
Unfreeze the object.
|
||||
\end{methoddesc}
|
||||
|
||||
%\begin{methoddesc}[FORMS object]{handle_object}{} XXX
|
||||
%\end{methoddesc}
|
||||
|
||||
%\begin{methoddesc}[FORMS object]{handle_object_direct}{} XXX
|
||||
%\end{methoddesc}
|
||||
|
||||
FORMS objects have these data attributes; see the FORMS documentation:
|
||||
|
||||
\begin{tableiii}{l|l|l}{member}{Name}{C Type}{Meaning}
|
||||
\lineiii{objclass}{int (read-only)}{object class}
|
||||
\lineiii{type}{int (read-only)}{object type}
|
||||
\lineiii{boxtype}{int}{box type}
|
||||
\lineiii{x}{float}{x origin}
|
||||
\lineiii{y}{float}{y origin}
|
||||
\lineiii{w}{float}{width}
|
||||
\lineiii{h}{float}{height}
|
||||
\lineiii{col1}{int}{primary color}
|
||||
\lineiii{col2}{int}{secondary color}
|
||||
\lineiii{align}{int}{alignment}
|
||||
\lineiii{lcol}{int}{label color}
|
||||
\lineiii{lsize}{float}{label font size}
|
||||
\lineiii{label}{string}{label string}
|
||||
\lineiii{lstyle}{int}{label style}
|
||||
\lineiii{pushed}{int (read-only)}{(see FORMS docs)}
|
||||
\lineiii{focus}{int (read-only)}{(see FORMS docs)}
|
||||
\lineiii{belowmouse}{int (read-only)}{(see FORMS docs)}
|
||||
\lineiii{frozen}{int (read-only)}{(see FORMS docs)}
|
||||
\lineiii{active}{int (read-only)}{(see FORMS docs)}
|
||||
\lineiii{input}{int (read-only)}{(see FORMS docs)}
|
||||
\lineiii{visible}{int (read-only)}{(see FORMS docs)}
|
||||
\lineiii{radio}{int (read-only)}{(see FORMS docs)}
|
||||
\lineiii{automatic}{int (read-only)}{(see FORMS docs)}
|
||||
\end{tableiii}
|
||||
|
||||
|
||||
\section{\module{FL} ---
|
||||
Constants used with the \module{fl} module}
|
||||
|
||||
\declaremodule[fl-constants]{standard}{FL}
|
||||
\platform{IRIX}
|
||||
\modulesynopsis{Constants used with the \module{fl} module.}
|
||||
|
||||
|
||||
This module defines symbolic constants needed to use the built-in
|
||||
module \refmodule{fl} (see above); they are equivalent to those defined in
|
||||
the C header file \code{<forms.h>} except that the name prefix
|
||||
\samp{FL_} is omitted. Read the module source for a complete list of
|
||||
the defined names. Suggested use:
|
||||
|
||||
\begin{verbatim}
|
||||
import fl
|
||||
from FL import *
|
||||
\end{verbatim}
|
||||
|
||||
|
||||
\section{\module{flp} ---
|
||||
Functions for loading stored FORMS designs}
|
||||
|
||||
\declaremodule{standard}{flp}
|
||||
\platform{IRIX}
|
||||
\modulesynopsis{Functions for loading stored FORMS designs.}
|
||||
|
||||
|
||||
This module defines functions that can read form definitions created
|
||||
by the `form designer' (\program{fdesign}) program that comes with the
|
||||
FORMS library (see module \refmodule{fl} above).
|
||||
|
||||
For now, see the file \file{flp.doc} in the Python library source
|
||||
directory for a description.
|
||||
|
||||
XXX A complete description should be inserted here!
|
|
@ -1,93 +0,0 @@
|
|||
\section{\module{fm} ---
|
||||
\emph{Font Manager} interface}
|
||||
|
||||
\declaremodule{builtin}{fm}
|
||||
\platform{IRIX}
|
||||
\modulesynopsis{\emph{Font Manager} interface for SGI workstations.}
|
||||
|
||||
|
||||
This module provides access to the IRIS \emph{Font Manager} library.
|
||||
\index{Font Manager, IRIS}
|
||||
\index{IRIS Font Manager}
|
||||
It is available only on Silicon Graphics machines.
|
||||
See also: \emph{4Sight User's Guide}, section 1, chapter 5: ``Using
|
||||
the IRIS Font Manager.''
|
||||
|
||||
This is not yet a full interface to the IRIS Font Manager.
|
||||
Among the unsupported features are: matrix operations; cache
|
||||
operations; character operations (use string operations instead); some
|
||||
details of font info; individual glyph metrics; and printer matching.
|
||||
|
||||
It supports the following operations:
|
||||
|
||||
\begin{funcdesc}{init}{}
|
||||
Initialization function.
|
||||
Calls \cfunction{fminit()}.
|
||||
It is normally not necessary to call this function, since it is called
|
||||
automatically the first time the \module{fm} module is imported.
|
||||
\end{funcdesc}
|
||||
|
||||
\begin{funcdesc}{findfont}{fontname}
|
||||
Return a font handle object.
|
||||
Calls \code{fmfindfont(\var{fontname})}.
|
||||
\end{funcdesc}
|
||||
|
||||
\begin{funcdesc}{enumerate}{}
|
||||
Returns a list of available font names.
|
||||
This is an interface to \cfunction{fmenumerate()}.
|
||||
\end{funcdesc}
|
||||
|
||||
\begin{funcdesc}{prstr}{string}
|
||||
Render a string using the current font (see the \function{setfont()} font
|
||||
handle method below).
|
||||
Calls \code{fmprstr(\var{string})}.
|
||||
\end{funcdesc}
|
||||
|
||||
\begin{funcdesc}{setpath}{string}
|
||||
Sets the font search path.
|
||||
Calls \code{fmsetpath(\var{string})}.
|
||||
(XXX Does not work!?!)
|
||||
\end{funcdesc}
|
||||
|
||||
\begin{funcdesc}{fontpath}{}
|
||||
Returns the current font search path.
|
||||
\end{funcdesc}
|
||||
|
||||
Font handle objects support the following operations:
|
||||
|
||||
\begin{methoddesc}[font handle]{scalefont}{factor}
|
||||
Returns a handle for a scaled version of this font.
|
||||
Calls \code{fmscalefont(\var{fh}, \var{factor})}.
|
||||
\end{methoddesc}
|
||||
|
||||
\begin{methoddesc}[font handle]{setfont}{}
|
||||
Makes this font the current font.
|
||||
Note: the effect is undone silently when the font handle object is
|
||||
deleted.
|
||||
Calls \code{fmsetfont(\var{fh})}.
|
||||
\end{methoddesc}
|
||||
|
||||
\begin{methoddesc}[font handle]{getfontname}{}
|
||||
Returns this font's name.
|
||||
Calls \code{fmgetfontname(\var{fh})}.
|
||||
\end{methoddesc}
|
||||
|
||||
\begin{methoddesc}[font handle]{getcomment}{}
|
||||
Returns the comment string associated with this font.
|
||||
Raises an exception if there is none.
|
||||
Calls \code{fmgetcomment(\var{fh})}.
|
||||
\end{methoddesc}
|
||||
|
||||
\begin{methoddesc}[font handle]{getfontinfo}{}
|
||||
Returns a tuple giving some pertinent data about this font.
|
||||
This is an interface to \code{fmgetfontinfo()}.
|
||||
The returned tuple contains the following numbers:
|
||||
\code{(}\var{printermatched}, \var{fixed_width}, \var{xorig},
|
||||
\var{yorig}, \var{xsize}, \var{ysize}, \var{height},
|
||||
\var{nglyphs}\code{)}.
|
||||
\end{methoddesc}
|
||||
|
||||
\begin{methoddesc}[font handle]{getstrwidth}{string}
|
||||
Returns the width, in pixels, of \var{string} when drawn in this font.
|
||||
Calls \code{fmgetstrwidth(\var{fh}, \var{string})}.
|
||||
\end{methoddesc}
|
|
@ -1,224 +0,0 @@
|
|||
\section{\module{gl} ---
|
||||
\emph{Graphics Library} interface}
|
||||
|
||||
\declaremodule{builtin}{gl}
|
||||
\platform{IRIX}
|
||||
\modulesynopsis{Functions from the Silicon Graphics \emph{Graphics Library}.}
|
||||
|
||||
|
||||
This module provides access to the Silicon Graphics
|
||||
\emph{Graphics Library}.
|
||||
It is available only on Silicon Graphics machines.
|
||||
|
||||
\warning{Some illegal calls to the GL library cause the Python
|
||||
interpreter to dump core.
|
||||
In particular, the use of most GL calls is unsafe before the first
|
||||
window is opened.}
|
||||
|
||||
The module is too large to document here in its entirety, but the
|
||||
following should help you to get started.
|
||||
The parameter conventions for the C functions are translated to Python as
|
||||
follows:
|
||||
|
||||
\begin{itemize}
|
||||
\item
|
||||
All (short, long, unsigned) int values are represented by Python
|
||||
integers.
|
||||
\item
|
||||
All float and double values are represented by Python floating point
|
||||
numbers.
|
||||
In most cases, Python integers are also allowed.
|
||||
\item
|
||||
All arrays are represented by one-dimensional Python lists.
|
||||
In most cases, tuples are also allowed.
|
||||
\item
|
||||
\begin{sloppypar}
|
||||
All string and character arguments are represented by Python strings,
|
||||
for instance,
|
||||
\code{winopen('Hi There!')}
|
||||
and
|
||||
\code{rotate(900, 'z')}.
|
||||
\end{sloppypar}
|
||||
\item
|
||||
All (short, long, unsigned) integer arguments or return values that are
|
||||
only used to specify the length of an array argument are omitted.
|
||||
For example, the C call
|
||||
|
||||
\begin{verbatim}
|
||||
lmdef(deftype, index, np, props)
|
||||
\end{verbatim}
|
||||
|
||||
is translated to Python as
|
||||
|
||||
\begin{verbatim}
|
||||
lmdef(deftype, index, props)
|
||||
\end{verbatim}
|
||||
|
||||
\item
|
||||
Output arguments are omitted from the argument list; they are
|
||||
transmitted as function return values instead.
|
||||
If more than one value must be returned, the return value is a tuple.
|
||||
If the C function has both a regular return value (that is not omitted
|
||||
because of the previous rule) and an output argument, the return value
|
||||
comes first in the tuple.
|
||||
Examples: the C call
|
||||
|
||||
\begin{verbatim}
|
||||
getmcolor(i, &red, &green, &blue)
|
||||
\end{verbatim}
|
||||
|
||||
is translated to Python as
|
||||
|
||||
\begin{verbatim}
|
||||
red, green, blue = getmcolor(i)
|
||||
\end{verbatim}
|
||||
|
||||
\end{itemize}
|
||||
|
||||
The following functions are non-standard or have special argument
|
||||
conventions:
|
||||
|
||||
\begin{funcdesc}{varray}{argument}
|
||||
%JHXXX the argument-argument added
|
||||
Equivalent to but faster than a number of
|
||||
\code{v3d()}
|
||||
calls.
|
||||
The \var{argument} is a list (or tuple) of points.
|
||||
Each point must be a tuple of coordinates
|
||||
\code{(\var{x}, \var{y}, \var{z})} or \code{(\var{x}, \var{y})}.
|
||||
The points may be 2- or 3-dimensional but must all have the
|
||||
same dimension.
|
||||
Float and int values may be mixed however.
|
||||
The points are always converted to 3D double precision points
|
||||
by assuming \code{\var{z} = 0.0} if necessary (as indicated in the man page),
|
||||
and for each point
|
||||
\code{v3d()}
|
||||
is called.
|
||||
\end{funcdesc}
|
||||
|
||||
\begin{funcdesc}{nvarray}{}
|
||||
Equivalent to but faster than a number of
|
||||
\code{n3f}
|
||||
and
|
||||
\code{v3f}
|
||||
calls.
|
||||
The argument is an array (list or tuple) of pairs of normals and points.
|
||||
Each pair is a tuple of a point and a normal for that point.
|
||||
Each point or normal must be a tuple of coordinates
|
||||
\code{(\var{x}, \var{y}, \var{z})}.
|
||||
Three coordinates must be given.
|
||||
Float and int values may be mixed.
|
||||
For each pair,
|
||||
\code{n3f()}
|
||||
is called for the normal, and then
|
||||
\code{v3f()}
|
||||
is called for the point.
|
||||
\end{funcdesc}
|
||||
|
||||
\begin{funcdesc}{vnarray}{}
|
||||
Similar to
|
||||
\code{nvarray()}
|
||||
but the pairs have the point first and the normal second.
|
||||
\end{funcdesc}
|
||||
|
||||
\begin{funcdesc}{nurbssurface}{s_k, t_k, ctl, s_ord, t_ord, type}
|
||||
% XXX s_k[], t_k[], ctl[][]
|
||||
Defines a nurbs surface.
|
||||
The dimensions of
|
||||
\code{\var{ctl}[][]}
|
||||
are computed as follows:
|
||||
\code{[len(\var{s_k}) - \var{s_ord}]},
|
||||
\code{[len(\var{t_k}) - \var{t_ord}]}.
|
||||
\end{funcdesc}
|
||||
|
||||
\begin{funcdesc}{nurbscurve}{knots, ctlpoints, order, type}
|
||||
Defines a nurbs curve.
|
||||
The length of ctlpoints is
|
||||
\code{len(\var{knots}) - \var{order}}.
|
||||
\end{funcdesc}
|
||||
|
||||
\begin{funcdesc}{pwlcurve}{points, type}
|
||||
Defines a piecewise-linear curve.
|
||||
\var{points}
|
||||
is a list of points.
|
||||
\var{type}
|
||||
must be
|
||||
\code{N_ST}.
|
||||
\end{funcdesc}
|
||||
|
||||
\begin{funcdesc}{pick}{n}
|
||||
\funcline{select}{n}
|
||||
The only argument to these functions specifies the desired size of the
|
||||
pick or select buffer.
|
||||
\end{funcdesc}
|
||||
|
||||
\begin{funcdesc}{endpick}{}
|
||||
\funcline{endselect}{}
|
||||
These functions have no arguments.
|
||||
They return a list of integers representing the used part of the
|
||||
pick/select buffer.
|
||||
No method is provided to detect buffer overrun.
|
||||
\end{funcdesc}
|
||||
|
||||
Here is a tiny but complete example GL program in Python:
|
||||
|
||||
\begin{verbatim}
|
||||
import gl, GL, time
|
||||
|
||||
def main():
|
||||
gl.foreground()
|
||||
gl.prefposition(500, 900, 500, 900)
|
||||
w = gl.winopen('CrissCross')
|
||||
gl.ortho2(0.0, 400.0, 0.0, 400.0)
|
||||
gl.color(GL.WHITE)
|
||||
gl.clear()
|
||||
gl.color(GL.RED)
|
||||
gl.bgnline()
|
||||
gl.v2f(0.0, 0.0)
|
||||
gl.v2f(400.0, 400.0)
|
||||
gl.endline()
|
||||
gl.bgnline()
|
||||
gl.v2f(400.0, 0.0)
|
||||
gl.v2f(0.0, 400.0)
|
||||
gl.endline()
|
||||
time.sleep(5)
|
||||
|
||||
main()
|
||||
\end{verbatim}
|
||||
|
||||
|
||||
\begin{seealso}
|
||||
\seetitle[http://pyopengl.sourceforge.net/]
|
||||
{PyOpenGL: The Python OpenGL Binding}
|
||||
{An interface to OpenGL\index{OpenGL} is also available;
|
||||
see information about the
|
||||
\strong{PyOpenGL}\index{PyOpenGL} project online at
|
||||
\url{http://pyopengl.sourceforge.net/}. This may be a
|
||||
better option if support for SGI hardware from before
|
||||
about 1996 is not required.}
|
||||
\end{seealso}
|
||||
|
||||
|
||||
\section{\module{DEVICE} ---
|
||||
Constants used with the \module{gl} module}
|
||||
|
||||
\declaremodule{standard}{DEVICE}
|
||||
\platform{IRIX}
|
||||
\modulesynopsis{Constants used with the \module{gl} module.}
|
||||
|
||||
This modules defines the constants used by the Silicon Graphics
|
||||
\emph{Graphics Library} that C programmers find in the header file
|
||||
\code{<gl/device.h>}.
|
||||
Read the module source file for details.
|
||||
|
||||
|
||||
\section{\module{GL} ---
|
||||
Constants used with the \module{gl} module}
|
||||
|
||||
\declaremodule[gl-constants]{standard}{GL}
|
||||
\platform{IRIX}
|
||||
\modulesynopsis{Constants used with the \module{gl} module.}
|
||||
|
||||
This module contains constants used by the Silicon Graphics
|
||||
\emph{Graphics Library} from the C header file \code{<gl/gl.h>}.
|
||||
Read the module source file for details.
|
|
@ -1,66 +0,0 @@
|
|||
\section{\module{imgfile} ---
|
||||
Support for SGI imglib files}
|
||||
|
||||
\declaremodule{builtin}{imgfile}
|
||||
\platform{IRIX}
|
||||
\modulesynopsis{Support for SGI imglib files.}
|
||||
|
||||
|
||||
The \module{imgfile} module allows Python programs to access SGI imglib image
|
||||
files (also known as \file{.rgb} files). The module is far from
|
||||
complete, but is provided anyway since the functionality that there is
|
||||
enough in some cases. Currently, colormap files are not supported.
|
||||
|
||||
The module defines the following variables and functions:
|
||||
|
||||
\begin{excdesc}{error}
|
||||
This exception is raised on all errors, such as unsupported file type, etc.
|
||||
\end{excdesc}
|
||||
|
||||
\begin{funcdesc}{getsizes}{file}
|
||||
This function returns a tuple \code{(\var{x}, \var{y}, \var{z})} where
|
||||
\var{x} and \var{y} are the size of the image in pixels and
|
||||
\var{z} is the number of
|
||||
bytes per pixel. Only 3 byte RGB pixels and 1 byte greyscale pixels
|
||||
are currently supported.
|
||||
\end{funcdesc}
|
||||
|
||||
\begin{funcdesc}{read}{file}
|
||||
This function reads and decodes the image on the specified file, and
|
||||
returns it as a Python string. The string has either 1 byte greyscale
|
||||
pixels or 4 byte RGBA pixels. The bottom left pixel is the first in
|
||||
the string. This format is suitable to pass to \function{gl.lrectwrite()},
|
||||
for instance.
|
||||
\end{funcdesc}
|
||||
|
||||
\begin{funcdesc}{readscaled}{file, x, y, filter\optional{, blur}}
|
||||
This function is identical to read but it returns an image that is
|
||||
scaled to the given \var{x} and \var{y} sizes. If the \var{filter} and
|
||||
\var{blur} parameters are omitted scaling is done by
|
||||
simply dropping or duplicating pixels, so the result will be less than
|
||||
perfect, especially for computer-generated images.
|
||||
|
||||
Alternatively, you can specify a filter to use to smooth the image
|
||||
after scaling. The filter forms supported are \code{'impulse'},
|
||||
\code{'box'}, \code{'triangle'}, \code{'quadratic'} and
|
||||
\code{'gaussian'}. If a filter is specified \var{blur} is an optional
|
||||
parameter specifying the blurriness of the filter. It defaults to \code{1.0}.
|
||||
|
||||
\function{readscaled()} makes no attempt to keep the aspect ratio
|
||||
correct, so that is the users' responsibility.
|
||||
\end{funcdesc}
|
||||
|
||||
\begin{funcdesc}{ttob}{flag}
|
||||
This function sets a global flag which defines whether the scan lines
|
||||
of the image are read or written from bottom to top (flag is zero,
|
||||
compatible with SGI GL) or from top to bottom(flag is one,
|
||||
compatible with X). The default is zero.
|
||||
\end{funcdesc}
|
||||
|
||||
\begin{funcdesc}{write}{file, data, x, y, z}
|
||||
This function writes the RGB or greyscale data in \var{data} to image
|
||||
file \var{file}. \var{x} and \var{y} give the size of the image,
|
||||
\var{z} is 1 for 1 byte greyscale images or 3 for RGB images (which are
|
||||
stored as 4 byte values of which only the lower three bytes are used).
|
||||
These are the formats returned by \function{gl.lrectread()}.
|
||||
\end{funcdesc}
|
|
@ -1,7 +0,0 @@
|
|||
\chapter{SGI IRIX Specific Services}
|
||||
\label{sgi}
|
||||
|
||||
The modules described in this chapter provide interfaces to features
|
||||
that are unique to SGI's IRIX operating system (versions 4 and 5).
|
||||
|
||||
\localmoduletable
|
|
@ -46,11 +46,6 @@ document these.
|
|||
|
||||
\item[\module{posixpath}]
|
||||
--- Implementation of \module{os.path} on \POSIX.
|
||||
|
||||
\item[\module{bsddb185}]
|
||||
--- Backwards compatibility module for systems which still use the Berkeley
|
||||
DB 1.85 module. It is normally only available on certain BSD \UNIX-based
|
||||
systems. It should never be used directly.
|
||||
\end{description}
|
||||
|
||||
|
||||
|
@ -97,17 +92,3 @@ installing the shared object if using dynamically-loaded extensions.
|
|||
--- Measure time intervals to high resolution (use \function{time.clock()}
|
||||
instead).
|
||||
\end{description}
|
||||
|
||||
\section{SGI-specific Extension modules}
|
||||
|
||||
The following are SGI specific, and may be out of touch with the
|
||||
current version of reality.
|
||||
|
||||
\begin{description}
|
||||
\item[\module{cl}]
|
||||
--- Interface to the SGI compression library.
|
||||
|
||||
\item[\module{sv}]
|
||||
--- Interface to the ``simple video'' board on SGI Indigo
|
||||
(obsolete hardware).
|
||||
\end{description}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
#! /usr/bin/env python
|
||||
# -*- Python -*-
|
||||
|
||||
import string
|
||||
import support
|
||||
import sys
|
||||
|
||||
|
@ -12,7 +11,7 @@ def collect(fp):
|
|||
line = fp.readline()
|
||||
if not line:
|
||||
break
|
||||
line = string.strip(line)
|
||||
line = line.strip()
|
||||
if line:
|
||||
names.append(line)
|
||||
else:
|
||||
|
@ -32,7 +31,7 @@ def main():
|
|||
colnums.append(percol*i)
|
||||
options.aesop_type = "information"
|
||||
fp = options.get_output_file()
|
||||
fp.write(string.rstrip(options.get_header()) + "\n")
|
||||
fp.write(options.get_header().rstrip() + "\n")
|
||||
fp.write(THANKS + "\n")
|
||||
fp.write('<table width="100%" align="center">\n')
|
||||
for i in range(percol):
|
||||
|
@ -44,7 +43,7 @@ def main():
|
|||
pass
|
||||
fp.write(" </tr>\n")
|
||||
fp.write("</table>\n")
|
||||
fp.write(string.rstrip(options.get_footer()) + "\n")
|
||||
fp.write(options.get_footer().rstrip() + "\n")
|
||||
fp.close()
|
||||
|
||||
THANKS = '''\
|
||||
|
|
|
@ -89,8 +89,9 @@ lambdef_nocond: 'lambda' [varargslist] ':' test_nocond
|
|||
or_test: and_test ('or' and_test)*
|
||||
and_test: not_test ('and' not_test)*
|
||||
not_test: 'not' not_test | comparison
|
||||
comparison: expr (comp_op expr)*
|
||||
comparison: star_expr (comp_op star_expr)*
|
||||
comp_op: '<'|'>'|'=='|'>='|'<='|'!='|'in'|'not' 'in'|'is'|'is' 'not'
|
||||
star_expr: ['*'] expr
|
||||
expr: xor_expr ('|' xor_expr)*
|
||||
xor_expr: and_expr ('^' and_expr)*
|
||||
and_expr: shift_expr ('&' shift_expr)*
|
||||
|
@ -108,7 +109,7 @@ trailer: '(' [arglist] ')' | '[' subscriptlist ']' | '.' NAME
|
|||
subscriptlist: subscript (',' subscript)* [',']
|
||||
subscript: test | [test] ':' [test] [sliceop]
|
||||
sliceop: ':' [test]
|
||||
exprlist: expr (',' expr)* [',']
|
||||
exprlist: star_expr (',' star_expr)* [',']
|
||||
testlist: test (',' test)* [',']
|
||||
dictorsetmaker: ( (test ':' test (',' test ':' test)* [',']) |
|
||||
(test (comp_for | (',' test)* [','])) )
|
||||
|
|
|
@ -186,7 +186,8 @@ enum _expr_kind {BoolOp_kind=1, BinOp_kind=2, UnaryOp_kind=3, Lambda_kind=4,
|
|||
SetComp_kind=9, GeneratorExp_kind=10, Yield_kind=11,
|
||||
Compare_kind=12, Call_kind=13, Num_kind=14, Str_kind=15,
|
||||
Bytes_kind=16, Ellipsis_kind=17, Attribute_kind=18,
|
||||
Subscript_kind=19, Name_kind=20, List_kind=21, Tuple_kind=22};
|
||||
Subscript_kind=19, Starred_kind=20, Name_kind=21,
|
||||
List_kind=22, Tuple_kind=23};
|
||||
struct _expr {
|
||||
enum _expr_kind kind;
|
||||
union {
|
||||
|
@ -283,6 +284,11 @@ struct _expr {
|
|||
expr_context_ty ctx;
|
||||
} Subscript;
|
||||
|
||||
struct {
|
||||
expr_ty value;
|
||||
expr_context_ty ctx;
|
||||
} Starred;
|
||||
|
||||
struct {
|
||||
identifier id;
|
||||
expr_context_ty ctx;
|
||||
|
@ -499,6 +505,9 @@ expr_ty _Py_Attribute(expr_ty value, identifier attr, expr_context_ty ctx, int
|
|||
#define Subscript(a0, a1, a2, a3, a4, a5) _Py_Subscript(a0, a1, a2, a3, a4, a5)
|
||||
expr_ty _Py_Subscript(expr_ty value, slice_ty slice, expr_context_ty ctx, int
|
||||
lineno, int col_offset, PyArena *arena);
|
||||
#define Starred(a0, a1, a2, a3, a4) _Py_Starred(a0, a1, a2, a3, a4)
|
||||
expr_ty _Py_Starred(expr_ty value, expr_context_ty ctx, int lineno, int
|
||||
col_offset, PyArena *arena);
|
||||
#define Name(a0, a1, a2, a3, a4) _Py_Name(a0, a1, a2, a3, a4)
|
||||
expr_ty _Py_Name(identifier id, expr_context_ty ctx, int lineno, int
|
||||
col_offset, PyArena *arena);
|
||||
|
|
|
@ -55,29 +55,30 @@
|
|||
#define not_test 310
|
||||
#define comparison 311
|
||||
#define comp_op 312
|
||||
#define expr 313
|
||||
#define xor_expr 314
|
||||
#define and_expr 315
|
||||
#define shift_expr 316
|
||||
#define arith_expr 317
|
||||
#define term 318
|
||||
#define factor 319
|
||||
#define power 320
|
||||
#define atom 321
|
||||
#define testlist_comp 322
|
||||
#define trailer 323
|
||||
#define subscriptlist 324
|
||||
#define subscript 325
|
||||
#define sliceop 326
|
||||
#define exprlist 327
|
||||
#define testlist 328
|
||||
#define dictorsetmaker 329
|
||||
#define classdef 330
|
||||
#define arglist 331
|
||||
#define argument 332
|
||||
#define comp_iter 333
|
||||
#define comp_for 334
|
||||
#define comp_if 335
|
||||
#define testlist1 336
|
||||
#define encoding_decl 337
|
||||
#define yield_expr 338
|
||||
#define star_expr 313
|
||||
#define expr 314
|
||||
#define xor_expr 315
|
||||
#define and_expr 316
|
||||
#define shift_expr 317
|
||||
#define arith_expr 318
|
||||
#define term 319
|
||||
#define factor 320
|
||||
#define power 321
|
||||
#define atom 322
|
||||
#define testlist_comp 323
|
||||
#define trailer 324
|
||||
#define subscriptlist 325
|
||||
#define subscript 326
|
||||
#define sliceop 327
|
||||
#define exprlist 328
|
||||
#define testlist 329
|
||||
#define dictorsetmaker 330
|
||||
#define classdef 331
|
||||
#define arglist 332
|
||||
#define argument 333
|
||||
#define comp_iter 334
|
||||
#define comp_for 335
|
||||
#define comp_if 336
|
||||
#define testlist1 337
|
||||
#define encoding_decl 338
|
||||
#define yield_expr 339
|
||||
|
|
|
@ -85,6 +85,8 @@ extern "C" {
|
|||
#define DELETE_NAME 91 /* "" */
|
||||
#define UNPACK_SEQUENCE 92 /* Number of sequence items */
|
||||
#define FOR_ITER 93
|
||||
#define UNPACK_EX 94 /* Num items before variable part +
|
||||
(Num items after variable part << 8) */
|
||||
|
||||
#define STORE_ATTR 95 /* Index in name list */
|
||||
#define DELETE_ATTR 96 /* "" */
|
||||
|
|
|
@ -19,7 +19,7 @@ Encapsulates the basic operation:
|
|||
[Note: it would be nice to add functions to interpret the exit status.]
|
||||
"""
|
||||
|
||||
__all__ = ["getstatusoutput","getoutput","getstatus"]
|
||||
__all__ = ["getstatusoutput", "getoutput"]
|
||||
|
||||
# Module 'commands'
|
||||
#
|
||||
|
@ -28,15 +28,6 @@ __all__ = ["getstatusoutput","getoutput","getstatus"]
|
|||
# NB This only works (and is only relevant) for UNIX.
|
||||
|
||||
|
||||
# Get 'ls -l' status for an object into a string
|
||||
#
|
||||
def getstatus(file):
|
||||
"""Return output of "ls -ld <file>" in a string."""
|
||||
import warnings
|
||||
warnings.warn("commands.getstatus() is deprecated", DeprecationWarning)
|
||||
return getoutput('ls -ld' + mkarg(file))
|
||||
|
||||
|
||||
# Get the output from a shell command into a string.
|
||||
# The exit status is ignored; a trailing newline is stripped.
|
||||
# Assume the command will work with '{ ... ; } 2>&1' around it..
|
||||
|
|
|
@ -17,8 +17,6 @@ intends to replace several other, older modules and functions, like:
|
|||
|
||||
os.system
|
||||
os.spawn*
|
||||
os.popen*
|
||||
popen2.*
|
||||
commands.*
|
||||
|
||||
Information about how the subprocess module can be used to replace these
|
||||
|
@ -283,73 +281,6 @@ Environment example:
|
|||
os.spawnlpe(os.P_NOWAIT, "/bin/mycmd", "mycmd", "myarg", env)
|
||||
==>
|
||||
Popen(["/bin/mycmd", "myarg"], env={"PATH": "/usr/bin"})
|
||||
|
||||
|
||||
Replacing os.popen*
|
||||
-------------------
|
||||
pipe = os.popen(cmd, mode='r', bufsize)
|
||||
==>
|
||||
pipe = Popen(cmd, shell=True, bufsize=bufsize, stdout=PIPE).stdout
|
||||
|
||||
pipe = os.popen(cmd, mode='w', bufsize)
|
||||
==>
|
||||
pipe = Popen(cmd, shell=True, bufsize=bufsize, stdin=PIPE).stdin
|
||||
|
||||
|
||||
(child_stdin, child_stdout) = os.popen2(cmd, mode, bufsize)
|
||||
==>
|
||||
p = Popen(cmd, shell=True, bufsize=bufsize,
|
||||
stdin=PIPE, stdout=PIPE, close_fds=True)
|
||||
(child_stdin, child_stdout) = (p.stdin, p.stdout)
|
||||
|
||||
|
||||
(child_stdin,
|
||||
child_stdout,
|
||||
child_stderr) = os.popen3(cmd, mode, bufsize)
|
||||
==>
|
||||
p = Popen(cmd, shell=True, bufsize=bufsize,
|
||||
stdin=PIPE, stdout=PIPE, stderr=PIPE, close_fds=True)
|
||||
(child_stdin,
|
||||
child_stdout,
|
||||
child_stderr) = (p.stdin, p.stdout, p.stderr)
|
||||
|
||||
|
||||
(child_stdin, child_stdout_and_stderr) = os.popen4(cmd, mode, bufsize)
|
||||
==>
|
||||
p = Popen(cmd, shell=True, bufsize=bufsize,
|
||||
stdin=PIPE, stdout=PIPE, stderr=STDOUT, close_fds=True)
|
||||
(child_stdin, child_stdout_and_stderr) = (p.stdin, p.stdout)
|
||||
|
||||
|
||||
Replacing popen2.*
|
||||
------------------
|
||||
Note: If the cmd argument to popen2 functions is a string, the command
|
||||
is executed through /bin/sh. If it is a list, the command is directly
|
||||
executed.
|
||||
|
||||
(child_stdout, child_stdin) = popen2.popen2("somestring", bufsize, mode)
|
||||
==>
|
||||
p = Popen(["somestring"], shell=True, bufsize=bufsize
|
||||
stdin=PIPE, stdout=PIPE, close_fds=True)
|
||||
(child_stdout, child_stdin) = (p.stdout, p.stdin)
|
||||
|
||||
|
||||
(child_stdout, child_stdin) = popen2.popen2(["mycmd", "myarg"], bufsize, mode)
|
||||
==>
|
||||
p = Popen(["mycmd", "myarg"], bufsize=bufsize,
|
||||
stdin=PIPE, stdout=PIPE, close_fds=True)
|
||||
(child_stdout, child_stdin) = (p.stdout, p.stdin)
|
||||
|
||||
The popen2.Popen3 and popen3.Popen4 basically works as subprocess.Popen,
|
||||
except that:
|
||||
|
||||
* subprocess.Popen raises an exception if the execution fails
|
||||
* the capturestderr argument is replaced with the stderr argument.
|
||||
* stdin=PIPE and stdout=PIPE must be specified.
|
||||
* popen2 closes all filedescriptors by default, but you have to specify
|
||||
close_fds=True with subprocess.Popen.
|
||||
|
||||
|
||||
"""
|
||||
|
||||
import sys
|
||||
|
|
|
@ -818,11 +818,7 @@ _expectations = {
|
|||
"""
|
||||
test__locale
|
||||
test_applesingle
|
||||
test_al
|
||||
test_bsddb185
|
||||
test_bsddb3
|
||||
test_cd
|
||||
test_cl
|
||||
test_commands
|
||||
test_crypt
|
||||
test_curses
|
||||
|
@ -831,9 +827,7 @@ _expectations = {
|
|||
test_fcntl
|
||||
test_fork1
|
||||
test_gdbm
|
||||
test_gl
|
||||
test_grp
|
||||
test_imgfile
|
||||
test_ioctl
|
||||
test_largefile
|
||||
test_linuxaudiodev
|
||||
|
@ -855,15 +849,9 @@ _expectations = {
|
|||
""",
|
||||
'linux2':
|
||||
"""
|
||||
test_al
|
||||
test_applesingle
|
||||
test_bsddb185
|
||||
test_cd
|
||||
test_cl
|
||||
test_curses
|
||||
test_dl
|
||||
test_gl
|
||||
test_imgfile
|
||||
test_largefile
|
||||
test_linuxaudiodev
|
||||
test_nis
|
||||
|
@ -875,14 +863,10 @@ _expectations = {
|
|||
""",
|
||||
'mac':
|
||||
"""
|
||||
test_al
|
||||
test_atexit
|
||||
test_bsddb
|
||||
test_bsddb185
|
||||
test_bsddb3
|
||||
test_bz2
|
||||
test_cd
|
||||
test_cl
|
||||
test_commands
|
||||
test_crypt
|
||||
test_curses
|
||||
|
@ -890,10 +874,8 @@ _expectations = {
|
|||
test_dl
|
||||
test_fcntl
|
||||
test_fork1
|
||||
test_gl
|
||||
test_grp
|
||||
test_ioctl
|
||||
test_imgfile
|
||||
test_largefile
|
||||
test_linuxaudiodev
|
||||
test_locale
|
||||
|
@ -919,15 +901,9 @@ _expectations = {
|
|||
""",
|
||||
'unixware7':
|
||||
"""
|
||||
test_al
|
||||
test_applesingle
|
||||
test_bsddb
|
||||
test_bsddb185
|
||||
test_cd
|
||||
test_cl
|
||||
test_dl
|
||||
test_gl
|
||||
test_imgfile
|
||||
test_largefile
|
||||
test_linuxaudiodev
|
||||
test_minidom
|
||||
|
@ -943,15 +919,9 @@ _expectations = {
|
|||
""",
|
||||
'openunix8':
|
||||
"""
|
||||
test_al
|
||||
test_applesingle
|
||||
test_bsddb
|
||||
test_bsddb185
|
||||
test_cd
|
||||
test_cl
|
||||
test_dl
|
||||
test_gl
|
||||
test_imgfile
|
||||
test_largefile
|
||||
test_linuxaudiodev
|
||||
test_minidom
|
||||
|
@ -967,18 +937,12 @@ _expectations = {
|
|||
""",
|
||||
'sco_sv3':
|
||||
"""
|
||||
test_al
|
||||
test_applesingle
|
||||
test_asynchat
|
||||
test_bsddb
|
||||
test_bsddb185
|
||||
test_cd
|
||||
test_cl
|
||||
test_dl
|
||||
test_fork1
|
||||
test_gettext
|
||||
test_gl
|
||||
test_imgfile
|
||||
test_largefile
|
||||
test_linuxaudiodev
|
||||
test_locale
|
||||
|
@ -1000,15 +964,11 @@ _expectations = {
|
|||
""",
|
||||
'riscos':
|
||||
"""
|
||||
test_al
|
||||
test_applesingle
|
||||
test_asynchat
|
||||
test_atexit
|
||||
test_bsddb
|
||||
test_bsddb185
|
||||
test_bsddb3
|
||||
test_cd
|
||||
test_cl
|
||||
test_commands
|
||||
test_crypt
|
||||
test_dbm
|
||||
|
@ -1016,9 +976,7 @@ _expectations = {
|
|||
test_fcntl
|
||||
test_fork1
|
||||
test_gdbm
|
||||
test_gl
|
||||
test_grp
|
||||
test_imgfile
|
||||
test_largefile
|
||||
test_linuxaudiodev
|
||||
test_locale
|
||||
|
@ -1043,12 +1001,7 @@ _expectations = {
|
|||
""",
|
||||
'darwin':
|
||||
"""
|
||||
test_al
|
||||
test_cd
|
||||
test_cl
|
||||
test_gdbm
|
||||
test_gl
|
||||
test_imgfile
|
||||
test_largefile
|
||||
test_linuxaudiodev
|
||||
test_locale
|
||||
|
@ -1059,18 +1012,12 @@ _expectations = {
|
|||
""",
|
||||
'sunos5':
|
||||
"""
|
||||
test_al
|
||||
test_applesingle
|
||||
test_bsddb
|
||||
test_bsddb185
|
||||
test_cd
|
||||
test_cl
|
||||
test_curses
|
||||
test_dbm
|
||||
test_gdbm
|
||||
test_gl
|
||||
test_gzip
|
||||
test_imgfile
|
||||
test_linuxaudiodev
|
||||
test_openpty
|
||||
test_sqlite
|
||||
|
@ -1080,18 +1027,12 @@ _expectations = {
|
|||
""",
|
||||
'hp-ux11':
|
||||
"""
|
||||
test_al
|
||||
test_applesingle
|
||||
test_bsddb
|
||||
test_bsddb185
|
||||
test_cd
|
||||
test_cl
|
||||
test_curses
|
||||
test_dl
|
||||
test_gdbm
|
||||
test_gl
|
||||
test_gzip
|
||||
test_imgfile
|
||||
test_largefile
|
||||
test_linuxaudiodev
|
||||
test_locale
|
||||
|
@ -1109,16 +1050,10 @@ _expectations = {
|
|||
""",
|
||||
'atheos':
|
||||
"""
|
||||
test_al
|
||||
test_applesingle
|
||||
test_bsddb185
|
||||
test_cd
|
||||
test_cl
|
||||
test_curses
|
||||
test_dl
|
||||
test_gdbm
|
||||
test_gl
|
||||
test_imgfile
|
||||
test_largefile
|
||||
test_linuxaudiodev
|
||||
test_locale
|
||||
|
@ -1134,16 +1069,10 @@ _expectations = {
|
|||
""",
|
||||
'cygwin':
|
||||
"""
|
||||
test_al
|
||||
test_applesingle
|
||||
test_bsddb185
|
||||
test_bsddb3
|
||||
test_cd
|
||||
test_cl
|
||||
test_curses
|
||||
test_dbm
|
||||
test_gl
|
||||
test_imgfile
|
||||
test_ioctl
|
||||
test_largefile
|
||||
test_linuxaudiodev
|
||||
|
@ -1156,18 +1085,12 @@ _expectations = {
|
|||
""",
|
||||
'os2emx':
|
||||
"""
|
||||
test_al
|
||||
test_applesingle
|
||||
test_audioop
|
||||
test_bsddb185
|
||||
test_bsddb3
|
||||
test_cd
|
||||
test_cl
|
||||
test_commands
|
||||
test_curses
|
||||
test_dl
|
||||
test_gl
|
||||
test_imgfile
|
||||
test_largefile
|
||||
test_linuxaudiodev
|
||||
test_mhlib
|
||||
|
@ -1185,15 +1108,10 @@ _expectations = {
|
|||
'freebsd4':
|
||||
"""
|
||||
test_aepack
|
||||
test_al
|
||||
test_applesingle
|
||||
test_bsddb
|
||||
test_bsddb3
|
||||
test_cd
|
||||
test_cl
|
||||
test_gdbm
|
||||
test_gl
|
||||
test_imgfile
|
||||
test_linuxaudiodev
|
||||
test_locale
|
||||
test_macfs
|
||||
|
@ -1219,19 +1137,13 @@ _expectations = {
|
|||
'aix5':
|
||||
"""
|
||||
test_aepack
|
||||
test_al
|
||||
test_applesingle
|
||||
test_bsddb
|
||||
test_bsddb185
|
||||
test_bsddb3
|
||||
test_bz2
|
||||
test_cd
|
||||
test_cl
|
||||
test_dl
|
||||
test_gdbm
|
||||
test_gl
|
||||
test_gzip
|
||||
test_imgfile
|
||||
test_linuxaudiodev
|
||||
test_macfs
|
||||
test_macostools
|
||||
|
@ -1249,17 +1161,12 @@ _expectations = {
|
|||
'openbsd3':
|
||||
"""
|
||||
test_aepack
|
||||
test_al
|
||||
test_applesingle
|
||||
test_bsddb
|
||||
test_bsddb3
|
||||
test_cd
|
||||
test_cl
|
||||
test_ctypes
|
||||
test_dl
|
||||
test_gdbm
|
||||
test_gl
|
||||
test_imgfile
|
||||
test_linuxaudiodev
|
||||
test_locale
|
||||
test_macfs
|
||||
|
@ -1281,19 +1188,13 @@ _expectations = {
|
|||
'netbsd3':
|
||||
"""
|
||||
test_aepack
|
||||
test_al
|
||||
test_applesingle
|
||||
test_bsddb
|
||||
test_bsddb185
|
||||
test_bsddb3
|
||||
test_cd
|
||||
test_cl
|
||||
test_ctypes
|
||||
test_curses
|
||||
test_dl
|
||||
test_gdbm
|
||||
test_gl
|
||||
test_imgfile
|
||||
test_linuxaudiodev
|
||||
test_locale
|
||||
test_macfs
|
||||
|
|
|
@ -1,23 +0,0 @@
|
|||
#! /usr/bin/env python
|
||||
"""Whimpy test script for the al module
|
||||
Roger E. Masse
|
||||
"""
|
||||
import al
|
||||
from test.test_support import verbose
|
||||
|
||||
alattrs = ['__doc__', '__name__', 'getdefault', 'getminmax', 'getname', 'getparams',
|
||||
'newconfig', 'openport', 'queryparams', 'setparams']
|
||||
|
||||
# This is a very unobtrusive test for the existence of the al module and all its
|
||||
# attributes. More comprehensive examples can be found in Demo/al
|
||||
|
||||
def main():
|
||||
# touch all the attributes of al without doing anything
|
||||
if verbose:
|
||||
print('Touching al module attributes...')
|
||||
for attr in alattrs:
|
||||
if verbose:
|
||||
print('touching: ', attr)
|
||||
getattr(al, attr)
|
||||
|
||||
main()
|
|
@ -1,43 +0,0 @@
|
|||
"""Tests for the bsddb185 module.
|
||||
|
||||
The file 185test.db found in Lib/test/ is for testing purposes with this
|
||||
testing suite.
|
||||
|
||||
"""
|
||||
from test.test_support import verbose, run_unittest, findfile
|
||||
import unittest
|
||||
import bsddb185
|
||||
import anydbm
|
||||
import whichdb
|
||||
import os
|
||||
import tempfile
|
||||
import shutil
|
||||
|
||||
class Bsddb185Tests(unittest.TestCase):
|
||||
|
||||
def test_open_existing_hash(self):
|
||||
# Verify we can open a file known to be a hash v2 file
|
||||
db = bsddb185.hashopen(findfile("185test.db"))
|
||||
self.assertEqual(db["1"], "1")
|
||||
db.close()
|
||||
|
||||
def test_whichdb(self):
|
||||
# Verify that whichdb correctly sniffs the known hash v2 file
|
||||
self.assertEqual(whichdb.whichdb(findfile("185test.db")), "bsddb185")
|
||||
|
||||
def test_anydbm_create(self):
|
||||
# Verify that anydbm.open does *not* create a bsddb185 file
|
||||
tmpdir = tempfile.mkdtemp()
|
||||
try:
|
||||
dbfile = os.path.join(tmpdir, "foo.db")
|
||||
anydbm.open(dbfile, "c").close()
|
||||
ftype = whichdb.whichdb(dbfile)
|
||||
self.assertNotEqual(ftype, "bsddb185")
|
||||
finally:
|
||||
shutil.rmtree(tmpdir)
|
||||
|
||||
def test_main():
|
||||
run_unittest(Bsddb185Tests)
|
||||
|
||||
if __name__ == "__main__":
|
||||
test_main()
|
|
@ -1,26 +0,0 @@
|
|||
#! /usr/bin/env python
|
||||
"""Whimpy test script for the cd module
|
||||
Roger E. Masse
|
||||
"""
|
||||
import cd
|
||||
from test.test_support import verbose
|
||||
|
||||
cdattrs = ['BLOCKSIZE', 'CDROM', 'DATASIZE', 'ERROR', 'NODISC', 'PAUSED', 'PLAYING', 'READY',
|
||||
'STILL', '__doc__', '__name__', 'atime', 'audio', 'catalog', 'control', 'createparser', 'error',
|
||||
'ident', 'index', 'msftoframe', 'open', 'pnum', 'ptime']
|
||||
|
||||
|
||||
# This is a very inobtrusive test for the existence of the cd module and all its
|
||||
# attributes. More comprehensive examples can be found in Demo/cd and
|
||||
# require that you have a CD and a CD ROM drive
|
||||
|
||||
def main():
|
||||
# touch all the attributes of cd without doing anything
|
||||
if verbose:
|
||||
print('Touching cd module attributes...')
|
||||
for attr in cdattrs:
|
||||
if verbose:
|
||||
print('touching: ', attr)
|
||||
getattr(cd, attr)
|
||||
|
||||
main()
|
|
@ -1,78 +0,0 @@
|
|||
#! /usr/bin/env python
|
||||
"""Whimpy test script for the cl module
|
||||
Roger E. Masse
|
||||
"""
|
||||
import cl
|
||||
from test.test_support import verbose
|
||||
|
||||
clattrs = ['ADDED_ALGORITHM_ERROR', 'ALAW', 'ALGORITHM_ID',
|
||||
'ALGORITHM_VERSION', 'AUDIO', 'AWARE_ERROR', 'AWARE_MPEG_AUDIO',
|
||||
'AWARE_MULTIRATE', 'AWCMP_CONST_QUAL', 'AWCMP_FIXED_RATE',
|
||||
'AWCMP_INDEPENDENT', 'AWCMP_JOINT_STEREO', 'AWCMP_LOSSLESS',
|
||||
'AWCMP_MPEG_LAYER_I', 'AWCMP_MPEG_LAYER_II', 'AWCMP_STEREO',
|
||||
'Algorithm', 'AlgorithmNumber', 'AlgorithmType', 'AudioFormatName',
|
||||
'BAD_ALGORITHM_NAME', 'BAD_ALGORITHM_TYPE', 'BAD_BLOCK_SIZE',
|
||||
'BAD_BOARD', 'BAD_BUFFERING', 'BAD_BUFFERLENGTH_NEG',
|
||||
'BAD_BUFFERLENGTH_ODD', 'BAD_BUFFER_EXISTS', 'BAD_BUFFER_HANDLE',
|
||||
'BAD_BUFFER_POINTER', 'BAD_BUFFER_QUERY_SIZE', 'BAD_BUFFER_SIZE',
|
||||
'BAD_BUFFER_SIZE_POINTER', 'BAD_BUFFER_TYPE',
|
||||
'BAD_COMPRESSION_SCHEME', 'BAD_COMPRESSOR_HANDLE',
|
||||
'BAD_COMPRESSOR_HANDLE_POINTER', 'BAD_FRAME_SIZE',
|
||||
'BAD_FUNCTIONALITY', 'BAD_FUNCTION_POINTER', 'BAD_HEADER_SIZE',
|
||||
'BAD_INITIAL_VALUE', 'BAD_INTERNAL_FORMAT', 'BAD_LICENSE',
|
||||
'BAD_MIN_GT_MAX', 'BAD_NO_BUFFERSPACE', 'BAD_NUMBER_OF_BLOCKS',
|
||||
'BAD_PARAM', 'BAD_PARAM_ID_POINTER', 'BAD_PARAM_TYPE', 'BAD_POINTER',
|
||||
'BAD_PVBUFFER', 'BAD_SCHEME_POINTER', 'BAD_STREAM_HEADER',
|
||||
'BAD_STRING_POINTER', 'BAD_TEXT_STRING_PTR', 'BEST_FIT',
|
||||
'BIDIRECTIONAL', 'BITRATE_POLICY', 'BITRATE_TARGET',
|
||||
'BITS_PER_COMPONENT', 'BLENDING', 'BLOCK_SIZE', 'BOTTOM_UP',
|
||||
'BUFFER_NOT_CREATED', 'BUF_DATA', 'BUF_FRAME', 'BytesPerPixel',
|
||||
'BytesPerSample', 'CHANNEL_POLICY', 'CHROMA_THRESHOLD', 'CODEC',
|
||||
'COMPONENTS', 'COMPRESSED_BUFFER_SIZE', 'COMPRESSION_RATIO',
|
||||
'COMPRESSOR', 'CONTINUOUS_BLOCK', 'CONTINUOUS_NONBLOCK',
|
||||
'CompressImage', 'DATA', 'DECOMPRESSOR', 'DecompressImage',
|
||||
'EDGE_THRESHOLD', 'ENABLE_IMAGEINFO', 'END_OF_SEQUENCE', 'ENUM_VALUE',
|
||||
'EXACT_COMPRESSION_RATIO', 'EXTERNAL_DEVICE', 'FLOATING_ENUM_VALUE',
|
||||
'FLOATING_RANGE_VALUE', 'FRAME', 'FRAME_BUFFER_SIZE',
|
||||
'FRAME_BUFFER_SIZE_ZERO', 'FRAME_RATE', 'FRAME_TYPE', 'G711_ALAW',
|
||||
'G711_ULAW', 'GRAYSCALE', 'GetAlgorithmName', 'HDCC',
|
||||
'HDCC_SAMPLES_PER_TILE', 'HDCC_TILE_THRESHOLD', 'HEADER_START_CODE',
|
||||
'IMAGE_HEIGHT', 'IMAGE_WIDTH', 'INTERNAL_FORMAT',
|
||||
'INTERNAL_IMAGE_HEIGHT', 'INTERNAL_IMAGE_WIDTH', 'INTRA', 'JPEG',
|
||||
'JPEG_ERROR', 'JPEG_NUM_PARAMS', 'JPEG_QUALITY_FACTOR',
|
||||
'JPEG_QUANTIZATION_TABLES', 'JPEG_SOFTWARE', 'JPEG_STREAM_HEADERS',
|
||||
'KEYFRAME', 'LAST_FRAME_INDEX', 'LAYER', 'LUMA_THRESHOLD',
|
||||
'MAX_NUMBER_OF_AUDIO_ALGORITHMS', 'MAX_NUMBER_OF_ORIGINAL_FORMATS',
|
||||
'MAX_NUMBER_OF_PARAMS', 'MAX_NUMBER_OF_VIDEO_ALGORITHMS', 'MONO',
|
||||
'MPEG_VIDEO', 'MVC1', 'MVC2', 'MVC2_BLENDING', 'MVC2_BLENDING_OFF',
|
||||
'MVC2_BLENDING_ON', 'MVC2_CHROMA_THRESHOLD', 'MVC2_EDGE_THRESHOLD',
|
||||
'MVC2_ERROR', 'MVC2_LUMA_THRESHOLD', 'NEXT_NOT_AVAILABLE',
|
||||
'NOISE_MARGIN', 'NONE', 'NUMBER_OF_FRAMES', 'NUMBER_OF_PARAMS',
|
||||
'ORIENTATION', 'ORIGINAL_FORMAT', 'OpenCompressor',
|
||||
'OpenDecompressor', 'PARAM_OUT_OF_RANGE', 'PREDICTED', 'PREROLL',
|
||||
'ParamID', 'ParamNumber', 'ParamType', 'QUALITY_FACTOR',
|
||||
'QUALITY_LEVEL', 'QueryAlgorithms', 'QueryMaxHeaderSize',
|
||||
'QueryScheme', 'QuerySchemeFromName', 'RANGE_VALUE', 'RGB', 'RGB332',
|
||||
'RGB8', 'RGBA', 'RGBX', 'RLE', 'RLE24', 'RTR', 'RTR1',
|
||||
'RTR_QUALITY_LEVEL', 'SAMPLES_PER_TILE', 'SCHEME_BUSY',
|
||||
'SCHEME_NOT_AVAILABLE', 'SPEED', 'STEREO_INTERLEAVED',
|
||||
'STREAM_HEADERS', 'SetDefault', 'SetMax', 'SetMin', 'TILE_THRESHOLD',
|
||||
'TOP_DOWN', 'ULAW', 'UNCOMPRESSED', 'UNCOMPRESSED_AUDIO',
|
||||
'UNCOMPRESSED_VIDEO', 'UNKNOWN_SCHEME', 'VIDEO', 'VideoFormatName',
|
||||
'Y', 'YCbCr', 'YCbCr422', 'YCbCr422DC', 'YCbCr422HC', 'YUV', 'YUV422',
|
||||
'YUV422DC', 'YUV422HC', '__doc__', '__name__', 'cvt_type', 'error']
|
||||
|
||||
|
||||
# This is a very inobtrusive test for the existence of the cl
|
||||
# module and all its attributes.
|
||||
|
||||
def main():
|
||||
# touch all the attributes of al without doing anything
|
||||
if verbose:
|
||||
print('Touching cl module attributes...')
|
||||
for attr in clattrs:
|
||||
if verbose:
|
||||
print('touching: ', attr)
|
||||
getattr(cl, attr)
|
||||
|
||||
main()
|
|
@ -4,10 +4,6 @@
|
|||
'''
|
||||
import unittest
|
||||
import os, tempfile, re
|
||||
import warnings
|
||||
|
||||
warnings.filterwarnings('ignore', r".*commands.getstatus.. is deprecated",
|
||||
DeprecationWarning)
|
||||
|
||||
from test.test_support import TestSkipped, run_unittest, reap_children
|
||||
from commands import *
|
||||
|
@ -42,28 +38,10 @@ class CommandTests(unittest.TestCase):
|
|||
if dir is not None:
|
||||
os.rmdir(dir)
|
||||
|
||||
def test_getstatus(self):
|
||||
# This pattern should match 'ls -ld /.' on any posix
|
||||
# system, however perversely configured. Even on systems
|
||||
# (e.g., Cygwin) where user and group names can have spaces:
|
||||
# drwxr-xr-x 15 Administ Domain U 4096 Aug 12 12:50 /
|
||||
# drwxr-xr-x 15 Joe User My Group 4096 Aug 12 12:50 /
|
||||
# Note that the first case above has a space in the group name
|
||||
# while the second one has a space in both names.
|
||||
pat = r'''d......... # It is a directory.
|
||||
\+? # It may have ACLs.
|
||||
\s+\d+ # It has some number of links.
|
||||
[^/]* # Skip user, group, size, and date.
|
||||
/\. # and end with the name of the file.
|
||||
'''
|
||||
|
||||
self.assert_(re.match(pat, getstatus("/."), re.VERBOSE))
|
||||
|
||||
|
||||
def test_main():
|
||||
run_unittest(CommandTests)
|
||||
reap_children()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
test_main()
|
||||
|
|
|
@ -1,150 +0,0 @@
|
|||
#! /usr/bin/env python
|
||||
"""Very simple test script for the SGI gl library extension module
|
||||
taken mostly from the documentation.
|
||||
Roger E. Masse
|
||||
"""
|
||||
from test.test_support import verbose, TestSkipped
|
||||
import gl, GL, time
|
||||
|
||||
glattrs = ['RGBcolor', 'RGBcursor', 'RGBmode', 'RGBrange', 'RGBwritemask',
|
||||
'__doc__', '__name__', 'addtopup', 'altgetmatrix', 'arc', 'arcf',
|
||||
'arcfi', 'arcfs', 'arci', 'arcs', 'attachcursor', 'backbuffer',
|
||||
'backface', 'bbox2', 'bbox2i', 'bbox2s', 'bgnclosedline', 'bgnline',
|
||||
'bgnpoint', 'bgnpolygon', 'bgnsurface', 'bgntmesh', 'bgntrim',
|
||||
'blankscreen', 'blanktime', 'blendfunction', 'blink', 'c3f', 'c3i',
|
||||
'c3s', 'c4f', 'c4i', 'c4s', 'callobj', 'charstr', 'chunksize', 'circ',
|
||||
'circf', 'circfi', 'circfs', 'circi', 'circs', 'clear',
|
||||
'clearhitcode', 'clkoff', 'clkon', 'closeobj', 'cmode', 'cmov',
|
||||
'cmov2', 'cmov2i', 'cmov2s', 'cmovi', 'cmovs', 'color', 'colorf',
|
||||
'compactify', 'concave', 'cpack', 'crv', 'crvn', 'curorigin',
|
||||
'cursoff', 'curson', 'curstype', 'curvebasis', 'curveit',
|
||||
'curveprecision', 'cyclemap', 'czclear', 'defbasis', 'defcursor',
|
||||
'deflinestyle', 'delobj', 'deltag', 'depthcue', 'devport', 'dglclose',
|
||||
'dglopen', 'dither', 'dopup', 'doublebuffer', 'draw', 'draw2',
|
||||
'draw2i', 'draw2s', 'drawi', 'drawmode', 'draws', 'editobj',
|
||||
'endclosedline', 'endfullscrn', 'endline', 'endpick', 'endpoint',
|
||||
'endpolygon', 'endpupmode', 'endselect', 'endsurface', 'endtmesh',
|
||||
'endtrim', 'finish', 'font', 'foreground', 'freepup', 'frontbuffer',
|
||||
'fudge', 'fullscrn', 'gRGBcolor', 'gRGBmask', 'gammaramp', 'gbegin',
|
||||
'gconfig', 'genobj', 'gentag', 'getbackface', 'getbuffer',
|
||||
'getbutton', 'getcmmode', 'getcolor', 'getcpos', 'getcursor',
|
||||
'getdcm', 'getdepth', 'getdescender', 'getdisplaymode', 'getdrawmode',
|
||||
'getfont', 'getgdesc', 'getgpos', 'getheight', 'gethitcode',
|
||||
'getlsbackup', 'getlsrepeat', 'getlstyle', 'getlwidth', 'getmap',
|
||||
'getmatrix', 'getmcolor', 'getmmode', 'getmonitor',
|
||||
'getnurbsproperty', 'getopenobj', 'getorigin', 'getothermonitor',
|
||||
'getpattern', 'getplanes', 'getport', 'getresetls', 'getscrmask',
|
||||
'getshade', 'getsize', 'getsm', 'gettp', 'getvaluator', 'getvideo',
|
||||
'getviewport', 'getwritemask', 'getzbuffer', 'gewrite', 'gflush',
|
||||
'ginit', 'glcompat', 'greset', 'gselect', 'gsync', 'gversion',
|
||||
'iconsize', 'icontitle', 'imakebackground', 'initnames', 'ismex',
|
||||
'isobj', 'isqueued', 'istag', 'keepaspect', 'lRGBrange', 'lampoff',
|
||||
'lampon', 'linesmooth', 'linewidth', 'lmbind', 'lmcolor', 'lmdef',
|
||||
'loadmatrix', 'loadname', 'logicop', 'lookat', 'lrectread',
|
||||
'lrectwrite', 'lsbackup', 'lsetdepth', 'lshaderange', 'lsrepeat',
|
||||
'makeobj', 'maketag', 'mapcolor', 'mapw', 'mapw2', 'maxsize',
|
||||
'minsize', 'mmode', 'move', 'move2', 'move2i', 'move2s', 'movei',
|
||||
'moves', 'multimap', 'multmatrix', 'n3f', 'newpup', 'newtag',
|
||||
'noborder', 'noise', 'noport', 'normal', 'nurbscurve', 'nurbssurface',
|
||||
'nvarray', 'objdelete', 'objinsert', 'objreplace', 'onemap', 'ortho',
|
||||
'ortho2', 'overlay', 'packrect', 'pagecolor', 'pagewritemask',
|
||||
'passthrough', 'patch', 'patchbasis', 'patchcurves', 'patchprecision',
|
||||
'pclos', 'pdr', 'pdr2', 'pdr2i', 'pdr2s', 'pdri', 'pdrs',
|
||||
'perspective', 'pick', 'picksize', 'pixmode', 'pmv', 'pmv2', 'pmv2i',
|
||||
'pmv2s', 'pmvi', 'pmvs', 'pnt', 'pnt2', 'pnt2i', 'pnt2s', 'pnti',
|
||||
'pnts', 'pntsmooth', 'polarview', 'polf', 'polf2', 'polf2i', 'polf2s',
|
||||
'polfi', 'polfs', 'poly', 'poly2', 'poly2i', 'poly2s', 'polyi',
|
||||
'polys', 'popattributes', 'popmatrix', 'popname', 'popviewport',
|
||||
'prefposition', 'prefsize', 'pupmode', 'pushattributes', 'pushmatrix',
|
||||
'pushname', 'pushviewport', 'pwlcurve', 'qdevice', 'qenter', 'qgetfd',
|
||||
'qread', 'qreset', 'qtest', 'rcrv', 'rcrvn', 'rdr', 'rdr2', 'rdr2i',
|
||||
'rdr2s', 'rdri', 'rdrs', 'readdisplay', 'readsource', 'rect',
|
||||
'rectcopy', 'rectf', 'rectfi', 'rectfs', 'recti', 'rects', 'rectzoom',
|
||||
'resetls', 'reshapeviewport', 'ringbell', 'rmv', 'rmv2', 'rmv2i',
|
||||
'rmv2s', 'rmvi', 'rmvs', 'rot', 'rotate', 'rpatch', 'rpdr', 'rpdr2',
|
||||
'rpdr2i', 'rpdr2s', 'rpdri', 'rpdrs', 'rpmv', 'rpmv2', 'rpmv2i',
|
||||
'rpmv2s', 'rpmvi', 'rpmvs', 'sbox', 'sboxf', 'sboxfi', 'sboxfs',
|
||||
'sboxi', 'sboxs', 'scale', 'screenspace', 'scrmask', 'setbell',
|
||||
'setcursor', 'setdepth', 'setlinestyle', 'setmap', 'setmonitor',
|
||||
'setnurbsproperty', 'setpattern', 'setpup', 'setshade', 'setvaluator',
|
||||
'setvideo', 'shademodel', 'shaderange', 'singlebuffer', 'smoothline',
|
||||
'spclos', 'splf', 'splf2', 'splf2i', 'splf2s', 'splfi', 'splfs',
|
||||
'stepunit', 'strwidth', 'subpixel', 'swapbuffers', 'swapinterval',
|
||||
'swaptmesh', 'swinopen', 'textcolor', 'textinit', 'textport',
|
||||
'textwritemask', 'tie', 'tpoff', 'tpon', 'translate', 'underlay',
|
||||
'unpackrect', 'unqdevice', 'v2d', 'v2f', 'v2i', 'v2s', 'v3d', 'v3f',
|
||||
'v3i', 'v3s', 'v4d', 'v4f', 'v4i', 'v4s', 'varray', 'videocmd',
|
||||
'viewport', 'vnarray', 'winattach', 'winclose', 'winconstraints',
|
||||
'windepth', 'window', 'winget', 'winmove', 'winopen', 'winpop',
|
||||
'winposition', 'winpush', 'winset', 'wintitle', 'wmpack', 'writemask',
|
||||
'writepixels', 'xfpt', 'xfpt2', 'xfpt2i', 'xfpt2s', 'xfpt4', 'xfpt4i',
|
||||
'xfpt4s', 'xfpti', 'xfpts', 'zbuffer', 'zclear', 'zdraw', 'zfunction',
|
||||
'zsource', 'zwritemask']
|
||||
|
||||
def main():
|
||||
# insure that we at least have an X display before continuing.
|
||||
import os
|
||||
try:
|
||||
display = os.environ['DISPLAY']
|
||||
except:
|
||||
raise TestSkipped, "No $DISPLAY -- skipping gl test"
|
||||
|
||||
# touch all the attributes of gl without doing anything
|
||||
if verbose:
|
||||
print('Touching gl module attributes...')
|
||||
for attr in glattrs:
|
||||
if verbose:
|
||||
print('touching: ', attr)
|
||||
getattr(gl, attr)
|
||||
|
||||
# create a small 'Crisscross' window
|
||||
if verbose:
|
||||
print('Creating a small "CrissCross" window...')
|
||||
print('foreground')
|
||||
gl.foreground()
|
||||
if verbose:
|
||||
print('prefposition')
|
||||
gl.prefposition(500, 900, 500, 900)
|
||||
if verbose:
|
||||
print('winopen "CrissCross"')
|
||||
w = gl.winopen('CrissCross')
|
||||
if verbose:
|
||||
print('clear')
|
||||
gl.clear()
|
||||
if verbose:
|
||||
print('ortho2')
|
||||
gl.ortho2(0.0, 400.0, 0.0, 400.0)
|
||||
if verbose:
|
||||
print('color WHITE')
|
||||
gl.color(GL.WHITE)
|
||||
if verbose:
|
||||
print('color RED')
|
||||
gl.color(GL.RED)
|
||||
if verbose:
|
||||
print('bgnline')
|
||||
gl.bgnline()
|
||||
if verbose:
|
||||
print('v2f')
|
||||
gl.v2f(0.0, 0.0)
|
||||
gl.v2f(400.0, 400.0)
|
||||
if verbose:
|
||||
print('endline')
|
||||
gl.endline()
|
||||
if verbose:
|
||||
print('bgnline')
|
||||
gl.bgnline()
|
||||
if verbose:
|
||||
print('v2i')
|
||||
gl.v2i(400, 0)
|
||||
gl.v2i(0, 400)
|
||||
if verbose:
|
||||
print('endline')
|
||||
gl.endline()
|
||||
if verbose:
|
||||
print('Displaying window for 2 seconds...')
|
||||
time.sleep(2)
|
||||
if verbose:
|
||||
print('winclose')
|
||||
gl.winclose(w)
|
||||
|
||||
main()
|
|
@ -1,116 +0,0 @@
|
|||
#! /usr/bin/env python
|
||||
|
||||
"""Simple test script for imgfile.c
|
||||
Roger E. Masse
|
||||
"""
|
||||
|
||||
from test.test_support import verbose, unlink, findfile
|
||||
|
||||
import imgfile, uu, os
|
||||
|
||||
|
||||
def main():
|
||||
|
||||
uu.decode(findfile('testrgb.uue'), 'test.rgb')
|
||||
uu.decode(findfile('greyrgb.uue'), 'greytest.rgb')
|
||||
|
||||
# Test a 3 byte color image
|
||||
testimage('test.rgb')
|
||||
|
||||
# Test a 1 byte greyscale image
|
||||
testimage('greytest.rgb')
|
||||
|
||||
unlink('test.rgb')
|
||||
unlink('greytest.rgb')
|
||||
|
||||
def testimage(name):
|
||||
"""Run through the imgfile's battery of possible methods
|
||||
on the image passed in name.
|
||||
"""
|
||||
|
||||
import sys
|
||||
import os
|
||||
|
||||
outputfile = '/tmp/deleteme'
|
||||
|
||||
# try opening the name directly
|
||||
try:
|
||||
# This function returns a tuple (x, y, z) where x and y are the size
|
||||
# of the image in pixels and z is the number of bytes per pixel. Only
|
||||
# 3 byte RGB pixels and 1 byte greyscale pixels are supported.
|
||||
sizes = imgfile.getsizes(name)
|
||||
except imgfile.error:
|
||||
# get a more qualified path component of the script...
|
||||
if __name__ == '__main__':
|
||||
ourname = sys.argv[0]
|
||||
else: # ...or the full path of the module
|
||||
ourname = sys.modules[__name__].__file__
|
||||
|
||||
parts = ourname.split(os.sep)
|
||||
parts[-1] = name
|
||||
name = os.sep.join(parts)
|
||||
sizes = imgfile.getsizes(name)
|
||||
if verbose:
|
||||
print('Opening test image: %s, sizes: %s' % (name, str(sizes)))
|
||||
# This function reads and decodes the image on the specified file,
|
||||
# and returns it as a python string. The string has either 1 byte
|
||||
# greyscale pixels or 4 byte RGBA pixels. The bottom left pixel
|
||||
# is the first in the string. This format is suitable to pass
|
||||
# to gl.lrectwrite, for instance.
|
||||
image = imgfile.read(name)
|
||||
|
||||
# This function writes the RGB or greyscale data in data to
|
||||
# image file file. x and y give the size of the image, z is
|
||||
# 1 for 1 byte greyscale images or 3 for RGB images (which
|
||||
# are stored as 4 byte values of which only the lower three
|
||||
# bytes are used). These are the formats returned by gl.lrectread.
|
||||
if verbose:
|
||||
print('Writing output file')
|
||||
imgfile.write (outputfile, image, sizes[0], sizes[1], sizes[2])
|
||||
|
||||
|
||||
if verbose:
|
||||
print('Opening scaled test image: %s, sizes: %s' % (name, str(sizes)))
|
||||
# This function is identical to read but it returns an image that
|
||||
# is scaled to the given x and y sizes. If the filter and blur
|
||||
# parameters are omitted scaling is done by simply dropping
|
||||
# or duplicating pixels, so the result will be less than perfect,
|
||||
# especially for computer-generated images. Alternatively,
|
||||
# you can specify a filter to use to smoothen the image after
|
||||
# scaling. The filter forms supported are 'impulse', 'box',
|
||||
# 'triangle', 'quadratic' and 'gaussian'. If a filter is
|
||||
# specified blur is an optional parameter specifying the
|
||||
# blurriness of the filter. It defaults to 1.0. readscaled
|
||||
# makes no attempt to keep the aspect ratio correct, so that
|
||||
# is the users' responsibility.
|
||||
if verbose:
|
||||
print('Filtering with "impulse"')
|
||||
simage = imgfile.readscaled (name, sizes[0]/2, sizes[1]/2, 'impulse', 2.0)
|
||||
|
||||
# This function sets a global flag which defines whether the
|
||||
# scan lines of the image are read or written from bottom to
|
||||
# top (flag is zero, compatible with SGI GL) or from top to
|
||||
# bottom(flag is one, compatible with X). The default is zero.
|
||||
if verbose:
|
||||
print('Switching to X compatibility')
|
||||
imgfile.ttob (1)
|
||||
|
||||
if verbose:
|
||||
print('Filtering with "triangle"')
|
||||
simage = imgfile.readscaled (name, sizes[0]/2, sizes[1]/2, 'triangle', 3.0)
|
||||
if verbose:
|
||||
print('Switching back to SGI compatibility')
|
||||
imgfile.ttob (0)
|
||||
|
||||
if verbose: print('Filtering with "quadratic"')
|
||||
simage = imgfile.readscaled (name, sizes[0]/2, sizes[1]/2, 'quadratic')
|
||||
if verbose: print('Filtering with "gaussian"')
|
||||
simage = imgfile.readscaled (name, sizes[0]/2, sizes[1]/2, 'gaussian', 1.0)
|
||||
|
||||
if verbose:
|
||||
print('Writing output file')
|
||||
imgfile.write (outputfile, simage, sizes[0]/2, sizes[1]/2, sizes[2])
|
||||
|
||||
os.unlink(outputfile)
|
||||
|
||||
main()
|
|
@ -435,7 +435,7 @@ def test_main(verbose=None):
|
|||
import gc
|
||||
counts = [None] * 5
|
||||
for i in range(len(counts)):
|
||||
test_support.run_doctest(test_genexps, verbose)
|
||||
test_support.run_doctest(test_listcomps, verbose)
|
||||
gc.collect()
|
||||
counts[i] = sys.gettotalrefcount()
|
||||
print(counts)
|
||||
|
|
|
@ -436,15 +436,15 @@ __test__ = {'doctests' : doctests}
|
|||
def test_main(verbose=None):
|
||||
import sys
|
||||
from test import test_support
|
||||
from test import test_listcomps
|
||||
test_support.run_doctest(test_listcomps, verbose)
|
||||
from test import test_setcomps
|
||||
test_support.run_doctest(test_setcomps, verbose)
|
||||
|
||||
# verify reference counting
|
||||
if verbose and hasattr(sys, "gettotalrefcount"):
|
||||
import gc
|
||||
counts = [None] * 5
|
||||
for i in range(len(counts)):
|
||||
test_support.run_doctest(test_genexps, verbose)
|
||||
test_support.run_doctest(test_setcomps, verbose)
|
||||
gc.collect()
|
||||
counts[i] = sys.gettotalrefcount()
|
||||
print(counts)
|
||||
|
|
|
@ -0,0 +1,157 @@
|
|||
# Tests for extended unpacking, starred expressions.
|
||||
|
||||
doctests = """
|
||||
|
||||
Unpack tuple
|
||||
|
||||
>>> t = (1, 2, 3)
|
||||
>>> a, *b, c = t
|
||||
>>> a == 1 and b == [2] and c == 3
|
||||
True
|
||||
|
||||
Unpack list
|
||||
|
||||
>>> l = [4, 5, 6]
|
||||
>>> a, *b = l
|
||||
>>> a == 4 and b == [5, 6]
|
||||
True
|
||||
|
||||
Unpack implied tuple
|
||||
|
||||
>>> *a, = 7, 8, 9
|
||||
>>> a == [7, 8, 9]
|
||||
True
|
||||
|
||||
Unpack string... fun!
|
||||
|
||||
>>> a, *b = 'one'
|
||||
>>> a == 'o' and b == ['n', 'e']
|
||||
True
|
||||
|
||||
Unpack long sequence
|
||||
|
||||
>>> a, b, c, *d, e, f, g = range(10)
|
||||
>>> (a, b, c, d, e, f, g) == (0, 1, 2, [3, 4, 5, 6], 7, 8, 9)
|
||||
True
|
||||
|
||||
Unpack short sequence
|
||||
|
||||
>>> a, *b, c = (1, 2)
|
||||
>>> a == 1 and c == 2 and b == []
|
||||
True
|
||||
|
||||
Unpack generic sequence
|
||||
|
||||
>>> class Seq:
|
||||
... def __getitem__(self, i):
|
||||
... if i >= 0 and i < 3: return i
|
||||
... raise IndexError
|
||||
...
|
||||
>>> a, *b = Seq()
|
||||
>>> a == 0 and b == [1, 2]
|
||||
True
|
||||
|
||||
Unpack in for statement
|
||||
|
||||
>>> for a, *b, c in [(1,2,3), (4,5,6,7)]:
|
||||
... print(a, b, c)
|
||||
...
|
||||
1 [2] 3
|
||||
4 [5, 6] 7
|
||||
|
||||
Unpack in list
|
||||
|
||||
>>> [a, *b, c] = range(5)
|
||||
>>> a == 0 and b == [1, 2, 3] and c == 4
|
||||
True
|
||||
|
||||
Multiple targets
|
||||
|
||||
>>> a, *b, c = *d, e = range(5)
|
||||
>>> a == 0 and b == [1, 2, 3] and c == 4 and d == [0, 1, 2, 3] and e == 4
|
||||
True
|
||||
|
||||
Now for some failures
|
||||
|
||||
Unpacking non-sequence
|
||||
|
||||
>>> a, *b = 7
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
TypeError: 'int' object is not iterable
|
||||
|
||||
Unpacking sequence too short
|
||||
|
||||
>>> a, *b, c, d, e = Seq()
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
ValueError: need more than 3 values to unpack
|
||||
|
||||
Unpacking a sequence where the test for too long raises a different kind of
|
||||
error
|
||||
|
||||
>>> class BozoError(Exception):
|
||||
... pass
|
||||
...
|
||||
>>> class BadSeq:
|
||||
... def __getitem__(self, i):
|
||||
... if i >= 0 and i < 3:
|
||||
... return i
|
||||
... elif i == 3:
|
||||
... raise BozoError
|
||||
... else:
|
||||
... raise IndexError
|
||||
...
|
||||
|
||||
Trigger code while not expecting an IndexError (unpack sequence too long, wrong
|
||||
error)
|
||||
|
||||
>>> a, *b, c, d, e = BadSeq()
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
test.test_unpack_ex.BozoError
|
||||
|
||||
Now some general starred expressions (all fail).
|
||||
|
||||
>>> a, *b, c, *d, e = range(10) # doctest:+ELLIPSIS
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
SyntaxError: two starred expressions in assignment (...)
|
||||
|
||||
>>> [*b, *c] = range(10) # doctest:+ELLIPSIS
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
SyntaxError: two starred expressions in assignment (...)
|
||||
|
||||
>>> *a = range(10) # doctest:+ELLIPSIS
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
SyntaxError: starred assignment target must be in a list or tuple (...)
|
||||
|
||||
>>> *a # doctest:+ELLIPSIS
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
SyntaxError: can use starred expression only as assignment target (...)
|
||||
|
||||
>>> *1 # doctest:+ELLIPSIS
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
SyntaxError: can use starred expression only as assignment target (...)
|
||||
|
||||
>>> x = *a # doctest:+ELLIPSIS
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
SyntaxError: can use starred expression only as assignment target (...)
|
||||
|
||||
"""
|
||||
|
||||
__test__ = {'doctests' : doctests}
|
||||
|
||||
def test_main(verbose=False):
|
||||
import sys
|
||||
from test import test_support
|
||||
from test import test_unpack_ex
|
||||
test_support.run_doctest(test_unpack_ex, verbose)
|
||||
|
||||
if __name__ == "__main__":
|
||||
test_main(verbose=True)
|
|
@ -26,6 +26,9 @@ TO DO
|
|||
Core and Builtins
|
||||
-----------------
|
||||
|
||||
- PEP 3132 was accepted. That means that you can do ``a, *b = range(5)``
|
||||
to assign 0 to a and [1, 2, 3, 4] to b.
|
||||
|
||||
- range() now returns an iterator rather than a list. Floats are not allowed.
|
||||
xrange() is no longer defined.
|
||||
|
||||
|
@ -172,6 +175,12 @@ Extension Modules
|
|||
Library
|
||||
-------
|
||||
|
||||
- Remove obsolete IRIX modules: al, cd, cl, fl, fm, gl, imgfile, sgi, sv.
|
||||
|
||||
- Remove bsddb185 module it was obsolete.
|
||||
|
||||
- Remove commands.getstatus() it was obsolete.
|
||||
|
||||
- Remove functions in string and strop modules that are also string methods.
|
||||
|
||||
- Remove obsolete modules: xmllib, stringold.
|
||||
|
|
|
@ -133,11 +133,6 @@ zipimport zipimport.c
|
|||
# The Python symtable module depends on .h files that setup.py doesn't track
|
||||
_symtable symtablemodule.c
|
||||
|
||||
# The SGI specific GL module:
|
||||
|
||||
GLHACK=-Dclear=__GLclear
|
||||
#gl glmodule.c cgensupport.c -I$(srcdir) $(GLHACK) -lgl -lX11
|
||||
|
||||
# Pure module. Cannot be linked dynamically.
|
||||
# -DWITH_QUANTIFY, -DWITH_PURIFY, or -DWITH_ALL_PURE
|
||||
#WHICH_PURE_PRODUCTS=-DWITH_ALL_PURE
|
||||
|
@ -250,42 +245,6 @@ GLHACK=-Dclear=__GLclear
|
|||
#_sha shamodule.c
|
||||
|
||||
|
||||
# SGI IRIX specific modules -- off by default.
|
||||
|
||||
# These module work on any SGI machine:
|
||||
|
||||
# *** gl must be enabled higher up in this file ***
|
||||
#fm fmmodule.c $(GLHACK) -lfm -lgl # Font Manager
|
||||
#sgi sgimodule.c # sgi.nap() and a few more
|
||||
|
||||
# This module requires the header file
|
||||
# /usr/people/4Dgifts/iristools/include/izoom.h:
|
||||
#imgfile imgfile.c -limage -lgutil -lgl -lm # Image Processing Utilities
|
||||
|
||||
|
||||
# These modules require the Multimedia Development Option (I think):
|
||||
|
||||
#al almodule.c -laudio # Audio Library
|
||||
#cd cdmodule.c -lcdaudio -lds -lmediad # CD Audio Library
|
||||
#cl clmodule.c -lcl -lawareaudio # Compression Library
|
||||
#sv svmodule.c yuvconvert.c -lsvideo -lXext -lX11 # Starter Video
|
||||
|
||||
|
||||
# The FORMS library, by Mark Overmars, implements user interface
|
||||
# components such as dialogs and buttons using SGI's GL and FM
|
||||
# libraries. You must ftp the FORMS library separately from
|
||||
# ftp://ftp.cs.ruu.nl/pub/SGI/FORMS. It was tested with FORMS 2.2a.
|
||||
# NOTE: if you want to be able to use FORMS and curses simultaneously
|
||||
# (or both link them statically into the same binary), you must
|
||||
# compile all of FORMS with the cc option "-Dclear=__GLclear".
|
||||
|
||||
# The FORMS variable must point to the FORMS subdirectory of the forms
|
||||
# toplevel directory:
|
||||
|
||||
#FORMS=/ufs/guido/src/forms/FORMS
|
||||
#fl flmodule.c -I$(FORMS) $(GLHACK) $(FORMS)/libforms.a -lfm -lgl
|
||||
|
||||
|
||||
# SunOS specific modules -- off by default:
|
||||
|
||||
#sunaudiodev sunaudiodev.c
|
||||
|
@ -409,17 +368,6 @@ GLHACK=-Dclear=__GLclear
|
|||
#DBLIB=$(DB)/lib
|
||||
#_bsddb _bsddb.c -I$(DBINC) -L$(DBLIB) -ldb-$(DBLIBVER)
|
||||
|
||||
# Historical Berkeley DB 1.85
|
||||
#
|
||||
# This module is deprecated; the 1.85 version of the Berkeley DB library has
|
||||
# bugs that can cause data corruption. If you can, use later versions of the
|
||||
# library instead, available from <http://www.sleepycat.com/>.
|
||||
|
||||
#DB=/depot/sundry/src/berkeley-db/db.1.85
|
||||
#DBPORT=$(DB)/PORT/irix.5.3
|
||||
#bsddb185 bsddbmodule.c -I$(DBPORT)/include -I$(DBPORT) $(DBPORT)/libdb.a
|
||||
|
||||
|
||||
|
||||
# Helper module for various ascii-encoders
|
||||
#binascii binascii.c
|
||||
|
|
3226
Modules/almodule.c
3226
Modules/almodule.c
File diff suppressed because it is too large
Load Diff
|
@ -1,858 +0,0 @@
|
|||
/* Berkeley DB interface.
|
||||
Author: Michael McLay
|
||||
Hacked: Guido van Rossum
|
||||
Btree and Recno additions plus sequence methods: David Ely
|
||||
Hacked by Gustavo Niemeyer <niemeyer@conectiva.com> fixing recno
|
||||
support.
|
||||
|
||||
XXX To do:
|
||||
- provide a way to access the various hash functions
|
||||
- support more open flags
|
||||
|
||||
The windows port of the Berkeley DB code is hard to find on the web:
|
||||
www.nightmare.com/software.html
|
||||
*/
|
||||
|
||||
#include "Python.h"
|
||||
#ifdef WITH_THREAD
|
||||
#include "pythread.h"
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#ifdef HAVE_DB_185_H
|
||||
#include <db_185.h>
|
||||
#else
|
||||
#include <db.h>
|
||||
#endif
|
||||
/* Please don't include internal header files of the Berkeley db package
|
||||
(it messes up the info required in the Setup file) */
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
DB *di_bsddb;
|
||||
int di_size; /* -1 means recompute */
|
||||
int di_type;
|
||||
#ifdef WITH_THREAD
|
||||
PyThread_type_lock di_lock;
|
||||
#endif
|
||||
} bsddbobject;
|
||||
|
||||
static PyTypeObject Bsddbtype;
|
||||
|
||||
#define is_bsddbobject(v) ((v)->ob_type == &Bsddbtype)
|
||||
#define check_bsddbobject_open(v, r) if ((v)->di_bsddb == NULL) \
|
||||
{ PyErr_SetString(BsddbError, \
|
||||
"BSDDB object has already been closed"); \
|
||||
return r; }
|
||||
|
||||
static PyObject *BsddbError;
|
||||
|
||||
static PyObject *
|
||||
newdbhashobject(char *file, int flags, int mode,
|
||||
int bsize, int ffactor, int nelem, int cachesize,
|
||||
int hash, int lorder)
|
||||
{
|
||||
bsddbobject *dp;
|
||||
HASHINFO info;
|
||||
|
||||
if ((dp = PyObject_New(bsddbobject, &Bsddbtype)) == NULL)
|
||||
return NULL;
|
||||
|
||||
info.bsize = bsize;
|
||||
info.ffactor = ffactor;
|
||||
info.nelem = nelem;
|
||||
info.cachesize = cachesize;
|
||||
info.hash = NULL; /* XXX should derive from hash argument */
|
||||
info.lorder = lorder;
|
||||
|
||||
#ifdef O_BINARY
|
||||
flags |= O_BINARY;
|
||||
#endif
|
||||
Py_BEGIN_ALLOW_THREADS
|
||||
dp->di_bsddb = dbopen(file, flags, mode, DB_HASH, &info);
|
||||
Py_END_ALLOW_THREADS
|
||||
if (dp->di_bsddb == NULL) {
|
||||
PyErr_SetFromErrno(BsddbError);
|
||||
#ifdef WITH_THREAD
|
||||
dp->di_lock = NULL;
|
||||
#endif
|
||||
Py_DECREF(dp);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
dp->di_size = -1;
|
||||
dp->di_type = DB_HASH;
|
||||
|
||||
#ifdef WITH_THREAD
|
||||
dp->di_lock = PyThread_allocate_lock();
|
||||
if (dp->di_lock == NULL) {
|
||||
PyErr_SetString(BsddbError, "can't allocate lock");
|
||||
Py_DECREF(dp);
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
return (PyObject *)dp;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
newdbbtobject(char *file, int flags, int mode,
|
||||
int btflags, int cachesize, int maxkeypage,
|
||||
int minkeypage, int psize, int lorder)
|
||||
{
|
||||
bsddbobject *dp;
|
||||
BTREEINFO info;
|
||||
|
||||
if ((dp = PyObject_New(bsddbobject, &Bsddbtype)) == NULL)
|
||||
return NULL;
|
||||
|
||||
info.flags = btflags;
|
||||
info.cachesize = cachesize;
|
||||
info.maxkeypage = maxkeypage;
|
||||
info.minkeypage = minkeypage;
|
||||
info.psize = psize;
|
||||
info.lorder = lorder;
|
||||
info.compare = 0; /* Use default comparison functions, for now..*/
|
||||
info.prefix = 0;
|
||||
|
||||
#ifdef O_BINARY
|
||||
flags |= O_BINARY;
|
||||
#endif
|
||||
Py_BEGIN_ALLOW_THREADS
|
||||
dp->di_bsddb = dbopen(file, flags, mode, DB_BTREE, &info);
|
||||
Py_END_ALLOW_THREADS
|
||||
if (dp->di_bsddb == NULL) {
|
||||
PyErr_SetFromErrno(BsddbError);
|
||||
#ifdef WITH_THREAD
|
||||
dp->di_lock = NULL;
|
||||
#endif
|
||||
Py_DECREF(dp);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
dp->di_size = -1;
|
||||
dp->di_type = DB_BTREE;
|
||||
|
||||
#ifdef WITH_THREAD
|
||||
dp->di_lock = PyThread_allocate_lock();
|
||||
if (dp->di_lock == NULL) {
|
||||
PyErr_SetString(BsddbError, "can't allocate lock");
|
||||
Py_DECREF(dp);
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
return (PyObject *)dp;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
newdbrnobject(char *file, int flags, int mode,
|
||||
int rnflags, int cachesize, int psize, int lorder,
|
||||
size_t reclen, u_char bval, char *bfname)
|
||||
{
|
||||
bsddbobject *dp;
|
||||
RECNOINFO info;
|
||||
int fd;
|
||||
|
||||
if ((dp = PyObject_New(bsddbobject, &Bsddbtype)) == NULL)
|
||||
return NULL;
|
||||
|
||||
info.flags = rnflags;
|
||||
info.cachesize = cachesize;
|
||||
info.psize = psize;
|
||||
info.lorder = lorder;
|
||||
info.reclen = reclen;
|
||||
info.bval = bval;
|
||||
info.bfname = bfname;
|
||||
|
||||
#ifdef O_BINARY
|
||||
flags |= O_BINARY;
|
||||
#endif
|
||||
/* This is a hack to avoid a dbopen() bug that happens when
|
||||
* it fails. */
|
||||
fd = open(file, flags);
|
||||
if (fd == -1) {
|
||||
dp->di_bsddb = NULL;
|
||||
}
|
||||
else {
|
||||
close(fd);
|
||||
Py_BEGIN_ALLOW_THREADS
|
||||
dp->di_bsddb = dbopen(file, flags, mode, DB_RECNO, &info);
|
||||
Py_END_ALLOW_THREADS
|
||||
}
|
||||
if (dp->di_bsddb == NULL) {
|
||||
PyErr_SetFromErrno(BsddbError);
|
||||
#ifdef WITH_THREAD
|
||||
dp->di_lock = NULL;
|
||||
#endif
|
||||
Py_DECREF(dp);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
dp->di_size = -1;
|
||||
dp->di_type = DB_RECNO;
|
||||
|
||||
#ifdef WITH_THREAD
|
||||
dp->di_lock = PyThread_allocate_lock();
|
||||
if (dp->di_lock == NULL) {
|
||||
PyErr_SetString(BsddbError, "can't allocate lock");
|
||||
Py_DECREF(dp);
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
return (PyObject *)dp;
|
||||
}
|
||||
|
||||
static void
|
||||
bsddb_dealloc(bsddbobject *dp)
|
||||
{
|
||||
#ifdef WITH_THREAD
|
||||
if (dp->di_lock) {
|
||||
PyThread_acquire_lock(dp->di_lock, 0);
|
||||
PyThread_release_lock(dp->di_lock);
|
||||
PyThread_free_lock(dp->di_lock);
|
||||
dp->di_lock = NULL;
|
||||
}
|
||||
#endif
|
||||
if (dp->di_bsddb != NULL) {
|
||||
int status;
|
||||
Py_BEGIN_ALLOW_THREADS
|
||||
status = (dp->di_bsddb->close)(dp->di_bsddb);
|
||||
Py_END_ALLOW_THREADS
|
||||
if (status != 0)
|
||||
fprintf(stderr,
|
||||
"Python bsddb: close errno %d in dealloc\n",
|
||||
errno);
|
||||
}
|
||||
PyObject_Del(dp);
|
||||
}
|
||||
|
||||
#ifdef WITH_THREAD
|
||||
#define BSDDB_BGN_SAVE(_dp) \
|
||||
Py_BEGIN_ALLOW_THREADS PyThread_acquire_lock(_dp->di_lock,1);
|
||||
#define BSDDB_END_SAVE(_dp) \
|
||||
PyThread_release_lock(_dp->di_lock); Py_END_ALLOW_THREADS
|
||||
#else
|
||||
#define BSDDB_BGN_SAVE(_dp) Py_BEGIN_ALLOW_THREADS
|
||||
#define BSDDB_END_SAVE(_dp) Py_END_ALLOW_THREADS
|
||||
#endif
|
||||
|
||||
static Py_ssize_t
|
||||
bsddb_length(bsddbobject *dp)
|
||||
{
|
||||
check_bsddbobject_open(dp, -1);
|
||||
if (dp->di_size < 0) {
|
||||
DBT krec, drec;
|
||||
int status;
|
||||
int size = 0;
|
||||
BSDDB_BGN_SAVE(dp)
|
||||
for (status = (dp->di_bsddb->seq)(dp->di_bsddb,
|
||||
&krec, &drec,R_FIRST);
|
||||
status == 0;
|
||||
status = (dp->di_bsddb->seq)(dp->di_bsddb,
|
||||
&krec, &drec, R_NEXT))
|
||||
size++;
|
||||
BSDDB_END_SAVE(dp)
|
||||
if (status < 0) {
|
||||
PyErr_SetFromErrno(BsddbError);
|
||||
return -1;
|
||||
}
|
||||
dp->di_size = size;
|
||||
}
|
||||
return dp->di_size;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
bsddb_subscript(bsddbobject *dp, PyObject *key)
|
||||
{
|
||||
int status;
|
||||
DBT krec, drec;
|
||||
char *data,buf[4096];
|
||||
int size;
|
||||
PyObject *result;
|
||||
recno_t recno;
|
||||
|
||||
if (dp->di_type == DB_RECNO) {
|
||||
if (!PyArg_Parse(key, "i", &recno)) {
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
"key type must be integer");
|
||||
return NULL;
|
||||
}
|
||||
krec.data = &recno;
|
||||
krec.size = sizeof(recno);
|
||||
}
|
||||
else {
|
||||
if (!PyArg_Parse(key, "s#", &data, &size)) {
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
"key type must be string");
|
||||
return NULL;
|
||||
}
|
||||
krec.data = data;
|
||||
krec.size = size;
|
||||
}
|
||||
check_bsddbobject_open(dp, NULL);
|
||||
|
||||
BSDDB_BGN_SAVE(dp)
|
||||
status = (dp->di_bsddb->get)(dp->di_bsddb, &krec, &drec, 0);
|
||||
if (status == 0) {
|
||||
if (drec.size > sizeof(buf)) data = malloc(drec.size);
|
||||
else data = buf;
|
||||
if (data!=NULL) memcpy(data,drec.data,drec.size);
|
||||
}
|
||||
BSDDB_END_SAVE(dp)
|
||||
if (data==NULL) return PyErr_NoMemory();
|
||||
if (status != 0) {
|
||||
if (status < 0)
|
||||
PyErr_SetFromErrno(BsddbError);
|
||||
else
|
||||
PyErr_SetObject(PyExc_KeyError, key);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
result = PyString_FromStringAndSize(data, (int)drec.size);
|
||||
if (data != buf) free(data);
|
||||
return result;
|
||||
}
|
||||
|
||||
static int
|
||||
bsddb_ass_sub(bsddbobject *dp, PyObject *key, PyObject *value)
|
||||
{
|
||||
int status;
|
||||
DBT krec, drec;
|
||||
char *data;
|
||||
int size;
|
||||
recno_t recno;
|
||||
|
||||
if (dp->di_type == DB_RECNO) {
|
||||
if (!PyArg_Parse(key, "i", &recno)) {
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
"bsddb key type must be integer");
|
||||
return -1;
|
||||
}
|
||||
krec.data = &recno;
|
||||
krec.size = sizeof(recno);
|
||||
}
|
||||
else {
|
||||
if (!PyArg_Parse(key, "s#", &data, &size)) {
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
"bsddb key type must be string");
|
||||
return -1;
|
||||
}
|
||||
krec.data = data;
|
||||
krec.size = size;
|
||||
}
|
||||
check_bsddbobject_open(dp, -1);
|
||||
dp->di_size = -1;
|
||||
if (value == NULL) {
|
||||
BSDDB_BGN_SAVE(dp)
|
||||
status = (dp->di_bsddb->del)(dp->di_bsddb, &krec, 0);
|
||||
BSDDB_END_SAVE(dp)
|
||||
}
|
||||
else {
|
||||
if (!PyArg_Parse(value, "s#", &data, &size)) {
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
"bsddb value type must be string");
|
||||
return -1;
|
||||
}
|
||||
drec.data = data;
|
||||
drec.size = size;
|
||||
BSDDB_BGN_SAVE(dp)
|
||||
status = (dp->di_bsddb->put)(dp->di_bsddb, &krec, &drec, 0);
|
||||
BSDDB_END_SAVE(dp)
|
||||
}
|
||||
if (status != 0) {
|
||||
if (status < 0)
|
||||
PyErr_SetFromErrno(BsddbError);
|
||||
else
|
||||
PyErr_SetObject(PyExc_KeyError, key);
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static PyMappingMethods bsddb_as_mapping = {
|
||||
(lenfunc)bsddb_length, /*mp_length*/
|
||||
(binaryfunc)bsddb_subscript, /*mp_subscript*/
|
||||
(objobjargproc)bsddb_ass_sub, /*mp_ass_subscript*/
|
||||
};
|
||||
|
||||
static PyObject *
|
||||
bsddb_close(bsddbobject *dp)
|
||||
{
|
||||
if (dp->di_bsddb != NULL) {
|
||||
int status;
|
||||
BSDDB_BGN_SAVE(dp)
|
||||
status = (dp->di_bsddb->close)(dp->di_bsddb);
|
||||
BSDDB_END_SAVE(dp)
|
||||
if (status != 0) {
|
||||
dp->di_bsddb = NULL;
|
||||
PyErr_SetFromErrno(BsddbError);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
dp->di_bsddb = NULL;
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
bsddb_keys(bsddbobject *dp)
|
||||
{
|
||||
PyObject *list, *item=NULL;
|
||||
DBT krec, drec;
|
||||
char *data=NULL,buf[4096];
|
||||
int status;
|
||||
int err;
|
||||
|
||||
check_bsddbobject_open(dp, NULL);
|
||||
list = PyList_New(0);
|
||||
if (list == NULL)
|
||||
return NULL;
|
||||
BSDDB_BGN_SAVE(dp)
|
||||
status = (dp->di_bsddb->seq)(dp->di_bsddb, &krec, &drec, R_FIRST);
|
||||
if (status == 0) {
|
||||
if (krec.size > sizeof(buf)) data = malloc(krec.size);
|
||||
else data = buf;
|
||||
if (data != NULL) memcpy(data,krec.data,krec.size);
|
||||
}
|
||||
BSDDB_END_SAVE(dp)
|
||||
if (status == 0 && data==NULL) return PyErr_NoMemory();
|
||||
while (status == 0) {
|
||||
if (dp->di_type == DB_RECNO)
|
||||
item = PyInt_FromLong(*((int*)data));
|
||||
else
|
||||
item = PyString_FromStringAndSize(data,
|
||||
(int)krec.size);
|
||||
if (data != buf) free(data);
|
||||
if (item == NULL) {
|
||||
Py_DECREF(list);
|
||||
return NULL;
|
||||
}
|
||||
err = PyList_Append(list, item);
|
||||
Py_DECREF(item);
|
||||
if (err != 0) {
|
||||
Py_DECREF(list);
|
||||
return NULL;
|
||||
}
|
||||
BSDDB_BGN_SAVE(dp)
|
||||
status = (dp->di_bsddb->seq)
|
||||
(dp->di_bsddb, &krec, &drec, R_NEXT);
|
||||
if (status == 0) {
|
||||
if (krec.size > sizeof(buf))
|
||||
data = malloc(krec.size);
|
||||
else data = buf;
|
||||
if (data != NULL)
|
||||
memcpy(data,krec.data,krec.size);
|
||||
}
|
||||
BSDDB_END_SAVE(dp)
|
||||
if (data == NULL) return PyErr_NoMemory();
|
||||
}
|
||||
if (status < 0) {
|
||||
PyErr_SetFromErrno(BsddbError);
|
||||
Py_DECREF(list);
|
||||
return NULL;
|
||||
}
|
||||
if (dp->di_size < 0)
|
||||
dp->di_size = PyList_Size(list); /* We just did the work */
|
||||
return list;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
bsddb_contains(bsddbobject *dp, PyObject *args)
|
||||
{
|
||||
DBT krec, drec;
|
||||
int status;
|
||||
char *data;
|
||||
int size;
|
||||
recno_t recno;
|
||||
|
||||
if (dp->di_type == DB_RECNO) {
|
||||
if (!PyArg_ParseTuple(args, "i;key type must be integer",
|
||||
&recno)) {
|
||||
return NULL;
|
||||
}
|
||||
krec.data = &recno;
|
||||
krec.size = sizeof(recno);
|
||||
}
|
||||
else {
|
||||
if (!PyArg_ParseTuple(args, "s#;key type must be string",
|
||||
&data, &size)) {
|
||||
return NULL;
|
||||
}
|
||||
krec.data = data;
|
||||
krec.size = size;
|
||||
}
|
||||
check_bsddbobject_open(dp, NULL);
|
||||
|
||||
BSDDB_BGN_SAVE(dp)
|
||||
status = (dp->di_bsddb->get)(dp->di_bsddb, &krec, &drec, 0);
|
||||
BSDDB_END_SAVE(dp)
|
||||
if (status < 0) {
|
||||
PyErr_SetFromErrno(BsddbError);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return PyInt_FromLong(status == 0);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
bsddb_set_location(bsddbobject *dp, PyObject *key)
|
||||
{
|
||||
int status;
|
||||
DBT krec, drec;
|
||||
char *data,buf[4096];
|
||||
int size;
|
||||
PyObject *result;
|
||||
recno_t recno;
|
||||
|
||||
if (dp->di_type == DB_RECNO) {
|
||||
if (!PyArg_ParseTuple(key, "i;key type must be integer",
|
||||
&recno)) {
|
||||
return NULL;
|
||||
}
|
||||
krec.data = &recno;
|
||||
krec.size = sizeof(recno);
|
||||
}
|
||||
else {
|
||||
if (!PyArg_ParseTuple(key, "s#;key type must be string",
|
||||
&data, &size)) {
|
||||
return NULL;
|
||||
}
|
||||
krec.data = data;
|
||||
krec.size = size;
|
||||
}
|
||||
check_bsddbobject_open(dp, NULL);
|
||||
|
||||
BSDDB_BGN_SAVE(dp)
|
||||
status = (dp->di_bsddb->seq)(dp->di_bsddb, &krec, &drec, R_CURSOR);
|
||||
if (status == 0) {
|
||||
if (drec.size > sizeof(buf)) data = malloc(drec.size);
|
||||
else data = buf;
|
||||
if (data!=NULL) memcpy(data,drec.data,drec.size);
|
||||
}
|
||||
BSDDB_END_SAVE(dp)
|
||||
if (data==NULL) return PyErr_NoMemory();
|
||||
if (status != 0) {
|
||||
if (status < 0)
|
||||
PyErr_SetFromErrno(BsddbError);
|
||||
else
|
||||
PyErr_SetObject(PyExc_KeyError, key);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (dp->di_type == DB_RECNO)
|
||||
result = Py_BuildValue("is#", *((int*)krec.data),
|
||||
data, drec.size);
|
||||
else
|
||||
result = Py_BuildValue("s#s#", krec.data, krec.size,
|
||||
data, drec.size);
|
||||
if (data != buf) free(data);
|
||||
return result;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
bsddb_seq(bsddbobject *dp, int sequence_request)
|
||||
{
|
||||
int status;
|
||||
DBT krec, drec;
|
||||
char *kdata=NULL,kbuf[4096];
|
||||
char *ddata=NULL,dbuf[4096];
|
||||
PyObject *result;
|
||||
|
||||
check_bsddbobject_open(dp, NULL);
|
||||
krec.data = 0;
|
||||
krec.size = 0;
|
||||
|
||||
BSDDB_BGN_SAVE(dp)
|
||||
status = (dp->di_bsddb->seq)(dp->di_bsddb, &krec,
|
||||
&drec, sequence_request);
|
||||
if (status == 0) {
|
||||
if (krec.size > sizeof(kbuf)) kdata = malloc(krec.size);
|
||||
else kdata = kbuf;
|
||||
if (kdata != NULL) memcpy(kdata,krec.data,krec.size);
|
||||
if (drec.size > sizeof(dbuf)) ddata = malloc(drec.size);
|
||||
else ddata = dbuf;
|
||||
if (ddata != NULL) memcpy(ddata,drec.data,drec.size);
|
||||
}
|
||||
BSDDB_END_SAVE(dp)
|
||||
if (status == 0) {
|
||||
if ((kdata == NULL) || (ddata == NULL))
|
||||
return PyErr_NoMemory();
|
||||
}
|
||||
else {
|
||||
/* (status != 0) */
|
||||
if (status < 0)
|
||||
PyErr_SetFromErrno(BsddbError);
|
||||
else
|
||||
PyErr_SetString(PyExc_KeyError, "no key/data pairs");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (dp->di_type == DB_RECNO)
|
||||
result = Py_BuildValue("is#", *((int*)kdata),
|
||||
ddata, drec.size);
|
||||
else
|
||||
result = Py_BuildValue("s#s#", kdata, krec.size,
|
||||
ddata, drec.size);
|
||||
if (kdata != kbuf) free(kdata);
|
||||
if (ddata != dbuf) free(ddata);
|
||||
return result;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
bsddb_next(bsddbobject *dp)
|
||||
{
|
||||
return bsddb_seq(dp, R_NEXT);
|
||||
}
|
||||
static PyObject *
|
||||
bsddb_previous(bsddbobject *dp)
|
||||
{
|
||||
return bsddb_seq(dp, R_PREV);
|
||||
}
|
||||
static PyObject *
|
||||
bsddb_first(bsddbobject *dp)
|
||||
{
|
||||
return bsddb_seq(dp, R_FIRST);
|
||||
}
|
||||
static PyObject *
|
||||
bsddb_last(bsddbobject *dp)
|
||||
{
|
||||
return bsddb_seq(dp, R_LAST);
|
||||
}
|
||||
static PyObject *
|
||||
bsddb_sync(bsddbobject *dp)
|
||||
{
|
||||
int status;
|
||||
|
||||
check_bsddbobject_open(dp, NULL);
|
||||
BSDDB_BGN_SAVE(dp)
|
||||
status = (dp->di_bsddb->sync)(dp->di_bsddb, 0);
|
||||
BSDDB_END_SAVE(dp)
|
||||
if (status != 0) {
|
||||
PyErr_SetFromErrno(BsddbError);
|
||||
return NULL;
|
||||
}
|
||||
return PyInt_FromLong(status = 0);
|
||||
}
|
||||
static PyMethodDef bsddb_methods[] = {
|
||||
{"close", (PyCFunction)bsddb_close, METH_NOARGS},
|
||||
{"keys", (PyCFunction)bsddb_keys, METH_NOARGS},
|
||||
{"__contains__", (PyCFunction)bsddb_contains, METH_VARARGS},
|
||||
{"set_location", (PyCFunction)bsddb_set_location, METH_VARARGS},
|
||||
{"next", (PyCFunction)bsddb_next, METH_NOARGS},
|
||||
{"previous", (PyCFunction)bsddb_previous, METH_NOARGS},
|
||||
{"first", (PyCFunction)bsddb_first, METH_NOARGS},
|
||||
{"last", (PyCFunction)bsddb_last, METH_NOARGS},
|
||||
{"sync", (PyCFunction)bsddb_sync, METH_NOARGS},
|
||||
{NULL, NULL} /* sentinel */
|
||||
};
|
||||
|
||||
static PyObject *
|
||||
bsddb_getattr(PyObject *dp, char *name)
|
||||
{
|
||||
return Py_FindMethod(bsddb_methods, dp, name);
|
||||
}
|
||||
|
||||
static PyTypeObject Bsddbtype = {
|
||||
PyObject_HEAD_INIT(NULL)
|
||||
0,
|
||||
"bsddb.bsddb",
|
||||
sizeof(bsddbobject),
|
||||
0,
|
||||
(destructor)bsddb_dealloc, /*tp_dealloc*/
|
||||
0, /*tp_print*/
|
||||
(getattrfunc)bsddb_getattr, /*tp_getattr*/
|
||||
0, /*tp_setattr*/
|
||||
0, /*tp_compare*/
|
||||
0, /*tp_repr*/
|
||||
0, /*tp_as_number*/
|
||||
0, /*tp_as_sequence*/
|
||||
&bsddb_as_mapping, /*tp_as_mapping*/
|
||||
};
|
||||
|
||||
static PyObject *
|
||||
bsdhashopen(PyObject *self, PyObject *args)
|
||||
{
|
||||
char *file;
|
||||
char *flag = NULL;
|
||||
int flags = O_RDONLY;
|
||||
int mode = 0666;
|
||||
int bsize = 0;
|
||||
int ffactor = 0;
|
||||
int nelem = 0;
|
||||
int cachesize = 0;
|
||||
int hash = 0; /* XXX currently ignored */
|
||||
int lorder = 0;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "z|siiiiiii:hashopen",
|
||||
&file, &flag, &mode,
|
||||
&bsize, &ffactor, &nelem, &cachesize,
|
||||
&hash, &lorder))
|
||||
return NULL;
|
||||
if (flag != NULL) {
|
||||
/* XXX need to pass O_EXCL, O_EXLOCK, O_NONBLOCK, O_SHLOCK */
|
||||
if (flag[0] == 'r')
|
||||
flags = O_RDONLY;
|
||||
else if (flag[0] == 'w')
|
||||
flags = O_RDWR;
|
||||
else if (flag[0] == 'c')
|
||||
flags = O_RDWR|O_CREAT;
|
||||
else if (flag[0] == 'n')
|
||||
flags = O_RDWR|O_CREAT|O_TRUNC;
|
||||
else {
|
||||
PyErr_SetString(BsddbError,
|
||||
"Flag should begin with 'r', 'w', 'c' or 'n'");
|
||||
return NULL;
|
||||
}
|
||||
if (flag[1] == 'l') {
|
||||
#if defined(O_EXLOCK) && defined(O_SHLOCK)
|
||||
if (flag[0] == 'r')
|
||||
flags |= O_SHLOCK;
|
||||
else
|
||||
flags |= O_EXLOCK;
|
||||
#else
|
||||
PyErr_SetString(BsddbError,
|
||||
"locking not supported on this platform");
|
||||
return NULL;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
return newdbhashobject(file, flags, mode,
|
||||
bsize, ffactor, nelem, cachesize, hash, lorder);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
bsdbtopen(PyObject *self, PyObject *args)
|
||||
{
|
||||
char *file;
|
||||
char *flag = NULL;
|
||||
int flags = O_RDONLY;
|
||||
int mode = 0666;
|
||||
int cachesize = 0;
|
||||
int maxkeypage = 0;
|
||||
int minkeypage = 0;
|
||||
int btflags = 0;
|
||||
unsigned int psize = 0;
|
||||
int lorder = 0;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "z|siiiiiii:btopen",
|
||||
&file, &flag, &mode,
|
||||
&btflags, &cachesize, &maxkeypage, &minkeypage,
|
||||
&psize, &lorder))
|
||||
return NULL;
|
||||
if (flag != NULL) {
|
||||
/* XXX need to pass O_EXCL, O_EXLOCK, O_NONBLOCK, O_SHLOCK */
|
||||
if (flag[0] == 'r')
|
||||
flags = O_RDONLY;
|
||||
else if (flag[0] == 'w')
|
||||
flags = O_RDWR;
|
||||
else if (flag[0] == 'c')
|
||||
flags = O_RDWR|O_CREAT;
|
||||
else if (flag[0] == 'n')
|
||||
flags = O_RDWR|O_CREAT|O_TRUNC;
|
||||
else {
|
||||
PyErr_SetString(BsddbError,
|
||||
"Flag should begin with 'r', 'w', 'c' or 'n'");
|
||||
return NULL;
|
||||
}
|
||||
if (flag[1] == 'l') {
|
||||
#if defined(O_EXLOCK) && defined(O_SHLOCK)
|
||||
if (flag[0] == 'r')
|
||||
flags |= O_SHLOCK;
|
||||
else
|
||||
flags |= O_EXLOCK;
|
||||
#else
|
||||
PyErr_SetString(BsddbError,
|
||||
"locking not supported on this platform");
|
||||
return NULL;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
return newdbbtobject(file, flags, mode,
|
||||
btflags, cachesize, maxkeypage, minkeypage,
|
||||
psize, lorder);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
bsdrnopen(PyObject *self, PyObject *args)
|
||||
{
|
||||
char *file;
|
||||
char *flag = NULL;
|
||||
int flags = O_RDONLY;
|
||||
int mode = 0666;
|
||||
int cachesize = 0;
|
||||
int rnflags = 0;
|
||||
unsigned int psize = 0;
|
||||
int lorder = 0;
|
||||
size_t reclen = 0;
|
||||
char *bval = "";
|
||||
char *bfname = NULL;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "z|siiiiiiss:rnopen",
|
||||
&file, &flag, &mode,
|
||||
&rnflags, &cachesize, &psize, &lorder,
|
||||
&reclen, &bval, &bfname))
|
||||
return NULL;
|
||||
|
||||
if (flag != NULL) {
|
||||
/* XXX need to pass O_EXCL, O_EXLOCK, O_NONBLOCK, O_SHLOCK */
|
||||
if (flag[0] == 'r')
|
||||
flags = O_RDONLY;
|
||||
else if (flag[0] == 'w')
|
||||
flags = O_RDWR;
|
||||
else if (flag[0] == 'c')
|
||||
flags = O_RDWR|O_CREAT;
|
||||
else if (flag[0] == 'n')
|
||||
flags = O_RDWR|O_CREAT|O_TRUNC;
|
||||
else {
|
||||
PyErr_SetString(BsddbError,
|
||||
"Flag should begin with 'r', 'w', 'c' or 'n'");
|
||||
return NULL;
|
||||
}
|
||||
if (flag[1] == 'l') {
|
||||
#if defined(O_EXLOCK) && defined(O_SHLOCK)
|
||||
if (flag[0] == 'r')
|
||||
flags |= O_SHLOCK;
|
||||
else
|
||||
flags |= O_EXLOCK;
|
||||
#else
|
||||
PyErr_SetString(BsddbError,
|
||||
"locking not supported on this platform");
|
||||
return NULL;
|
||||
#endif
|
||||
}
|
||||
else if (flag[1] != '\0') {
|
||||
PyErr_SetString(BsddbError,
|
||||
"Flag char 2 should be 'l' or absent");
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
return newdbrnobject(file, flags, mode, rnflags, cachesize,
|
||||
psize, lorder, reclen, bval[0], bfname);
|
||||
}
|
||||
|
||||
static PyMethodDef bsddbmodule_methods[] = {
|
||||
{"hashopen", (PyCFunction)bsdhashopen, METH_VARARGS},
|
||||
{"btopen", (PyCFunction)bsdbtopen, METH_VARARGS},
|
||||
{"rnopen", (PyCFunction)bsdrnopen, METH_VARARGS},
|
||||
/* strictly for use by dbhhash!!! */
|
||||
{"open", (PyCFunction)bsdhashopen, METH_VARARGS},
|
||||
{0, 0},
|
||||
};
|
||||
|
||||
PyMODINIT_FUNC
|
||||
initbsddb185(void) {
|
||||
PyObject *m, *d;
|
||||
|
||||
Bsddbtype.ob_type = &PyType_Type;
|
||||
m = Py_InitModule("bsddb185", bsddbmodule_methods);
|
||||
if (m == NULL)
|
||||
return;
|
||||
d = PyModule_GetDict(m);
|
||||
BsddbError = PyErr_NewException("bsddb.error", NULL, NULL);
|
||||
if (BsddbError != NULL)
|
||||
PyDict_SetItemString(d, "error", BsddbError);
|
||||
}
|
|
@ -1,796 +0,0 @@
|
|||
/* CD module -- interface to Mark Callow's and Roger Chickering's */
|
||||
/* CD Audio Library (CD). */
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <cdaudio.h>
|
||||
#include "Python.h"
|
||||
|
||||
#define NCALLBACKS 8
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
CDPLAYER *ob_cdplayer;
|
||||
} cdplayerobject;
|
||||
|
||||
static PyObject *CdError; /* exception cd.error */
|
||||
|
||||
static PyObject *
|
||||
CD_allowremoval(cdplayerobject *self, PyObject *args)
|
||||
{
|
||||
if (!PyArg_ParseTuple(args, ":allowremoval"))
|
||||
return NULL;
|
||||
|
||||
CDallowremoval(self->ob_cdplayer);
|
||||
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
CD_preventremoval(cdplayerobject *self, PyObject *args)
|
||||
{
|
||||
if (!PyArg_ParseTuple(args, ":preventremoval"))
|
||||
return NULL;
|
||||
|
||||
CDpreventremoval(self->ob_cdplayer);
|
||||
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
CD_bestreadsize(cdplayerobject *self, PyObject *args)
|
||||
{
|
||||
if (!PyArg_ParseTuple(args, ":bestreadsize"))
|
||||
return NULL;
|
||||
|
||||
return PyInt_FromLong((long) CDbestreadsize(self->ob_cdplayer));
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
CD_close(cdplayerobject *self, PyObject *args)
|
||||
{
|
||||
if (!PyArg_ParseTuple(args, ":close"))
|
||||
return NULL;
|
||||
|
||||
if (!CDclose(self->ob_cdplayer)) {
|
||||
PyErr_SetFromErrno(CdError); /* XXX - ??? */
|
||||
return NULL;
|
||||
}
|
||||
self->ob_cdplayer = NULL;
|
||||
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
CD_eject(cdplayerobject *self, PyObject *args)
|
||||
{
|
||||
CDSTATUS status;
|
||||
|
||||
if (!PyArg_ParseTuple(args, ":eject"))
|
||||
return NULL;
|
||||
|
||||
if (!CDeject(self->ob_cdplayer)) {
|
||||
if (CDgetstatus(self->ob_cdplayer, &status) &&
|
||||
status.state == CD_NODISC)
|
||||
PyErr_SetString(CdError, "no disc in player");
|
||||
else
|
||||
PyErr_SetString(CdError, "eject failed");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
CD_getstatus(cdplayerobject *self, PyObject *args)
|
||||
{
|
||||
CDSTATUS status;
|
||||
|
||||
if (!PyArg_ParseTuple(args, ":getstatus"))
|
||||
return NULL;
|
||||
|
||||
if (!CDgetstatus(self->ob_cdplayer, &status)) {
|
||||
PyErr_SetFromErrno(CdError); /* XXX - ??? */
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return Py_BuildValue("(ii(iii)(iii)(iii)iiii)", status.state,
|
||||
status.track, status.min, status.sec, status.frame,
|
||||
status.abs_min, status.abs_sec, status.abs_frame,
|
||||
status.total_min, status.total_sec, status.total_frame,
|
||||
status.first, status.last, status.scsi_audio,
|
||||
status.cur_block);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
CD_gettrackinfo(cdplayerobject *self, PyObject *args)
|
||||
{
|
||||
int track;
|
||||
CDTRACKINFO info;
|
||||
CDSTATUS status;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "i:gettrackinfo", &track))
|
||||
return NULL;
|
||||
|
||||
if (!CDgettrackinfo(self->ob_cdplayer, track, &info)) {
|
||||
if (CDgetstatus(self->ob_cdplayer, &status) &&
|
||||
status.state == CD_NODISC)
|
||||
PyErr_SetString(CdError, "no disc in player");
|
||||
else
|
||||
PyErr_SetString(CdError, "gettrackinfo failed");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return Py_BuildValue("((iii)(iii))",
|
||||
info.start_min, info.start_sec, info.start_frame,
|
||||
info.total_min, info.total_sec, info.total_frame);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
CD_msftoblock(cdplayerobject *self, PyObject *args)
|
||||
{
|
||||
int min, sec, frame;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "iii:msftoblock", &min, &sec, &frame))
|
||||
return NULL;
|
||||
|
||||
return PyInt_FromLong((long) CDmsftoblock(self->ob_cdplayer,
|
||||
min, sec, frame));
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
CD_play(cdplayerobject *self, PyObject *args)
|
||||
{
|
||||
int start, play;
|
||||
CDSTATUS status;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "ii:play", &start, &play))
|
||||
return NULL;
|
||||
|
||||
if (!CDplay(self->ob_cdplayer, start, play)) {
|
||||
if (CDgetstatus(self->ob_cdplayer, &status) &&
|
||||
status.state == CD_NODISC)
|
||||
PyErr_SetString(CdError, "no disc in player");
|
||||
else
|
||||
PyErr_SetString(CdError, "play failed");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
CD_playabs(cdplayerobject *self, PyObject *args)
|
||||
{
|
||||
int min, sec, frame, play;
|
||||
CDSTATUS status;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "iiii:playabs", &min, &sec, &frame, &play))
|
||||
return NULL;
|
||||
|
||||
if (!CDplayabs(self->ob_cdplayer, min, sec, frame, play)) {
|
||||
if (CDgetstatus(self->ob_cdplayer, &status) &&
|
||||
status.state == CD_NODISC)
|
||||
PyErr_SetString(CdError, "no disc in player");
|
||||
else
|
||||
PyErr_SetString(CdError, "playabs failed");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
CD_playtrack(cdplayerobject *self, PyObject *args)
|
||||
{
|
||||
int start, play;
|
||||
CDSTATUS status;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "ii:playtrack", &start, &play))
|
||||
return NULL;
|
||||
|
||||
if (!CDplaytrack(self->ob_cdplayer, start, play)) {
|
||||
if (CDgetstatus(self->ob_cdplayer, &status) &&
|
||||
status.state == CD_NODISC)
|
||||
PyErr_SetString(CdError, "no disc in player");
|
||||
else
|
||||
PyErr_SetString(CdError, "playtrack failed");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
CD_playtrackabs(cdplayerobject *self, PyObject *args)
|
||||
{
|
||||
int track, min, sec, frame, play;
|
||||
CDSTATUS status;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "iiiii:playtrackabs", &track, &min, &sec,
|
||||
&frame, &play))
|
||||
return NULL;
|
||||
|
||||
if (!CDplaytrackabs(self->ob_cdplayer, track, min, sec, frame, play)) {
|
||||
if (CDgetstatus(self->ob_cdplayer, &status) &&
|
||||
status.state == CD_NODISC)
|
||||
PyErr_SetString(CdError, "no disc in player");
|
||||
else
|
||||
PyErr_SetString(CdError, "playtrackabs failed");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
CD_readda(cdplayerobject *self, PyObject *args)
|
||||
{
|
||||
int numframes, n;
|
||||
PyObject *result;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "i:readda", &numframes))
|
||||
return NULL;
|
||||
|
||||
result = PyString_FromStringAndSize(NULL, numframes * sizeof(CDFRAME));
|
||||
if (result == NULL)
|
||||
return NULL;
|
||||
|
||||
n = CDreadda(self->ob_cdplayer,
|
||||
(CDFRAME *) PyString_AsString(result), numframes);
|
||||
if (n == -1) {
|
||||
Py_DECREF(result);
|
||||
PyErr_SetFromErrno(CdError);
|
||||
return NULL;
|
||||
}
|
||||
if (n < numframes)
|
||||
_PyString_Resize(&result, n * sizeof(CDFRAME));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
CD_seek(cdplayerobject *self, PyObject *args)
|
||||
{
|
||||
int min, sec, frame;
|
||||
long PyTryBlock;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "iii:seek", &min, &sec, &frame))
|
||||
return NULL;
|
||||
|
||||
PyTryBlock = CDseek(self->ob_cdplayer, min, sec, frame);
|
||||
if (PyTryBlock == -1) {
|
||||
PyErr_SetFromErrno(CdError);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return PyInt_FromLong(PyTryBlock);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
CD_seektrack(cdplayerobject *self, PyObject *args)
|
||||
{
|
||||
int track;
|
||||
long PyTryBlock;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "i:seektrack", &track))
|
||||
return NULL;
|
||||
|
||||
PyTryBlock = CDseektrack(self->ob_cdplayer, track);
|
||||
if (PyTryBlock == -1) {
|
||||
PyErr_SetFromErrno(CdError);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return PyInt_FromLong(PyTryBlock);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
CD_seekblock(cdplayerobject *self, PyObject *args)
|
||||
{
|
||||
unsigned long PyTryBlock;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "l:seekblock", &PyTryBlock))
|
||||
return NULL;
|
||||
|
||||
PyTryBlock = CDseekblock(self->ob_cdplayer, PyTryBlock);
|
||||
if (PyTryBlock == (unsigned long) -1) {
|
||||
PyErr_SetFromErrno(CdError);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return PyInt_FromLong(PyTryBlock);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
CD_stop(cdplayerobject *self, PyObject *args)
|
||||
{
|
||||
CDSTATUS status;
|
||||
|
||||
if (!PyArg_ParseTuple(args, ":stop"))
|
||||
return NULL;
|
||||
|
||||
if (!CDstop(self->ob_cdplayer)) {
|
||||
if (CDgetstatus(self->ob_cdplayer, &status) &&
|
||||
status.state == CD_NODISC)
|
||||
PyErr_SetString(CdError, "no disc in player");
|
||||
else
|
||||
PyErr_SetString(CdError, "stop failed");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
CD_togglepause(cdplayerobject *self, PyObject *args)
|
||||
{
|
||||
CDSTATUS status;
|
||||
|
||||
if (!PyArg_ParseTuple(args, ":togglepause"))
|
||||
return NULL;
|
||||
|
||||
if (!CDtogglepause(self->ob_cdplayer)) {
|
||||
if (CDgetstatus(self->ob_cdplayer, &status) &&
|
||||
status.state == CD_NODISC)
|
||||
PyErr_SetString(CdError, "no disc in player");
|
||||
else
|
||||
PyErr_SetString(CdError, "togglepause failed");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
static PyMethodDef cdplayer_methods[] = {
|
||||
{"allowremoval", (PyCFunction)CD_allowremoval, METH_VARARGS},
|
||||
{"bestreadsize", (PyCFunction)CD_bestreadsize, METH_VARARGS},
|
||||
{"close", (PyCFunction)CD_close, METH_VARARGS},
|
||||
{"eject", (PyCFunction)CD_eject, METH_VARARGS},
|
||||
{"getstatus", (PyCFunction)CD_getstatus, METH_VARARGS},
|
||||
{"gettrackinfo", (PyCFunction)CD_gettrackinfo, METH_VARARGS},
|
||||
{"msftoblock", (PyCFunction)CD_msftoblock, METH_VARARGS},
|
||||
{"play", (PyCFunction)CD_play, METH_VARARGS},
|
||||
{"playabs", (PyCFunction)CD_playabs, METH_VARARGS},
|
||||
{"playtrack", (PyCFunction)CD_playtrack, METH_VARARGS},
|
||||
{"playtrackabs", (PyCFunction)CD_playtrackabs, METH_VARARGS},
|
||||
{"preventremoval", (PyCFunction)CD_preventremoval, METH_VARARGS},
|
||||
{"readda", (PyCFunction)CD_readda, METH_VARARGS},
|
||||
{"seek", (PyCFunction)CD_seek, METH_VARARGS},
|
||||
{"seekblock", (PyCFunction)CD_seekblock, METH_VARARGS},
|
||||
{"seektrack", (PyCFunction)CD_seektrack, METH_VARARGS},
|
||||
{"stop", (PyCFunction)CD_stop, METH_VARARGS},
|
||||
{"togglepause", (PyCFunction)CD_togglepause, METH_VARARGS},
|
||||
{NULL, NULL} /* sentinel */
|
||||
};
|
||||
|
||||
static void
|
||||
cdplayer_dealloc(cdplayerobject *self)
|
||||
{
|
||||
if (self->ob_cdplayer != NULL)
|
||||
CDclose(self->ob_cdplayer);
|
||||
PyObject_Del(self);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
cdplayer_getattr(cdplayerobject *self, char *name)
|
||||
{
|
||||
if (self->ob_cdplayer == NULL) {
|
||||
PyErr_SetString(PyExc_RuntimeError, "no player active");
|
||||
return NULL;
|
||||
}
|
||||
return Py_FindMethod(cdplayer_methods, (PyObject *)self, name);
|
||||
}
|
||||
|
||||
PyTypeObject CdPlayertype = {
|
||||
PyObject_HEAD_INIT(&PyType_Type)
|
||||
0, /*ob_size*/
|
||||
"cd.cdplayer", /*tp_name*/
|
||||
sizeof(cdplayerobject), /*tp_size*/
|
||||
0, /*tp_itemsize*/
|
||||
/* methods */
|
||||
(destructor)cdplayer_dealloc, /*tp_dealloc*/
|
||||
0, /*tp_print*/
|
||||
(getattrfunc)cdplayer_getattr, /*tp_getattr*/
|
||||
0, /*tp_setattr*/
|
||||
0, /*tp_compare*/
|
||||
0, /*tp_repr*/
|
||||
};
|
||||
|
||||
static PyObject *
|
||||
newcdplayerobject(CDPLAYER *cdp)
|
||||
{
|
||||
cdplayerobject *p;
|
||||
|
||||
p = PyObject_New(cdplayerobject, &CdPlayertype);
|
||||
if (p == NULL)
|
||||
return NULL;
|
||||
p->ob_cdplayer = cdp;
|
||||
return (PyObject *) p;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
CD_open(PyObject *self, PyObject *args)
|
||||
{
|
||||
char *dev, *direction;
|
||||
CDPLAYER *cdp;
|
||||
|
||||
/*
|
||||
* Variable number of args.
|
||||
* First defaults to "None", second defaults to "r".
|
||||
*/
|
||||
dev = NULL;
|
||||
direction = "r";
|
||||
if (!PyArg_ParseTuple(args, "|zs:open", &dev, &direction))
|
||||
return NULL;
|
||||
|
||||
cdp = CDopen(dev, direction);
|
||||
if (cdp == NULL) {
|
||||
PyErr_SetFromErrno(CdError);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return newcdplayerobject(cdp);
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
CDPARSER *ob_cdparser;
|
||||
struct {
|
||||
PyObject *ob_cdcallback;
|
||||
PyObject *ob_cdcallbackarg;
|
||||
} ob_cdcallbacks[NCALLBACKS];
|
||||
} cdparserobject;
|
||||
|
||||
static void
|
||||
CD_callback(void *arg, CDDATATYPES type, void *data)
|
||||
{
|
||||
PyObject *result, *args, *v = NULL;
|
||||
char *p;
|
||||
int i;
|
||||
cdparserobject *self;
|
||||
|
||||
self = (cdparserobject *) arg;
|
||||
args = PyTuple_New(3);
|
||||
if (args == NULL)
|
||||
return;
|
||||
Py_INCREF(self->ob_cdcallbacks[type].ob_cdcallbackarg);
|
||||
PyTuple_SetItem(args, 0, self->ob_cdcallbacks[type].ob_cdcallbackarg);
|
||||
PyTuple_SetItem(args, 1, PyInt_FromLong((long) type));
|
||||
switch (type) {
|
||||
case cd_audio:
|
||||
v = PyString_FromStringAndSize(data, CDDA_DATASIZE);
|
||||
break;
|
||||
case cd_pnum:
|
||||
case cd_index:
|
||||
v = PyInt_FromLong(((CDPROGNUM *) data)->value);
|
||||
break;
|
||||
case cd_ptime:
|
||||
case cd_atime:
|
||||
#define ptr ((struct cdtimecode *) data)
|
||||
v = Py_BuildValue("(iii)",
|
||||
ptr->mhi * 10 + ptr->mlo,
|
||||
ptr->shi * 10 + ptr->slo,
|
||||
ptr->fhi * 10 + ptr->flo);
|
||||
#undef ptr
|
||||
break;
|
||||
case cd_catalog:
|
||||
v = PyString_FromStringAndSize(NULL, 13);
|
||||
p = PyString_AsString(v);
|
||||
for (i = 0; i < 13; i++)
|
||||
*p++ = ((char *) data)[i] + '0';
|
||||
break;
|
||||
case cd_ident:
|
||||
#define ptr ((struct cdident *) data)
|
||||
v = PyString_FromStringAndSize(NULL, 12);
|
||||
p = PyString_AsString(v);
|
||||
CDsbtoa(p, ptr->country, 2);
|
||||
p += 2;
|
||||
CDsbtoa(p, ptr->owner, 3);
|
||||
p += 3;
|
||||
*p++ = ptr->year[0] + '0';
|
||||
*p++ = ptr->year[1] + '0';
|
||||
*p++ = ptr->serial[0] + '0';
|
||||
*p++ = ptr->serial[1] + '0';
|
||||
*p++ = ptr->serial[2] + '0';
|
||||
*p++ = ptr->serial[3] + '0';
|
||||
*p++ = ptr->serial[4] + '0';
|
||||
#undef ptr
|
||||
break;
|
||||
case cd_control:
|
||||
v = PyInt_FromLong((long) *((unchar *) data));
|
||||
break;
|
||||
}
|
||||
PyTuple_SetItem(args, 2, v);
|
||||
if (PyErr_Occurred()) {
|
||||
Py_DECREF(args);
|
||||
return;
|
||||
}
|
||||
|
||||
result = PyEval_CallObject(self->ob_cdcallbacks[type].ob_cdcallback,
|
||||
args);
|
||||
Py_DECREF(args);
|
||||
Py_XDECREF(result);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
CD_deleteparser(cdparserobject *self, PyObject *args)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (!PyArg_ParseTuple(args, ":deleteparser"))
|
||||
return NULL;
|
||||
|
||||
CDdeleteparser(self->ob_cdparser);
|
||||
self->ob_cdparser = NULL;
|
||||
|
||||
/* no sense in keeping the callbacks, so remove them */
|
||||
for (i = 0; i < NCALLBACKS; i++) {
|
||||
Py_XDECREF(self->ob_cdcallbacks[i].ob_cdcallback);
|
||||
self->ob_cdcallbacks[i].ob_cdcallback = NULL;
|
||||
Py_XDECREF(self->ob_cdcallbacks[i].ob_cdcallbackarg);
|
||||
self->ob_cdcallbacks[i].ob_cdcallbackarg = NULL;
|
||||
}
|
||||
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
CD_parseframe(cdparserobject *self, PyObject *args)
|
||||
{
|
||||
char *cdfp;
|
||||
int length;
|
||||
CDFRAME *p;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "s#:parseframe", &cdfp, &length))
|
||||
return NULL;
|
||||
|
||||
if (length % sizeof(CDFRAME) != 0) {
|
||||
PyErr_SetString(PyExc_TypeError, "bad length");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
p = (CDFRAME *) cdfp;
|
||||
while (length > 0) {
|
||||
CDparseframe(self->ob_cdparser, p);
|
||||
length -= sizeof(CDFRAME);
|
||||
p++;
|
||||
if (PyErr_Occurred())
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
CD_removecallback(cdparserobject *self, PyObject *args)
|
||||
{
|
||||
int type;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "i:removecallback", &type))
|
||||
return NULL;
|
||||
|
||||
if (type < 0 || type >= NCALLBACKS) {
|
||||
PyErr_SetString(PyExc_TypeError, "bad type");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
CDremovecallback(self->ob_cdparser, (CDDATATYPES) type);
|
||||
|
||||
Py_XDECREF(self->ob_cdcallbacks[type].ob_cdcallback);
|
||||
self->ob_cdcallbacks[type].ob_cdcallback = NULL;
|
||||
|
||||
Py_XDECREF(self->ob_cdcallbacks[type].ob_cdcallbackarg);
|
||||
self->ob_cdcallbacks[type].ob_cdcallbackarg = NULL;
|
||||
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
CD_resetparser(cdparserobject *self, PyObject *args)
|
||||
{
|
||||
if (!PyArg_ParseTuple(args, ":resetparser"))
|
||||
return NULL;
|
||||
|
||||
CDresetparser(self->ob_cdparser);
|
||||
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
CD_addcallback(cdparserobject *self, PyObject *args)
|
||||
{
|
||||
int type;
|
||||
PyObject *func, *funcarg;
|
||||
|
||||
/* XXX - more work here */
|
||||
if (!PyArg_ParseTuple(args, "iOO:addcallback", &type, &func, &funcarg))
|
||||
return NULL;
|
||||
|
||||
if (type < 0 || type >= NCALLBACKS) {
|
||||
PyErr_SetString(PyExc_TypeError, "argument out of range");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#ifdef CDsetcallback
|
||||
CDaddcallback(self->ob_cdparser, (CDDATATYPES) type, CD_callback,
|
||||
(void *) self);
|
||||
#else
|
||||
CDsetcallback(self->ob_cdparser, (CDDATATYPES) type, CD_callback,
|
||||
(void *) self);
|
||||
#endif
|
||||
Py_XDECREF(self->ob_cdcallbacks[type].ob_cdcallback);
|
||||
Py_INCREF(func);
|
||||
self->ob_cdcallbacks[type].ob_cdcallback = func;
|
||||
Py_XDECREF(self->ob_cdcallbacks[type].ob_cdcallbackarg);
|
||||
Py_INCREF(funcarg);
|
||||
self->ob_cdcallbacks[type].ob_cdcallbackarg = funcarg;
|
||||
|
||||
/*
|
||||
if (type == cd_audio) {
|
||||
sigfpe_[_UNDERFL].repls = _ZERO;
|
||||
handle_sigfpes(_ON, _EN_UNDERFL, NULL,
|
||||
_ABORT_ON_ERROR, NULL);
|
||||
}
|
||||
*/
|
||||
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
static PyMethodDef cdparser_methods[] = {
|
||||
{"addcallback", (PyCFunction)CD_addcallback, METH_VARARGS},
|
||||
{"deleteparser", (PyCFunction)CD_deleteparser, METH_VARARGS},
|
||||
{"parseframe", (PyCFunction)CD_parseframe, METH_VARARGS},
|
||||
{"removecallback", (PyCFunction)CD_removecallback, METH_VARARGS},
|
||||
{"resetparser", (PyCFunction)CD_resetparser, METH_VARARGS},
|
||||
/* backward compatibility */
|
||||
{"setcallback", (PyCFunction)CD_addcallback, METH_VARARGS},
|
||||
{NULL, NULL} /* sentinel */
|
||||
};
|
||||
|
||||
static void
|
||||
cdparser_dealloc(cdparserobject *self)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < NCALLBACKS; i++) {
|
||||
Py_XDECREF(self->ob_cdcallbacks[i].ob_cdcallback);
|
||||
self->ob_cdcallbacks[i].ob_cdcallback = NULL;
|
||||
Py_XDECREF(self->ob_cdcallbacks[i].ob_cdcallbackarg);
|
||||
self->ob_cdcallbacks[i].ob_cdcallbackarg = NULL;
|
||||
}
|
||||
CDdeleteparser(self->ob_cdparser);
|
||||
PyObject_Del(self);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
cdparser_getattr(cdparserobject *self, char *name)
|
||||
{
|
||||
if (self->ob_cdparser == NULL) {
|
||||
PyErr_SetString(PyExc_RuntimeError, "no parser active");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return Py_FindMethod(cdparser_methods, (PyObject *)self, name);
|
||||
}
|
||||
|
||||
PyTypeObject CdParsertype = {
|
||||
PyObject_HEAD_INIT(&PyType_Type)
|
||||
0, /*ob_size*/
|
||||
"cd.cdparser", /*tp_name*/
|
||||
sizeof(cdparserobject), /*tp_size*/
|
||||
0, /*tp_itemsize*/
|
||||
/* methods */
|
||||
(destructor)cdparser_dealloc, /*tp_dealloc*/
|
||||
0, /*tp_print*/
|
||||
(getattrfunc)cdparser_getattr, /*tp_getattr*/
|
||||
0, /*tp_setattr*/
|
||||
0, /*tp_compare*/
|
||||
0, /*tp_repr*/
|
||||
};
|
||||
|
||||
static PyObject *
|
||||
newcdparserobject(CDPARSER *cdp)
|
||||
{
|
||||
cdparserobject *p;
|
||||
int i;
|
||||
|
||||
p = PyObject_New(cdparserobject, &CdParsertype);
|
||||
if (p == NULL)
|
||||
return NULL;
|
||||
p->ob_cdparser = cdp;
|
||||
for (i = 0; i < NCALLBACKS; i++) {
|
||||
p->ob_cdcallbacks[i].ob_cdcallback = NULL;
|
||||
p->ob_cdcallbacks[i].ob_cdcallbackarg = NULL;
|
||||
}
|
||||
return (PyObject *) p;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
CD_createparser(PyObject *self, PyObject *args)
|
||||
{
|
||||
CDPARSER *cdp;
|
||||
|
||||
if (!PyArg_ParseTuple(args, ":createparser"))
|
||||
return NULL;
|
||||
cdp = CDcreateparser();
|
||||
if (cdp == NULL) {
|
||||
PyErr_SetString(CdError, "createparser failed");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return newcdparserobject(cdp);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
CD_msftoframe(PyObject *self, PyObject *args)
|
||||
{
|
||||
int min, sec, frame;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "iii:msftoframe", &min, &sec, &frame))
|
||||
return NULL;
|
||||
|
||||
return PyInt_FromLong((long) CDmsftoframe(min, sec, frame));
|
||||
}
|
||||
|
||||
static PyMethodDef CD_methods[] = {
|
||||
{"open", (PyCFunction)CD_open, METH_VARARGS},
|
||||
{"createparser", (PyCFunction)CD_createparser, METH_VARARGS},
|
||||
{"msftoframe", (PyCFunction)CD_msftoframe, METH_VARARGS},
|
||||
{NULL, NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
void
|
||||
initcd(void)
|
||||
{
|
||||
PyObject *m, *d;
|
||||
|
||||
m = Py_InitModule("cd", CD_methods);
|
||||
if (m == NULL)
|
||||
return;
|
||||
d = PyModule_GetDict(m);
|
||||
|
||||
CdError = PyErr_NewException("cd.error", NULL, NULL);
|
||||
PyDict_SetItemString(d, "error", CdError);
|
||||
|
||||
/* Identifiers for the different types of callbacks from the parser */
|
||||
PyDict_SetItemString(d, "audio", PyInt_FromLong((long) cd_audio));
|
||||
PyDict_SetItemString(d, "pnum", PyInt_FromLong((long) cd_pnum));
|
||||
PyDict_SetItemString(d, "index", PyInt_FromLong((long) cd_index));
|
||||
PyDict_SetItemString(d, "ptime", PyInt_FromLong((long) cd_ptime));
|
||||
PyDict_SetItemString(d, "atime", PyInt_FromLong((long) cd_atime));
|
||||
PyDict_SetItemString(d, "catalog", PyInt_FromLong((long) cd_catalog));
|
||||
PyDict_SetItemString(d, "ident", PyInt_FromLong((long) cd_ident));
|
||||
PyDict_SetItemString(d, "control", PyInt_FromLong((long) cd_control));
|
||||
|
||||
/* Block size information for digital audio data */
|
||||
PyDict_SetItemString(d, "DATASIZE",
|
||||
PyInt_FromLong((long) CDDA_DATASIZE));
|
||||
PyDict_SetItemString(d, "BLOCKSIZE",
|
||||
PyInt_FromLong((long) CDDA_BLOCKSIZE));
|
||||
|
||||
/* Possible states for the cd player */
|
||||
PyDict_SetItemString(d, "ERROR", PyInt_FromLong((long) CD_ERROR));
|
||||
PyDict_SetItemString(d, "NODISC", PyInt_FromLong((long) CD_NODISC));
|
||||
PyDict_SetItemString(d, "READY", PyInt_FromLong((long) CD_READY));
|
||||
PyDict_SetItemString(d, "PLAYING", PyInt_FromLong((long) CD_PLAYING));
|
||||
PyDict_SetItemString(d, "PAUSED", PyInt_FromLong((long) CD_PAUSED));
|
||||
PyDict_SetItemString(d, "STILL", PyInt_FromLong((long) CD_STILL));
|
||||
#ifdef CD_CDROM /* only newer versions of the library */
|
||||
PyDict_SetItemString(d, "CDROM", PyInt_FromLong((long) CD_CDROM));
|
||||
#endif
|
||||
}
|
520
Modules/cgen.py
520
Modules/cgen.py
|
@ -1,520 +0,0 @@
|
|||
########################################################################
|
||||
# Copyright (c) 2000, BeOpen.com.
|
||||
# Copyright (c) 1995-2000, Corporation for National Research Initiatives.
|
||||
# Copyright (c) 1990-1995, Stichting Mathematisch Centrum.
|
||||
# All rights reserved.
|
||||
#
|
||||
# See the file "Misc/COPYRIGHT" for information on usage and
|
||||
# redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
|
||||
########################################################################
|
||||
|
||||
# Python script to parse cstubs file for gl and generate C stubs.
|
||||
# usage: python cgen.py <cstubs >glmodule.c
|
||||
#
|
||||
# NOTE: You must first make a python binary without the "GL" option
|
||||
# before you can run this, when building Python for the first time.
|
||||
# See comments in the Makefile.
|
||||
#
|
||||
# XXX BUG return arrays generate wrong code
|
||||
# XXX need to change error returns into gotos to free mallocked arrays
|
||||
|
||||
|
||||
import string
|
||||
import sys
|
||||
|
||||
|
||||
# Function to print to stderr
|
||||
#
|
||||
def err(*args):
|
||||
savestdout = sys.stdout
|
||||
try:
|
||||
sys.stdout = sys.stderr
|
||||
for i in args:
|
||||
print i,
|
||||
print
|
||||
finally:
|
||||
sys.stdout = savestdout
|
||||
|
||||
|
||||
# The set of digits that form a number
|
||||
#
|
||||
digits = '0123456789'
|
||||
|
||||
|
||||
# Function to extract a string of digits from the front of the string.
|
||||
# Returns the leading string of digits and the remaining string.
|
||||
# If no number is found, returns '' and the original string.
|
||||
#
|
||||
def getnum(s):
|
||||
n = ''
|
||||
while s and s[0] in digits:
|
||||
n = n + s[0]
|
||||
s = s[1:]
|
||||
return n, s
|
||||
|
||||
|
||||
# Function to check if a string is a number
|
||||
#
|
||||
def isnum(s):
|
||||
if not s: return False
|
||||
for c in s:
|
||||
if not c in digits: return False
|
||||
return True
|
||||
|
||||
|
||||
# Allowed function return types
|
||||
#
|
||||
return_types = ['void', 'short', 'long']
|
||||
|
||||
|
||||
# Allowed function argument types
|
||||
#
|
||||
arg_types = ['char', 'string', 'short', 'u_short', 'float', 'long', 'double']
|
||||
|
||||
|
||||
# Need to classify arguments as follows
|
||||
# simple input variable
|
||||
# simple output variable
|
||||
# input array
|
||||
# output array
|
||||
# input giving size of some array
|
||||
#
|
||||
# Array dimensions can be specified as follows
|
||||
# constant
|
||||
# argN
|
||||
# constant * argN
|
||||
# retval
|
||||
# constant * retval
|
||||
#
|
||||
# The dimensions given as constants * something are really
|
||||
# arrays of points where points are 2- 3- or 4-tuples
|
||||
#
|
||||
# We have to consider three lists:
|
||||
# python input arguments
|
||||
# C stub arguments (in & out)
|
||||
# python output arguments (really return values)
|
||||
#
|
||||
# There is a mapping from python input arguments to the input arguments
|
||||
# of the C stub, and a further mapping from C stub arguments to the
|
||||
# python return values
|
||||
|
||||
|
||||
# Exception raised by checkarg() and generate()
|
||||
#
|
||||
arg_error = 'bad arg'
|
||||
|
||||
|
||||
# Function to check one argument.
|
||||
# Arguments: the type and the arg "name" (really mode plus subscript).
|
||||
# Raises arg_error if something's wrong.
|
||||
# Return type, mode, factor, rest of subscript; factor and rest may be empty.
|
||||
#
|
||||
def checkarg(type, arg):
|
||||
#
|
||||
# Turn "char *x" into "string x".
|
||||
#
|
||||
if type == 'char' and arg[0] == '*':
|
||||
type = 'string'
|
||||
arg = arg[1:]
|
||||
#
|
||||
# Check that the type is supported.
|
||||
#
|
||||
if type not in arg_types:
|
||||
raise arg_error, ('bad type', type)
|
||||
if type[:2] == 'u_':
|
||||
type = 'unsigned ' + type[2:]
|
||||
#
|
||||
# Split it in the mode (first character) and the rest.
|
||||
#
|
||||
mode, rest = arg[:1], arg[1:]
|
||||
#
|
||||
# The mode must be 's' for send (= input) or 'r' for return argument.
|
||||
#
|
||||
if mode not in ('r', 's'):
|
||||
raise arg_error, ('bad arg mode', mode)
|
||||
#
|
||||
# Is it a simple argument: if so, we are done.
|
||||
#
|
||||
if not rest:
|
||||
return type, mode, '', ''
|
||||
#
|
||||
# Not a simple argument; must be an array.
|
||||
# The 'rest' must be a subscript enclosed in [ and ].
|
||||
# The subscript must be one of the following forms,
|
||||
# otherwise we don't handle it (where N is a number):
|
||||
# N
|
||||
# argN
|
||||
# retval
|
||||
# N*argN
|
||||
# N*retval
|
||||
#
|
||||
if rest[:1] != '[' or rest[-1:] != ']':
|
||||
raise arg_error, ('subscript expected', rest)
|
||||
sub = rest[1:-1]
|
||||
#
|
||||
# Is there a leading number?
|
||||
#
|
||||
num, sub = getnum(sub)
|
||||
if num:
|
||||
# There is a leading number
|
||||
if not sub:
|
||||
# The subscript is just a number
|
||||
return type, mode, num, ''
|
||||
if sub[:1] == '*':
|
||||
# There is a factor prefix
|
||||
sub = sub[1:]
|
||||
else:
|
||||
raise arg_error, ('\'*\' expected', sub)
|
||||
if sub == 'retval':
|
||||
# size is retval -- must be a reply argument
|
||||
if mode != 'r':
|
||||
raise arg_error, ('non-r mode with [retval]', mode)
|
||||
elif not isnum(sub) and (sub[:3] != 'arg' or not isnum(sub[3:])):
|
||||
raise arg_error, ('bad subscript', sub)
|
||||
#
|
||||
return type, mode, num, sub
|
||||
|
||||
|
||||
# List of functions for which we have generated stubs
|
||||
#
|
||||
functions = []
|
||||
|
||||
|
||||
# Generate the stub for the given function, using the database of argument
|
||||
# information build by successive calls to checkarg()
|
||||
#
|
||||
def generate(type, func, database):
|
||||
#
|
||||
# Check that we can handle this case:
|
||||
# no variable size reply arrays yet
|
||||
#
|
||||
n_in_args = 0
|
||||
n_out_args = 0
|
||||
#
|
||||
for a_type, a_mode, a_factor, a_sub in database:
|
||||
if a_mode == 's':
|
||||
n_in_args = n_in_args + 1
|
||||
elif a_mode == 'r':
|
||||
n_out_args = n_out_args + 1
|
||||
else:
|
||||
# Can't happen
|
||||
raise arg_error, ('bad a_mode', a_mode)
|
||||
if (a_mode == 'r' and a_sub) or a_sub == 'retval':
|
||||
err('Function', func, 'too complicated:',
|
||||
a_type, a_mode, a_factor, a_sub)
|
||||
print '/* XXX Too complicated to generate code for */'
|
||||
return
|
||||
#
|
||||
functions.append(func)
|
||||
#
|
||||
# Stub header
|
||||
#
|
||||
print
|
||||
print 'static PyObject *'
|
||||
print 'gl_' + func + '(self, args)'
|
||||
print '\tPyObject *self;'
|
||||
print '\tPyObject *args;'
|
||||
print '{'
|
||||
#
|
||||
# Declare return value if any
|
||||
#
|
||||
if type != 'void':
|
||||
print '\t' + type, 'retval;'
|
||||
#
|
||||
# Declare arguments
|
||||
#
|
||||
for i in range(len(database)):
|
||||
a_type, a_mode, a_factor, a_sub = database[i]
|
||||
print '\t' + a_type,
|
||||
brac = ket = ''
|
||||
if a_sub and not isnum(a_sub):
|
||||
if a_factor:
|
||||
brac = '('
|
||||
ket = ')'
|
||||
print brac + '*',
|
||||
print 'arg' + repr(i+1) + ket,
|
||||
if a_sub and isnum(a_sub):
|
||||
print '[', a_sub, ']',
|
||||
if a_factor:
|
||||
print '[', a_factor, ']',
|
||||
print ';'
|
||||
#
|
||||
# Find input arguments derived from array sizes
|
||||
#
|
||||
for i in range(len(database)):
|
||||
a_type, a_mode, a_factor, a_sub = database[i]
|
||||
if a_mode == 's' and a_sub[:3] == 'arg' and isnum(a_sub[3:]):
|
||||
# Sending a variable-length array
|
||||
n = eval(a_sub[3:])
|
||||
if 1 <= n <= len(database):
|
||||
b_type, b_mode, b_factor, b_sub = database[n-1]
|
||||
if b_mode == 's':
|
||||
database[n-1] = b_type, 'i', a_factor, repr(i)
|
||||
n_in_args = n_in_args - 1
|
||||
#
|
||||
# Assign argument positions in the Python argument list
|
||||
#
|
||||
in_pos = []
|
||||
i_in = 0
|
||||
for i in range(len(database)):
|
||||
a_type, a_mode, a_factor, a_sub = database[i]
|
||||
if a_mode == 's':
|
||||
in_pos.append(i_in)
|
||||
i_in = i_in + 1
|
||||
else:
|
||||
in_pos.append(-1)
|
||||
#
|
||||
# Get input arguments
|
||||
#
|
||||
for i in range(len(database)):
|
||||
a_type, a_mode, a_factor, a_sub = database[i]
|
||||
if a_type[:9] == 'unsigned ':
|
||||
xtype = a_type[9:]
|
||||
else:
|
||||
xtype = a_type
|
||||
if a_mode == 'i':
|
||||
#
|
||||
# Implicit argument;
|
||||
# a_factor is divisor if present,
|
||||
# a_sub indicates which arg (`database index`)
|
||||
#
|
||||
j = eval(a_sub)
|
||||
print '\tif',
|
||||
print '(!geti' + xtype + 'arraysize(args,',
|
||||
print repr(n_in_args) + ',',
|
||||
print repr(in_pos[j]) + ',',
|
||||
if xtype != a_type:
|
||||
print '('+xtype+' *)',
|
||||
print '&arg' + repr(i+1) + '))'
|
||||
print '\t\treturn NULL;'
|
||||
if a_factor:
|
||||
print '\targ' + repr(i+1),
|
||||
print '= arg' + repr(i+1),
|
||||
print '/', a_factor + ';'
|
||||
elif a_mode == 's':
|
||||
if a_sub and not isnum(a_sub):
|
||||
# Allocate memory for varsize array
|
||||
print '\tif ((arg' + repr(i+1), '=',
|
||||
if a_factor:
|
||||
print '('+a_type+'(*)['+a_factor+'])',
|
||||
print 'PyMem_NEW(' + a_type, ',',
|
||||
if a_factor:
|
||||
print a_factor, '*',
|
||||
print a_sub, ')) == NULL)'
|
||||
print '\t\treturn PyErr_NoMemory();'
|
||||
print '\tif',
|
||||
if a_factor or a_sub: # Get a fixed-size array array
|
||||
print '(!geti' + xtype + 'array(args,',
|
||||
print repr(n_in_args) + ',',
|
||||
print repr(in_pos[i]) + ',',
|
||||
if a_factor: print a_factor,
|
||||
if a_factor and a_sub: print '*',
|
||||
if a_sub: print a_sub,
|
||||
print ',',
|
||||
if (a_sub and a_factor) or xtype != a_type:
|
||||
print '('+xtype+' *)',
|
||||
print 'arg' + repr(i+1) + '))'
|
||||
else: # Get a simple variable
|
||||
print '(!geti' + xtype + 'arg(args,',
|
||||
print repr(n_in_args) + ',',
|
||||
print repr(in_pos[i]) + ',',
|
||||
if xtype != a_type:
|
||||
print '('+xtype+' *)',
|
||||
print '&arg' + repr(i+1) + '))'
|
||||
print '\t\treturn NULL;'
|
||||
#
|
||||
# Begin of function call
|
||||
#
|
||||
if type != 'void':
|
||||
print '\tretval =', func + '(',
|
||||
else:
|
||||
print '\t' + func + '(',
|
||||
#
|
||||
# Argument list
|
||||
#
|
||||
for i in range(len(database)):
|
||||
if i > 0: print ',',
|
||||
a_type, a_mode, a_factor, a_sub = database[i]
|
||||
if a_mode == 'r' and not a_factor:
|
||||
print '&',
|
||||
print 'arg' + repr(i+1),
|
||||
#
|
||||
# End of function call
|
||||
#
|
||||
print ');'
|
||||
#
|
||||
# Free varsize arrays
|
||||
#
|
||||
for i in range(len(database)):
|
||||
a_type, a_mode, a_factor, a_sub = database[i]
|
||||
if a_mode == 's' and a_sub and not isnum(a_sub):
|
||||
print '\tPyMem_DEL(arg' + repr(i+1) + ');'
|
||||
#
|
||||
# Return
|
||||
#
|
||||
if n_out_args:
|
||||
#
|
||||
# Multiple return values -- construct a tuple
|
||||
#
|
||||
if type != 'void':
|
||||
n_out_args = n_out_args + 1
|
||||
if n_out_args == 1:
|
||||
for i in range(len(database)):
|
||||
a_type, a_mode, a_factor, a_sub = database[i]
|
||||
if a_mode == 'r':
|
||||
break
|
||||
else:
|
||||
raise arg_error, 'expected r arg not found'
|
||||
print '\treturn',
|
||||
print mkobject(a_type, 'arg' + repr(i+1)) + ';'
|
||||
else:
|
||||
print '\t{ PyObject *v = PyTuple_New(',
|
||||
print n_out_args, ');'
|
||||
print '\t if (v == NULL) return NULL;'
|
||||
i_out = 0
|
||||
if type != 'void':
|
||||
print '\t PyTuple_SetItem(v,',
|
||||
print repr(i_out) + ',',
|
||||
print mkobject(type, 'retval') + ');'
|
||||
i_out = i_out + 1
|
||||
for i in range(len(database)):
|
||||
a_type, a_mode, a_factor, a_sub = database[i]
|
||||
if a_mode == 'r':
|
||||
print '\t PyTuple_SetItem(v,',
|
||||
print repr(i_out) + ',',
|
||||
s = mkobject(a_type, 'arg' + repr(i+1))
|
||||
print s + ');'
|
||||
i_out = i_out + 1
|
||||
print '\t return v;'
|
||||
print '\t}'
|
||||
else:
|
||||
#
|
||||
# Simple function return
|
||||
# Return None or return value
|
||||
#
|
||||
if type == 'void':
|
||||
print '\tPy_INCREF(Py_None);'
|
||||
print '\treturn Py_None;'
|
||||
else:
|
||||
print '\treturn', mkobject(type, 'retval') + ';'
|
||||
#
|
||||
# Stub body closing brace
|
||||
#
|
||||
print '}'
|
||||
|
||||
|
||||
# Subroutine to return a function call to mknew<type>object(<arg>)
|
||||
#
|
||||
def mkobject(type, arg):
|
||||
if type[:9] == 'unsigned ':
|
||||
type = type[9:]
|
||||
return 'mknew' + type + 'object((' + type + ') ' + arg + ')'
|
||||
return 'mknew' + type + 'object(' + arg + ')'
|
||||
|
||||
|
||||
defined_archs = []
|
||||
|
||||
# usage: cgen [ -Dmach ... ] [ file ]
|
||||
for arg in sys.argv[1:]:
|
||||
if arg[:2] == '-D':
|
||||
defined_archs.append(arg[2:])
|
||||
else:
|
||||
# Open optional file argument
|
||||
sys.stdin = open(arg, 'r')
|
||||
|
||||
|
||||
# Input line number
|
||||
lno = 0
|
||||
|
||||
|
||||
# Input is divided in two parts, separated by a line containing '%%'.
|
||||
# <part1> -- literally copied to stdout
|
||||
# <part2> -- stub definitions
|
||||
|
||||
# Variable indicating the current input part.
|
||||
#
|
||||
part = 1
|
||||
|
||||
# Main loop over the input
|
||||
#
|
||||
while 1:
|
||||
try:
|
||||
line = raw_input()
|
||||
except EOFError:
|
||||
break
|
||||
#
|
||||
lno = lno+1
|
||||
words = string.split(line)
|
||||
#
|
||||
if part == 1:
|
||||
#
|
||||
# In part 1, copy everything literally
|
||||
# except look for a line of just '%%'
|
||||
#
|
||||
if words == ['%%']:
|
||||
part = part + 1
|
||||
else:
|
||||
#
|
||||
# Look for names of manually written
|
||||
# stubs: a single percent followed by the name
|
||||
# of the function in Python.
|
||||
# The stub name is derived by prefixing 'gl_'.
|
||||
#
|
||||
if words and words[0][0] == '%':
|
||||
func = words[0][1:]
|
||||
if (not func) and words[1:]:
|
||||
func = words[1]
|
||||
if func:
|
||||
functions.append(func)
|
||||
else:
|
||||
print line
|
||||
continue
|
||||
if not words:
|
||||
continue # skip empty line
|
||||
elif words[0] == 'if':
|
||||
# if XXX rest
|
||||
# if !XXX rest
|
||||
if words[1][0] == '!':
|
||||
if words[1][1:] in defined_archs:
|
||||
continue
|
||||
elif words[1] not in defined_archs:
|
||||
continue
|
||||
words = words[2:]
|
||||
if words[0] == '#include':
|
||||
print line
|
||||
elif words[0][:1] == '#':
|
||||
pass # ignore comment
|
||||
elif words[0] not in return_types:
|
||||
err('Line', lno, ': bad return type :', words[0])
|
||||
elif len(words) < 2:
|
||||
err('Line', lno, ': no funcname :', line)
|
||||
else:
|
||||
if len(words) % 2 != 0:
|
||||
err('Line', lno, ': odd argument list :', words[2:])
|
||||
else:
|
||||
database = []
|
||||
try:
|
||||
for i in range(2, len(words), 2):
|
||||
x = checkarg(words[i], words[i+1])
|
||||
database.append(x)
|
||||
print
|
||||
print '/*',
|
||||
for w in words: print w,
|
||||
print '*/'
|
||||
generate(words[0], words[1], database)
|
||||
except arg_error, msg:
|
||||
err('Line', lno, ':', msg)
|
||||
|
||||
|
||||
print
|
||||
print 'static struct PyMethodDef gl_methods[] = {'
|
||||
for func in functions:
|
||||
print '\t{"' + func + '", gl_' + func + '},'
|
||||
print '\t{NULL, NULL} /* Sentinel */'
|
||||
print '};'
|
||||
print
|
||||
print 'void'
|
||||
print 'initgl()'
|
||||
print '{'
|
||||
print '\t(void) Py_InitModule("gl", gl_methods);'
|
||||
print '}'
|
|
@ -1,310 +0,0 @@
|
|||
|
||||
/* Functions used by cgen output */
|
||||
|
||||
#include "Python.h"
|
||||
#include "cgensupport.h"
|
||||
|
||||
|
||||
/* Functions to extract arguments.
|
||||
These needs to know the total number of arguments supplied,
|
||||
since the argument list is a tuple only of there is more than
|
||||
one argument. */
|
||||
|
||||
int
|
||||
PyArg_GetObject(register PyObject *args, int nargs, int i, PyObject **p_arg)
|
||||
{
|
||||
if (nargs != 1) {
|
||||
if (args == NULL || !PyTuple_Check(args) ||
|
||||
nargs != PyTuple_Size(args) ||
|
||||
i < 0 || i >= nargs) {
|
||||
return PyErr_BadArgument();
|
||||
}
|
||||
else {
|
||||
args = PyTuple_GetItem(args, i);
|
||||
}
|
||||
}
|
||||
if (args == NULL) {
|
||||
return PyErr_BadArgument();
|
||||
}
|
||||
*p_arg = args;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int
|
||||
PyArg_GetLong(register PyObject *args, int nargs, int i, long *p_arg)
|
||||
{
|
||||
if (nargs != 1) {
|
||||
if (args == NULL || !PyTuple_Check(args) ||
|
||||
nargs != PyTuple_Size(args) ||
|
||||
i < 0 || i >= nargs) {
|
||||
return PyErr_BadArgument();
|
||||
}
|
||||
args = PyTuple_GetItem(args, i);
|
||||
}
|
||||
if (args == NULL || !PyInt_Check(args)) {
|
||||
return PyErr_BadArgument();
|
||||
}
|
||||
*p_arg = PyInt_AsLong(args);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int
|
||||
PyArg_GetShort(register PyObject *args, int nargs, int i, short *p_arg)
|
||||
{
|
||||
long x;
|
||||
if (!PyArg_GetLong(args, nargs, i, &x))
|
||||
return 0;
|
||||
*p_arg = (short) x;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
extractdouble(register PyObject *v, double *p_arg)
|
||||
{
|
||||
if (v == NULL) {
|
||||
/* Fall through to error return at end of function */
|
||||
}
|
||||
else if (PyFloat_Check(v)) {
|
||||
*p_arg = PyFloat_AS_DOUBLE((PyFloatObject *)v);
|
||||
return 1;
|
||||
}
|
||||
else if (PyInt_Check(v)) {
|
||||
*p_arg = PyInt_AS_LONG((PyIntObject *)v);
|
||||
return 1;
|
||||
}
|
||||
else if (PyLong_Check(v)) {
|
||||
*p_arg = PyLong_AsDouble(v);
|
||||
return 1;
|
||||
}
|
||||
return PyErr_BadArgument();
|
||||
}
|
||||
|
||||
static int
|
||||
extractfloat(register PyObject *v, float *p_arg)
|
||||
{
|
||||
if (v == NULL) {
|
||||
/* Fall through to error return at end of function */
|
||||
}
|
||||
else if (PyFloat_Check(v)) {
|
||||
*p_arg = (float) PyFloat_AS_DOUBLE((PyFloatObject *)v);
|
||||
return 1;
|
||||
}
|
||||
else if (PyInt_Check(v)) {
|
||||
*p_arg = (float) PyInt_AS_LONG((PyIntObject *)v);
|
||||
return 1;
|
||||
}
|
||||
else if (PyLong_Check(v)) {
|
||||
*p_arg = (float) PyLong_AsDouble(v);
|
||||
return 1;
|
||||
}
|
||||
return PyErr_BadArgument();
|
||||
}
|
||||
|
||||
int
|
||||
PyArg_GetFloat(register PyObject *args, int nargs, int i, float *p_arg)
|
||||
{
|
||||
PyObject *v;
|
||||
float x;
|
||||
if (!PyArg_GetObject(args, nargs, i, &v))
|
||||
return 0;
|
||||
if (!extractfloat(v, &x))
|
||||
return 0;
|
||||
*p_arg = x;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int
|
||||
PyArg_GetString(PyObject *args, int nargs, int i, string *p_arg)
|
||||
{
|
||||
PyObject *v;
|
||||
if (!PyArg_GetObject(args, nargs, i, &v))
|
||||
return 0;
|
||||
if (!PyString_Check(v)) {
|
||||
return PyErr_BadArgument();
|
||||
}
|
||||
*p_arg = PyString_AsString(v);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int
|
||||
PyArg_GetChar(PyObject *args, int nargs, int i, char *p_arg)
|
||||
{
|
||||
string x;
|
||||
if (!PyArg_GetString(args, nargs, i, &x))
|
||||
return 0;
|
||||
if (x[0] == '\0' || x[1] != '\0') {
|
||||
/* Not exactly one char */
|
||||
return PyErr_BadArgument();
|
||||
}
|
||||
*p_arg = x[0];
|
||||
return 1;
|
||||
}
|
||||
|
||||
int
|
||||
PyArg_GetLongArraySize(PyObject *args, int nargs, int i, long *p_arg)
|
||||
{
|
||||
PyObject *v;
|
||||
if (!PyArg_GetObject(args, nargs, i, &v))
|
||||
return 0;
|
||||
if (PyTuple_Check(v)) {
|
||||
*p_arg = PyTuple_Size(v);
|
||||
return 1;
|
||||
}
|
||||
if (PyList_Check(v)) {
|
||||
*p_arg = PyList_Size(v);
|
||||
return 1;
|
||||
}
|
||||
return PyErr_BadArgument();
|
||||
}
|
||||
|
||||
int
|
||||
PyArg_GetShortArraySize(PyObject *args, int nargs, int i, short *p_arg)
|
||||
{
|
||||
long x;
|
||||
if (!PyArg_GetLongArraySize(args, nargs, i, &x))
|
||||
return 0;
|
||||
*p_arg = (short) x;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* XXX The following four are too similar. Should share more code. */
|
||||
|
||||
int
|
||||
PyArg_GetLongArray(PyObject *args, int nargs, int i, int n, long *p_arg)
|
||||
{
|
||||
PyObject *v, *w;
|
||||
if (!PyArg_GetObject(args, nargs, i, &v))
|
||||
return 0;
|
||||
if (PyTuple_Check(v)) {
|
||||
if (PyTuple_Size(v) != n) {
|
||||
return PyErr_BadArgument();
|
||||
}
|
||||
for (i = 0; i < n; i++) {
|
||||
w = PyTuple_GetItem(v, i);
|
||||
if (!PyInt_Check(w)) {
|
||||
return PyErr_BadArgument();
|
||||
}
|
||||
p_arg[i] = PyInt_AsLong(w);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
else if (PyList_Check(v)) {
|
||||
if (PyList_Size(v) != n) {
|
||||
return PyErr_BadArgument();
|
||||
}
|
||||
for (i = 0; i < n; i++) {
|
||||
w = PyList_GetItem(v, i);
|
||||
if (!PyInt_Check(w)) {
|
||||
return PyErr_BadArgument();
|
||||
}
|
||||
p_arg[i] = PyInt_AsLong(w);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
else {
|
||||
return PyErr_BadArgument();
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
PyArg_GetShortArray(PyObject *args, int nargs, int i, int n, short *p_arg)
|
||||
{
|
||||
PyObject *v, *w;
|
||||
if (!PyArg_GetObject(args, nargs, i, &v))
|
||||
return 0;
|
||||
if (PyTuple_Check(v)) {
|
||||
if (PyTuple_Size(v) != n) {
|
||||
return PyErr_BadArgument();
|
||||
}
|
||||
for (i = 0; i < n; i++) {
|
||||
w = PyTuple_GetItem(v, i);
|
||||
if (!PyInt_Check(w)) {
|
||||
return PyErr_BadArgument();
|
||||
}
|
||||
p_arg[i] = (short) PyInt_AsLong(w);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
else if (PyList_Check(v)) {
|
||||
if (PyList_Size(v) != n) {
|
||||
return PyErr_BadArgument();
|
||||
}
|
||||
for (i = 0; i < n; i++) {
|
||||
w = PyList_GetItem(v, i);
|
||||
if (!PyInt_Check(w)) {
|
||||
return PyErr_BadArgument();
|
||||
}
|
||||
p_arg[i] = (short) PyInt_AsLong(w);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
else {
|
||||
return PyErr_BadArgument();
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
PyArg_GetDoubleArray(PyObject *args, int nargs, int i, int n, double *p_arg)
|
||||
{
|
||||
PyObject *v, *w;
|
||||
if (!PyArg_GetObject(args, nargs, i, &v))
|
||||
return 0;
|
||||
if (PyTuple_Check(v)) {
|
||||
if (PyTuple_Size(v) != n) {
|
||||
return PyErr_BadArgument();
|
||||
}
|
||||
for (i = 0; i < n; i++) {
|
||||
w = PyTuple_GetItem(v, i);
|
||||
if (!extractdouble(w, &p_arg[i]))
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
else if (PyList_Check(v)) {
|
||||
if (PyList_Size(v) != n) {
|
||||
return PyErr_BadArgument();
|
||||
}
|
||||
for (i = 0; i < n; i++) {
|
||||
w = PyList_GetItem(v, i);
|
||||
if (!extractdouble(w, &p_arg[i]))
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
else {
|
||||
return PyErr_BadArgument();
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
PyArg_GetFloatArray(PyObject *args, int nargs, int i, int n, float *p_arg)
|
||||
{
|
||||
PyObject *v, *w;
|
||||
if (!PyArg_GetObject(args, nargs, i, &v))
|
||||
return 0;
|
||||
if (PyTuple_Check(v)) {
|
||||
if (PyTuple_Size(v) != n) {
|
||||
return PyErr_BadArgument();
|
||||
}
|
||||
for (i = 0; i < n; i++) {
|
||||
w = PyTuple_GetItem(v, i);
|
||||
if (!extractfloat(w, &p_arg[i]))
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
else if (PyList_Check(v)) {
|
||||
if (PyList_Size(v) != n) {
|
||||
return PyErr_BadArgument();
|
||||
}
|
||||
for (i = 0; i < n; i++) {
|
||||
w = PyList_GetItem(v, i);
|
||||
if (!extractfloat(w, &p_arg[i]))
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
else {
|
||||
return PyErr_BadArgument();
|
||||
}
|
||||
}
|
|
@ -1,64 +0,0 @@
|
|||
#ifndef Py_CGENSUPPORT_H
|
||||
#define Py_CGENSUPPORT_H
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/* Definitions used by cgen output */
|
||||
|
||||
/* XXX This file is obsolete. It is *only* used by glmodule.c. */
|
||||
|
||||
typedef char *string;
|
||||
|
||||
#define mknewlongobject(x) PyInt_FromLong(x)
|
||||
#define mknewshortobject(x) PyInt_FromLong((long)x)
|
||||
#define mknewfloatobject(x) PyFloat_FromDouble(x)
|
||||
#define mknewcharobject(ch) Py_BuildValue("c", ch)
|
||||
|
||||
#define getichararg PyArg_GetChar
|
||||
#define getidoublearray PyArg_GetDoubleArray
|
||||
#define getifloatarg PyArg_GetFloat
|
||||
#define getifloatarray PyArg_GetFloatArray
|
||||
#define getilongarg PyArg_GetLong
|
||||
#define getilongarray PyArg_GetLongArray
|
||||
#define getilongarraysize PyArg_GetLongArraySize
|
||||
#define getiobjectarg PyArg_GetObject
|
||||
#define getishortarg PyArg_GetShort
|
||||
#define getishortarray PyArg_GetShortArray
|
||||
#define getishortarraysize PyArg_GetShortArraySize
|
||||
#define getistringarg PyArg_GetString
|
||||
|
||||
extern int PyArg_GetObject(PyObject *args, int nargs,
|
||||
int i, PyObject **p_a);
|
||||
extern int PyArg_GetLong(PyObject *args, int nargs,
|
||||
int i, long *p_a);
|
||||
extern int PyArg_GetShort(PyObject *args, int nargs,
|
||||
int i, short *p_a);
|
||||
extern int PyArg_GetFloat(PyObject *args, int nargs,
|
||||
int i, float *p_a);
|
||||
extern int PyArg_GetString(PyObject *args, int nargs,
|
||||
int i, string *p_a);
|
||||
extern int PyArg_GetChar(PyObject *args, int nargs,
|
||||
int i, char *p_a);
|
||||
extern int PyArg_GetLongArray(PyObject *args, int nargs,
|
||||
int i, int n, long *p_a);
|
||||
extern int PyArg_GetShortArray(PyObject *args, int nargs,
|
||||
int i, int n, short *p_a);
|
||||
extern int PyArg_GetDoubleArray(PyObject *args, int nargs,
|
||||
int i, int n, double *p_a);
|
||||
extern int PyArg_GetFloatArray(PyObject *args, int nargs,
|
||||
int i, int n, float *p_a);
|
||||
extern int PyArg_GetLongArraySize(PyObject *args, int nargs,
|
||||
int i, long *p_a);
|
||||
extern int PyArg_GetShortArraySize(PyObject *args, int nargs,
|
||||
int i, short *p_a);
|
||||
extern int PyArg_GetDoubleArraySize(PyObject *args, int nargs,
|
||||
int i, double *p_a);
|
||||
extern int PyArg_GetFloatArraySize(PyObject *args, int nargs,
|
||||
int i, float *p_a);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /* !Py_CGENSUPPORT_H */
|
2559
Modules/clmodule.c
2559
Modules/clmodule.c
File diff suppressed because it is too large
Load Diff
2139
Modules/flmodule.c
2139
Modules/flmodule.c
File diff suppressed because it is too large
Load Diff
|
@ -1,264 +0,0 @@
|
|||
|
||||
/* Font Manager module */
|
||||
|
||||
#include "Python.h"
|
||||
|
||||
#include <gl.h>
|
||||
#include <device.h>
|
||||
#include <fmclient.h>
|
||||
|
||||
|
||||
/* Font Handle object implementation */
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
fmfonthandle fh_fh;
|
||||
} fhobject;
|
||||
|
||||
static PyTypeObject Fhtype;
|
||||
|
||||
#define is_fhobject(v) ((v)->ob_type == &Fhtype)
|
||||
|
||||
static PyObject *
|
||||
newfhobject(fmfonthandle fh)
|
||||
{
|
||||
fhobject *fhp;
|
||||
if (fh == NULL) {
|
||||
PyErr_SetString(PyExc_RuntimeError,
|
||||
"error creating new font handle");
|
||||
return NULL;
|
||||
}
|
||||
fhp = PyObject_New(fhobject, &Fhtype);
|
||||
if (fhp == NULL)
|
||||
return NULL;
|
||||
fhp->fh_fh = fh;
|
||||
return (PyObject *)fhp;
|
||||
}
|
||||
|
||||
/* Font Handle methods */
|
||||
|
||||
static PyObject *
|
||||
fh_scalefont(fhobject *self, PyObject *args)
|
||||
{
|
||||
double size;
|
||||
if (!PyArg_ParseTuple(args, "d", &size))
|
||||
return NULL;
|
||||
return newfhobject(fmscalefont(self->fh_fh, size));
|
||||
}
|
||||
|
||||
/* XXX fmmakefont */
|
||||
|
||||
static PyObject *
|
||||
fh_setfont(fhobject *self)
|
||||
{
|
||||
fmsetfont(self->fh_fh);
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
fh_getfontname(fhobject *self)
|
||||
{
|
||||
char fontname[256];
|
||||
int len;
|
||||
len = fmgetfontname(self->fh_fh, sizeof fontname, fontname);
|
||||
if (len < 0) {
|
||||
PyErr_SetString(PyExc_RuntimeError, "error in fmgetfontname");
|
||||
return NULL;
|
||||
}
|
||||
return PyString_FromStringAndSize(fontname, len);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
fh_getcomment(fhobject *self)
|
||||
{
|
||||
char comment[256];
|
||||
int len;
|
||||
len = fmgetcomment(self->fh_fh, sizeof comment, comment);
|
||||
if (len < 0) {
|
||||
PyErr_SetString(PyExc_RuntimeError, "error in fmgetcomment");
|
||||
return NULL;
|
||||
}
|
||||
return PyString_FromStringAndSize(comment, len);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
fh_getfontinfo(fhobject *self)
|
||||
{
|
||||
fmfontinfo info;
|
||||
if (fmgetfontinfo(self->fh_fh, &info) < 0) {
|
||||
PyErr_SetString(PyExc_RuntimeError, "error in fmgetfontinfo");
|
||||
return NULL;
|
||||
}
|
||||
return Py_BuildValue("(llllllll)",
|
||||
info.printermatched,
|
||||
info.fixed_width,
|
||||
info.xorig,
|
||||
info.yorig,
|
||||
info.xsize,
|
||||
info.ysize,
|
||||
info.height,
|
||||
info.nglyphs);
|
||||
}
|
||||
|
||||
#if 0
|
||||
static PyObject *
|
||||
fh_getwholemetrics(fhobject *self, PyObject *args)
|
||||
{
|
||||
}
|
||||
#endif
|
||||
|
||||
static PyObject *
|
||||
fh_getstrwidth(fhobject *self, PyObject *args)
|
||||
{
|
||||
char *str;
|
||||
if (!PyArg_ParseTuple(args, "s", &str))
|
||||
return NULL;
|
||||
return PyInt_FromLong(fmgetstrwidth(self->fh_fh, str));
|
||||
}
|
||||
|
||||
static PyMethodDef fh_methods[] = {
|
||||
{"scalefont", (PyCFunction)fh_scalefont, METH_VARARGS},
|
||||
{"setfont", (PyCFunction)fh_setfont, METH_NOARGS},
|
||||
{"getfontname", (PyCFunction)fh_getfontname, METH_NOARGS},
|
||||
{"getcomment", (PyCFunction)fh_getcomment, METH_NOARGS},
|
||||
{"getfontinfo", (PyCFunction)fh_getfontinfo, METH_NOARGS},
|
||||
#if 0
|
||||
{"getwholemetrics", (PyCFunction)fh_getwholemetrics, METH_VARARGS},
|
||||
#endif
|
||||
{"getstrwidth", (PyCFunction)fh_getstrwidth, METH_VARARGS},
|
||||
{NULL, NULL} /* sentinel */
|
||||
};
|
||||
|
||||
static PyObject *
|
||||
fh_getattr(fhobject *fhp, char *name)
|
||||
{
|
||||
return Py_FindMethod(fh_methods, (PyObject *)fhp, name);
|
||||
}
|
||||
|
||||
static void
|
||||
fh_dealloc(fhobject *fhp)
|
||||
{
|
||||
fmfreefont(fhp->fh_fh);
|
||||
PyObject_Del(fhp);
|
||||
}
|
||||
|
||||
static PyTypeObject Fhtype = {
|
||||
PyObject_HEAD_INIT(&PyType_Type)
|
||||
0, /*ob_size*/
|
||||
"fm.font handle", /*tp_name*/
|
||||
sizeof(fhobject), /*tp_size*/
|
||||
0, /*tp_itemsize*/
|
||||
/* methods */
|
||||
(destructor)fh_dealloc, /*tp_dealloc*/
|
||||
0, /*tp_print*/
|
||||
(getattrfunc)fh_getattr, /*tp_getattr*/
|
||||
0, /*tp_setattr*/
|
||||
0, /*tp_compare*/
|
||||
0, /*tp_repr*/
|
||||
};
|
||||
|
||||
|
||||
/* Font Manager functions */
|
||||
|
||||
static PyObject *
|
||||
fm_init(PyObject *self)
|
||||
{
|
||||
fminit();
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
fm_findfont(PyObject *self, PyObject *args)
|
||||
{
|
||||
char *str;
|
||||
if (!PyArg_ParseTuple(args, "s", &str))
|
||||
return NULL;
|
||||
return newfhobject(fmfindfont(str));
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
fm_prstr(PyObject *self, PyObject *args)
|
||||
{
|
||||
char *str;
|
||||
if (!PyArg_ParseTuple(args, "s", &str))
|
||||
return NULL;
|
||||
fmprstr(str);
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
/* XXX This uses a global variable as temporary! Not re-entrant! */
|
||||
|
||||
static PyObject *fontlist;
|
||||
|
||||
static void
|
||||
clientproc(char *fontname)
|
||||
{
|
||||
int err;
|
||||
PyObject *v;
|
||||
if (fontlist == NULL)
|
||||
return;
|
||||
v = PyString_FromString(fontname);
|
||||
if (v == NULL)
|
||||
err = -1;
|
||||
else {
|
||||
err = PyList_Append(fontlist, v);
|
||||
Py_DECREF(v);
|
||||
}
|
||||
if (err != 0) {
|
||||
Py_DECREF(fontlist);
|
||||
fontlist = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
fm_enumerate(PyObject *self)
|
||||
{
|
||||
PyObject *res;
|
||||
fontlist = PyList_New(0);
|
||||
if (fontlist == NULL)
|
||||
return NULL;
|
||||
fmenumerate(clientproc);
|
||||
res = fontlist;
|
||||
fontlist = NULL;
|
||||
return res;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
fm_setpath(PyObject *self, PyObject *args)
|
||||
{
|
||||
char *str;
|
||||
if (!PyArg_ParseTuple(args, "s", &str))
|
||||
return NULL;
|
||||
fmsetpath(str);
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
fm_fontpath(PyObject *self)
|
||||
{
|
||||
return PyString_FromString(fmfontpath());
|
||||
}
|
||||
|
||||
static PyMethodDef fm_methods[] = {
|
||||
{"init", fm_init, METH_NOARGS},
|
||||
{"findfont", fm_findfont, METH_VARARGS},
|
||||
{"enumerate", fm_enumerate, METH_NOARGS},
|
||||
{"prstr", fm_prstr, METH_VARARGS},
|
||||
{"setpath", fm_setpath, METH_VARARGS},
|
||||
{"fontpath", fm_fontpath, METH_NOARGS},
|
||||
{NULL, NULL} /* sentinel */
|
||||
};
|
||||
|
||||
|
||||
void
|
||||
initfm(void)
|
||||
{
|
||||
Py_InitModule("fm", fm_methods);
|
||||
if (m == NULL)
|
||||
return;
|
||||
fminit();
|
||||
}
|
7628
Modules/glmodule.c
7628
Modules/glmodule.c
File diff suppressed because it is too large
Load Diff
|
@ -1,504 +0,0 @@
|
|||
|
||||
/* IMGFILE module - Interface to sgi libimage */
|
||||
|
||||
/* XXX This module should be done better at some point. It should return
|
||||
** an object of image file class, and have routines to manipulate these
|
||||
** image files in a neater way (so you can get rgb images off a greyscale
|
||||
** file, for instance, or do a straight display without having to get the
|
||||
** image bits into python, etc).
|
||||
**
|
||||
** Warning: this module is very non-reentrant (esp. the readscaled stuff)
|
||||
*/
|
||||
|
||||
#include "Python.h"
|
||||
|
||||
#include <gl/image.h>
|
||||
|
||||
#include "/usr/people/4Dgifts/iristools/include/izoom.h"
|
||||
|
||||
/* Bunch of missing extern decls; keep gcc -Wall happy... */
|
||||
extern void i_seterror();
|
||||
extern void iclose();
|
||||
extern void filterzoom();
|
||||
extern void putrow();
|
||||
extern void getrow();
|
||||
|
||||
static PyObject * ImgfileError; /* Exception we raise for various trouble */
|
||||
|
||||
static int top_to_bottom; /* True if we want top-to-bottom images */
|
||||
|
||||
/* The image library does not always call the error hander :-(,
|
||||
therefore we have a global variable indicating that it was called.
|
||||
It is cleared by imgfile_open(). */
|
||||
|
||||
static int error_called;
|
||||
|
||||
|
||||
/* The error handler */
|
||||
|
||||
static void
|
||||
imgfile_error(char *str)
|
||||
{
|
||||
PyErr_SetString(ImgfileError, str);
|
||||
error_called = 1;
|
||||
return; /* To imglib, which will return a failure indicator */
|
||||
}
|
||||
|
||||
|
||||
/* Open an image file and return a pointer to it.
|
||||
Make sure we raise an exception if we fail. */
|
||||
|
||||
static IMAGE *
|
||||
imgfile_open(char *fname)
|
||||
{
|
||||
IMAGE *image;
|
||||
i_seterror(imgfile_error);
|
||||
error_called = 0;
|
||||
errno = 0;
|
||||
if ( (image = iopen(fname, "r")) == NULL ) {
|
||||
/* Error may already be set by imgfile_error */
|
||||
if ( !error_called ) {
|
||||
if (errno)
|
||||
PyErr_SetFromErrno(ImgfileError);
|
||||
else
|
||||
PyErr_SetString(ImgfileError,
|
||||
"Can't open image file");
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
return image;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
imgfile_ttob(PyObject *self, PyObject *args)
|
||||
{
|
||||
int newval;
|
||||
PyObject *rv;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "i:ttob", &newval))
|
||||
return NULL;
|
||||
rv = PyInt_FromLong(top_to_bottom);
|
||||
top_to_bottom = newval;
|
||||
return rv;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
imgfile_read(PyObject *self, PyObject *args)
|
||||
{
|
||||
char *fname;
|
||||
PyObject *rv;
|
||||
int xsize, ysize, zsize;
|
||||
char *cdatap;
|
||||
long *idatap;
|
||||
static short rs[8192], gs[8192], bs[8192];
|
||||
int x, y;
|
||||
IMAGE *image;
|
||||
int yfirst, ylast, ystep;
|
||||
|
||||
if ( !PyArg_ParseTuple(args, "s:read", &fname) )
|
||||
return NULL;
|
||||
|
||||
if ( (image = imgfile_open(fname)) == NULL )
|
||||
return NULL;
|
||||
|
||||
if ( image->colormap != CM_NORMAL ) {
|
||||
iclose(image);
|
||||
PyErr_SetString(ImgfileError,
|
||||
"Can only handle CM_NORMAL images");
|
||||
return NULL;
|
||||
}
|
||||
if ( BPP(image->type) != 1 ) {
|
||||
iclose(image);
|
||||
PyErr_SetString(ImgfileError,
|
||||
"Can't handle imgfiles with bpp!=1");
|
||||
return NULL;
|
||||
}
|
||||
xsize = image->xsize;
|
||||
ysize = image->ysize;
|
||||
zsize = image->zsize;
|
||||
if ( zsize != 1 && zsize != 3) {
|
||||
iclose(image);
|
||||
PyErr_SetString(ImgfileError,
|
||||
"Can only handle 1 or 3 byte pixels");
|
||||
return NULL;
|
||||
}
|
||||
if ( xsize > 8192 ) {
|
||||
iclose(image);
|
||||
PyErr_SetString(ImgfileError,
|
||||
"Can't handle image with > 8192 columns");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if ( zsize == 3 ) zsize = 4;
|
||||
rv = PyString_FromStringAndSize((char *)NULL, xsize*ysize*zsize);
|
||||
if ( rv == NULL ) {
|
||||
iclose(image);
|
||||
return NULL;
|
||||
}
|
||||
cdatap = PyString_AsString(rv);
|
||||
idatap = (long *)cdatap;
|
||||
|
||||
if (top_to_bottom) {
|
||||
yfirst = ysize-1;
|
||||
ylast = -1;
|
||||
ystep = -1;
|
||||
} else {
|
||||
yfirst = 0;
|
||||
ylast = ysize;
|
||||
ystep = 1;
|
||||
}
|
||||
for ( y=yfirst; y != ylast && !error_called; y += ystep ) {
|
||||
if ( zsize == 1 ) {
|
||||
getrow(image, rs, y, 0);
|
||||
for(x=0; x<xsize; x++ )
|
||||
*cdatap++ = rs[x];
|
||||
} else {
|
||||
getrow(image, rs, y, 0);
|
||||
getrow(image, gs, y, 1);
|
||||
getrow(image, bs, y, 2);
|
||||
for(x=0; x<xsize; x++ )
|
||||
*idatap++ = (rs[x] & 0xff) |
|
||||
((gs[x] & 0xff)<<8) |
|
||||
((bs[x] & 0xff)<<16);
|
||||
}
|
||||
}
|
||||
iclose(image);
|
||||
if ( error_called ) {
|
||||
Py_DECREF(rv);
|
||||
return NULL;
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
static IMAGE *glob_image;
|
||||
static long *glob_datap;
|
||||
static int glob_width, glob_z, glob_ysize;
|
||||
|
||||
static void
|
||||
xs_get(short *buf, int y)
|
||||
{
|
||||
if (top_to_bottom)
|
||||
getrow(glob_image, buf, (glob_ysize-1-y), glob_z);
|
||||
else
|
||||
getrow(glob_image, buf, y, glob_z);
|
||||
}
|
||||
|
||||
static void
|
||||
xs_put_c(short *buf, int y)
|
||||
{
|
||||
char *datap = (char *)glob_datap + y*glob_width;
|
||||
int width = glob_width;
|
||||
|
||||
while ( width-- )
|
||||
*datap++ = (*buf++) & 0xff;
|
||||
}
|
||||
|
||||
static void
|
||||
xs_put_0(short *buf, int y)
|
||||
{
|
||||
long *datap = glob_datap + y*glob_width;
|
||||
int width = glob_width;
|
||||
|
||||
while ( width-- )
|
||||
*datap++ = (*buf++) & 0xff;
|
||||
}
|
||||
static void
|
||||
xs_put_12(short *buf, int y)
|
||||
{
|
||||
long *datap = glob_datap + y*glob_width;
|
||||
int width = glob_width;
|
||||
|
||||
while ( width-- )
|
||||
*datap++ |= ((*buf++) & 0xff) << (glob_z*8);
|
||||
}
|
||||
|
||||
static void
|
||||
xscale(IMAGE *image, int xsize, int ysize, int zsize,
|
||||
long *datap, int xnew, int ynew, int fmode, double blur)
|
||||
{
|
||||
glob_image = image;
|
||||
glob_datap = datap;
|
||||
glob_width = xnew;
|
||||
glob_ysize = ysize;
|
||||
if ( zsize == 1 ) {
|
||||
glob_z = 0;
|
||||
filterzoom(xs_get, xs_put_c, xsize, ysize,
|
||||
xnew, ynew, fmode, blur);
|
||||
} else {
|
||||
glob_z = 0;
|
||||
filterzoom(xs_get, xs_put_0, xsize, ysize,
|
||||
xnew, ynew, fmode, blur);
|
||||
glob_z = 1;
|
||||
filterzoom(xs_get, xs_put_12, xsize, ysize,
|
||||
xnew, ynew, fmode, blur);
|
||||
glob_z = 2;
|
||||
filterzoom(xs_get, xs_put_12, xsize, ysize,
|
||||
xnew, ynew, fmode, blur);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static PyObject *
|
||||
imgfile_readscaled(PyObject *self, PyObject *args)
|
||||
{
|
||||
char *fname;
|
||||
PyObject *rv;
|
||||
int xsize, ysize, zsize;
|
||||
char *cdatap;
|
||||
long *idatap;
|
||||
static short rs[8192], gs[8192], bs[8192];
|
||||
int x, y;
|
||||
int xwtd, ywtd, xorig, yorig;
|
||||
float xfac, yfac;
|
||||
IMAGE *image;
|
||||
char *filter;
|
||||
double blur = 1.0;
|
||||
int extended;
|
||||
int fmode = 0;
|
||||
int yfirst, ylast, ystep;
|
||||
|
||||
/*
|
||||
** Parse args. Funny, since arg 4 and 5 are optional
|
||||
** (filter name and blur factor). Also, 4 or 5 arguments indicates
|
||||
** extended scale algorithm in stead of simple-minded pixel drop/dup.
|
||||
*/
|
||||
extended = PyTuple_Size(args) >= 4;
|
||||
if ( !PyArg_ParseTuple(args, "sii|sd",
|
||||
&fname, &xwtd, &ywtd, &filter, &blur) )
|
||||
return NULL;
|
||||
|
||||
/*
|
||||
** Check parameters, open file and check type, rows, etc.
|
||||
*/
|
||||
if ( extended ) {
|
||||
if ( strcmp(filter, "impulse") == 0 )
|
||||
fmode = IMPULSE;
|
||||
else if ( strcmp( filter, "box") == 0 )
|
||||
fmode = BOX;
|
||||
else if ( strcmp( filter, "triangle") == 0 )
|
||||
fmode = TRIANGLE;
|
||||
else if ( strcmp( filter, "quadratic") == 0 )
|
||||
fmode = QUADRATIC;
|
||||
else if ( strcmp( filter, "gaussian") == 0 )
|
||||
fmode = GAUSSIAN;
|
||||
else {
|
||||
PyErr_SetString(ImgfileError, "Unknown filter type");
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if ( (image = imgfile_open(fname)) == NULL )
|
||||
return NULL;
|
||||
|
||||
if ( image->colormap != CM_NORMAL ) {
|
||||
iclose(image);
|
||||
PyErr_SetString(ImgfileError,
|
||||
"Can only handle CM_NORMAL images");
|
||||
return NULL;
|
||||
}
|
||||
if ( BPP(image->type) != 1 ) {
|
||||
iclose(image);
|
||||
PyErr_SetString(ImgfileError,
|
||||
"Can't handle imgfiles with bpp!=1");
|
||||
return NULL;
|
||||
}
|
||||
xsize = image->xsize;
|
||||
ysize = image->ysize;
|
||||
zsize = image->zsize;
|
||||
if ( zsize != 1 && zsize != 3) {
|
||||
iclose(image);
|
||||
PyErr_SetString(ImgfileError,
|
||||
"Can only handle 1 or 3 byte pixels");
|
||||
return NULL;
|
||||
}
|
||||
if ( xsize > 8192 ) {
|
||||
iclose(image);
|
||||
PyErr_SetString(ImgfileError,
|
||||
"Can't handle image with > 8192 columns");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if ( zsize == 3 ) zsize = 4;
|
||||
rv = PyString_FromStringAndSize(NULL, xwtd*ywtd*zsize);
|
||||
if ( rv == NULL ) {
|
||||
iclose(image);
|
||||
return NULL;
|
||||
}
|
||||
PyFPE_START_PROTECT("readscaled", return 0)
|
||||
xfac = (float)xsize/(float)xwtd;
|
||||
yfac = (float)ysize/(float)ywtd;
|
||||
PyFPE_END_PROTECT(yfac)
|
||||
cdatap = PyString_AsString(rv);
|
||||
idatap = (long *)cdatap;
|
||||
|
||||
if ( extended ) {
|
||||
xscale(image, xsize, ysize, zsize,
|
||||
idatap, xwtd, ywtd, fmode, blur);
|
||||
} else {
|
||||
if (top_to_bottom) {
|
||||
yfirst = ywtd-1;
|
||||
ylast = -1;
|
||||
ystep = -1;
|
||||
} else {
|
||||
yfirst = 0;
|
||||
ylast = ywtd;
|
||||
ystep = 1;
|
||||
}
|
||||
for ( y=yfirst; y != ylast && !error_called; y += ystep ) {
|
||||
yorig = (int)(y*yfac);
|
||||
if ( zsize == 1 ) {
|
||||
getrow(image, rs, yorig, 0);
|
||||
for(x=0; x<xwtd; x++ ) {
|
||||
*cdatap++ = rs[(int)(x*xfac)];
|
||||
}
|
||||
} else {
|
||||
getrow(image, rs, yorig, 0);
|
||||
getrow(image, gs, yorig, 1);
|
||||
getrow(image, bs, yorig, 2);
|
||||
for(x=0; x<xwtd; x++ ) {
|
||||
xorig = (int)(x*xfac);
|
||||
*idatap++ = (rs[xorig] & 0xff) |
|
||||
((gs[xorig] & 0xff)<<8) |
|
||||
((bs[xorig] & 0xff)<<16);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
iclose(image);
|
||||
if ( error_called ) {
|
||||
Py_DECREF(rv);
|
||||
return NULL;
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
imgfile_getsizes(PyObject *self, PyObject *args)
|
||||
{
|
||||
char *fname;
|
||||
PyObject *rv;
|
||||
IMAGE *image;
|
||||
|
||||
if ( !PyArg_ParseTuple(args, "s:getsizes", &fname) )
|
||||
return NULL;
|
||||
|
||||
if ( (image = imgfile_open(fname)) == NULL )
|
||||
return NULL;
|
||||
rv = Py_BuildValue("(iii)", image->xsize, image->ysize, image->zsize);
|
||||
iclose(image);
|
||||
return rv;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
imgfile_write(PyObject *self, PyObject *args)
|
||||
{
|
||||
IMAGE *image;
|
||||
char *fname;
|
||||
int xsize, ysize, zsize, len;
|
||||
char *cdatap;
|
||||
long *idatap;
|
||||
short rs[8192], gs[8192], bs[8192];
|
||||
short r, g, b;
|
||||
long rgb;
|
||||
int x, y;
|
||||
int yfirst, ylast, ystep;
|
||||
|
||||
|
||||
if ( !PyArg_ParseTuple(args, "ss#iii:write",
|
||||
&fname, &cdatap, &len, &xsize, &ysize, &zsize) )
|
||||
return NULL;
|
||||
|
||||
if ( zsize != 1 && zsize != 3 ) {
|
||||
PyErr_SetString(ImgfileError,
|
||||
"Can only handle 1 or 3 byte pixels");
|
||||
return NULL;
|
||||
}
|
||||
if ( len != xsize * ysize * (zsize == 1 ? 1 : 4) ) {
|
||||
PyErr_SetString(ImgfileError, "Data does not match sizes");
|
||||
return NULL;
|
||||
}
|
||||
if ( xsize > 8192 ) {
|
||||
PyErr_SetString(ImgfileError,
|
||||
"Can't handle image with > 8192 columns");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
error_called = 0;
|
||||
errno = 0;
|
||||
image =iopen(fname, "w", RLE(1), 3, xsize, ysize, zsize);
|
||||
if ( image == 0 ) {
|
||||
if ( ! error_called ) {
|
||||
if (errno)
|
||||
PyErr_SetFromErrno(ImgfileError);
|
||||
else
|
||||
PyErr_SetString(ImgfileError,
|
||||
"Can't create image file");
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
idatap = (long *)cdatap;
|
||||
|
||||
if (top_to_bottom) {
|
||||
yfirst = ysize-1;
|
||||
ylast = -1;
|
||||
ystep = -1;
|
||||
} else {
|
||||
yfirst = 0;
|
||||
ylast = ysize;
|
||||
ystep = 1;
|
||||
}
|
||||
for ( y=yfirst; y != ylast && !error_called; y += ystep ) {
|
||||
if ( zsize == 1 ) {
|
||||
for( x=0; x<xsize; x++ )
|
||||
rs[x] = *cdatap++;
|
||||
putrow(image, rs, y, 0);
|
||||
} else {
|
||||
for( x=0; x<xsize; x++ ) {
|
||||
rgb = *idatap++;
|
||||
r = rgb & 0xff;
|
||||
g = (rgb >> 8 ) & 0xff;
|
||||
b = (rgb >> 16 ) & 0xff;
|
||||
rs[x] = r;
|
||||
gs[x] = g;
|
||||
bs[x] = b;
|
||||
}
|
||||
putrow(image, rs, y, 0);
|
||||
putrow(image, gs, y, 1);
|
||||
putrow(image, bs, y, 2);
|
||||
}
|
||||
}
|
||||
iclose(image);
|
||||
if ( error_called )
|
||||
return NULL;
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
|
||||
}
|
||||
|
||||
|
||||
static PyMethodDef imgfile_methods[] = {
|
||||
{ "getsizes", imgfile_getsizes, METH_VARARGS },
|
||||
{ "read", imgfile_read, METH_VARARGS },
|
||||
{ "readscaled", imgfile_readscaled, METH_VARARGS},
|
||||
{ "write", imgfile_write, METH_VARARGS },
|
||||
{ "ttob", imgfile_ttob, METH_VARARGS },
|
||||
{ NULL, NULL } /* Sentinel */
|
||||
};
|
||||
|
||||
|
||||
void
|
||||
initimgfile(void)
|
||||
{
|
||||
PyObject *m, *d;
|
||||
m = Py_InitModule("imgfile", imgfile_methods);
|
||||
if (m == NULL)
|
||||
return;
|
||||
d = PyModule_GetDict(m);
|
||||
ImgfileError = PyErr_NewException("imgfile.error", NULL, NULL);
|
||||
if (ImgfileError != NULL)
|
||||
PyDict_SetItemString(d, "error", ImgfileError);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -867,7 +867,8 @@ VALIDATER(while); VALIDATER(for);
|
|||
VALIDATER(try); VALIDATER(except_clause);
|
||||
VALIDATER(test); VALIDATER(and_test);
|
||||
VALIDATER(not_test); VALIDATER(comparison);
|
||||
VALIDATER(comp_op); VALIDATER(expr);
|
||||
VALIDATER(comp_op);
|
||||
VALIDATER(star_expr); VALIDATER(expr);
|
||||
VALIDATER(xor_expr); VALIDATER(and_expr);
|
||||
VALIDATER(shift_expr); VALIDATER(arith_expr);
|
||||
VALIDATER(term); VALIDATER(factor);
|
||||
|
@ -2094,11 +2095,11 @@ validate_comparison(node *tree)
|
|||
int nch = NCH(tree);
|
||||
int res = (validate_ntype(tree, comparison)
|
||||
&& is_odd(nch)
|
||||
&& validate_expr(CHILD(tree, 0)));
|
||||
&& validate_star_expr(CHILD(tree, 0)));
|
||||
|
||||
for (pos = 1; res && (pos < nch); pos += 2)
|
||||
res = (validate_comp_op(CHILD(tree, pos))
|
||||
&& validate_expr(CHILD(tree, pos + 1)));
|
||||
&& validate_star_expr(CHILD(tree, pos + 1)));
|
||||
|
||||
return (res);
|
||||
}
|
||||
|
@ -2155,6 +2156,20 @@ validate_comp_op(node *tree)
|
|||
}
|
||||
|
||||
|
||||
static int
|
||||
validate_star_expr(node *tree)
|
||||
{
|
||||
int res = validate_ntype(tree, star_expr);
|
||||
if (!res) return res;
|
||||
if (NCH(tree) == 2) {
|
||||
return validate_ntype(CHILD(tree, 0), STAR) && \
|
||||
validate_expr(CHILD(tree, 1));
|
||||
} else {
|
||||
return validate_expr(CHILD(tree, 0));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
validate_expr(node *tree)
|
||||
{
|
||||
|
@ -2745,7 +2760,7 @@ static int
|
|||
validate_exprlist(node *tree)
|
||||
{
|
||||
return (validate_repeating_list(tree, exprlist,
|
||||
validate_expr, "exprlist"));
|
||||
validate_star_expr, "exprlist"));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,55 +0,0 @@
|
|||
|
||||
/* SGI module -- random SGI-specific things */
|
||||
|
||||
#include "Python.h"
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
static PyObject *
|
||||
sgi_nap(PyObject *self, PyObject *args)
|
||||
{
|
||||
long ticks;
|
||||
if (!PyArg_ParseTuple(args, "l:nap", &ticks))
|
||||
return NULL;
|
||||
Py_BEGIN_ALLOW_THREADS
|
||||
sginap(ticks);
|
||||
Py_END_ALLOW_THREADS
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
extern char *_getpty(int *, int, mode_t, int);
|
||||
|
||||
static PyObject *
|
||||
sgi__getpty(PyObject *self, PyObject *args)
|
||||
{
|
||||
int oflag;
|
||||
int mode;
|
||||
int nofork;
|
||||
char *name;
|
||||
int fildes;
|
||||
if (!PyArg_ParseTuple(args, "iii:_getpty", &oflag, &mode, &nofork))
|
||||
return NULL;
|
||||
errno = 0;
|
||||
name = _getpty(&fildes, oflag, (mode_t)mode, nofork);
|
||||
if (name == NULL) {
|
||||
PyErr_SetFromErrno(PyExc_IOError);
|
||||
return NULL;
|
||||
}
|
||||
return Py_BuildValue("(si)", name, fildes);
|
||||
}
|
||||
|
||||
static PyMethodDef sgi_methods[] = {
|
||||
{"nap", sgi_nap, METH_VARARGS},
|
||||
{"_getpty", sgi__getpty, METH_VARARGS},
|
||||
{NULL, NULL} /* sentinel */
|
||||
};
|
||||
|
||||
|
||||
void
|
||||
initsgi(void)
|
||||
{
|
||||
Py_InitModule("sgi", sgi_methods);
|
||||
}
|
|
@ -1,966 +0,0 @@
|
|||
/* SV module -- interface to the Indigo video board */
|
||||
|
||||
/* WARNING! This module is for hardware that we don't have any more,
|
||||
so it hasn't been tested. It has been converted to the new coding
|
||||
style, and it is possible that this conversion has broken something
|
||||
-- user beware! */
|
||||
|
||||
#include <sys/time.h>
|
||||
#include <svideo.h>
|
||||
#include "Python.h"
|
||||
#include "compile.h"
|
||||
#include "yuv.h" /* for YUV conversion functions */
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
SV_nodeP ob_svideo;
|
||||
svCaptureInfo ob_info;
|
||||
} svobject;
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
void *ob_capture;
|
||||
int ob_mustunlock;
|
||||
svCaptureInfo ob_info;
|
||||
svobject *ob_svideo;
|
||||
} captureobject;
|
||||
|
||||
static PyObject *SvError; /* exception sv.error */
|
||||
|
||||
static PyObject *newcaptureobject(svobject *, void *, int);
|
||||
|
||||
/* Set a SV-specific error from svideo_errno and return NULL */
|
||||
static PyObject *
|
||||
sv_error(void)
|
||||
{
|
||||
PyErr_SetString(SvError, svStrerror(svideo_errno));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
svc_conversion(captureobject *self, PyObject *args, void (*function)(), float factor)
|
||||
{
|
||||
PyObject *output;
|
||||
int invert;
|
||||
char* outstr;
|
||||
|
||||
if (!PyArg_Parse(args, "i", &invert))
|
||||
return NULL;
|
||||
|
||||
if (!(output = PyString_FromStringAndSize(
|
||||
NULL,
|
||||
(int)(self->ob_info.width * self->ob_info.height * factor))))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
if (!(outstr = PyString_AsString(output))) {
|
||||
Py_DECREF(output);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
(*function)((boolean)invert, self->ob_capture,
|
||||
outstr,
|
||||
self->ob_info.width, self->ob_info.height);
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
/*
|
||||
* 3 functions to convert from Starter Video YUV 4:1:1 format to
|
||||
* Compression Library 4:2:2 Duplicate Chroma format.
|
||||
*/
|
||||
static PyObject *
|
||||
svc_YUVtoYUV422DC(captureobject *self, PyObject *args)
|
||||
{
|
||||
if (self->ob_info.format != SV_YUV411_FRAMES) {
|
||||
PyErr_SetString(SvError, "data has bad format");
|
||||
return NULL;
|
||||
}
|
||||
return svc_conversion(self, args, yuv_sv411_to_cl422dc, 2.0);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
svc_YUVtoYUV422DC_quarter(captureobject *self, PyObject *args)
|
||||
{
|
||||
if (self->ob_info.format != SV_YUV411_FRAMES) {
|
||||
PyErr_SetString(SvError, "data has bad format");
|
||||
return NULL;
|
||||
}
|
||||
return svc_conversion(self, args,
|
||||
yuv_sv411_to_cl422dc_quartersize, 0.5);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
svc_YUVtoYUV422DC_sixteenth(captureobject *self, PyObject *args)
|
||||
{
|
||||
if (self->ob_info.format != SV_YUV411_FRAMES) {
|
||||
PyErr_SetString(SvError, "data has bad format");
|
||||
return NULL;
|
||||
}
|
||||
return svc_conversion(self, args,
|
||||
yuv_sv411_to_cl422dc_sixteenthsize, 0.125);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
svc_YUVtoRGB(captureobject *self, PyObject *args)
|
||||
{
|
||||
switch (self->ob_info.format) {
|
||||
case SV_YUV411_FRAMES:
|
||||
case SV_YUV411_FRAMES_AND_BLANKING_BUFFER:
|
||||
break;
|
||||
default:
|
||||
PyErr_SetString(SvError, "data had bad format");
|
||||
return NULL;
|
||||
}
|
||||
return svc_conversion(self, args, svYUVtoRGB, (float) sizeof(long));
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
svc_RGB8toRGB32(captureobject *self, PyObject *args)
|
||||
{
|
||||
if (self->ob_info.format != SV_RGB8_FRAMES) {
|
||||
PyErr_SetString(SvError, "data has bad format");
|
||||
return NULL;
|
||||
}
|
||||
return svc_conversion(self, args, svRGB8toRGB32, (float) sizeof(long));
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
svc_InterleaveFields(captureobject *self, PyObject *args)
|
||||
{
|
||||
if (self->ob_info.format != SV_RGB8_FRAMES) {
|
||||
PyErr_SetString(SvError, "data has bad format");
|
||||
return NULL;
|
||||
}
|
||||
return svc_conversion(self, args, svInterleaveFields, 1.0);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
svc_GetFields(captureobject *self, PyObject *args)
|
||||
{
|
||||
PyObject *f1 = NULL;
|
||||
PyObject *f2 = NULL;
|
||||
PyObject *ret = NULL;
|
||||
int fieldsize;
|
||||
char* obcapture;
|
||||
|
||||
if (self->ob_info.format != SV_RGB8_FRAMES) {
|
||||
PyErr_SetString(SvError, "data has bad format");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
fieldsize = self->ob_info.width * self->ob_info.height / 2;
|
||||
obcapture = (char*)self->ob_capture;
|
||||
|
||||
if (!(f1 = PyString_FromStringAndSize(obcapture, fieldsize)))
|
||||
goto finally;
|
||||
if (!(f2 = PyString_FromStringAndSize(obcapture + fieldsize,
|
||||
fieldsize)))
|
||||
goto finally;
|
||||
ret = PyTuple_Pack(2, f1, f2);
|
||||
|
||||
finally:
|
||||
Py_XDECREF(f1);
|
||||
Py_XDECREF(f2);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
svc_UnlockCaptureData(captureobject *self, PyObject *args)
|
||||
{
|
||||
if (!PyArg_Parse(args, ""))
|
||||
return NULL;
|
||||
|
||||
if (!self->ob_mustunlock) {
|
||||
PyErr_SetString(SvError, "buffer should not be unlocked");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (svUnlockCaptureData(self->ob_svideo->ob_svideo, self->ob_capture))
|
||||
return sv_error();
|
||||
|
||||
self->ob_mustunlock = 0;
|
||||
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
#ifdef USE_GL
|
||||
#include <gl.h>
|
||||
|
||||
static PyObject *
|
||||
svc_lrectwrite(captureobject *self, PyObject *args)
|
||||
{
|
||||
Screencoord x1, x2, y1, y2;
|
||||
|
||||
if (!PyArg_Parse(args, "(hhhh)", &x1, &x2, &y1, &y2))
|
||||
return NULL;
|
||||
|
||||
lrectwrite(x1, x2, y1, y2, (unsigned long *) self->ob_capture);
|
||||
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
#endif
|
||||
|
||||
static PyObject *
|
||||
svc_writefile(captureobject *self, PyObject *args)
|
||||
{
|
||||
PyObject *file;
|
||||
int size;
|
||||
FILE* fp;
|
||||
|
||||
if (!PyArg_Parse(args, "O", &file))
|
||||
return NULL;
|
||||
|
||||
if (!PyFile_Check(file)) {
|
||||
PyErr_SetString(SvError, "not a file object");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!(fp = PyFile_AsFile(file)))
|
||||
return NULL;
|
||||
|
||||
size = self->ob_info.width * self->ob_info.height;
|
||||
|
||||
if (fwrite(self->ob_capture, sizeof(long), size, fp) != size) {
|
||||
PyErr_SetString(SvError, "writing failed");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
svc_FindVisibleRegion(captureobject *self, PyObject *args)
|
||||
{
|
||||
void *visible;
|
||||
int width;
|
||||
|
||||
if (!PyArg_Parse(args, ""))
|
||||
return NULL;
|
||||
|
||||
if (svFindVisibleRegion(self->ob_svideo->ob_svideo,
|
||||
self->ob_capture, &visible,
|
||||
self->ob_info.width))
|
||||
return sv_error();
|
||||
|
||||
if (visible == NULL) {
|
||||
PyErr_SetString(SvError, "data in wrong format");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return newcaptureobject(self->ob_svideo, visible, 0);
|
||||
}
|
||||
|
||||
static PyMethodDef capture_methods[] = {
|
||||
{"YUVtoRGB", (PyCFunction)svc_YUVtoRGB, METH_OLDARGS},
|
||||
{"RGB8toRGB32", (PyCFunction)svc_RGB8toRGB32, METH_OLDARGS},
|
||||
{"InterleaveFields", (PyCFunction)svc_InterleaveFields, METH_OLDARGS},
|
||||
{"UnlockCaptureData", (PyCFunction)svc_UnlockCaptureData, METH_OLDARGS},
|
||||
{"FindVisibleRegion", (PyCFunction)svc_FindVisibleRegion, METH_OLDARGS},
|
||||
{"GetFields", (PyCFunction)svc_GetFields, METH_OLDARGS},
|
||||
{"YUVtoYUV422DC", (PyCFunction)svc_YUVtoYUV422DC, METH_OLDARGS},
|
||||
{"YUVtoYUV422DC_quarter",(PyCFunction)svc_YUVtoYUV422DC_quarter, METH_OLDARGS},
|
||||
{"YUVtoYUV422DC_sixteenth",(PyCFunction)svc_YUVtoYUV422DC_sixteenth, METH_OLDARGS},
|
||||
#ifdef USE_GL
|
||||
{"lrectwrite", (PyCFunction)svc_lrectwrite, METH_OLDARGS},
|
||||
#endif
|
||||
{"writefile", (PyCFunction)svc_writefile, METH_OLDARGS},
|
||||
{NULL, NULL} /* sentinel */
|
||||
};
|
||||
|
||||
static void
|
||||
capture_dealloc(captureobject *self)
|
||||
{
|
||||
if (self->ob_capture != NULL) {
|
||||
if (self->ob_mustunlock)
|
||||
(void)svUnlockCaptureData(self->ob_svideo->ob_svideo,
|
||||
self->ob_capture);
|
||||
self->ob_capture = NULL;
|
||||
Py_DECREF(self->ob_svideo);
|
||||
self->ob_svideo = NULL;
|
||||
}
|
||||
PyObject_Del(self);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
capture_getattr(svobject *self, char *name)
|
||||
{
|
||||
return Py_FindMethod(capture_methods, (PyObject *)self, name);
|
||||
}
|
||||
|
||||
PyTypeObject Capturetype = {
|
||||
PyObject_HEAD_INIT(&PyType_Type)
|
||||
0, /*ob_size*/
|
||||
"sv.capture", /*tp_name*/
|
||||
sizeof(captureobject), /*tp_size*/
|
||||
0, /*tp_itemsize*/
|
||||
/* methods */
|
||||
(destructor)capture_dealloc, /*tp_dealloc*/
|
||||
0, /*tp_print*/
|
||||
(getattrfunc)capture_getattr, /*tp_getattr*/
|
||||
0, /*tp_setattr*/
|
||||
0, /*tp_compare*/
|
||||
0, /*tp_repr*/
|
||||
};
|
||||
|
||||
static PyObject *
|
||||
newcaptureobject(svobject *self, void *ptr, int mustunlock)
|
||||
{
|
||||
captureobject *p;
|
||||
|
||||
p = PyObject_New(captureobject, &Capturetype);
|
||||
if (p == NULL)
|
||||
return NULL;
|
||||
p->ob_svideo = self;
|
||||
Py_INCREF(self);
|
||||
p->ob_capture = ptr;
|
||||
p->ob_mustunlock = mustunlock;
|
||||
p->ob_info = self->ob_info;
|
||||
return (PyObject *) p;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
sv_GetCaptureData(svobject *self, PyObject *args)
|
||||
{
|
||||
void *ptr;
|
||||
long fieldID;
|
||||
PyObject *res, *c;
|
||||
|
||||
if (!PyArg_Parse(args, ""))
|
||||
return NULL;
|
||||
|
||||
if (svGetCaptureData(self->ob_svideo, &ptr, &fieldID))
|
||||
return sv_error();
|
||||
|
||||
if (ptr == NULL) {
|
||||
PyErr_SetString(SvError, "no data available");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
c = newcaptureobject(self, ptr, 1);
|
||||
if (c == NULL)
|
||||
return NULL;
|
||||
res = Py_BuildValue("(Oi)", c, fieldID);
|
||||
Py_DECREF(c);
|
||||
return res;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
sv_BindGLWindow(svobject *self, PyObject *args)
|
||||
{
|
||||
long wid;
|
||||
int mode;
|
||||
|
||||
if (!PyArg_Parse(args, "(ii)", &wid, &mode))
|
||||
return NULL;
|
||||
|
||||
if (svBindGLWindow(self->ob_svideo, wid, mode))
|
||||
return sv_error();
|
||||
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
sv_EndContinuousCapture(svobject *self, PyObject *args)
|
||||
{
|
||||
|
||||
if (!PyArg_Parse(args, ""))
|
||||
return NULL;
|
||||
|
||||
if (svEndContinuousCapture(self->ob_svideo))
|
||||
return sv_error();
|
||||
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
sv_IsVideoDisplayed(svobject *self, PyObject *args)
|
||||
{
|
||||
int v;
|
||||
|
||||
if (!PyArg_Parse(args, ""))
|
||||
return NULL;
|
||||
|
||||
v = svIsVideoDisplayed(self->ob_svideo);
|
||||
if (v == -1)
|
||||
return sv_error();
|
||||
|
||||
return PyInt_FromLong((long) v);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
sv_OutputOffset(svobject *self, PyObject *args)
|
||||
{
|
||||
int x_offset;
|
||||
int y_offset;
|
||||
|
||||
if (!PyArg_Parse(args, "(ii)", &x_offset, &y_offset))
|
||||
return NULL;
|
||||
|
||||
if (svOutputOffset(self->ob_svideo, x_offset, y_offset))
|
||||
return sv_error();
|
||||
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
sv_PutFrame(svobject *self, PyObject *args)
|
||||
{
|
||||
char *buffer;
|
||||
|
||||
if (!PyArg_Parse(args, "s", &buffer))
|
||||
return NULL;
|
||||
|
||||
if (svPutFrame(self->ob_svideo, buffer))
|
||||
return sv_error();
|
||||
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
sv_QuerySize(svobject *self, PyObject *args)
|
||||
{
|
||||
int w;
|
||||
int h;
|
||||
int rw;
|
||||
int rh;
|
||||
|
||||
if (!PyArg_Parse(args, "(ii)", &w, &h))
|
||||
return NULL;
|
||||
|
||||
if (svQuerySize(self->ob_svideo, w, h, &rw, &rh))
|
||||
return sv_error();
|
||||
|
||||
return Py_BuildValue("(ii)", (long) rw, (long) rh);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
sv_SetSize(svobject *self, PyObject *args)
|
||||
{
|
||||
int w;
|
||||
int h;
|
||||
|
||||
if (!PyArg_Parse(args, "(ii)", &w, &h))
|
||||
return NULL;
|
||||
|
||||
if (svSetSize(self->ob_svideo, w, h))
|
||||
return sv_error();
|
||||
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
sv_SetStdDefaults(svobject *self, PyObject *args)
|
||||
{
|
||||
|
||||
if (!PyArg_Parse(args, ""))
|
||||
return NULL;
|
||||
|
||||
if (svSetStdDefaults(self->ob_svideo))
|
||||
return sv_error();
|
||||
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
sv_UseExclusive(svobject *self, PyObject *args)
|
||||
{
|
||||
boolean onoff;
|
||||
int mode;
|
||||
|
||||
if (!PyArg_Parse(args, "(ii)", &onoff, &mode))
|
||||
return NULL;
|
||||
|
||||
if (svUseExclusive(self->ob_svideo, onoff, mode))
|
||||
return sv_error();
|
||||
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
sv_WindowOffset(svobject *self, PyObject *args)
|
||||
{
|
||||
int x_offset;
|
||||
int y_offset;
|
||||
|
||||
if (!PyArg_Parse(args, "(ii)", &x_offset, &y_offset))
|
||||
return NULL;
|
||||
|
||||
if (svWindowOffset(self->ob_svideo, x_offset, y_offset))
|
||||
return sv_error();
|
||||
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
sv_CaptureBurst(svobject *self, PyObject *args)
|
||||
{
|
||||
int bytes, i;
|
||||
svCaptureInfo info;
|
||||
void *bitvector = NULL;
|
||||
PyObject *videodata = NULL;
|
||||
PyObject *bitvecobj = NULL;
|
||||
PyObject *res = NULL;
|
||||
static PyObject *evenitem, *odditem;
|
||||
|
||||
if (!PyArg_Parse(args, "(iiiii)", &info.format,
|
||||
&info.width, &info.height,
|
||||
&info.size, &info.samplingrate))
|
||||
return NULL;
|
||||
|
||||
switch (info.format) {
|
||||
case SV_RGB8_FRAMES:
|
||||
bitvector = malloc(SV_BITVEC_SIZE(info.size));
|
||||
break;
|
||||
case SV_YUV411_FRAMES_AND_BLANKING_BUFFER:
|
||||
break;
|
||||
default:
|
||||
PyErr_SetString(SvError, "illegal format specified");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (svQueryCaptureBufferSize(self->ob_svideo, &info, &bytes)) {
|
||||
res = sv_error();
|
||||
goto finally;
|
||||
}
|
||||
|
||||
if (!(videodata = PyString_FromStringAndSize(NULL, bytes)))
|
||||
goto finally;
|
||||
|
||||
/* XXX -- need to do something about the bitvector */
|
||||
{
|
||||
char* str = PyString_AsString(videodata);
|
||||
if (!str)
|
||||
goto finally;
|
||||
|
||||
if (svCaptureBurst(self->ob_svideo, &info, str, bitvector)) {
|
||||
res = sv_error();
|
||||
goto finally;
|
||||
}
|
||||
}
|
||||
|
||||
if (bitvector) {
|
||||
if (evenitem == NULL) {
|
||||
if (!(evenitem = PyInt_FromLong(0)))
|
||||
goto finally;
|
||||
}
|
||||
if (odditem == NULL) {
|
||||
if (!(odditem = PyInt_FromLong(1)))
|
||||
goto finally;
|
||||
}
|
||||
if (!(bitvecobj = PyTuple_New(2 * info.size)))
|
||||
goto finally;
|
||||
|
||||
for (i = 0; i < 2 * info.size; i++) {
|
||||
int sts;
|
||||
|
||||
if (SV_GET_FIELD(bitvector, i) == SV_EVEN_FIELD) {
|
||||
Py_INCREF(evenitem);
|
||||
sts = PyTuple_SetItem(bitvecobj, i, evenitem);
|
||||
} else {
|
||||
Py_INCREF(odditem);
|
||||
sts = PyTuple_SetItem(bitvecobj, i, odditem);
|
||||
}
|
||||
if (sts < 0)
|
||||
goto finally;
|
||||
}
|
||||
} else {
|
||||
bitvecobj = Py_None;
|
||||
Py_INCREF(Py_None);
|
||||
}
|
||||
|
||||
res = Py_BuildValue("((iiiii)OO)", info.format,
|
||||
info.width, info.height,
|
||||
info.size, info.samplingrate,
|
||||
videodata, bitvecobj);
|
||||
|
||||
finally:
|
||||
if (bitvector)
|
||||
free(bitvector);
|
||||
|
||||
Py_XDECREF(videodata);
|
||||
Py_XDECREF(bitvecobj);
|
||||
return res;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
sv_CaptureOneFrame(svobject *self, PyObject *args)
|
||||
{
|
||||
svCaptureInfo info;
|
||||
int format, width, height;
|
||||
int bytes;
|
||||
PyObject *videodata = NULL;
|
||||
PyObject *res = NULL;
|
||||
char *str;
|
||||
|
||||
if (!PyArg_Parse(args, "(iii)", &format, &width, &height))
|
||||
return NULL;
|
||||
|
||||
info.format = format;
|
||||
info.width = width;
|
||||
info.height = height;
|
||||
info.size = 0;
|
||||
info.samplingrate = 0;
|
||||
if (svQueryCaptureBufferSize(self->ob_svideo, &info, &bytes))
|
||||
return sv_error();
|
||||
|
||||
if (!(videodata = PyString_FromStringAndSize(NULL, bytes)))
|
||||
return NULL;
|
||||
|
||||
str = PyString_AsString(videodata);
|
||||
if (!str)
|
||||
goto finally;
|
||||
|
||||
if (svCaptureOneFrame(self->ob_svideo, format, &width, &height, str)) {
|
||||
res = sv_error();
|
||||
goto finally;
|
||||
}
|
||||
|
||||
res = Py_BuildValue("(iiO)", width, height, videodata);
|
||||
|
||||
finally:
|
||||
Py_XDECREF(videodata);
|
||||
return res;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
sv_InitContinuousCapture(svobject *self, PyObject *args)
|
||||
{
|
||||
svCaptureInfo info;
|
||||
|
||||
if (!PyArg_Parse(args, "(iiiii)", &info.format,
|
||||
&info.width, &info.height,
|
||||
&info.size, &info.samplingrate))
|
||||
return NULL;
|
||||
|
||||
if (svInitContinuousCapture(self->ob_svideo, &info))
|
||||
return sv_error();
|
||||
|
||||
self->ob_info = info;
|
||||
|
||||
return Py_BuildValue("(iiiii)", info.format, info.width, info.height,
|
||||
info.size, info.samplingrate);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
sv_LoadMap(svobject *self, PyObject *args)
|
||||
{
|
||||
PyObject *rgb;
|
||||
PyObject *res = NULL;
|
||||
rgb_tuple *mapp = NULL;
|
||||
int maptype;
|
||||
int i, j; /* indices */
|
||||
|
||||
if (!PyArg_Parse(args, "(iO)", &maptype, &rgb))
|
||||
return NULL;
|
||||
|
||||
if (!PyList_Check(rgb) || PyList_Size(rgb) != 256) {
|
||||
PyErr_BadArgument();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!(mapp = PyMem_NEW(rgb_tuple, 256)))
|
||||
return PyErr_NoMemory();
|
||||
|
||||
for (i = 0; i < 256; i++) {
|
||||
PyObject* v = PyList_GetItem(rgb, i);
|
||||
if (!v)
|
||||
goto finally;
|
||||
|
||||
if (!PyTuple_Check(v) || PyTuple_Size(v) != 3) {
|
||||
PyErr_BadArgument();
|
||||
goto finally;
|
||||
}
|
||||
for (j = 0; j < 3; j++) {
|
||||
PyObject* cell = PyTuple_GetItem(v, j);
|
||||
if (!cell)
|
||||
goto finally;
|
||||
|
||||
if (!PyInt_Check(cell)) {
|
||||
PyErr_BadArgument();
|
||||
goto finally;
|
||||
}
|
||||
switch (j) {
|
||||
case 0: mapp[i].red = PyInt_AsLong(cell); break;
|
||||
case 1: mapp[i].blue = PyInt_AsLong(cell); break;
|
||||
case 2: mapp[i].green = PyInt_AsLong(cell); break;
|
||||
}
|
||||
if (PyErr_Occurred())
|
||||
goto finally;
|
||||
}
|
||||
}
|
||||
|
||||
if (svLoadMap(self->ob_svideo, maptype, mapp)) {
|
||||
res = sv_error();
|
||||
goto finally;
|
||||
}
|
||||
|
||||
Py_INCREF(Py_None);
|
||||
res = Py_None;
|
||||
|
||||
finally:
|
||||
PyMem_DEL(mapp);
|
||||
return res;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
sv_CloseVideo(svobject *self, PyObject *args)
|
||||
{
|
||||
if (!PyArg_Parse(args, ""))
|
||||
return NULL;
|
||||
|
||||
if (svCloseVideo(self->ob_svideo))
|
||||
return sv_error();
|
||||
|
||||
self->ob_svideo = NULL;
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
doParams(svobject *self, PyObject *args,
|
||||
int (*func)(SV_nodeP, long *, int), int modified)
|
||||
{
|
||||
PyObject *list;
|
||||
PyObject *res = NULL;
|
||||
long *PVbuffer = NULL;
|
||||
long length;
|
||||
int i;
|
||||
|
||||
if (!PyArg_Parse(args, "O", &list))
|
||||
return NULL;
|
||||
|
||||
if (!PyList_Check(list)) {
|
||||
PyErr_BadArgument();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if ((length = PyList_Size(list)) < 0)
|
||||
return NULL;
|
||||
|
||||
PVbuffer = PyMem_NEW(long, length);
|
||||
if (PVbuffer == NULL)
|
||||
return PyErr_NoMemory();
|
||||
|
||||
for (i = 0; i < length; i++) {
|
||||
PyObject *v = PyList_GetItem(list, i);
|
||||
if (!v)
|
||||
goto finally;
|
||||
|
||||
if (!PyInt_Check(v)) {
|
||||
PyErr_BadArgument();
|
||||
goto finally;
|
||||
}
|
||||
PVbuffer[i] = PyInt_AsLong(v);
|
||||
/* can't just test the return value, because what if the
|
||||
value was -1?!
|
||||
*/
|
||||
if (PVbuffer[i] == -1 && PyErr_Occurred())
|
||||
goto finally;
|
||||
}
|
||||
|
||||
if ((*func)(self->ob_svideo, PVbuffer, length)) {
|
||||
res = sv_error();
|
||||
goto finally;
|
||||
}
|
||||
|
||||
if (modified) {
|
||||
for (i = 0; i < length; i++) {
|
||||
PyObject* v = PyInt_FromLong(PVbuffer[i]);
|
||||
if (!v || PyList_SetItem(list, i, v) < 0)
|
||||
goto finally;
|
||||
}
|
||||
}
|
||||
|
||||
Py_INCREF(Py_None);
|
||||
res = Py_None;
|
||||
|
||||
finally:
|
||||
PyMem_DEL(PVbuffer);
|
||||
return res;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
sv_GetParam(PyObject *self, PyObject *args)
|
||||
{
|
||||
return doParams(self, args, svGetParam, 1);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
sv_GetParamRange(PyObject *self, PyObject *args)
|
||||
{
|
||||
return doParams(self, args, svGetParamRange, 1);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
sv_SetParam(PyObject *self, PyObject *args)
|
||||
{
|
||||
return doParams(self, args, svSetParam, 0);
|
||||
}
|
||||
|
||||
static PyMethodDef svideo_methods[] = {
|
||||
{"BindGLWindow", (PyCFunction)sv_BindGLWindow, METH_OLDARGS},
|
||||
{"EndContinuousCapture",(PyCFunction)sv_EndContinuousCapture, METH_OLDARGS},
|
||||
{"IsVideoDisplayed", (PyCFunction)sv_IsVideoDisplayed, METH_OLDARGS},
|
||||
{"OutputOffset", (PyCFunction)sv_OutputOffset, METH_OLDARGS},
|
||||
{"PutFrame", (PyCFunction)sv_PutFrame, METH_OLDARGS},
|
||||
{"QuerySize", (PyCFunction)sv_QuerySize, METH_OLDARGS},
|
||||
{"SetSize", (PyCFunction)sv_SetSize, METH_OLDARGS},
|
||||
{"SetStdDefaults", (PyCFunction)sv_SetStdDefaults, METH_OLDARGS},
|
||||
{"UseExclusive", (PyCFunction)sv_UseExclusive, METH_OLDARGS},
|
||||
{"WindowOffset", (PyCFunction)sv_WindowOffset, METH_OLDARGS},
|
||||
{"InitContinuousCapture",(PyCFunction)sv_InitContinuousCapture, METH_OLDARGS},
|
||||
{"CaptureBurst", (PyCFunction)sv_CaptureBurst, METH_OLDARGS},
|
||||
{"CaptureOneFrame", (PyCFunction)sv_CaptureOneFrame, METH_OLDARGS},
|
||||
{"GetCaptureData", (PyCFunction)sv_GetCaptureData, METH_OLDARGS},
|
||||
{"CloseVideo", (PyCFunction)sv_CloseVideo, METH_OLDARGS},
|
||||
{"LoadMap", (PyCFunction)sv_LoadMap, METH_OLDARGS},
|
||||
{"GetParam", (PyCFunction)sv_GetParam, METH_OLDARGS},
|
||||
{"GetParamRange", (PyCFunction)sv_GetParamRange, METH_OLDARGS},
|
||||
{"SetParam", (PyCFunction)sv_SetParam, METH_OLDARGS},
|
||||
{NULL, NULL} /* sentinel */
|
||||
};
|
||||
|
||||
static PyObject *
|
||||
sv_conversion(PyObject *self, PyObject *args, void (*function)(),
|
||||
int inputfactor, float factor)
|
||||
{
|
||||
int invert, width, height, inputlength;
|
||||
char *input, *str;
|
||||
PyObject *output;
|
||||
|
||||
if (!PyArg_Parse(args, "(is#ii)", &invert,
|
||||
&input, &inputlength, &width, &height))
|
||||
return NULL;
|
||||
|
||||
if (width * height * inputfactor > inputlength) {
|
||||
PyErr_SetString(SvError, "input buffer not long enough");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!(output = PyString_FromStringAndSize(NULL,
|
||||
(int)(width * height * factor))))
|
||||
return NULL;
|
||||
|
||||
str = PyString_AsString(output);
|
||||
if (!str) {
|
||||
Py_DECREF(output);
|
||||
return NULL;
|
||||
}
|
||||
(*function)(invert, input, str, width, height);
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
sv_InterleaveFields(PyObject *self, PyObject *args)
|
||||
{
|
||||
return sv_conversion(self, args, svInterleaveFields, 1, 1.0);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
sv_RGB8toRGB32(PyObject *self, PyObject *args)
|
||||
{
|
||||
return sv_conversion(self, args, svRGB8toRGB32, 1, (float) sizeof(long));
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
sv_YUVtoRGB(PyObject *self, PyObject *args)
|
||||
{
|
||||
return sv_conversion(self, args, svYUVtoRGB, 2, (float) sizeof(long));
|
||||
}
|
||||
|
||||
static void
|
||||
svideo_dealloc(svobject *self)
|
||||
{
|
||||
if (self->ob_svideo != NULL)
|
||||
(void) svCloseVideo(self->ob_svideo);
|
||||
PyObject_Del(self);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
svideo_getattr(svobject *self, char *name)
|
||||
{
|
||||
return Py_FindMethod(svideo_methods, (PyObject *)self, name);
|
||||
}
|
||||
|
||||
PyTypeObject Svtype = {
|
||||
PyObject_HEAD_INIT(&PyType_Type)
|
||||
0, /*ob_size*/
|
||||
"sv.sv", /*tp_name*/
|
||||
sizeof(svobject), /*tp_size*/
|
||||
0, /*tp_itemsize*/
|
||||
/* methods */
|
||||
(destructor)svideo_dealloc, /*tp_dealloc*/
|
||||
0, /*tp_print*/
|
||||
(getattrfunc)svideo_getattr, /*tp_getattr*/
|
||||
0, /*tp_setattr*/
|
||||
0, /*tp_compare*/
|
||||
0, /*tp_repr*/
|
||||
};
|
||||
|
||||
static PyObject *
|
||||
newsvobject(SV_nodeP svp)
|
||||
{
|
||||
svobject *p;
|
||||
|
||||
p = PyObject_New(svobject, &Svtype);
|
||||
if (p == NULL)
|
||||
return NULL;
|
||||
p->ob_svideo = svp;
|
||||
p->ob_info.format = 0;
|
||||
p->ob_info.size = 0;
|
||||
p->ob_info.width = 0;
|
||||
p->ob_info.height = 0;
|
||||
p->ob_info.samplingrate = 0;
|
||||
return (PyObject *) p;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
sv_OpenVideo(PyObject *self, PyObject *args)
|
||||
{
|
||||
SV_nodeP svp;
|
||||
|
||||
if (!PyArg_Parse(args, ""))
|
||||
return NULL;
|
||||
|
||||
svp = svOpenVideo();
|
||||
if (svp == NULL)
|
||||
return sv_error();
|
||||
|
||||
return newsvobject(svp);
|
||||
}
|
||||
|
||||
static PyMethodDef sv_methods[] = {
|
||||
{"InterleaveFields", (PyCFunction)sv_InterleaveFields, METH_OLDARGS},
|
||||
{"RGB8toRGB32", (PyCFunction)sv_RGB8toRGB32, METH_OLDARGS},
|
||||
{"YUVtoRGB", (PyCFunction)sv_YUVtoRGB, METH_OLDARGS},
|
||||
{"OpenVideo", (PyCFunction)sv_OpenVideo, METH_OLDARGS},
|
||||
{NULL, NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
void
|
||||
initsv(void)
|
||||
{
|
||||
PyObject *m, *d;
|
||||
|
||||
m = Py_InitModule("sv", sv_methods);
|
||||
if (m == NULL)
|
||||
return;
|
||||
d = PyModule_GetDict(m);
|
||||
|
||||
SvError = PyErr_NewException("sv.error", NULL, NULL);
|
||||
if (SvError == NULL || PyDict_SetItemString(d, "error", SvError) != 0)
|
||||
return;
|
||||
}
|
|
@ -268,7 +268,6 @@ DESCRIPTION.zlib$(MODULE.EXT)= Python Extension DLL for accessing the InfoZip c
|
|||
DESCRIPTION.crypt$(MODULE.EXT)= Python Extension DLL implementing the crypt$(BRO)$(BRC) function
|
||||
DESCRIPTION._tkinter$(MODULE.EXT)= Python Extension DLL for access to Tcl/Tk Environment
|
||||
DESCRIPTION.readline$(MODULE.EXT)= Python Extension DLL for access to GNU ReadLine library
|
||||
DESCRIPTION.bsddb185$(MODULE.EXT)= Python Extension DLL for access to BSD DB (v1.85) library
|
||||
DESCRIPTION._curses$(MODLIB.EXT)= Python Extension DLL for access to ncurses library
|
||||
DESCRIPTION.pyexpat$(MODULE.EXT)= Python Extension DLL for access to expat library
|
||||
DESCRIPTION.bz2$(MODULE.EXT)= Python Extension DLL for accessing the bz2 compression library
|
||||
|
@ -471,9 +470,6 @@ endif
|
|||
ifeq ($(HAVE_GREADLINE),yes)
|
||||
HARDEXTMODULES+= readline
|
||||
endif
|
||||
ifeq ($(HAVE_BSDDB),yes)
|
||||
HARDEXTMODULES+= bsddb185
|
||||
endif
|
||||
ifeq ($(HAVE_NCURSES),yes)
|
||||
LIBEXTMODULES+= _curses
|
||||
HARDEXTMODULES+= _curses_
|
||||
|
@ -600,10 +596,6 @@ unicodedata$(MODULE.EXT): $(OUT)unicodedata$O $(OUT)unicodedata_m.def $(PYTHON.I
|
|||
unicoded$(MODULE.EXT): unicodedata$(MODULE.EXT)
|
||||
cp $^ $@
|
||||
|
||||
# - optional modules (requiring other software to be installed)
|
||||
bsddb185$(MODULE.EXT): $(OUT)bsddbmodule$O $(OUT)bsddb185_m.def $(PYTHON.IMPLIB)
|
||||
$(LD) $(LDFLAGS.DLL) -o $@ $(^^) $(L^) -ldb $(LIBS)
|
||||
|
||||
crypt$(MODULE.EXT): $(OUT)cryptmodule$O $(OUT)crypt_m.def $(PYTHON.IMPLIB)
|
||||
$(LD) $(LDFLAGS.DLL) -o $@ $(^^) $(L^) -lufc $(LIBS)
|
||||
|
||||
|
|
|
@ -81,7 +81,6 @@ extern void init_curses();
|
|||
extern void init_curses_panel();
|
||||
extern void init_hotshot();
|
||||
extern void init_testcapi();
|
||||
extern void initbsddb185();
|
||||
extern void initbz2();
|
||||
extern void initfpectl();
|
||||
extern void initfpetest();
|
||||
|
@ -147,7 +146,6 @@ struct _inittab _PyImport_Inittab[] = {
|
|||
{"_curses_panel", init_curses_panel},
|
||||
{"_hotshot", init_hotshot},
|
||||
{"_testcapi", init_testcapi},
|
||||
{"bsddb185", initbsddb185},
|
||||
{"bz2", initbz2},
|
||||
{"fpectl", initfpectl},
|
||||
{"fpetest", initfpetest},
|
||||
|
|
|
@ -74,6 +74,7 @@ module Python version "$Revision$"
|
|||
-- the following expression can appear in assignment context
|
||||
| Attribute(expr value, identifier attr, expr_context ctx)
|
||||
| Subscript(expr value, slice slice, expr_context ctx)
|
||||
| Starred(expr value, expr_context ctx)
|
||||
| Name(identifier id, expr_context ctx)
|
||||
| List(expr* elts, expr_context ctx)
|
||||
| Tuple(expr* elts, expr_context ctx)
|
||||
|
|
|
@ -245,6 +245,11 @@ static char *Subscript_fields[]={
|
|||
"slice",
|
||||
"ctx",
|
||||
};
|
||||
static PyTypeObject *Starred_type;
|
||||
static char *Starred_fields[]={
|
||||
"value",
|
||||
"ctx",
|
||||
};
|
||||
static PyTypeObject *Name_type;
|
||||
static char *Name_fields[]={
|
||||
"id",
|
||||
|
@ -571,6 +576,8 @@ static int init_types(void)
|
|||
if (!Attribute_type) return 0;
|
||||
Subscript_type = make_type("Subscript", expr_type, Subscript_fields, 3);
|
||||
if (!Subscript_type) return 0;
|
||||
Starred_type = make_type("Starred", expr_type, Starred_fields, 2);
|
||||
if (!Starred_type) return 0;
|
||||
Name_type = make_type("Name", expr_type, Name_fields, 2);
|
||||
if (!Name_type) return 0;
|
||||
List_type = make_type("List", expr_type, List_fields, 2);
|
||||
|
@ -1661,6 +1668,32 @@ Subscript(expr_ty value, slice_ty slice, expr_context_ty ctx, int lineno, int
|
|||
return p;
|
||||
}
|
||||
|
||||
expr_ty
|
||||
Starred(expr_ty value, expr_context_ty ctx, int lineno, int col_offset, PyArena
|
||||
*arena)
|
||||
{
|
||||
expr_ty p;
|
||||
if (!value) {
|
||||
PyErr_SetString(PyExc_ValueError,
|
||||
"field value is required for Starred");
|
||||
return NULL;
|
||||
}
|
||||
if (!ctx) {
|
||||
PyErr_SetString(PyExc_ValueError,
|
||||
"field ctx is required for Starred");
|
||||
return NULL;
|
||||
}
|
||||
p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
|
||||
if (!p)
|
||||
return NULL;
|
||||
p->kind = Starred_kind;
|
||||
p->v.Starred.value = value;
|
||||
p->v.Starred.ctx = ctx;
|
||||
p->lineno = lineno;
|
||||
p->col_offset = col_offset;
|
||||
return p;
|
||||
}
|
||||
|
||||
expr_ty
|
||||
Name(identifier id, expr_context_ty ctx, int lineno, int col_offset, PyArena
|
||||
*arena)
|
||||
|
@ -2606,6 +2639,20 @@ ast2obj_expr(void* _o)
|
|||
goto failed;
|
||||
Py_DECREF(value);
|
||||
break;
|
||||
case Starred_kind:
|
||||
result = PyType_GenericNew(Starred_type, NULL, NULL);
|
||||
if (!result) goto failed;
|
||||
value = ast2obj_expr(o->v.Starred.value);
|
||||
if (!value) goto failed;
|
||||
if (PyObject_SetAttrString(result, "value", value) == -1)
|
||||
goto failed;
|
||||
Py_DECREF(value);
|
||||
value = ast2obj_expr_context(o->v.Starred.ctx);
|
||||
if (!value) goto failed;
|
||||
if (PyObject_SetAttrString(result, "ctx", value) == -1)
|
||||
goto failed;
|
||||
Py_DECREF(value);
|
||||
break;
|
||||
case Name_kind:
|
||||
result = PyType_GenericNew(Name_type, NULL, NULL);
|
||||
if (!result) goto failed;
|
||||
|
@ -3180,6 +3227,8 @@ init_ast(void)
|
|||
0) return;
|
||||
if (PyDict_SetItemString(d, "Subscript", (PyObject*)Subscript_type) <
|
||||
0) return;
|
||||
if (PyDict_SetItemString(d, "Starred", (PyObject*)Starred_type) < 0)
|
||||
return;
|
||||
if (PyDict_SetItemString(d, "Name", (PyObject*)Name_type) < 0) return;
|
||||
if (PyDict_SetItemString(d, "List", (PyObject*)List_type) < 0) return;
|
||||
if (PyDict_SetItemString(d, "Tuple", (PyObject*)Tuple_type) < 0) return;
|
||||
|
|
28
Python/ast.c
28
Python/ast.c
|
@ -355,6 +355,11 @@ set_context(expr_ty e, expr_context_ty ctx, const node *n)
|
|||
case Subscript_kind:
|
||||
e->v.Subscript.ctx = ctx;
|
||||
break;
|
||||
case Starred_kind:
|
||||
e->v.Starred.ctx = ctx;
|
||||
if (!set_context(e->v.Starred.value, ctx, n))
|
||||
return 0;
|
||||
break;
|
||||
case Name_kind:
|
||||
if (ctx == Store &&
|
||||
!strcmp(PyString_AS_STRING(e->v.Name.id), "None")) {
|
||||
|
@ -392,6 +397,9 @@ set_context(expr_ty e, expr_context_ty ctx, const node *n)
|
|||
case ListComp_kind:
|
||||
expr_name = "list comprehension";
|
||||
break;
|
||||
case SetComp_kind:
|
||||
expr_name = "set comprehension";
|
||||
break;
|
||||
case Dict_kind:
|
||||
case Set_kind:
|
||||
case Num_kind:
|
||||
|
@ -1661,6 +1669,21 @@ ast_for_power(struct compiling *c, const node *n)
|
|||
return e;
|
||||
}
|
||||
|
||||
static expr_ty
|
||||
ast_for_starred(struct compiling *c, const node *n)
|
||||
{
|
||||
expr_ty tmp;
|
||||
REQ(n, star_expr);
|
||||
|
||||
tmp = ast_for_expr(c, CHILD(n, 1));
|
||||
if (!tmp)
|
||||
return NULL;
|
||||
|
||||
/* The Load context is changed later. */
|
||||
return Starred(tmp, Load, LINENO(n), n->n_col_offset, c->c_arena);
|
||||
}
|
||||
|
||||
|
||||
/* Do not name a variable 'expr'! Will cause a compile error.
|
||||
*/
|
||||
|
||||
|
@ -1772,6 +1795,11 @@ ast_for_expr(struct compiling *c, const node *n)
|
|||
}
|
||||
break;
|
||||
|
||||
case star_expr:
|
||||
if (TYPE(CHILD(n, 0)) == STAR) {
|
||||
return ast_for_starred(c, n);
|
||||
}
|
||||
/* Fallthrough */
|
||||
/* The next five cases all handle BinOps. The main body of code
|
||||
is the same in each case, but the switch turned inside out to
|
||||
reuse the code for each type of operator.
|
||||
|
|
|
@ -477,7 +477,7 @@ enum why_code {
|
|||
};
|
||||
|
||||
static enum why_code do_raise(PyObject *, PyObject *, PyObject *);
|
||||
static int unpack_iterable(PyObject *, int, PyObject **);
|
||||
static int unpack_iterable(PyObject *, int, int, PyObject **);
|
||||
|
||||
/* for manipulating the thread switch and periodic "stuff" - used to be
|
||||
per thread, now just a pair o' globals */
|
||||
|
@ -1656,7 +1656,7 @@ PyEval_EvalFrameEx(PyFrameObject *f, int throwflag)
|
|||
Py_INCREF(w);
|
||||
PUSH(w);
|
||||
}
|
||||
} else if (unpack_iterable(v, oparg,
|
||||
} else if (unpack_iterable(v, oparg, -1,
|
||||
stack_pointer + oparg)) {
|
||||
stack_pointer += oparg;
|
||||
} else {
|
||||
|
@ -1666,6 +1666,21 @@ PyEval_EvalFrameEx(PyFrameObject *f, int throwflag)
|
|||
Py_DECREF(v);
|
||||
break;
|
||||
|
||||
case UNPACK_EX:
|
||||
{
|
||||
int totalargs = 1 + (oparg & 0xFF) + (oparg >> 8);
|
||||
v = POP();
|
||||
|
||||
if (unpack_iterable(v, oparg & 0xFF, oparg >> 8,
|
||||
stack_pointer + totalargs)) {
|
||||
stack_pointer += totalargs;
|
||||
} else {
|
||||
why = WHY_EXCEPTION;
|
||||
}
|
||||
Py_DECREF(v);
|
||||
break;
|
||||
}
|
||||
|
||||
case STORE_ATTR:
|
||||
w = GETITEM(names, oparg);
|
||||
v = TOP();
|
||||
|
@ -3077,14 +3092,20 @@ do_raise(PyObject *type, PyObject *value, PyObject *tb)
|
|||
}
|
||||
|
||||
/* Iterate v argcnt times and store the results on the stack (via decreasing
|
||||
sp). Return 1 for success, 0 if error. */
|
||||
sp). Return 1 for success, 0 if error.
|
||||
|
||||
If argcntafter == -1, do a simple unpack. If it is >= 0, do an unpack
|
||||
with a variable target.
|
||||
*/
|
||||
|
||||
static int
|
||||
unpack_iterable(PyObject *v, int argcnt, PyObject **sp)
|
||||
unpack_iterable(PyObject *v, int argcnt, int argcntafter, PyObject **sp)
|
||||
{
|
||||
int i = 0;
|
||||
int i = 0, j = 0;
|
||||
Py_ssize_t ll = 0;
|
||||
PyObject *it; /* iter(v) */
|
||||
PyObject *w;
|
||||
PyObject *l = NULL; /* variable list */
|
||||
|
||||
assert(v != NULL);
|
||||
|
||||
|
@ -3106,17 +3127,42 @@ unpack_iterable(PyObject *v, int argcnt, PyObject **sp)
|
|||
*--sp = w;
|
||||
}
|
||||
|
||||
/* We better have exhausted the iterator now. */
|
||||
w = PyIter_Next(it);
|
||||
if (w == NULL) {
|
||||
if (PyErr_Occurred())
|
||||
goto Error;
|
||||
Py_DECREF(it);
|
||||
return 1;
|
||||
if (argcntafter == -1) {
|
||||
/* We better have exhausted the iterator now. */
|
||||
w = PyIter_Next(it);
|
||||
if (w == NULL) {
|
||||
if (PyErr_Occurred())
|
||||
goto Error;
|
||||
Py_DECREF(it);
|
||||
return 1;
|
||||
}
|
||||
Py_DECREF(w);
|
||||
PyErr_SetString(PyExc_ValueError, "too many values to unpack");
|
||||
goto Error;
|
||||
}
|
||||
Py_DECREF(w);
|
||||
PyErr_SetString(PyExc_ValueError, "too many values to unpack");
|
||||
/* fall through */
|
||||
|
||||
l = PySequence_List(it);
|
||||
if (l == NULL)
|
||||
goto Error;
|
||||
*--sp = l;
|
||||
i++;
|
||||
|
||||
ll = PyList_GET_SIZE(l);
|
||||
if (ll < argcntafter) {
|
||||
PyErr_Format(PyExc_ValueError, "need more than %zd values to unpack",
|
||||
argcnt + ll);
|
||||
goto Error;
|
||||
}
|
||||
|
||||
/* Pop the "after-variable" args off the list. */
|
||||
for (j = argcntafter; j > 0; j--, i++) {
|
||||
*--sp = PyList_GET_ITEM(l, ll - j);
|
||||
}
|
||||
/* Resize the list. */
|
||||
((PyListObject *)l)->ob_size = ll - argcntafter;
|
||||
Py_DECREF(it);
|
||||
return 1;
|
||||
|
||||
Error:
|
||||
for (; i > 0; i--, sp++)
|
||||
Py_DECREF(*sp);
|
||||
|
|
|
@ -786,6 +786,8 @@ opcode_stack_effect(int opcode, int oparg)
|
|||
return 0;
|
||||
case UNPACK_SEQUENCE:
|
||||
return oparg-1;
|
||||
case UNPACK_EX:
|
||||
return (oparg&0xFF) + (oparg>>8);
|
||||
case FOR_ITER:
|
||||
return 1;
|
||||
|
||||
|
@ -2617,7 +2619,21 @@ compiler_list(struct compiler *c, expr_ty e)
|
|||
{
|
||||
int n = asdl_seq_LEN(e->v.List.elts);
|
||||
if (e->v.List.ctx == Store) {
|
||||
ADDOP_I(c, UNPACK_SEQUENCE, n);
|
||||
int i, seen_star = 0;
|
||||
for (i = 0; i < n; i++) {
|
||||
expr_ty elt = asdl_seq_GET(e->v.List.elts, i);
|
||||
if (elt->kind == Starred_kind && !seen_star) {
|
||||
ADDOP_I(c, UNPACK_EX, (i + ((n-i-1) << 8)));
|
||||
seen_star = 1;
|
||||
asdl_seq_SET(e->v.List.elts, i, elt->v.Starred.value);
|
||||
} else if (elt->kind == Starred_kind) {
|
||||
return compiler_error(c,
|
||||
"two starred expressions in assignment");
|
||||
}
|
||||
}
|
||||
if (!seen_star) {
|
||||
ADDOP_I(c, UNPACK_SEQUENCE, n);
|
||||
}
|
||||
}
|
||||
VISIT_SEQ(c, expr, e->v.List.elts);
|
||||
if (e->v.List.ctx == Load) {
|
||||
|
@ -2631,7 +2647,21 @@ compiler_tuple(struct compiler *c, expr_ty e)
|
|||
{
|
||||
int n = asdl_seq_LEN(e->v.Tuple.elts);
|
||||
if (e->v.Tuple.ctx == Store) {
|
||||
ADDOP_I(c, UNPACK_SEQUENCE, n);
|
||||
int i, seen_star = 0;
|
||||
for (i = 0; i < n; i++) {
|
||||
expr_ty elt = asdl_seq_GET(e->v.Tuple.elts, i);
|
||||
if (elt->kind == Starred_kind && !seen_star) {
|
||||
ADDOP_I(c, UNPACK_EX, (i + ((n-i-1) << 8)));
|
||||
seen_star = 1;
|
||||
asdl_seq_SET(e->v.Tuple.elts, i, elt->v.Starred.value);
|
||||
} else if (elt->kind == Starred_kind) {
|
||||
return compiler_error(c,
|
||||
"two starred expressions in assignment");
|
||||
}
|
||||
}
|
||||
if (!seen_star) {
|
||||
ADDOP_I(c, UNPACK_SEQUENCE, n);
|
||||
}
|
||||
}
|
||||
VISIT_SEQ(c, expr, e->v.Tuple.elts);
|
||||
if (e->v.Tuple.ctx == Load) {
|
||||
|
@ -3257,6 +3287,18 @@ compiler_visit_expr(struct compiler *c, expr_ty e)
|
|||
return 0;
|
||||
}
|
||||
break;
|
||||
case Starred_kind:
|
||||
switch (e->v.Starred.ctx) {
|
||||
case Store:
|
||||
/* In all legitimate cases, the Starred node was already replaced
|
||||
* by compiler_list/compiler_tuple. XXX: is that okay? */
|
||||
return compiler_error(c,
|
||||
"starred assignment target must be in a list or tuple");
|
||||
default:
|
||||
return compiler_error(c,
|
||||
"can use starred expression only as assignment target");
|
||||
}
|
||||
break;
|
||||
case Name_kind:
|
||||
return compiler_nameop(c, e->v.Name.id, e->v.Name.ctx);
|
||||
/* child nodes of List and Tuple will have expr_context set */
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1294,6 +1294,9 @@ symtable_visit_expr(struct symtable *st, expr_ty e)
|
|||
VISIT(st, expr, e->v.Subscript.value);
|
||||
VISIT(st, slice, e->v.Subscript.slice);
|
||||
break;
|
||||
case Starred_kind:
|
||||
VISIT(st, expr, e->v.Starred.value);
|
||||
break;
|
||||
case Name_kind:
|
||||
if (!symtable_add_def(st, e->v.Name.id,
|
||||
e->v.Name.ctx == Load ? USE : DEF_LOCAL))
|
||||
|
|
14
README
14
README
|
@ -290,16 +290,6 @@ on these platforms without the special directions mentioned here,
|
|||
submit a documentation bug report to SourceForge (see Bug Reports
|
||||
above) so we can remove them!)
|
||||
|
||||
Unix platforms: If your vendor still ships (and you still use) Berkeley DB
|
||||
1.85 you will need to edit Modules/Setup to build the bsddb185
|
||||
module and add a line to sitecustomize.py which makes it the
|
||||
default. In Modules/Setup a line like
|
||||
|
||||
bsddb185 bsddbmodule.c
|
||||
|
||||
should work. (You may need to add -I, -L or -l flags to direct the
|
||||
compiler and linker to your include files and libraries.)
|
||||
|
||||
XXX I think this next bit is out of date:
|
||||
|
||||
64-bit platforms: The modules audioop, imageop and rgbimg don't work.
|
||||
|
@ -752,9 +742,7 @@ Beginning with Python version 2.3, the PyBsddb package
|
|||
exposing a set of package-level functions which provide
|
||||
backwards-compatible behavior. Only versions 3.3 through 4.4 of
|
||||
Sleepycat's libraries provide the necessary API, so older versions
|
||||
aren't supported through this interface. The old bsddb module has
|
||||
been retained as bsddb185, though it is not built by default. Users
|
||||
wishing to use it will have to tweak Modules/Setup to build it. The
|
||||
aren't supported through this interface. The
|
||||
dbm module will still be built against the Sleepycat libraries if
|
||||
other preferred alternatives (ndbm, gdbm) are not found.
|
||||
|
||||
|
|
26
setup.py
26
setup.py
|
@ -896,32 +896,6 @@ class PyBuildExt(build_ext):
|
|||
else:
|
||||
missing.append('_sqlite3')
|
||||
|
||||
# Look for Berkeley db 1.85. Note that it is built as a different
|
||||
# module name so it can be included even when later versions are
|
||||
# available. A very restrictive search is performed to avoid
|
||||
# accidentally building this module with a later version of the
|
||||
# underlying db library. May BSD-ish Unixes incorporate db 1.85
|
||||
# symbols into libc and place the include file in /usr/include.
|
||||
f = "/usr/include/db.h"
|
||||
if os.path.exists(f):
|
||||
data = open(f).read()
|
||||
m = re.search(r"#s*define\s+HASHVERSION\s+2\s*", data)
|
||||
if m is not None:
|
||||
# bingo - old version used hash file format version 2
|
||||
### XXX this should be fixed to not be platform-dependent
|
||||
### but I don't have direct access to an osf1 platform and
|
||||
### seemed to be muffing the search somehow
|
||||
libraries = platform == "osf1" and ['db'] or None
|
||||
if libraries is not None:
|
||||
exts.append(Extension('bsddb185', ['bsddbmodule.c'],
|
||||
libraries=libraries))
|
||||
else:
|
||||
exts.append(Extension('bsddb185', ['bsddbmodule.c']))
|
||||
else:
|
||||
missing.append('bsddb185')
|
||||
else:
|
||||
missing.append('bsddb185')
|
||||
|
||||
# The standard Unix dbm module:
|
||||
if platform not in ['cygwin']:
|
||||
if find_file("ndbm.h", inc_dirs, []) is not None:
|
||||
|
|
Loading…
Reference in New Issue