| 1 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> |
| 2 | <html> |
| 3 | <head> |
| 4 | <link rel="STYLESHEET" href="lib.css" type='text/css' /> |
| 5 | <link rel="SHORTCUT ICON" href="../icons/pyfav.png" type="image/png" /> |
| 6 | <link rel='start' href='../index.html' title='Python Documentation Index' /> |
| 7 | <link rel="first" href="lib.html" title='Python Library Reference' /> |
| 8 | <link rel='contents' href='contents.html' title="Contents" /> |
| 9 | <link rel='index' href='genindex.html' title='Index' /> |
| 10 | <link rel='last' href='about.html' title='About this document...' /> |
| 11 | <link rel='help' href='about.html' title='About this document...' /> |
| 12 | <link rel="next" href="xdr-exceptions.html" /> |
| 13 | <link rel="prev" href="xdr-packer-objects.html" /> |
| 14 | <link rel="parent" href="module-xdrlib.html" /> |
| 15 | <link rel="next" href="xdr-exceptions.html" /> |
| 16 | <meta name='aesop' content='information' /> |
| 17 | <title>12.17.2 Unpacker Objects </title> |
| 18 | </head> |
| 19 | <body> |
| 20 | <DIV CLASS="navigation"> |
| 21 | <div id='top-navigation-panel' xml:id='top-navigation-panel'> |
| 22 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> |
| 23 | <tr> |
| 24 | <td class='online-navigation'><a rel="prev" title="12.17.1 Packer Objects" |
| 25 | href="xdr-packer-objects.html"><img src='../icons/previous.png' |
| 26 | border='0' height='32' alt='Previous Page' width='32' /></A></td> |
| 27 | <td class='online-navigation'><a rel="parent" title="12.17 xdrlib " |
| 28 | href="module-xdrlib.html"><img src='../icons/up.png' |
| 29 | border='0' height='32' alt='Up One Level' width='32' /></A></td> |
| 30 | <td class='online-navigation'><a rel="next" title="12.17.3 Exceptions" |
| 31 | href="xdr-exceptions.html"><img src='../icons/next.png' |
| 32 | border='0' height='32' alt='Next Page' width='32' /></A></td> |
| 33 | <td align="center" width="100%">Python Library Reference</td> |
| 34 | <td class='online-navigation'><a rel="contents" title="Table of Contents" |
| 35 | href="contents.html"><img src='../icons/contents.png' |
| 36 | border='0' height='32' alt='Contents' width='32' /></A></td> |
| 37 | <td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png' |
| 38 | border='0' height='32' alt='Module Index' width='32' /></a></td> |
| 39 | <td class='online-navigation'><a rel="index" title="Index" |
| 40 | href="genindex.html"><img src='../icons/index.png' |
| 41 | border='0' height='32' alt='Index' width='32' /></A></td> |
| 42 | </tr></table> |
| 43 | <div class='online-navigation'> |
| 44 | <b class="navlabel">Previous:</b> |
| 45 | <a class="sectref" rel="prev" href="xdr-packer-objects.html">12.17.1 Packer Objects</A> |
| 46 | <b class="navlabel">Up:</b> |
| 47 | <a class="sectref" rel="parent" href="module-xdrlib.html">12.17 xdrlib </A> |
| 48 | <b class="navlabel">Next:</b> |
| 49 | <a class="sectref" rel="next" href="xdr-exceptions.html">12.17.3 Exceptions</A> |
| 50 | </div> |
| 51 | <hr /></div> |
| 52 | </DIV> |
| 53 | <!--End of Navigation Panel--> |
| 54 | |
| 55 | <H2><A NAME="SECTION00141720000000000000000"></A><A NAME="xdr-unpacker-objects"></A> |
| 56 | <BR> |
| 57 | 12.17.2 Unpacker Objects |
| 58 | </H2> |
| 59 | |
| 60 | <P> |
| 61 | The <tt class="class">Unpacker</tt> class offers the following methods: |
| 62 | |
| 63 | <P> |
| 64 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> |
| 65 | <td><nobr><b><tt id='l2h-4177' xml:id='l2h-4177' class="method">reset</tt></b>(</nobr></td> |
| 66 | <td><var>data</var>)</td></tr></table></dt> |
| 67 | <dd> |
| 68 | Resets the string buffer with the given <var>data</var>. |
| 69 | </dl> |
| 70 | |
| 71 | <P> |
| 72 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> |
| 73 | <td><nobr><b><tt id='l2h-4178' xml:id='l2h-4178' class="method">get_position</tt></b>(</nobr></td> |
| 74 | <td><var></var>)</td></tr></table></dt> |
| 75 | <dd> |
| 76 | Returns the current unpack position in the data buffer. |
| 77 | </dl> |
| 78 | |
| 79 | <P> |
| 80 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> |
| 81 | <td><nobr><b><tt id='l2h-4179' xml:id='l2h-4179' class="method">set_position</tt></b>(</nobr></td> |
| 82 | <td><var>position</var>)</td></tr></table></dt> |
| 83 | <dd> |
| 84 | Sets the data buffer unpack position to <var>position</var>. You should be |
| 85 | careful about using <tt class="method">get_position()</tt> and <tt class="method">set_position()</tt>. |
| 86 | </dl> |
| 87 | |
| 88 | <P> |
| 89 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> |
| 90 | <td><nobr><b><tt id='l2h-4180' xml:id='l2h-4180' class="method">get_buffer</tt></b>(</nobr></td> |
| 91 | <td><var></var>)</td></tr></table></dt> |
| 92 | <dd> |
| 93 | Returns the current unpack data buffer as a string. |
| 94 | </dl> |
| 95 | |
| 96 | <P> |
| 97 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> |
| 98 | <td><nobr><b><tt id='l2h-4181' xml:id='l2h-4181' class="method">done</tt></b>(</nobr></td> |
| 99 | <td><var></var>)</td></tr></table></dt> |
| 100 | <dd> |
| 101 | Indicates unpack completion. Raises an <tt class="exception">Error</tt> exception |
| 102 | if all of the data has not been unpacked. |
| 103 | </dl> |
| 104 | |
| 105 | <P> |
| 106 | In addition, every data type that can be packed with a <tt class="class">Packer</tt>, |
| 107 | can be unpacked with an <tt class="class">Unpacker</tt>. Unpacking methods are of the |
| 108 | form <code>unpack_<var>type</var>()</code>, and take no arguments. They return the |
| 109 | unpacked object. |
| 110 | |
| 111 | <P> |
| 112 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> |
| 113 | <td><nobr><b><tt id='l2h-4182' xml:id='l2h-4182' class="method">unpack_float</tt></b>(</nobr></td> |
| 114 | <td><var></var>)</td></tr></table></dt> |
| 115 | <dd> |
| 116 | Unpacks a single-precision floating point number. |
| 117 | </dl> |
| 118 | |
| 119 | <P> |
| 120 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> |
| 121 | <td><nobr><b><tt id='l2h-4183' xml:id='l2h-4183' class="method">unpack_double</tt></b>(</nobr></td> |
| 122 | <td><var></var>)</td></tr></table></dt> |
| 123 | <dd> |
| 124 | Unpacks a double-precision floating point number, similarly to |
| 125 | <tt class="method">unpack_float()</tt>. |
| 126 | </dl> |
| 127 | |
| 128 | <P> |
| 129 | In addition, the following methods unpack strings, bytes, and opaque |
| 130 | data: |
| 131 | |
| 132 | <P> |
| 133 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> |
| 134 | <td><nobr><b><tt id='l2h-4184' xml:id='l2h-4184' class="method">unpack_fstring</tt></b>(</nobr></td> |
| 135 | <td><var>n</var>)</td></tr></table></dt> |
| 136 | <dd> |
| 137 | Unpacks and returns a fixed length string. <var>n</var> is the number of |
| 138 | characters expected. Padding with null bytes to guaranteed 4 byte |
| 139 | alignment is assumed. |
| 140 | </dl> |
| 141 | |
| 142 | <P> |
| 143 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> |
| 144 | <td><nobr><b><tt id='l2h-4185' xml:id='l2h-4185' class="method">unpack_fopaque</tt></b>(</nobr></td> |
| 145 | <td><var>n</var>)</td></tr></table></dt> |
| 146 | <dd> |
| 147 | Unpacks and returns a fixed length opaque data stream, similarly to |
| 148 | <tt class="method">unpack_fstring()</tt>. |
| 149 | </dl> |
| 150 | |
| 151 | <P> |
| 152 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> |
| 153 | <td><nobr><b><tt id='l2h-4186' xml:id='l2h-4186' class="method">unpack_string</tt></b>(</nobr></td> |
| 154 | <td><var></var>)</td></tr></table></dt> |
| 155 | <dd> |
| 156 | Unpacks and returns a variable length string. The length of the |
| 157 | string is first unpacked as an unsigned integer, then the string data |
| 158 | is unpacked with <tt class="method">unpack_fstring()</tt>. |
| 159 | </dl> |
| 160 | |
| 161 | <P> |
| 162 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> |
| 163 | <td><nobr><b><tt id='l2h-4187' xml:id='l2h-4187' class="method">unpack_opaque</tt></b>(</nobr></td> |
| 164 | <td><var></var>)</td></tr></table></dt> |
| 165 | <dd> |
| 166 | Unpacks and returns a variable length opaque data string, similarly to |
| 167 | <tt class="method">unpack_string()</tt>. |
| 168 | </dl> |
| 169 | |
| 170 | <P> |
| 171 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> |
| 172 | <td><nobr><b><tt id='l2h-4188' xml:id='l2h-4188' class="method">unpack_bytes</tt></b>(</nobr></td> |
| 173 | <td><var></var>)</td></tr></table></dt> |
| 174 | <dd> |
| 175 | Unpacks and returns a variable length byte stream, similarly to |
| 176 | <tt class="method">unpack_string()</tt>. |
| 177 | </dl> |
| 178 | |
| 179 | <P> |
| 180 | The following methods support unpacking arrays and lists: |
| 181 | |
| 182 | <P> |
| 183 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> |
| 184 | <td><nobr><b><tt id='l2h-4189' xml:id='l2h-4189' class="method">unpack_list</tt></b>(</nobr></td> |
| 185 | <td><var>unpack_item</var>)</td></tr></table></dt> |
| 186 | <dd> |
| 187 | Unpacks and returns a list of homogeneous items. The list is unpacked |
| 188 | one element at a time |
| 189 | by first unpacking an unsigned integer flag. If the flag is <code>1</code>, |
| 190 | then the item is unpacked and appended to the list. A flag of |
| 191 | <code>0</code> indicates the end of the list. <var>unpack_item</var> is the |
| 192 | function that is called to unpack the items. |
| 193 | </dl> |
| 194 | |
| 195 | <P> |
| 196 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> |
| 197 | <td><nobr><b><tt id='l2h-4190' xml:id='l2h-4190' class="method">unpack_farray</tt></b>(</nobr></td> |
| 198 | <td><var>n, unpack_item</var>)</td></tr></table></dt> |
| 199 | <dd> |
| 200 | Unpacks and returns (as a list) a fixed length array of homogeneous |
| 201 | items. <var>n</var> is number of list elements to expect in the buffer. |
| 202 | As above, <var>unpack_item</var> is the function used to unpack each element. |
| 203 | </dl> |
| 204 | |
| 205 | <P> |
| 206 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> |
| 207 | <td><nobr><b><tt id='l2h-4191' xml:id='l2h-4191' class="method">unpack_array</tt></b>(</nobr></td> |
| 208 | <td><var>unpack_item</var>)</td></tr></table></dt> |
| 209 | <dd> |
| 210 | Unpacks and returns a variable length <var>list</var> of homogeneous items. |
| 211 | First, the length of the list is unpacked as an unsigned integer, then |
| 212 | each element is unpacked as in <tt class="method">unpack_farray()</tt> above. |
| 213 | </dl> |
| 214 | |
| 215 | <P> |
| 216 | |
| 217 | <DIV CLASS="navigation"> |
| 218 | <div class='online-navigation'> |
| 219 | <p></p><hr /> |
| 220 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> |
| 221 | <tr> |
| 222 | <td class='online-navigation'><a rel="prev" title="12.17.1 Packer Objects" |
| 223 | href="xdr-packer-objects.html"><img src='../icons/previous.png' |
| 224 | border='0' height='32' alt='Previous Page' width='32' /></A></td> |
| 225 | <td class='online-navigation'><a rel="parent" title="12.17 xdrlib " |
| 226 | href="module-xdrlib.html"><img src='../icons/up.png' |
| 227 | border='0' height='32' alt='Up One Level' width='32' /></A></td> |
| 228 | <td class='online-navigation'><a rel="next" title="12.17.3 Exceptions" |
| 229 | href="xdr-exceptions.html"><img src='../icons/next.png' |
| 230 | border='0' height='32' alt='Next Page' width='32' /></A></td> |
| 231 | <td align="center" width="100%">Python Library Reference</td> |
| 232 | <td class='online-navigation'><a rel="contents" title="Table of Contents" |
| 233 | href="contents.html"><img src='../icons/contents.png' |
| 234 | border='0' height='32' alt='Contents' width='32' /></A></td> |
| 235 | <td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png' |
| 236 | border='0' height='32' alt='Module Index' width='32' /></a></td> |
| 237 | <td class='online-navigation'><a rel="index" title="Index" |
| 238 | href="genindex.html"><img src='../icons/index.png' |
| 239 | border='0' height='32' alt='Index' width='32' /></A></td> |
| 240 | </tr></table> |
| 241 | <div class='online-navigation'> |
| 242 | <b class="navlabel">Previous:</b> |
| 243 | <a class="sectref" rel="prev" href="xdr-packer-objects.html">12.17.1 Packer Objects</A> |
| 244 | <b class="navlabel">Up:</b> |
| 245 | <a class="sectref" rel="parent" href="module-xdrlib.html">12.17 xdrlib </A> |
| 246 | <b class="navlabel">Next:</b> |
| 247 | <a class="sectref" rel="next" href="xdr-exceptions.html">12.17.3 Exceptions</A> |
| 248 | </div> |
| 249 | </div> |
| 250 | <hr /> |
| 251 | <span class="release-info">Release 2.4.2, documentation updated on 28 September 2005.</span> |
| 252 | </DIV> |
| 253 | <!--End of Navigation Panel--> |
| 254 | <ADDRESS> |
| 255 | See <i><a href="about.html">About this document...</a></i> for information on suggesting changes. |
| 256 | </ADDRESS> |
| 257 | </BODY> |
| 258 | </HTML> |