Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/ShExBy/shex_roo.../lib64/python2..../Demo/rpc
File: xdr.py
# Implement (a subset of) Sun XDR -- RFC1014.
[0] Fix | Delete
[1] Fix | Delete
[2] Fix | Delete
try:
[3] Fix | Delete
import struct
[4] Fix | Delete
except ImportError:
[5] Fix | Delete
struct = None
[6] Fix | Delete
[7] Fix | Delete
[8] Fix | Delete
Long = type(0L)
[9] Fix | Delete
[10] Fix | Delete
[11] Fix | Delete
class Packer:
[12] Fix | Delete
[13] Fix | Delete
def __init__(self):
[14] Fix | Delete
self.reset()
[15] Fix | Delete
[16] Fix | Delete
def reset(self):
[17] Fix | Delete
self.buf = ''
[18] Fix | Delete
[19] Fix | Delete
def get_buf(self):
[20] Fix | Delete
return self.buf
[21] Fix | Delete
[22] Fix | Delete
def pack_uint(self, x):
[23] Fix | Delete
self.buf = self.buf + \
[24] Fix | Delete
(chr(int(x>>24 & 0xff)) + chr(int(x>>16 & 0xff)) + \
[25] Fix | Delete
chr(int(x>>8 & 0xff)) + chr(int(x & 0xff)))
[26] Fix | Delete
if struct and struct.pack('l', 1) == '\0\0\0\1':
[27] Fix | Delete
def pack_uint(self, x):
[28] Fix | Delete
if type(x) == Long:
[29] Fix | Delete
x = int((x + 0x80000000L) % 0x100000000L \
[30] Fix | Delete
- 0x80000000L)
[31] Fix | Delete
self.buf = self.buf + struct.pack('l', x)
[32] Fix | Delete
[33] Fix | Delete
pack_int = pack_uint
[34] Fix | Delete
[35] Fix | Delete
pack_enum = pack_int
[36] Fix | Delete
[37] Fix | Delete
def pack_bool(self, x):
[38] Fix | Delete
if x: self.buf = self.buf + '\0\0\0\1'
[39] Fix | Delete
else: self.buf = self.buf + '\0\0\0\0'
[40] Fix | Delete
[41] Fix | Delete
def pack_uhyper(self, x):
[42] Fix | Delete
self.pack_uint(int(x>>32 & 0xffffffff))
[43] Fix | Delete
self.pack_uint(int(x & 0xffffffff))
[44] Fix | Delete
[45] Fix | Delete
pack_hyper = pack_uhyper
[46] Fix | Delete
[47] Fix | Delete
def pack_float(self, x):
[48] Fix | Delete
# XXX
[49] Fix | Delete
self.buf = self.buf + struct.pack('f', x)
[50] Fix | Delete
[51] Fix | Delete
def pack_double(self, x):
[52] Fix | Delete
# XXX
[53] Fix | Delete
self.buf = self.buf + struct.pack('d', x)
[54] Fix | Delete
[55] Fix | Delete
def pack_fstring(self, n, s):
[56] Fix | Delete
if n < 0:
[57] Fix | Delete
raise ValueError, 'fstring size must be nonnegative'
[58] Fix | Delete
n = ((n + 3)//4)*4
[59] Fix | Delete
data = s[:n]
[60] Fix | Delete
data = data + (n - len(data)) * '\0'
[61] Fix | Delete
self.buf = self.buf + data
[62] Fix | Delete
[63] Fix | Delete
pack_fopaque = pack_fstring
[64] Fix | Delete
[65] Fix | Delete
def pack_string(self, s):
[66] Fix | Delete
n = len(s)
[67] Fix | Delete
self.pack_uint(n)
[68] Fix | Delete
self.pack_fstring(n, s)
[69] Fix | Delete
[70] Fix | Delete
pack_opaque = pack_string
[71] Fix | Delete
[72] Fix | Delete
def pack_list(self, list, pack_item):
[73] Fix | Delete
for item in list:
[74] Fix | Delete
self.pack_uint(1)
[75] Fix | Delete
pack_item(item)
[76] Fix | Delete
self.pack_uint(0)
[77] Fix | Delete
[78] Fix | Delete
def pack_farray(self, n, list, pack_item):
[79] Fix | Delete
if len(list) <> n:
[80] Fix | Delete
raise ValueError, 'wrong array size'
[81] Fix | Delete
for item in list:
[82] Fix | Delete
pack_item(item)
[83] Fix | Delete
[84] Fix | Delete
def pack_array(self, list, pack_item):
[85] Fix | Delete
n = len(list)
[86] Fix | Delete
self.pack_uint(n)
[87] Fix | Delete
self.pack_farray(n, list, pack_item)
[88] Fix | Delete
[89] Fix | Delete
[90] Fix | Delete
class Unpacker:
[91] Fix | Delete
[92] Fix | Delete
def __init__(self, data):
[93] Fix | Delete
self.reset(data)
[94] Fix | Delete
[95] Fix | Delete
def reset(self, data):
[96] Fix | Delete
self.buf = data
[97] Fix | Delete
self.pos = 0
[98] Fix | Delete
[99] Fix | Delete
def done(self):
[100] Fix | Delete
if self.pos < len(self.buf):
[101] Fix | Delete
raise RuntimeError, 'unextracted data remains'
[102] Fix | Delete
[103] Fix | Delete
def unpack_uint(self):
[104] Fix | Delete
i = self.pos
[105] Fix | Delete
self.pos = j = i+4
[106] Fix | Delete
data = self.buf[i:j]
[107] Fix | Delete
if len(data) < 4:
[108] Fix | Delete
raise EOFError
[109] Fix | Delete
x = long(ord(data[0]))<<24 | ord(data[1])<<16 | \
[110] Fix | Delete
ord(data[2])<<8 | ord(data[3])
[111] Fix | Delete
# Return a Python long only if the value is not representable
[112] Fix | Delete
# as a nonnegative Python int
[113] Fix | Delete
if x < 0x80000000L: x = int(x)
[114] Fix | Delete
return x
[115] Fix | Delete
if struct and struct.unpack('l', '\0\0\0\1') == 1:
[116] Fix | Delete
def unpack_uint(self):
[117] Fix | Delete
i = self.pos
[118] Fix | Delete
self.pos = j = i+4
[119] Fix | Delete
data = self.buf[i:j]
[120] Fix | Delete
if len(data) < 4:
[121] Fix | Delete
raise EOFError
[122] Fix | Delete
return struct.unpack('l', data)
[123] Fix | Delete
[124] Fix | Delete
def unpack_int(self):
[125] Fix | Delete
x = self.unpack_uint()
[126] Fix | Delete
if x >= 0x80000000L: x = x - 0x100000000L
[127] Fix | Delete
return int(x)
[128] Fix | Delete
[129] Fix | Delete
unpack_enum = unpack_int
[130] Fix | Delete
[131] Fix | Delete
unpack_bool = unpack_int
[132] Fix | Delete
[133] Fix | Delete
def unpack_uhyper(self):
[134] Fix | Delete
hi = self.unpack_uint()
[135] Fix | Delete
lo = self.unpack_uint()
[136] Fix | Delete
return long(hi)<<32 | lo
[137] Fix | Delete
[138] Fix | Delete
def unpack_hyper(self):
[139] Fix | Delete
x = self.unpack_uhyper()
[140] Fix | Delete
if x >= 0x8000000000000000L: x = x - 0x10000000000000000L
[141] Fix | Delete
return x
[142] Fix | Delete
[143] Fix | Delete
def unpack_float(self):
[144] Fix | Delete
# XXX
[145] Fix | Delete
i = self.pos
[146] Fix | Delete
self.pos = j = i+4
[147] Fix | Delete
data = self.buf[i:j]
[148] Fix | Delete
if len(data) < 4:
[149] Fix | Delete
raise EOFError
[150] Fix | Delete
return struct.unpack('f', data)[0]
[151] Fix | Delete
[152] Fix | Delete
def unpack_double(self):
[153] Fix | Delete
# XXX
[154] Fix | Delete
i = self.pos
[155] Fix | Delete
self.pos = j = i+8
[156] Fix | Delete
data = self.buf[i:j]
[157] Fix | Delete
if len(data) < 8:
[158] Fix | Delete
raise EOFError
[159] Fix | Delete
return struct.unpack('d', data)[0]
[160] Fix | Delete
[161] Fix | Delete
def unpack_fstring(self, n):
[162] Fix | Delete
if n < 0:
[163] Fix | Delete
raise ValueError, 'fstring size must be nonnegative'
[164] Fix | Delete
i = self.pos
[165] Fix | Delete
j = i + (n+3)//4*4
[166] Fix | Delete
if j > len(self.buf):
[167] Fix | Delete
raise EOFError
[168] Fix | Delete
self.pos = j
[169] Fix | Delete
return self.buf[i:i+n]
[170] Fix | Delete
[171] Fix | Delete
unpack_fopaque = unpack_fstring
[172] Fix | Delete
[173] Fix | Delete
def unpack_string(self):
[174] Fix | Delete
n = self.unpack_uint()
[175] Fix | Delete
return self.unpack_fstring(n)
[176] Fix | Delete
[177] Fix | Delete
unpack_opaque = unpack_string
[178] Fix | Delete
[179] Fix | Delete
def unpack_list(self, unpack_item):
[180] Fix | Delete
list = []
[181] Fix | Delete
while 1:
[182] Fix | Delete
x = self.unpack_uint()
[183] Fix | Delete
if x == 0: break
[184] Fix | Delete
if x <> 1:
[185] Fix | Delete
raise RuntimeError, '0 or 1 expected, got %r' % (x, )
[186] Fix | Delete
item = unpack_item()
[187] Fix | Delete
list.append(item)
[188] Fix | Delete
return list
[189] Fix | Delete
[190] Fix | Delete
def unpack_farray(self, n, unpack_item):
[191] Fix | Delete
list = []
[192] Fix | Delete
for i in range(n):
[193] Fix | Delete
list.append(unpack_item())
[194] Fix | Delete
return list
[195] Fix | Delete
[196] Fix | Delete
def unpack_array(self, unpack_item):
[197] Fix | Delete
n = self.unpack_uint()
[198] Fix | Delete
return self.unpack_farray(n, unpack_item)
[199] Fix | Delete
[200] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function