예제 #1
0
 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'])
예제 #3
0
 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])
예제 #4
0
 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()
예제 #5
0
 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()
예제 #6
0
 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'])
예제 #7
0
 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])
예제 #8
0
 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)
예제 #9
0
 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)
예제 #10
0
 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().
     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
예제 #12
0
    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)
예제 #13
0
    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)
예제 #14
0
    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)
예제 #15
0
#!/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)
예제 #16
0
 def test_closed(self):
     f = openfile(self.fname, 'wb')
     f.write(self.data)
     f.close()
     with self.assertRaises(IOError):
         f.write(self.data)
예제 #17
0
 def test_closed(self):
     f = openfile(self.fname, 'wb')
     f.write(self.data)
     f.close()
     self.assertRaises(IOError, f.write, self.data)