本文整理汇总了Python中xdrlib.Packer.pack_string方法的典型用法代码示例。如果您正苦于以下问题:Python Packer.pack_string方法的具体用法?Python Packer.pack_string怎么用?Python Packer.pack_string使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类xdrlib.Packer
的用法示例。
在下文中一共展示了Packer.pack_string方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: gmetric_meta
# 需要导入模块: from xdrlib import Packer [as 别名]
# 或者: from xdrlib.Packer import pack_string [as 别名]
def gmetric_meta(NAME, TYPE, UNITS, SLOPE, TMAX, DMAX, EXTRAS=None):
"""
Arguments are in all upper-case to match XML
"""
packer = Packer()
packer.pack_int(128) # "gmetadata_full"
packer.pack_string('nickg-macbook.local')
packer.pack_string(NAME)
packer.pack_bool(False)
packer.pack_string(TYPE)
packer.pack_string(NAME)
packer.pack_string(UNITS)
packer.pack_int(slope_str2int[SLOPE]) # map slope string to int
packer.pack_uint(int(TMAX))
packer.pack_uint(int(DMAX))
if EXTRAS is None:
packer.pack_uint(0)
else:
packer.pack_uint(len(EXTRAS))
for k,v in EXTRAS.iteritems():
packer.pack_string(k)
packer.pack_string(v)
return packer.get_buffer()
示例2: gmetric_write_meta
# 需要导入模块: from xdrlib import Packer [as 别名]
# 或者: from xdrlib.Packer import pack_string [as 别名]
def gmetric_write_meta(HOST, NAME, TYPE, UNITS, SLOPE, TMAX, DMAX, GROUP):
"""
Arguments are in all upper-case to match XML
"""
packer = Packer()
"""
ganglia message formats
gmetadata_full = 128,
gmetric_ushort = 129,
gmetric_short = 130,
gmetric_int = 131,
gmetric_uint = 132,
gmetric_string = 133,
gmetric_float = 134,
gmetric_double = 135
"""
packer.pack_int(128) # type gmetadata_full
packer.pack_string(HOST)
packer.pack_string(NAME)
packer.pack_int(0)
packer.pack_string(TYPE)
packer.pack_string(NAME)
packer.pack_string(UNITS)
packer.pack_int(slope_str2int[SLOPE]) # map slope string to int
packer.pack_int(TMAX)
packer.pack_int(DMAX)
packer.pack_int(1)
packer.pack_string("GROUP")
packer.pack_string(GROUP)
return packer.get_buffer()
示例3: _mix_counterparties
# 需要导入模块: from xdrlib import Packer [as 别名]
# 或者: from xdrlib.Packer import pack_string [as 别名]
def _mix_counterparties(cp1, cp2, data):
assert type(cp1) == type('')
assert type(cp2) == type('')
assert type(data) == type('')
p = Packer()
p.pack_string(cp1)
p.pack_string(cp2)
p.pack_string(data)
return sha(p.get_buffer()).digest()
示例4: __init__
# 需要导入模块: from xdrlib import Packer [as 别名]
# 或者: from xdrlib.Packer import pack_string [as 别名]
def __init__(self, stamp, machinename, uid, gid, gids):
if len(machinename) > 255:
raise SecError("machinename %s is too long" % machinename)
if len(gids) > 16:
raise SecError("gid array too long: %s" % str(gids))
try:
p = Packer()
p.pack_int(stamp)
p.pack_string(machinename)
p.pack_uint(uid)
p.pack_uint(gid)
p.pack_array(gids, p.pack_uint)
self.cred = p.get_buffer()
except Error, e:
raise SecError("Packing error: %s", str(e))
示例5: gmetric_value
# 需要导入模块: from xdrlib import Packer [as 别名]
# 或者: from xdrlib.Packer import pack_string [as 别名]
def gmetric_value(NAME, VAL):
packer = Packer()
packer.pack_int(128+5) # string
packer.pack_string('nickg-macbook.local')
packer.pack_string(NAME)
packer.pack_bool(False)
packer.pack_string('%s')
packer.pack_string(VAL)
return packer.get_buffer()
示例6: __init__
# 需要导入模块: from xdrlib import Packer [as 别名]
# 或者: from xdrlib.Packer import pack_string [as 别名]
def __init__(self, stamp=0, machinename='', uid=0, gid=0, gids=[]):
if len(machinename) > 255:
raise SecError("machinename %s is too long" % machinename)
if len(gids) > 16:
raise SecError("gid array too long: %s" % str(gids))
try:
p = Packer()
p.pack_int(stamp)
try: # for python2
p.pack_string(machinename)
except: # for python3
p.pack_string(bytes(machinename, 'utf-8'))
p.pack_uint(uid)
p.pack_uint(gid)
p.pack_array(gids, p.pack_uint)
self.cred = p.get_buffer()
except Error as e:
raise SecError("Packing error: %s", str(e))
self.uid = uid
self.gid = gid
示例7: __store_key
# 需要导入模块: from xdrlib import Packer [as 别名]
# 或者: from xdrlib.Packer import pack_string [as 别名]
def __store_key(self, full_key):
self.extres.db_env.nosyncerror_txn_checkpoint(MINS_BETWEEN_DB_CHECKPOINTS)
trans = self.extres.db_env.txn_begin()
try:
key_id = sha(full_key).digest()
if self.extres.counterparty_map.get(key_id, txn=trans, flags=db.DB_RMW) is not None :
return
id_in_rep = randsource.get(SIZE_OF_UNIQS)
id_in = _mix_counterparties(self.__my_public_key_id, key_id, id_in_rep)
id_out_rep = randsource.get(SIZE_OF_UNIQS)
id_out = _mix_counterparties(self.__my_public_key_id, key_id, id_out_rep)
key_seed = randsource.get(SIZE_OF_UNIQS)
sr = HashRandom.SHARandom(_mix_counterparties(self.__my_public_key_id, key_id, key_seed))
symmetric_key = sr.get(SIZE_OF_SYMMETRIC_KEYS)
iv = randsource.get(8)
p = Packer()
p.pack_fstring(SIZE_OF_UNIQS, key_id)
x = MojoKey.makeRSAPublicKeyMVFromSexpString(full_key)
padded = '\000' + cryptutil.oaep(symmetric_key, len(self.__key.get_modulus()) - 1) # The prepended 0 byte is to make modval happy.
assert len(padded) == len(self.__key.get_modulus())
x.set_value_string(padded)
x.encrypt()
p.pack_string(x.get_value())
p.pack_fstring(8, iv)
penc = Packer()
penc.pack_string(self.__key.get_modulus())
penc.pack_fstring(SIZE_OF_UNIQS, id_out_rep)
penc.pack_fstring(SIZE_OF_UNIQS, id_in_rep)
penc.pack_fstring(SIZE_OF_UNIQS, key_seed)
# debugprint("------ ------ ------ ------ hmachish(key=%s, message=%s)\n" % (`symmetric_key`, `penc.get_buffer()`))
hashie = cryptutil.hmacish(key=symmetric_key, message=penc.get_buffer())
paddedhashie = '\000' + cryptutil.oaep(hashie, len(self.__key.get_modulus()) - 1) # The prepended 0 byte is to make modval happy.
assert len(paddedhashie) == len(self.__key.get_modulus())
self.__key.set_value_string(paddedhashie)
self.__key.sign()
signature = self.__key.get_value()
penc.pack_fstring(len(signature), signature)
encrypted = tripledescbc.new(symmetric_key).encrypt(iv, penc.get_buffer())
p.pack_string(encrypted)
header = p.get_buffer()
self.extres.counterparty_map.put(key_id, dumps([id_in, id_out, symmetric_key, header, full_key], 1), txn=trans)
self.extres.session_map.put(id_in, full_key, txn=trans)
trans.commit()
trans = None
finally:
if trans is not None:
trans.abort()
示例8: send_metareq
# 需要导入模块: from xdrlib import Packer [as 别名]
# 或者: from xdrlib.Packer import pack_string [as 别名]
def send_metareq(self, values, address):
packer = Packer()
packer.pack_int(136)
if not values['spoof']:
packer.pack_string(address[0])
else:
packer.pack_string(":".join((address[0], values['hostname'])))
packer.pack_string(values['metricname'])
packer.pack_bool(values['spoof'])
self.transport.write(packer.get_buffer(),address)
return
示例9: gmetric_write
# 需要导入模块: from xdrlib import Packer [as 别名]
# 或者: from xdrlib.Packer import pack_string [as 别名]
def gmetric_write(ID, HOST, NAME, VAL):
"""
Arguments are in all upper-case to match XML
"""
packer = Packer()
packer.pack_int(133)
packer.pack_string(HOST)
packer.pack_string(NAME)
packer.pack_int(0)
packer.pack_string("%s")
packer.pack_string(str(VAL))
return packer.get_buffer()
示例10: generate_message
# 需要导入模块: from xdrlib import Packer [as 别名]
# 或者: from xdrlib.Packer import pack_string [as 别名]
def generate_message(self, recipient_id, message):
connect_info = self._session_keeper.get_connect_info(recipient_id)
symmetric_key = connect_info['symmetric_key']
p = Packer()
if connect_info.has_key('session_id_out'):
p.pack_fstring(4, '\000\000\000\001')
p.pack_fstring(SIZE_OF_UNIQS, connect_info['session_id_out'])
else:
#debugprint('including full header on message to %s\n', args=(recipient_id,), vs='mesgen') # XXX verbose
p.pack_fstring(4, '\000\000\000\000')
p.pack_string(connect_info['header'])
iv = randsource.get(8)
p.pack_fstring(8, iv)
pdec = Packer()
pdec.pack_string(message)
# debugprint("------ ------ ------ ------ hmachish(key=%s, message=%s)\n" % (`symmetric_key`, `message`))
mac = cryptutil.hmacish(key=symmetric_key, message=message)
pdec.pack_fstring(SIZE_OF_UNIQS, mac)
encrypted = tripledescbc.new(symmetric_key).encrypt(iv, pdec.get_buffer())
p.pack_string(encrypted)
return p.get_buffer()
示例11: gmetric_write
# 需要导入模块: from xdrlib import Packer [as 别名]
# 或者: from xdrlib.Packer import pack_string [as 别名]
def gmetric_write(NAME, VAL, TYPE, UNITS, SLOPE, TMAX, DMAX, GROUP, SPOOF):
"""
Arguments are in all upper-case to match XML
"""
packer = Packer()
HOSTNAME="test"
if SPOOF == "":
SPOOFENABLED=0
else :
SPOOFENABLED=1
# Meta data about a metric
packer.pack_int(128)
if SPOOFENABLED == 1:
packer.pack_string(SPOOF)
else:
packer.pack_string(HOSTNAME)
packer.pack_string(NAME)
packer.pack_int(SPOOFENABLED)
packer.pack_string(TYPE)
packer.pack_string(NAME)
packer.pack_string(UNITS)
packer.pack_int(slope_str2int[SLOPE]) # map slope string to int
packer.pack_uint(int(TMAX))
packer.pack_uint(int(DMAX))
# Magic number. Indicates number of entries to follow. Put in 1 for GROUP
if GROUP == "":
packer.pack_int(0)
else:
packer.pack_int(1)
packer.pack_string("GROUP")
packer.pack_string(GROUP)
# Actual data sent in a separate packet
data = Packer()
data.pack_int(128+5)
if SPOOFENABLED == 1:
data.pack_string(SPOOF)
else:
data.pack_string(HOSTNAME)
data.pack_string(NAME)
data.pack_int(SPOOFENABLED)
data.pack_string("%s")
data.pack_string(str(VAL))
return ( packer.get_buffer() , data.get_buffer() )
示例12: _gmetric
# 需要导入模块: from xdrlib import Packer [as 别名]
# 或者: from xdrlib.Packer import pack_string [as 别名]
def _gmetric(self, name, val, metric_type, units, slope, tmax, dmax, group, title, description, spoof):
meta = Packer()
HOSTNAME = socket.gethostname()
if spoof:
SPOOF_ENABLED = 1
else:
SPOOF_ENABLED = 0
# Meta data about a metric
packet_type = 128
meta.pack_int(packet_type)
if SPOOF_ENABLED == 1:
meta.pack_string(spoof)
else:
meta.pack_string(HOSTNAME)
meta.pack_string(name)
meta.pack_int(SPOOF_ENABLED)
meta.pack_string(metric_type)
meta.pack_string(name)
meta.pack_string(units)
meta.pack_int(METRIC_SLOPES[slope]) # map slope string to int
meta.pack_uint(int(tmax))
meta.pack_uint(int(dmax))
extra_data = 0
if group:
extra_data += 1
if title:
extra_data += 1
if description:
extra_data += 1
meta.pack_int(extra_data)
if group:
for g in group.split(','):
meta.pack_string("GROUP")
meta.pack_string(g)
if title:
meta.pack_string("TITLE")
meta.pack_string(title)
if description:
meta.pack_string("DESC")
meta.pack_string(description)
# Actual data sent in a separate packet
data = Packer()
packet_type = METRIC_TYPES[metric_type]
data.pack_int(packet_type)
if SPOOF_ENABLED == 1:
data.pack_string(spoof)
else:
data.pack_string(HOSTNAME)
data.pack_string(name)
data.pack_int(SPOOF_ENABLED)
if metric_type in ['int8', 'uint8', 'int16', 'uint16', 'int32']:
data.pack_string("%d")
data.pack_int(int(val))
if metric_type == 'uint32':
data.pack_string("%u")
data.pack_uint(long(val))
if metric_type == 'string':
data.pack_string("%s")
data.pack_string(str(val))
if metric_type == 'float':
data.pack_string("%f")
data.pack_float(float(val))
if metric_type == 'double':
data.pack_string("%f")
data.pack_double(float(val)) # XXX - double or float?
return meta.get_buffer(), data.get_buffer()
示例13: gmetric_write
# 需要导入模块: from xdrlib import Packer [as 别名]
# 或者: from xdrlib.Packer import pack_string [as 别名]
def gmetric_write(NAME, VAL, TYPE, UNITS, SLOPE, TMAX, DMAX, GROUP, SPOOF):
packer = Packer()
HOSTNAME = 'test'
if SPOOF == '':
SPOOFENABLED = 0
else:
SPOOFENABLED = 1
packer.pack_int(128)
if SPOOFENABLED == 1:
packer.pack_string(SPOOF)
else:
packer.pack_string(HOSTNAME)
packer.pack_string(NAME)
packer.pack_int(SPOOFENABLED)
packer.pack_string(TYPE)
packer.pack_string(NAME)
packer.pack_string(UNITS)
packer.pack_int(slope_str2int[SLOPE])
packer.pack_uint(int(TMAX))
packer.pack_uint(int(DMAX))
if GROUP == '':
packer.pack_int(0)
else:
packer.pack_int(1)
packer.pack_string('GROUP')
packer.pack_string(GROUP)
data = Packer()
data.pack_int(133)
if SPOOFENABLED == 1:
data.pack_string(SPOOF)
else:
data.pack_string(HOSTNAME)
data.pack_string(NAME)
data.pack_int(SPOOFENABLED)
data.pack_string('%s')
data.pack_string(str(VAL))
return (packer.get_buffer(), data.get_buffer())
示例14: compute_tlv
# 需要导入模块: from xdrlib import Packer [as 别名]
# 或者: from xdrlib.Packer import pack_string [as 别名]
def compute_tlv(tag, message):
packer = Packer()
packer.pack_uint(tag)
packer.pack_string(message)
return packer.get_buffer()
示例15: _gmetric
# 需要导入模块: from xdrlib import Packer [as 别名]
# 或者: from xdrlib.Packer import pack_string [as 别名]
def _gmetric(self, name, val, type, units, slope, tmax, dmax, group, title, description, spoof):
"""
Arguments are in all upper-case to match XML
"""
meta = Packer()
HOSTNAME=socket.gethostname()
if spoof == "":
SPOOFENABLED=0
else :
SPOOFENABLED=1
# Meta data about a metric
packet_type = 128
meta.pack_int(packet_type)
if SPOOFENABLED == 1:
meta.pack_string(spoof)
else:
meta.pack_string(HOSTNAME)
meta.pack_string(name)
meta.pack_int(SPOOFENABLED)
meta.pack_string(type)
meta.pack_string(name)
meta.pack_string(units)
meta.pack_int(SLOPES[slope]) # map slope string to int
meta.pack_uint(int(tmax))
meta.pack_uint(int(dmax))
extra_data = 0
if group != "":
extra_data += 1
if title != "":
extra_data += 1
if description != "":
extra_data += 1
meta.pack_int(extra_data)
if group != "":
meta.pack_string("GROUP")
meta.pack_string(group)
if title != "":
meta.pack_string("TITLE")
meta.pack_string(title)
if description != "":
meta.pack_string("DESC")
meta.pack_string(description)
# Actual data sent in a separate packet
data = Packer()
packet_type = TYPES[type]
data.pack_int(packet_type)
if SPOOFENABLED == 1:
data.pack_string(spoof)
else:
data.pack_string(HOSTNAME)
data.pack_string(name)
data.pack_int(SPOOFENABLED)
if type in ['int8','uint8','int16','uint16','int32']:
data.pack_string("%d")
data.pack_int(int(val))
if type == 'uint32':
data.pack_string("%u")
data.pack_uint(long(val))
if type == 'string':
data.pack_string("%s")
data.pack_string(str(val))
if type == 'float':
data.pack_string("%f")
data.pack_float(float(val))
if type == 'double':
data.pack_string("%f")
data.pack_double(float(val)) # XXX - double or float?
return (meta.get_buffer(), data.get_buffer())