コード例 #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'])
コード例 #2
0
 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
ファイル: crypto.py プロジェクト: unoffices/netsukuku
 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
ファイル: crypto.py プロジェクト: AlexVanGluk/netsukuku
 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
ファイル: test_bio_file.py プロジェクト: mcepl/M2Crypto
 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
ファイル: test_bio_file.py プロジェクト: mcepl/M2Crypto
 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
ファイル: test_bio_file.py プロジェクト: mcepl/M2Crypto
 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
ファイル: test_bio_file.py プロジェクト: 0xkag/M2Crypto
 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
コード例 #11
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
コード例 #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
ファイル: test_bio_file.py プロジェクト: mcepl/M2Crypto
    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
ファイル: test_bio_file.py プロジェクト: 0xkag/M2Crypto
 def test_closed(self):
     f = openfile(self.fname, 'wb')
     f.write(self.data)
     f.close()
     self.assertRaises(IOError, f.write, self.data)