Sophie

Sophie

distrib > Mandriva > 8.2 > i586 > media > contrib > by-pkgid > 331a6bf34b79ebee0665f953f5e37620 > files > 224

pyrite-0.9.3-4mdk.i586.rpm

<HTML
><HEAD
><TITLE
>Blocks</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.42"><LINK
REL="HOME"
TITLE="Pyrite Programmers Guide"
HREF="book1.html"><LINK
REL="UP"
TITLE="Reference"
HREF="p45.html"><LINK
REL="PREVIOUS"
TITLE="Reference"
HREF="p45.html"><LINK
REL="NEXT"
TITLE="Class: Record"
HREF="x187.html"></HEAD
><BODY
BGCOLOR="#FFFFFF"
TEXT="#000000"
LINK="#0000FF"
VLINK="#840084"
ALINK="#0000FF"
><DIV
CLASS="NAVHEADER"
><TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="3"
ALIGN="center"
>Pyrite Programmers Guide</TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="bottom"
><A
HREF="p45.html"
>Prev</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
></TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="x187.html"
>Next</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><DIV
CLASS="CHAPTER"
><H1
><A
NAME="REF-BLOCKS"
>Chapter 1. Blocks</A
></H1
><DIV
CLASS="TOC"
><DL
><DT
><B
>Table of Contents</B
></DT
><DT
><A
HREF="c47.html#REF-BLOCKS-BLOCK"
>Class: Block</A
></DT
><DT
><A
HREF="x187.html"
>Class: Record</A
></DT
><DT
><A
HREF="x263.html"
>Class: AppBlock</A
></DT
><DT
><A
HREF="x271.html"
>Class: CategoryAppBlock</A
></DT
><DT
><A
HREF="x306.html"
>Class: SortBlock</A
></DT
><DT
><A
HREF="x317.html"
>Class: Resource</A
></DT
><DT
><A
HREF="x320.html"
>Class: PrefBlock</A
></DT
><DT
><A
HREF="x323.html"
>Attributes</A
></DT
><DT
><A
HREF="x345.html"
>Functions</A
></DT
></DL
></DIV
><P
>    All objects and classes described here are located in the
    <TT
CLASS="CLASSNAME"
>Pyrite.Blocks</TT
> module.  The contents of that module are
    imported into the base package, so everything described in this
    chapter can be accessed directly from the <TT
CLASS="CLASSNAME"
>Pyrite</TT
>
    module as well.
  </P
><DIV
CLASS="SECT1"
><H1
CLASS="SECT1"
><A
NAME="REF-BLOCKS-BLOCK"
>Class: Block</A
></H1
><P
>      A <TT
CLASS="CLASSNAME"
>Block</TT
> object represents a generic chunk of data
      which can be stored in a Pyrite-accessible database.  The
      <TT
CLASS="CLASSNAME"
>Block</TT
> class provides support for conversion between
      an internal representation (a string of raw data) and a more
      useful Python-friendly representation consisting of named
      fields.
    </P
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="REF-BLOCKS-BLOCK-ATTRIBUTES"
>Attributes</A
></H2
><P
></P
><DL
><DT
><TT
CLASS="STRUCTFIELD"
><I
>fields</I
></TT
> (<SPAN
CLASS="TYPE"
>dictionary of sequences</SPAN
>)</DT
><DD
><P
>Definitions of named fields.  Each key is the name
	      of a field; the corresponding value is a sequence (tuple
	      or list) containing at least two elements.  The first
	      element is a constant specifying the type of the field,
	      and the second element holds the field's default value.
	      Elements beyond the first two are optional, and may be
	      used to specify type-dependent information.</P
><P
>The available field types are:</P
><P
></P
><DL
><DT
><TT
CLASS="LITERAL"
>FLD_UNKNOWN</TT
></DT
><DD
><P
>A field of unknown type.</P
></DD
><DT
><TT
CLASS="LITERAL"
>FLD_ANY</TT
></DT
><DD
><P
>A field that may contain any value.</P
></DD
><DT
><TT
CLASS="LITERAL"
>FLD_BOOLEAN</TT
></DT
><DD
><P
>A boolean field.  Its value will be treated as
		    either true or false, no matter what it actually
		    is. (By convention, boolean fields use a value of
		    1 to signify truth, and either 0 or None to
		    signify falsity.)</P
></DD
><DT
><TT
CLASS="LITERAL"
>FLD_INT</TT
></DT
><DD
><P
>A field containing an integer.</P
></DD
><DT
><TT
CLASS="LITERAL"
>FLD_FLOAT</TT
></DT
><DD
><P
>A field containing a floating-point number.</P
></DD
><DT
><TT
CLASS="LITERAL"
>FLD_TIME</TT
></DT
><DD
><P
>A field containing a date/time value, in the
		    normal Unix format of seconds since the epoch.</P
