def write_mif(music_filename, mif_filename): """Given an input WAVE file and a music information format (MIF) file, encode the MIF data into the WAVE file. The data is then saved to another WAVE file. """ mif_file = open(mif_filename, 'r') mif = yaml.load(mif_file) print(mif) for k in mif: if k not in ALLOWED_KEYS: print(sys.argv[0] + ' error: unknown attribute "' + k + '"') mif_file.close() sys.exit(1) mif_file.close() # We now encode the MIF data into audio data. mif_samples = codec.encode(mif_filename) # We superimpose the MIF data onto the music file, starting # at the first sample. music_data, params = codec.read_wav(music_filename) for i in range(len(mif_samples)): music_data[i] += mif_samples[i] codec.write_wav(music_filename + '-out', music_data, params)
def testEncodeDecode(self): """Test that we can encode and then decode an example of every known type.""" for ctype, val in self.ctypes: d = codec.encode(ctype, val) r, d2 = codec.decode(ctype, d) self.assertEqual(val, r) # also, nothing left over from the data self.assertEqual(d2, '')
def publish(msg, channel=_channel): if not msg: error('pubsub', 'publish error: undefined msg') return info('pubsub', 'publish: ' + str(msg)) try: data = encode(msg) redis.publish(channel, data) except Exception as ex: error('pubsub', 'publish error: ' + str(ex))
def write(self, key, value): """ encode the data and append to the file """ keysize = len(key) valuesize = len(value) timestamp = time.time() record = Record(timestamp, keysize, valuesize, key, value) data = codec.encode(record) count = 0 with open(self.filename, 'ab') as f: count = f.write(data) curr_offset = self.offset self.offset += count return (timestamp, curr_offset, count)
def Send(sock, cipher, data, fn=None): if not fn: data = data.encode() else: fn = fn.encode() data = fn + EFN + data + EOF data += EOD data = encode(cipher, data) try: sock.sendall(data) except socket.error as e: pr('⚠️ sendall:', e) return -1 return 0
# TODO: Is this doing anything? pointer_gamefile.edit_pointers_in_range( (previous_text_offset, t.location), diff) previous_text_offset = t.location this_diff = len(t.en_bytestring) - len(t.jp_bytestring) diff += this_diff block_diff = len(block.blockstring) - len(block.original_blockstring) if block_diff < 0: block.blockstring += (-1) * block_diff * b'\x00' block_diff = len(block.blockstring) - len(block.original_blockstring) assert block_diff == 0, block_diff block.incorporate() if filename in UNCOMPRESSED_FILES: # No compression needed if the file is uncompressed to begin with gamefile.write() # TODO: Do I need to explcitly insert it into the disk too? else: gamefile.write(skip_disk=True) decompressed_path = 'patched/%s' % gamefile.filename encode(decompressed_path) encoded_path = 'patched/' + filename TargetINS.insert(encoded_path, path_in_disk='') # TODO: Probably need to watch out for writing this multiple times? print(pointer_gamefile) pointer_gamefile.write(path_in_disk='')
def test_encode(self): data = encode(_decoded) self.assertEqual(data, _encoded, 'encoded content is incorrect: ' + data) self.assertTrue('||' in data, 'encoded data did not contain the correct separator')
print('\nNameError, please enter a valid dictionary;') continue_ = False while tasked == False and continue_ == True: print(f'\n{task[1]}:\n {{') for item in temp_dict: print(f" '{item}': {temp_dict[item]}") print('}\n') tasked = True if task[0] == 'clear': os.system('clear') tasked = True if task[0] == 'useradd': __continue__ = True _user = codec.encode(task[1]) if __continue__ == True: if len(task) > 1: new_username = _user users[new_username] = {} tasked = True elif len(task) < 2: print("'useradd' requires 1 argument, 0 given") tasked = True if task[0] == 'userdel': __continue__ = True _user = codec.encode(task[1]) if _user not in users: print('Please enter a valid user or create a new profile.') __continue__ = False
def encode_and_send(msg, socket, verbose=False): confirmation = codec.encode(msg, verbose=verbose) socket.sendall(confirmation)
import pickle import time import sys import codec tasks = { codec.encode('useradd [name]'): codec.encode('Adds new profile'), codec.encode('userdel [user]'): codec.encode('Deletes a profile'), codec.encode('addinfo [user] [item] [info]'): codec.encode('Adds info about a subject'), codec.encode('rminfo [user] [item]'): codec.encode("Deletes an item from a user's profile"), codec.encode('close'): codec.encode('Closes current instance of DosProfiler'), codec.encode('ls [dict]'): codec.encode('View all .dat data, or pass a specific table to view'), codec.encode('clear'): codec.encode('Clears the terminal output'), codec.encode('save'): codec.encode('Saves .dat file'), } local = {} users = {} data = [local, tasks, users] skip = False sub_run = False input_ = ''