def test_readline_bin(self): with open(self.fname, 'wb') as f: f.write(b'hello\nworld\n') with openfile(self.fname, 'rb') as f: self.assertTrue(f.readable()) self.assertEqual(f.readline(), b'hello\n') self.assertEqual(f.readline(), b'world\n') with openfile(self.fname, 'rb') as f: self.assertEqual(f.readlines(), [b'hello\n', b'world\n'])
def test_readline(self): with open(self.fname, 'w') as f: f.write('hello\nworld\n') with openfile(self.fname, 'r') as f: self.assertTrue(f.readable()) self.assertEqual(f.readline(), 'hello\n') self.assertEqual(f.readline(), 'world\n') with openfile(self.fname, 'r') as f: self.assertEqual(f.readlines(), ['hello\n', 'world\n'])
def test_readline(self): sep = os.linesep.encode() with open(self.fname, 'w') as f: f.write('hello\nworld\n') with openfile(self.fname, 'rb') as f: self.assertTrue(f.readable()) self.assertEqual(f.readline(), b'hello' + sep) self.assertEqual(f.readline(), b'world' + sep) with openfile(self.fname, 'rb') as f: self.assertEqual(f.readlines(), [b'hello' + sep, b'world' + sep])
def __init__(self, keys_path=settings.KEY_PAIR_DIR): if os.path.exists(keys_path) and os.path.getsize(keys_path) > 0: self.bio = openfile(keys_path, 'rb') self.rsa = load_key_bio(self.bio, callback=do_nothing) else: self.bio = openfile(keys_path, 'ab+') self.rsa = self.generate() self.rsa.save_key_bio(self.bio, callback=do_nothing) self.rsa.save_pub_key_bio(self.bio) self.bio.reset()
def test_readline_bin(self): with open(self.fname, 'wb') as f: f.write(b'hello\nworld\n') with openfile(self.fname, 'rb') as f: self.assertTrue(f.readable()) self.assertEqual(f.readline(), b'hello\n') self.assertEqual(f.readline(), b'world\n') with openfile(self.fname, 'rb') as f: self.assertEqual( f.readlines(), [b'hello\n', b'world\n'])
def test_readline(self): sep = os.linesep.encode() with open(self.fname, 'w') as f: f.write('hello\nworld\n') with openfile(self.fname, 'rb') as f: self.assertTrue(f.readable()) self.assertEqual(f.readline(), b'hello' + sep) self.assertEqual(f.readline(), b'world' + sep) with openfile(self.fname, 'rb') as f: self.assertEqual( f.readlines(), [b'hello' + sep, b'world' + sep])
def test_tell_seek(self): with open(self.fname, 'w') as f: f.write('hello world') with openfile(self.fname, 'r') as f: # Seek absolute f.seek(6) self.assertEqual(f.tell(), 6)
def test_openfile_wb(self): # First create the file using M2Crypto.BIO.openfile(). f = openfile(self.fname, 'wb') f.write(self.data) f.close() # Now open the file using Python's open(). f = open(self.fname, 'rb') data = f.read(len(self.data)) assert data == self.data
def test_openfile_wb(self): # First create the file using M2Crypto.BIO.openfile(). with openfile(self.fname, 'wb') as f: f.write(self.data) # Now open the file using Python's open(). with open(self.fname, 'rb') as f: data = f.read(len(self.data)) self.assertEqual(data, self.data)
def test_openfile_wb(self): # First create the file using M2Crypto.BIO.openfile(). log.info('self.fname = %s', self.fname) with openfile(self.fname, 'wb') as f: ret = f.write(self.data) log.info('ret = %s', ret) log.info('f = %s', f) # Now open the file using Python's open(). with open(self.fname, 'rb') as f: data = f.read(len(self.data)) self.assertEqual(data, self.data)
#!/usr/bin/env python3 # -*- coding: utf-8 -*- import logging import os from M2Crypto.BIO import openfile logging.basicConfig(format='%(levelname)s:%(funcName)s:%(message)s', level=logging.DEBUG) f = openfile('/tmp/test.txt', 'w') logging.debug('f = %s', f) ret = f.write('Zemské desky') logging.debug('ret = %s', ret) logging.debug('f.pyfile = dir %s', dir(f.pyfile)) f.close() logging.debug('f = %s', f) size = os.stat('/tmp/test.txt') logging.debug('size = %d', size.st_size)
def test_closed(self): f = openfile(self.fname, 'wb') f.write(self.data) f.close() with self.assertRaises(IOError): f.write(self.data)
def test_closed(self): f = openfile(self.fname, 'wb') f.write(self.data) f.close() self.assertRaises(IOError, f.write, self.data)