示例#1
0
文件: mif.py 项目: abreen/wispr
def read_mif(input_filename):
    """Given an input WAVE file, read the music information
    format (MIF) data and print it to the standard out.
    """

    data = codec.decode(input_filename)
    print(bytes(data).decode("utf-8"))
示例#2
0
 def test_decode(self):
     msg = decode(_encoded)
     self.assertEqual(msg.payload_str(), '[{"a": "A"}, {"b": "B"}]',
                      'decoded payload is incorrect: ' + msg.payload_str())
     self.assertEqual(msg.get_topic(), 'TEST',
                      'decoded topic does not match')
     self.assertEqual(msg.get_payload()[1]['b'], 'B',
                      'incorrect payload content')
示例#3
0
    def test_score_codec(self):
        score = 10
        expect = codec.SCORE_HEADER, score

        code_str = codec.encode_score(score)
        result = codec.decode(code_str)

        self.assertEqual(result, expect)
 def read(self, pos, size):
     """
     read bytes from the file and decode into record
     """
     data = b''
     with open(self.filename, 'rb') as f:
         f.seek(pos, 0)
         data = f.read(size)
     return codec.decode(data).value
	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, '')
示例#6
0
def get_message():
    psm = pubsub.get_message()
    if psm:
        ch = psm['channel']
        info('pubsub', 'message: ' + ch)
        if ch == 'admin':
            fns['admin'](psm['data'])
        else:
            msg = decode(psm['data'])
            fns[ch](msg)
示例#7
0
    def test_piece_codec(self):
        piece_id = pieces.J_PIECE
        px, py = 5, 7
        piece_direction = 2
        piece_status = (piece_id, px, py, piece_direction)

        expect = codec.PIECE_HEADER, piece_status

        code_str = codec.encode_piece(piece_status)
        result = codec.decode(code_str)

        self.assertEqual(result, expect)
def handle_event(e=None):
    if e: # key event
        return key_event(e)

    code_str = subscriber.poll()
    if not code_str:
        return False

    msg = codec.decode(code_str)
    if not msg:
        return False

    handle_message(msg)
    return True
示例#9
0
def main(args):
    enc_img = cv2.imread(args.enc_img_path)

    if args.info_in_fname:
        # "channels_samplerate_bitplane_YYYYmmdd-HHMMSS"
        fname, _ = os.path.splitext(os.path.basename(args.enc_img_path))
        try:
            ch, sr, b, *_ = fname.split('_')
            args.n_of_channels = int(ch)
            args.sample_rate = int(sr)
            args.bit_plane = int(b)
            if args.verbose:
                print("Info taken from file name:")
                print(" - channels:", args.n_of_channels)
                print(" - samplerate:", args.sample_rate)
                print(" - bitplane:", args.bit_plane)
        except:
            print(
                "When using --info_in_fname, the expected file name must be in the format: "
                "'channels_samplerate_bitplane_YYYYmmdd-HHMMSS.png'")
            exit()

    decoded_audio = decode(enc_img, args.bit_plane)
    assert decoded_audio.dtype == np.uint8
    decoded_audio = convert(decoded_audio, to='int16')

    if args.n_of_channels == 2:
        warnings.warn("\nWarning: stereo audio isn't currently supported")
        # TODO convert decoded_audio to a 2D array if it's stereo

    fname, _ = os.path.splitext(os.path.basename(args.enc_img_path))
    fname = os.path.join(args.output_folder, fname + "-decoded")
    wavfile.write(filename=fname + ".wav",
                  rate=args.sample_rate,
                  data=decoded_audio)
    if args.verbose:
        print(f"\nSaved audio to '{fname}.wav'")

    if args.playback:
        if args.verbose:
            print(
                f"\nPlaying (~{decoded_audio.size // args.sample_rate}s) audio..",
                end='')
        sd.play(decoded_audio, args.sample_rate)
        sd.wait()  # wait until it is done playing
        if args.verbose:
            print(". done.")
示例#10
0
def Receive(sock, decipher):
    data = b''

    while True:
        try:
            d = sock.recv(1024)
        except socket.error as e:
            pr('⚠️ recv:', e)
            break

        if not d:
            pr('⚠️ recv: 🥅 empty')
            break

        pr('⬇️ recv:', len(d), d[:20])

        data += decode(decipher, d)

        if data.endswith(EOD):
            break

        # TODO
        # if the last recv does not end with EOD
        # script will stuck at next recv (blocking)
        # one scenario is cipher pair out of sync

    pr('⬇️⬇️ recv:', data[-30:])

    if not data:
        return b''

    if data and not data.endswith(EOD):
        pr('⚠️ Data not end with EOD')
        return b''

    d = data[:-len(EOD)]

    if d.endswith(EOF):
        d = d[:-len(EOF)]
        d = d.split(EFN, 1)
        d[0] = d[0].decode()
    else:
        d = d.decode()

    return d
示例#11
0
    def test_board_codec(self):
        """
        board = [['_', '_', '_', '_', ...],
                 ...,
                 ['_', '_', '_', '_', ...],
                 ['_', 'S', '_', '_', ...],
                 ['_', 'S', 'S', '_', ...],
                 ['_', 'T', 'S', '_', ...],
                 ['T', 'T', 'T', '_', ...]]
        """
        board = boards.create_board_lines(boards.BOARD_HEIGHT, '_')
        board[-1][0] = board[-1][1] = board[-1][2] = board[-2][1] = 'T'
        board[-2][2] = board[-3][1] = board[-3][2] = board[-4][1] = 'S'

        expect = codec.BOARD_HEADER, board

        code_str = codec.encode_board(board)
        result = codec.decode(code_str)

        self.assertEqual(result, expect)
示例#12
0
文件: main.py 项目: Tea-1/dosprofiler
#!/Library/Frameworks/Python.framework/Versions/3.8/bin/python3

import codec
print('Codec.py imported...')
import sys
#import parser
from configparser import ConfigParser
config = ConfigParser()
#set config file
config.read('config.ini')
#set variables from config file
speed = config.get('SETTINGS', 'speed')
key = config.get('SETTINGS', 'key')
x = codec.decode(key)
#if not codec.decode(key) == '6942':
#	sys.exit()

#setup random timer to make loadings look cool
from random import randint
loadings = True
z = 1


def load_time():
    global z
    global loadings
    if speed == 0:
        loadings = False
    if speed == 1:
        z = 2
    elif speed == 2:
示例#13
0
import codec
en_pwd = 'wphkZmRrY2JrbA=='

pwd = codec.decode(codec.default_key, en_pwd)
VM_MSSQL = {'ip': '47.107.89.236', 'pwd': pwd, 'id': 'Chris'}
Ali = {'id': 'chris', 'pwd': pwd, 'ip': '47.107.89.236', 'port': '22'}
示例#14
0
import codec
import utils

with open('10.txt') as fp:
    base64_encoded_lines = fp.readlines()

base_64_encoded_ciphertext = ''.join(base64_encoded_lines)
ciphertext = codec.decode(base_64_encoded_ciphertext, 'base64')

cipher = utils.BlockCipher(utils.AES(KEY), utils.CBC(INITIALISATION_VECTOR))
plaintext = cipher.decrypt(ciphertext)