-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathf_of_data_text.py
More file actions
164 lines (138 loc) · 4.73 KB
/
Copy pathf_of_data_text.py
File metadata and controls
164 lines (138 loc) · 4.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
import re
import struct
#********** IDIOMAS INTERNACIONALES **********
i18n = {
'lang': {
'en': "English",
'es': "Español",
'it': "L'italiano - Google-translate",
'kr': "한국어 - Google-translate",
'hi': "हिन्दी - Google-translate",
'fr': "Français - Google-translate",
'pt': "Português - Google-translate",
'ja': "日本語 - Google-translate",
'zh_cn': "汉语 - Thanks to shiptux@github",
'ru': "русский язык - Google-translate",
'sv': "Svenska - Google-translate",
'de': "Deutsch - Google-translate"
},
'eltos': {
'gui': {},
'cfg': {},
'examples': {},
'states': {},
'help': {},
'dialogs': {},
'compiler': {},
'hw': {},
'tutorial_welcome': {},
'tutorial_simpleusage': {},
'tour_intro': {}
}
}
#********** FUNCIONES DE REGLAS INTERNACIONALES *********
def i18n_getTagFor (component, key):
try:
crea_idiom = get_cfg ('cre_idiom')
except KeyError:
crea_idiom = 'en'
translation = key + ''
if key in i18n['eltos'].get(component, {}).get(crea_idiom,{}):
translation = i18n['eltos'][component][crea_idiom][key]
return translation
#********** CONFIGURACIONES *********
def get_cfg (field):
WSCFG = {
'crea_idiom': {'value': 'es'}
}
return WSCFG[field]['value']
#******** FUNCION PARA CONVERTIR NUMEROS A REPRESENTACION BINARIA ********
def decimal2binary(number, size):
num_base2 = bin(number)[2:] # Convierte un número a binario y elimina el prefijo 0b
num_base2_length = len(num_base2)
WORD_LENGTH = 32 # Un tamaño de palabra de 32 bits
if num_base2_length > WORD_LENGTH:
return [num_base2, size - num_base2_length, num_base2_length]
num_base2 = bin(number & ((1 << size) - 1))[2:] # Convierte a binario sin signo
num_base2_length = len(num_base2)
if number >= 0:
return [num_base2, size - num_base2_length, num_base2_length]
num_base2 = "1" + num_base2.lstrip("1")
num_base2_length = len(num_base2)
if num_base2_length > size:
return [num_base2, size - num_base2_length, num_base2_length]
num_base2 = "1" * (size - len(num_base2)) + num_base2
return [num_base2, size - len(num_base2), num_base2_length]
def float2binary(f, size):
# Flotante con un valor de 32 bits
uint = struct.unpack('I', struct.pack('f', f))[0]
return decimal2binary(uint, size)
#******** FUNCION PARA CARACTERES **********
control_sequences = {
'b': '\b',
'f': '\f',
'n': '\n',
'r': '\r',
't': '\t',
'v': '\v',
'a': chr(0x0007),
"'": '\'',
'"': '\"',
'0': '\0'
}
def treat_control_sequences(possible_value):
ret = {
'string': "",
'error': False
}
i = 0
while i < len(possible_value):
if possible_value[i] != "\\":
ret['string'] += possible_value[i]
i += 1
continue
i += 1
if i >= len(possible_value):
ret['string'] += "\\"
break
# Control de sequences
if possible_value[i] in control_sequences:
ret['string'] += control_sequences[possible_value[i]]
i += 1
continue
# Unicode emojis
if possible_value[i] == 'u':
unicode_match = re.match(r'u\{([0-9A-Fa-f]+)\}', possible_value[i:])
if unicode_match:
unicode_char = chr(int(unicode_match.group(1), 16))
ret['string'] += unicode_char
i += len(unicode_match.group(0))
continue
# Para el control de errores o si se encuentra una secuencia Unicode
ret['string'] = f"Unknown escape char '\\{possible_value[i]}'"
ret['error'] = True
return ret
return ret
#******** ESTADO DEL SISTEMA *********
sim = {
'systems': [],
'active': None,
'index': 0,
}
def ctrlStates_get():
return sim['active']['ctrl_states']
# def ctrlStates_get():
# if sim['active'] is not None and isinstance(sim['active'], dict) and 'ctrl_states' in sim['active']:
# return sim['active']['ctrl_states']
# else:
# raise ValueError("'active' no está definido correctamente o no contiene 'ctrl_states'")
# def initialize_active():
# sim['active'] = {
# 'ctrl_states': 'initial_value' # Asigna un valor inicial adecuado
# }
#******** REEMPLAZO A UNA CADENA BASE *********
def base_escapeRegExp(string):
#caracteres especiales para uso de expresiones regulares
return re.sub(r'[.*+?^${}()|[\]\\]', r'\\\g<0>', string)
def base_replace_all(base_str, match, replacement):
return re.sub(base_escapeRegExp(match), replacement, base_str)