本文整理汇总了Python中convert.Convert类的典型用法代码示例。如果您正苦于以下问题:Python Convert类的具体用法?Python Convert怎么用?Python Convert使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Convert类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: decode
def decode(self, msg):
"""
Decides which type of message the server has sent and verifies that the
timing of the message is valid and communicates to the player if the
message is valid.
:param msg: the message from the server to decode.
:return: the message to send to the Dealer, if any.
"""
if msg == "ok":
return
if "feeding" in possible_next_states[self.state] and len(msg) == 5:
player = Convert.json_to_player_state(msg[0:3])
opponents = Convert.json_to_listof_listof_species(msg[4])
feeding = self.player.next_feeding(player, msg[3], opponents)
self.state = "feeding"
return Convert.feeding_to_json(feeding)
(player, wh) = self.decode_start(msg)
if player and "start" in possible_next_states[self.state]:
print("Got start message")
self.player.start(player, wh)
self.state = "start"
return
decode_choose = self.decode_choose(msg)
if decode_choose and "choose" in possible_next_states[self.state]:
print("Choosing action")
choice = self.player.choose(decode_choose)
self.state = "choose"
return Convert.action_to_json(choice)
raise Exception
示例2: new_post
def new_post():
key = request.forms.get('key')
if not key_verified(key):
return 'Verify Failured, Key Error!\n'
filename = request.forms.get('filename')
content = request.forms.get('content')
filename = os.path.basename(filename)
title, ext = os.path.splitext(filename)
ext = ext.lstrip('.')
try:
tags_str, content = content.split('\n', 1)
tags_str = tags_str.split(':')[-1]
tags = [t.strip() for t in tags_str.split(',')]
except:
return 'Invalid content!\n'
try:
c = Convert(ext)
except NotImplementedError:
return 'This format not supported yet!\n'
except Exception:
return 'Error occurred!\n'
try:
html = c.convert(content)
except ClassNotFound, e:
return 'ClassNotFound, %s\n' % str(e)
示例3: test_json_to_player
def test_json_to_player(self):
self.assertEqual(Convert.json_to_player(self.jPlayer_1), self.player_1)
self.assertEqual(Convert.json_to_player(self.jPlayer_2), self.player_2)
self.assertEqual(Convert.json_to_player(self.jPlayer_3), self.player_3)
self.assertNotEqual(Convert.json_to_player(self.jPlayer_1), self.player_2)
self.jPlayer_1[0][1] = -1
self.assertRaises(AssertionError, Convert.json_to_player, self.jPlayer_1)
示例4: operations_type2_n
def operations_type2_n(self,operator,n1):
operation_code = self.operations[operator]
c = Convert()
n1 = c.decimal_to_hexadecimal(n1)
n1 = n1[:-1]
del c
return operation_code + str(n1) + "0"
示例5: is_type_c
def is_type_c(self,desp):
c = Convert()
desp = c.to_decimal(desp)
del c
if desp < 4096:
return True
return False
示例6: test_json_to_player
def test_json_to_player(self):
self.assertTrue(self.player_soft_eq(Convert.json_to_player(self.jPlayer_1), self.player_1))
self.assertTrue(self.player_soft_eq(Convert.json_to_player(self.jPlayer_2), self.player_2))
self.assertTrue(self.player_soft_eq(Convert.json_to_player(self.jPlayer_3), self.player_3))
self.assertFalse(self.player_soft_eq(Convert.json_to_player(self.jPlayer_1), self.player_2))
self.jPlayer_1[0][1] = -1
self.assertRaises(AssertionError, Convert.json_to_player, self.jPlayer_1)
示例7: relative_base
def relative_base(self,arg):
hex = Hexadecimal()
c = Convert()
res = hex.subs(arg,self.base)
res_dec = c.to_decimal(res)
if res_dec >= 0 and res_dec <= 4095:
return res
return None
示例8: get_binary_code
def get_binary_code(self,operator):
code = self.operations[operator]
c = Convert()
dec_code = c.to_decimal(code+"H")
binary = c.decimal_to_binary(int(dec_code),8)
binary = binary[0:-2]
del c
return binary
示例9: operations_type_2_rn
def operations_type_2_rn(self,operator,r,n):
operation_code = self.operations[operator]
r = self.registers.get(r,"")
c = Convert()
n = c.decimal_to_hexadecimal(n)
n = n[:-1]
del c
obj_code = operation_code + r + str(n)
return obj_code
示例10: test_json_to_species
def test_json_to_species(self):
self.assertTrue(self.species_soft_eq(Convert.json_to_species(self.jSpecies_1),
self.species_1))
self.assertTrue(self.species_soft_eq(Convert.json_to_species(self.jSpecies_2),
self.species_2))
self.assertFalse(self.species_soft_eq(Convert.json_to_species(self.jSpecies_1),
self.species_2))
self.jSpecies_1[0][1] = -1
self.assertRaises(AssertionError, Convert.json_to_species, self.jSpecies_1)
示例11: get_len_program
def get_len_program(self):
c = Convert()
x = self.bloques[-1]
ini = self.bloques[0]
val = c.to_decimal(x.get_load_dir())
val_len = c.to_decimal(x.length)
val_ini = c.to_decimal(ini.get_load_dir())
val = val + val_len - val_ini
val = c.decimal_to_hexadecimal(val)
return val
示例12: directive_word
def directive_word(self,value):
c = Convert()
if not c.is_hexadecimal(value):
value = int(float(value))
value = c.decimal_to_hexadecimal(value)
r = Register("T")
value = r.adjust_bytes(value,6,True)
value = r.filter_number(value)
del r
return value
示例13: make_T
def make_T(self):
c = Convert()
dir = self.filter_number(self.init_dir)
dir = self.adjust_bytes(dir,6,False)
len_register = len(self.register)/2
len_hex = c.decimal_to_hexadecimal(len_register)
hex = self.filter_number(len_hex)
hex = self.adjust_bytes(hex,2,False)
register = "T" + dir +hex+self.register
return register
示例14: get_value_cad_BYTE
def get_value_cad_BYTE(self,data):
string_out =""
c = Convert()
r = Register("T")
for caracter in data:
car = str(ord(caracter))
car = c.decimal_to_hexadecimal(car)
car = r.filter_number(car)
string_out+=car
del c
return string_out
示例15: make_M_modificado
def make_M_modificado(self,obj_code,cp_num):
c = Convert()
cp_num = c.to_decimal(cp_num)
cp_num = c.decimal_to_hexadecimal(cp_num)
dir= self.filter_number(cp_num)
dir = self.adjust_bytes(dir,6,False)
edit_bytes = obj_code
len_bytes = len(edit_bytes)
len_bytes = self.adjust_bytes(str(len_bytes),2,False)
register = "M" + str(dir) + str(len_bytes)+"+"+self.name
return register