コード例 #1
0
 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
0
ファイル: views.py プロジェクト: Tary/py-web-dev
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
0
 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
0
ファイル: step2.py プロジェクト: Juanirow/esic
 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
0
ファイル: step2.py プロジェクト: Juanirow/esic
 def is_type_c(self,desp):
     c = Convert()
     desp = c.to_decimal(desp)
     del c
     if desp < 4096:
         return True
     return False
コード例 #6
0
 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
0
ファイル: views.py プロジェクト: Kingson/paper
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)
コード例 #8
0
ファイル: step2.py プロジェクト: Juanirow/esic
 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
コード例 #9
0
ファイル: step2.py プロジェクト: Juanirow/esic
 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
コード例 #10
0
ファイル: step2.py プロジェクト: Juanirow/esic
 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
コード例 #11
0
 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)
コード例 #12
0
ファイル: bloque.py プロジェクト: Juanirow/esic
 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
コード例 #13
0
ファイル: step2.py プロジェクト: Juanirow/esic
 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
コード例 #14
0
ファイル: register.py プロジェクト: Juanirow/esic
 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
コード例 #15
0
ファイル: step2.py プロジェクト: Juanirow/esic
 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
コード例 #16
0
ファイル: register.py プロジェクト: Juanirow/esic
 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
コード例 #17
0
ファイル: step2.py プロジェクト: Juanirow/esic
 def operation_type_3_4(self,cp,operator,arg,format_type,num_line,dir_type,type_c,is_index,valid_label):
     c = Convert()
     operator = self.get_binary_code(operator)
     flags = self.get_flags(dir_type)
     num_max = 3
     res = arg
     entra = True
     if format_type == 4:
         flags['e']=1
         num_max=5
         if not type_c and valid_label == "relativo":
             self.m_register.append(num_line)
         res = self.current_register.adjust_bytes(arg,num_max,True)
     else:
         if type_c:
             if not self.is_type_c(arg):
                 entra = True
             else:
                 entra = False
                 if not c.is_hexadecimal(arg):
                     arg = c.decimal_to_hexadecimal(arg)
                 res = self.current_register.adjust_bytes(arg,3,True)
         if entra:
             res = self.is_relative_cp(cp,arg)
             if not res:
                 res = self.relative_base(arg)
                 if res:
                     flags['b'] = 1
                 else:
                     res = arg
                     valid_label = False
             else:
                 flags['p'] = 1
             res = self.current_register.adjust_bytes(res,num_max,True)
     if is_index:
         flags['x'] = 1
     if not valid_label:
         flags['b'] = 1
         flags['p'] = 1
     if valid_label == "_":
         flags['b'] = 0
         flags['p'] = 0
     flags = self.flags_string(flags)
     val = operator + flags
     val = str(int(val,2))
     val = c.decimal_to_hexadecimal(val)
     if len(val)==3:
         val = "0"+val
     val = self.current_register.adjust_bytes(val,3,True)
     val += str(res)
     del c
     return val
コード例 #18
0
ファイル: Cargador.py プロジェクト: Juanirow/esic
 def get_address_tarjet(self, value):
     c = Convert()
     addressing = value[0] + "H"
     addressing = int(c.to_decimal(addressing))
     val = value
     bina = c.decimal_to_binary(addressing, 4)
     bina = c.mask_and(bina, "1000")
     if bina == "1000":
         val = self.hex.subs(value, "8000H")
         x = self.get_x_value()
         val = self.hex.plus(val, x)
         val = self.reg.filter_number(val)
     return val
コード例 #19
0
ファイル: step2.py プロジェクト: Juanirow/esic
 def is_relative_cp(self,cp,arg):
     hex = Hexadecimal()
     c = Convert()        
     res_hex = hex.subs_minus(arg,cp)
     sign = res_hex[1]
     res_hex = res_hex[0]
     res = int(c.to_decimal(res_hex))
     if sign == "-":
         res = (res ^ 4095)+1
         res = res * -1 
     if res <= 2047 and res >= -2048:
         return c.exp_to_hexadecimal(res)
     else: 
         return None