></DD
><DT
><TT
CLASS="LITERAL"
>FLD_TIME_T</TT
></DT
><DD
><P
>A field containing a date/time value, in the
		    Unix <SPAN
CLASS="TYPE"
>time_t</SPAN
> format (represented in Python
		    by a 9-element tuple.</P
></DD
><DT
><TT
CLASS="LITERAL"
>FLD_LIST</TT
></DT
><DD
><P
>A field containing a list of values.</P
></DD
></DL
></DD
></DL
><P
>	The field types are defined as constants at the module level.
      </P
></DIV
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="REF-BLOCKS-BLOCK-METHODS"
>Methods</A
></H2
><P
></P
><DL
><DT
><TT
CLASS="FUNCTION"
>__init__</TT
> (<TT
CLASS="PARAMETER"
><I
>raw</I
></TT
>=None)</DT
><DD
><P
>Create a Block object, setting its initial contents
	      to the supplied raw string, then unpack it so the
	      contents can be accessed as named fields.</P
></DD
><DT
><TT
CLASS="FUNCTION"
>unpack</TT
> (<TT
CLASS="PARAMETER"
><I
>raw</I
></TT
>)</DT
><DD
><P
>Set the contents of the Block to the supplied
	      string, and unpack it so the contents can be accessed as
	      named fields.</P
></DD
><DT
><TT
CLASS="FUNCTION"
>pack</TT
></DT
><DD
><P
>Pack the contents of the Block's named fields into a
	      raw string, and return it.</P
></DD
><DT
><TT
CLASS="FUNCTION"
>packfields</TT
> (<TT
CLASS="PARAMETER"
><I
>format</I
></TT
>,
	    <TT
CLASS="PARAMETER"
><I
>names</I
></TT
>)</DT
><DD
><P
>Pack the named fields into a raw string, according
	      to the supplied format string (which should be in the
	      format used by the standard <TT
CLASS="CLASSNAME"
>struct</TT
>
	      module).</P
><P
>This function is intended as a helper to developers
	      writing a custom <TT
CLASS="FUNCTION"
>pack</TT
> function.</P
></DD
><DT
><TT
CLASS="FUNCTION"
>unpackfields</TT
> (<TT
CLASS="PARAMETER"
><I
>format</I
></TT
>,
	    <TT
CLASS="PARAMETER"
><I
>names</I
></TT
>, <TT
CLASS="PARAMETER"
><I
>raw</I
></TT
>)</DT
><DD
><P
>Unpack the supplied raw string according to the
	      supplied format string (in the format used by the
	      <TT
CLASS="CLASSNAME"
>struct</TT
> module), putting the values obtained
	      into a series of named fields.</P
><P
>This function is intended as a helper to developers
	      writing a custom <TT
CLASS="FUNCTION"
>unpack</TT
> function.</P
></DD
><DT
><TT
CLASS="FUNCTION"
>__getitem__</TT
> (<TT
CLASS="PARAMETER"
><I
>name</I
></TT
>), <TT
CLASS="FUNCTION"
>__setitem__</TT
> (<TT
CLASS="PARAMETER"
><I
>name</I
></TT
>,
	    <TT
CLASS="PARAMETER"
><I
>value</I
></TT
>), <TT
CLASS="FUNCTION"
>get</TT
> (<TT
CLASS="PARAMETER"
><I
>name</I
></TT
>,
	    <TT
CLASS="PARAMETER"
><I
>default</I
></TT
>=None), <TT
CLASS="FUNCTION"
>keys</TT
>, <TT
CLASS="FUNCTION"
>values</TT
>, <TT
CLASS="FUNCTION"
>items</TT
>, <TT
CLASS="FUNCTION"
>has_key</TT
> (<TT
CLASS="PARAMETER"
><I
>name</I
></TT
>)</DT
><DD
><P
>Dictionary-like interface to named fields.</P
></DD
><DT
><TT
CLASS="FUNCTION"
>__len__</TT
></DT
><DD
><P
>Pack the contents of the Block's named fields into a
	      raw string, then return the length of that
	      string.</P
></DD
><DT
><TT
CLASS="FUNCTION"
>dump</TT
> (<TT
CLASS="PARAMETER"
><I
>file</I
></TT
>=sys.stdout,
	    <TT
CLASS="PARAMETER"
><I
>verbose</I
></TT
>=0)</DT
><DD
><P
>Print the raw contents of the Block to the specified
	      file, in a hex-dump format.  If <TT
CLASS="PARAMETER"
><I
>verbose</I
></TT
> is
	      true, print the unpacked values of the Block's named
	      fields as well.</P
></DD
></DL
></DIV
></DIV
></DIV
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="p45.html"
>Prev</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="book1.html"
>Home</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="x187.html"
>Next</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>Reference</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="p45.html"
>Up</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>Class: Record</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>