home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 5 / DATAFILE_PDCD5.iso / utilities / p / python / pyhtmldoc / u / unpacker_o next >
Text File  |  1996-11-14  |  4KB  |  86 lines

  1. <TITLE>Unpacker Objects -- Python library reference</TITLE>
  2. Next: <A HREF="../e/exceptions" TYPE="Next">Exceptions</A>  
  3. Prev: <A HREF="../p/packer_objects" TYPE="Prev">Packer Objects</A>  
  4. Up: <A HREF="../x/xdrlib" TYPE="Up">xdrlib</A>  
  5. Top: <A HREF="../t/top" TYPE="Top">Top</A>  
  6. <H2>10.16.2. Unpacker Objects</H2>
  7. <CODE>Unpacker</CODE> is the complementary class which unpacks XDR data
  8. values from a string buffer, and has the following methods:
  9. <P>
  10. <DL><DT><B>__init__</B> (<VAR>data</VAR>) -- function of module xdrlib<DD>
  11. Instantiates an <CODE>Unpacker</CODE> object with the string buffer
  12. <VAR>data</VAR>.
  13. </DL>
  14. <DL><DT><B>reset</B> (<VAR>data</VAR>) -- function of module xdrlib<DD>
  15. Resets the string buffer with the given <VAR>data</VAR>.
  16. </DL>
  17. <DL><DT><B>get_position</B> () -- function of module xdrlib<DD>
  18. Returns the current unpack position in the data buffer.
  19. </DL>
  20. <DL><DT><B>set_position</B> (<VAR>position</VAR>) -- function of module xdrlib<DD>
  21. Sets the data buffer unpack position to <VAR>position</VAR>.  You should be
  22. careful about using <CODE>get_position()</CODE> and <CODE>set_position()</CODE>.
  23. </DL>
  24. <DL><DT><B>done</B> () -- function of module xdrlib<DD>
  25. Indicates unpack completion.  Raises an <CODE>xdrlib.Error</CODE> exception
  26. if all of the data has not been unpacked.
  27. </DL>
  28. In addition, every data type that can be packed with a <CODE>Packer</CODE>,
  29. can be unpacked with an <CODE>Unpacker</CODE>.  Unpacking methods are of the
  30. form <CODE>unpack_<VAR>type</VAR></CODE>, and take no arguments.  They return the
  31. unpacked object.  The same caveats apply for <CODE>unpack_float</CODE> and
  32. <CODE>unpack_double</CODE> as above.
  33. <P>
  34. <DL><DT><B>unpack_float</B> () -- function of module xdrlib<DD>
  35. Unpacks a single-precision floating point number.
  36. </DL>
  37. <DL><DT><B>unpack_double</B> () -- function of module xdrlib<DD>
  38. Unpacks a double-precision floating point number, similarly to
  39. <CODE>unpack_float</CODE>.
  40. </DL>
  41. In addition, the following methods unpack strings, bytes, and opaque
  42. data:
  43. <P>
  44. <DL><DT><B>unpack_fstring</B> (<VAR>n</VAR>) -- function of module xdrlib<DD>
  45. Unpacks and returns a fixed length string.  <VAR>n</VAR> is the number of
  46. characters expected.  Padding with null bytes to guaranteed 4 byte
  47. alignment is assumed.
  48. </DL>
  49. <DL><DT><B>unpack_fopaque</B> (<VAR>n</VAR>) -- function of module xdrlib<DD>
  50. Unpacks and returns a fixed length opaque data stream, similarly to
  51. <CODE>unpack_fstring</CODE>.
  52. </DL>
  53. <DL><DT><B>unpack_string</B> () -- function of module xdrlib<DD>
  54. Unpacks and returns a variable length string.  The length of the
  55. string is first unpacked as an unsigned integer, then the string data
  56. is unpacked with <CODE>unpack_fstring</CODE>.
  57. </DL>
  58. <DL><DT><B>unpack_opaque</B> () -- function of module xdrlib<DD>
  59. Unpacks and returns a variable length opaque data string, similarly to
  60. <CODE>unpack_string</CODE>.
  61. </DL>
  62. <DL><DT><B>unpack_bytes</B> () -- function of module xdrlib<DD>
  63. Unpacks and returns a variable length byte stream, similarly to
  64. <CODE>unpack_string</CODE>.
  65. </DL>
  66. The following methods support unpacking arrays and lists:
  67. <P>
  68. <DL><DT><B>unpack_list</B> (<VAR>unpack_item</VAR>) -- function of module xdrlib<DD>
  69. Unpacks and returns a list of homogeneous items.  The list is unpacked
  70. one element at a time
  71. by first unpacking an unsigned integer flag.  If the flag is <CODE>1</CODE>,
  72. then the item is unpacked and appended to the list.  A flag of
  73. <CODE>0</CODE> indicates the end of the list.  <VAR>unpack_item</VAR> is the
  74. function that is called to unpack the items.
  75. </DL>
  76. <DL><DT><B>unpack_farray</B> (<VAR>n</VAR>, <VAR>unpack_item</VAR>) -- function of module xdrlib<DD>
  77. Unpacks and returns (as a list) a fixed length array of homogeneous
  78. items.  <VAR>n</VAR> is number of list elements to expect in the buffer.
  79. As above, <VAR>unpack_item</VAR> is the function used to unpack each element.
  80. </DL>
  81. <DL><DT><B>unpack_array</B> (<VAR>unpack_item</VAR>) -- function of module xdrlib<DD>
  82. Unpacks and returns a variable length <VAR>list</VAR> of homogeneous items.
  83. First, the length of the list is unpacked as an unsigned integer, then
  84. each element is unpacked as in <CODE>unpack_farray</CODE> above.
  85. </DL>
  86.