コード例 #20
0
 def test_json_to_dealer(self):
     dealer = Convert.json_to_dealer(self.jConfig_1)
     self.assertEqual(len(dealer.player_sets), 3)
     self.assertEqual(dealer.watering_hole, 42)
     self.assertEqual(len(dealer.deck), 2)
     self.assertEqual(dealer.deck[0], self.tc_5)
     self.assertEqual(dealer.deck[1], self.tc_6)
コード例 #21
0
ファイル: segment.py プロジェクト: Juanirow/esic
 def __init__(self):
     self.index = 0
     self.list_n = []
     self.conv = Convert()
     self.reg = Register("X")
     self.hexa = Hexadecimal()
     self.last_code = 0
コード例 #22
0
ファイル: sys_log.py プロジェクト: ahua/ismartv
    def append_field(self, k, v):

        assert k and isinstance(k, basestring)

        if k in self.__kset:

            return

            

        k = Convert.bs2utf8(k)

        v = Convert.bs2utf8(v)

            

        self.__fields.append('{0}={1}'.format(k, v))

        self.__kset.update({k: v})
コード例 #23
0
ファイル: Cargador.py プロジェクト: Juanirow/esic
 def charge_text(self):
     c = Convert()
     for r in self.registers:
         string = r[9:]
         index = 0
         init = r[1:7]
         col_start = init[-1] + "H"
         col = int(c.to_decimal(col_start) + 1)
         res = self.hex.subs(init[:-1], self.init[:-1])
         dec_res = int(c.to_decimal(res))
         while index < len(string):
             byte = string[index : index + 2]
             item = QtGui.QTableWidgetItem(byte)
             self.window.tableWidget.setItem(dec_res, col, item)
             index += 2
             col = (col + 1) % 17
             if col == 0:
                 col = 1
                 dec_res += 1
コード例 #24
0
ファイル: Cargador.py プロジェクト: Juanirow/esic
 def charge_header(self):
     init = self.header[7:13]
     self.init = init
     length = self.header[13:]
     self.end_program = self.hex.plus(init, length)
     star_rows = length[:-1]
     index = init[:-1]
     num_rows = star_rows + "H"
     c = Convert()
     num_rows = int(c.to_decimal(num_rows))
     self.window.tableWidget.setRowCount(num_rows + 1)
     it = 0
     while it <= num_rows:
         dir = index + "0H"
         r = Register("T")
         dir = r.adjust_bytes(dir, 6, False)
         item = QtGui.QTableWidgetItem(dir)
         self.window.tableWidget.setItem(it, 0, item)
         it += 1
         index = self.hex.plus(index, "1H")[:-1]
コード例 #25
0
ファイル: Cargadorx.py プロジェクト: Juanirow/esic
 def __init__(self,window):
     self.window = window
     self.tabse = Tabse()
     self.lonsc = "0H"
     self.dirsc = "0H"
     self.dirprog = "0H"
     self.direj = "0H"
     self.hexa = Hexadecimal()
     self.convert = Convert()
     self.register = Register("A")
     self.error_indefinido = False
     self.error_duplicado = False
コード例 #26
0
ファイル: convert_gui.py プロジェクト: musray/xls2csv
	def OnDropFiles(self, x, y, folders):
		
		for folder in folders:
			xl_list = fileList(folder)
			if len(xl_list) != 0:
				start_time = time.time()
				converter = Convert()
				for xl_file in xl_list:
					#print "type(xl_list) %s" % type(xl_file)
					xl_name = os.path.basename(xl_file)  # xl_name is xl_file without its path.
					self.window.WriteText('%s' % xl_name + '....')
					csv_file = re.sub('.xls[x]?$', '.csv', xl_file)
					converter.xlConvert(xl_file, xl_name, csv_file)
					#converter.xlConvert()
					self.window.WriteText('%s' % 'OK\n')

				converter.terminate()
				end_time = time.time() - start_time
				self.window.WriteText(u'转换完成,用时%r秒!\n' % round(end_time,1))
			else:
				self.window.WriteText('No excel file in the directory!\n')
