Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/ExeBy/smexe_ro.../usr/lib64/python2....
File: xdrlib.py
"""Implements (a subset of) Sun XDR -- eXternal Data Representation.
[0] Fix | Delete
[1] Fix | Delete
See: RFC 1014
[2] Fix | Delete
[3] Fix | Delete
"""
[4] Fix | Delete
[5] Fix | Delete
import struct
[6] Fix | Delete
try:
[7] Fix | Delete
from cStringIO import StringIO as _StringIO
[8] Fix | Delete
except ImportError:
[9] Fix | Delete
from StringIO import StringIO as _StringIO
[10] Fix | Delete
from functools import wraps
[11] Fix | Delete
[12] Fix | Delete
__all__ = ["Error", "Packer", "Unpacker", "ConversionError"]
[13] Fix | Delete
[14] Fix | Delete
# exceptions
[15] Fix | Delete
class Error(Exception):
[16] Fix | Delete
"""Exception class for this module. Use:
[17] Fix | Delete
[18] Fix | Delete
except xdrlib.Error, var:
[19] Fix | Delete
# var has the Error instance for the exception
[20] Fix | Delete
[21] Fix | Delete
Public ivars:
[22] Fix | Delete
msg -- contains the message
[23] Fix | Delete
[24] Fix | Delete
"""
[25] Fix | Delete
def __init__(self, msg):
[26] Fix | Delete
self.msg = msg
[27] Fix | Delete
def __repr__(self):
[28] Fix | Delete
return repr(self.msg)
[29] Fix | Delete
def __str__(self):
[30] Fix | Delete
return str(self.msg)
[31] Fix | Delete
[32] Fix | Delete
[33] Fix | Delete
class ConversionError(Error):
[34] Fix | Delete
pass
[35] Fix | Delete
[36] Fix | Delete
def raise_conversion_error(function):
[37] Fix | Delete
""" Wrap any raised struct.errors in a ConversionError. """
[38] Fix | Delete
[39] Fix | Delete
@wraps(function)
[40] Fix | Delete
def result(self, value):
[41] Fix | Delete
try:
[42] Fix | Delete
return function(self, value)
[43] Fix | Delete
except struct.error as e:
[44] Fix | Delete
raise ConversionError(e.args[0])
[45] Fix | Delete
return result
[46] Fix | Delete
[47] Fix | Delete
[48] Fix | Delete
class Packer:
[49] Fix | Delete
"""Pack various data representations into a buffer."""
[50] Fix | Delete
[51] Fix | Delete
def __init__(self):
[52] Fix | Delete
self.reset()
[53] Fix | Delete
[54] Fix | Delete
def reset(self):
[55] Fix | Delete
self.__buf = _StringIO()
[56] Fix | Delete
[57] Fix | Delete
def get_buffer(self):
[58] Fix | Delete
return self.__buf.getvalue()
[59] Fix | Delete
# backwards compatibility
[60] Fix | Delete
get_buf = get_buffer
[61] Fix | Delete
[62] Fix | Delete
@raise_conversion_error
[63] Fix | Delete
def pack_uint(self, x):
[64] Fix | Delete
self.__buf.write(struct.pack('>L', x))
[65] Fix | Delete
[66] Fix | Delete
@raise_conversion_error
[67] Fix | Delete
def pack_int(self, x):
[68] Fix | Delete
self.__buf.write(struct.pack('>l', x))
[69] Fix | Delete
[70] Fix | Delete
pack_enum = pack_int
[71] Fix | Delete
[72] Fix | Delete
def pack_bool(self, x):
[73] Fix | Delete
if x: self.__buf.write('\0\0\0\1')
[74] Fix | Delete
else: self.__buf.write('\0\0\0\0')
[75] Fix | Delete
[76] Fix | Delete
def pack_uhyper(self, x):
[77] Fix | Delete
try:
[78] Fix | Delete
self.pack_uint(x>>32 & 0xffffffffL)
[79] Fix | Delete
except (TypeError, struct.error) as e:
[80] Fix | Delete
raise ConversionError(e.args[0])
[81] Fix | Delete
try:
[82] Fix | Delete
self.pack_uint(x & 0xffffffffL)
[83] Fix | Delete
except (TypeError, struct.error) as e:
[84] Fix | Delete
raise ConversionError(e.args[0])
[85] Fix | Delete
[86] Fix | Delete
pack_hyper = pack_uhyper
[87] Fix | Delete
[88] Fix | Delete
@raise_conversion_error
[89] Fix | Delete
def pack_float(self, x):
[90] Fix | Delete
self.__buf.write(struct.pack('>f', x))
[91] Fix | Delete
[92] Fix | Delete
@raise_conversion_error
[93] Fix | Delete
def pack_double(self, x):
[94] Fix | Delete
self.__buf.write(struct.pack('>d', x))
[95] Fix | Delete
[96] Fix | Delete
def pack_fstring(self, n, s):
[97] Fix | Delete
if n < 0:
[98] Fix | Delete
raise ValueError, 'fstring size must be nonnegative'
[99] Fix | Delete
data = s[:n]
[100] Fix | Delete
n = ((n+3)//4)*4
[101] Fix | Delete
data = data + (n - len(data)) * '\0'
[102] Fix | Delete
self.__buf.write(data)
[103] Fix | Delete
[104] Fix | Delete
pack_fopaque = pack_fstring
[105] Fix | Delete
[106] Fix | Delete
def pack_string(self, s):
[107] Fix | Delete
n = len(s)
[108] Fix | Delete
self.pack_uint(n)
[109] Fix | Delete
self.pack_fstring(n, s)
[110] Fix | Delete
[111] Fix | Delete
pack_opaque = pack_string
[112] Fix | Delete
pack_bytes = pack_string
[113] Fix | Delete
[114] Fix | Delete
def pack_list(self, list, pack_item):
[115] Fix | Delete
for item in list:
[116] Fix | Delete
self.pack_uint(1)
[117] Fix | Delete
pack_item(item)
[118] Fix | Delete
self.pack_uint(0)
[119] Fix | Delete
[120] Fix | Delete
def pack_farray(self, n, list, pack_item):
[121] Fix | Delete
if len(list) != n:
[122] Fix | Delete
raise ValueError, 'wrong array size'
[123] Fix | Delete
for item in list:
[124] Fix | Delete
pack_item(item)
[125] Fix | Delete
[126] Fix | Delete
def pack_array(self, list, pack_item):
[127] Fix | Delete
n = len(list)
[128] Fix | Delete
self.pack_uint(n)
[129] Fix | Delete
self.pack_farray(n, list, pack_item)
[130] Fix | Delete
[131] Fix | Delete
[132] Fix | Delete
[133] Fix | Delete
class Unpacker:
[134] Fix | Delete
"""Unpacks various data representations from the given buffer."""
[135] Fix | Delete
[136] Fix | Delete
def __init__(self, data):
[137] Fix | Delete
self.reset(data)
[138] Fix | Delete
[139] Fix | Delete
def reset(self, data):
[140] Fix | Delete
self.__buf = data
[141] Fix | Delete
self.__pos = 0
[142] Fix | Delete
[143] Fix | Delete
def get_position(self):
[144] Fix | Delete
return self.__pos
[145] Fix | Delete
[146] Fix | Delete
def set_position(self, position):
[147] Fix | Delete
self.__pos = position
[148] Fix | Delete
[149] Fix | Delete
def get_buffer(self):
[150] Fix | Delete
return self.__buf
[151] Fix | Delete
[152] Fix | Delete
def done(self):
[153] Fix | Delete
if self.__pos < len(self.__buf):
[154] Fix | Delete
raise Error('unextracted data remains')
[155] Fix | Delete
[156] Fix | Delete
def unpack_uint(self):
[157] Fix | Delete
i = self.__pos
[158] Fix | Delete
self.__pos = j = i+4
[159] Fix | Delete
data = self.__buf[i:j]
[160] Fix | Delete
if len(data) < 4:
[161] Fix | Delete
raise EOFError
[162] Fix | Delete
x = struct.unpack('>L', data)[0]
[163] Fix | Delete
try:
[164] Fix | Delete
return int(x)
[165] Fix | Delete
except OverflowError:
[166] Fix | Delete
return x
[167] Fix | Delete
[168] Fix | Delete
def unpack_int(self):
[169] Fix | Delete
i = self.__pos
[170] Fix | Delete
self.__pos = j = i+4
[171] Fix | Delete
data = self.__buf[i:j]
[172] Fix | Delete
if len(data) < 4:
[173] Fix | Delete
raise EOFError
[174] Fix | Delete
return struct.unpack('>l', data)[0]
[175] Fix | Delete
[176] Fix | Delete
unpack_enum = unpack_int
[177] Fix | Delete
[178] Fix | Delete
def unpack_bool(self):
[179] Fix | Delete
return bool(self.unpack_int())
[180] Fix | Delete
[181] Fix | Delete
def unpack_uhyper(self):
[182] Fix | Delete
hi = self.unpack_uint()
[183] Fix | Delete
lo = self.unpack_uint()
[184] Fix | Delete
return long(hi)<<32 | lo
[185] Fix | Delete
[186] Fix | Delete
def unpack_hyper(self):
[187] Fix | Delete
x = self.unpack_uhyper()
[188] Fix | Delete
if x >= 0x8000000000000000L:
[189] Fix | Delete
x = x - 0x10000000000000000L
[190] Fix | Delete
return x
[191] Fix | Delete
[192] Fix | Delete
def unpack_float(self):
[193] Fix | Delete
i = self.__pos
[194] Fix | Delete
self.__pos = j = i+4
[195] Fix | Delete
data = self.__buf[i:j]
[196] Fix | Delete
if len(data) < 4:
[197] Fix | Delete
raise EOFError
[198] Fix | Delete
return struct.unpack('>f', data)[0]
[199] Fix | Delete
[200] Fix | Delete
def unpack_double(self):
[201] Fix | Delete
i = self.__pos
[202] Fix | Delete
self.__pos = j = i+8
[203] Fix | Delete
data = self.__buf[i:j]
[204] Fix | Delete
if len(data) < 8:
[205] Fix | Delete
raise EOFError
[206] Fix | Delete
return struct.unpack('>d', data)[0]
[207] Fix | Delete
[208] Fix | Delete
def unpack_fstring(self, n):
[209] Fix | Delete
if n < 0:
[210] Fix | Delete
raise ValueError, 'fstring size must be nonnegative'
[211] Fix | Delete
i = self.__pos
[212] Fix | Delete
j = i + (n+3)//4*4
[213] Fix | Delete
if j > len(self.__buf):
[214] Fix | Delete
raise EOFError
[215] Fix | Delete
self.__pos = j
[216] Fix | Delete
return self.__buf[i:i+n]
[217] Fix | Delete
[218] Fix | Delete
unpack_fopaque = unpack_fstring
[219] Fix | Delete
[220] Fix | Delete
def unpack_string(self):
[221] Fix | Delete
n = self.unpack_uint()
[222] Fix | Delete
return self.unpack_fstring(n)
[223] Fix | Delete
[224] Fix | Delete
unpack_opaque = unpack_string
[225] Fix | Delete
unpack_bytes = unpack_string
[226] Fix | Delete
[227] Fix | Delete
def unpack_list(self, unpack_item):
[228] Fix | Delete
list = []
[229] Fix | Delete
while 1:
[230] Fix | Delete
x = self.unpack_uint()
[231] Fix | Delete
if x == 0: break
[232] Fix | Delete
if x != 1:
[233] Fix | Delete
raise ConversionError, '0 or 1 expected, got %r' % (x,)
[234] Fix | Delete
item = unpack_item()
[235] Fix | Delete
list.append(item)
[236] Fix | Delete
return list
[237] Fix | Delete
[238] Fix | Delete
def unpack_farray(self, n, unpack_item):
[239] Fix | Delete
list = []
[240] Fix | Delete
for i in range(n):
[241] Fix | Delete
list.append(unpack_item())
[242] Fix | Delete
return list
[243] Fix | Delete
[244] Fix | Delete
def unpack_array(self, unpack_item):
[245] Fix | Delete
n = self.unpack_uint()
[246] Fix | Delete
return self.unpack_farray(n, unpack_item)
[247] Fix | Delete
[248] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function