コード例 #27
0
 def decode_start(self, msg):
     """
     Attempts to decode the given msg into a tuple (player, watering_hole)
     :param msg: The JSON message to decode.
     :return: The tuple (PlayerState, Int) representing the player and the
     food in the watering hole, or (False, False) if the conversion fails.
     """
     try:
         assert(isinstance(msg[0], int))
         return (Convert.json_to_player_state(msg[1:]), msg[0])
     except Exception:
         return (False, False)
コード例 #28
0
class TestConvert(unittest.TestCase):
    def setUp(self):
        self.convert = Convert()
        self.validtxt = "juego.txt"
        self.invalidtxt = "juego1.txt"
        self.validcsv = "juego.csv"
        self.invalidcsv = "juego1.csv"

### ******* Unittest for convert class *************

    def test_if_txt_file_is_converted_to_string(self):
        expected = type(self.validtxt)
        self.assertEqual(expected,type(self.convert.txt_file_to_string(self.validtxt)))

    def test_if_string_from_txt_file_is_correct_converted(self):
        expected = '003020600900305001001806400008102900700000008006708200002609500800203009005010300'
        self.assertEqual(expected,self.convert.txt_file_to_string(self.validtxt))

    def test_if_txt_file_convert_display_a_friendly_message_for_invalid_input(self):
        expected = "Please insert a txt file with the correct dimensions"
        self.assertEqual(expected,self.convert.txt_file_to_string(self.invalidtxt))

    def test_if_csv_file_is_converted_to_string(self):
        expected = type(self.validcsv)
        self.assertEqual(expected,type(self.convert.csv_file_to_string(self.validcsv)))

    def test_if_string_from_csv_file_is_correct_converted(self):
        expected = '003020600900305001001806400008102900700000008006708200002609500800203009005010300'
        self.assertEqual(expected,self.convert.csv_file_to_string(self.validcsv))

    def test_if_csv_file_convert_display_a_friendly_message_for_invalid_input(self):
        expected = "Please insert a csv file with the correct dimensions"
        self.assertEqual(expected,self.convert.csv_file_to_string(self.invalidcsv))
コード例 #29
0
 def test_json_to_trait_card(self):
     self.assertEqual(Convert.json_to_trait_card(self.jtc_1), self.tc_1)
     self.assertEqual(Convert.json_to_trait_card(self.jtc_2), self.tc_2)
     self.assertEqual(Convert.json_to_trait_card(self.jtc_3), self.tc_3)
     self.assertEqual(Convert.json_to_trait_card(self.jtc_4), self.tc_4)
     self.assertEqual(Convert.json_to_trait_card(self.jtc_5), self.tc_5)
     self.assertEqual(Convert.json_to_trait_card(self.jtc_6), self.tc_6)
コード例 #30
0
ファイル: step2.py プロジェクト: Juanirow/esic
 def operations_code(self,operator,m,is_index):
     r = Register("T")
     c = Convert()        
     op = self.operations[operator]
     op = op+"H"
     op = c.to_decimal(op)
     op = int(op)
     binary = c.decimal_to_binary(op,24)
     binary = c.shift_binary_left(binary,16)
     if is_index:
         binary = c.mask_or(binary,"000000001000000000000000")
     m = c.to_decimal(m)
     m = int(m)
     m = c.decimal_to_binary(m,24)
     binary = c.mask_or(binary,m)
     val = int(binary,2)
     val = c.decimal_to_hexadecimal(val)
     val = r.filter_number(val)  
     val = r.adjust_bytes(val,6,False)
     del r
     del c
     return val