def test_save(self): s = sol.SOL('hello') s.update({'name': 'value', 'spam': 'eggs'}) x = StringIO() s.save(x) self.assertTrue(check_buffer(x.getvalue(), HelperTestCase.contents)) x = tempfile.mkstemp()[1] try: fp = open(x, 'wb+') self.assertEqual(fp.closed, False) s.save(fp) self.assertNotEquals(fp.tell(), 0) fp.seek(0) self.assertTrue(check_buffer(fp.read(), HelperTestCase.contents)) self.assertEqual(fp.closed, False) self.assertTrue( check_buffer(open(x, 'rb').read(), HelperTestCase.contents)) except: if os.path.isfile(x): os.unlink(x) raise
def test_save(self): s = sol.SOL('hello') s.update({'name': 'value', 'spam': 'eggs'}) x = BytesIO() s.save(x) self.assertTrue(check_buffer(x.getvalue(), HelperTestCase.contents)) tmp_name = tempfile.mkstemp()[1] try: with open(tmp_name, 'wb+') as fp: self.assertEqual(fp.closed, False) s.save(fp) self.assertNotEqual(fp.tell(), 0) fp.seek(0) self.assertTrue(check_buffer(fp.read(), HelperTestCase.contents)) self.assertEqual(fp.closed, False) with open(tmp_name, 'rb') as fp2: self.assertTrue( check_buffer(fp2.read(), HelperTestCase.contents) ) except: if os.path.isfile(tmp_name): os.unlink(tmp_name) raise
def test_save(self): s = sol.SOL('hello') s.update({'name': 'value', 'spam': 'eggs'}) x = os.tempnam() s.save(x) try: self.assertEquals(open(x, 'rb').read(), HelperTestCase.contents) except: if os.path.isfile(x): os.unlink(x) raise x = os.tempnam() fp = open(x, 'wb+') self.assertEquals(fp.closed, False) s.save(fp) self.assertNotEquals(fp.tell(), 0) fp.seek(0) self.assertEquals(fp.read(), HelperTestCase.contents) self.assertEquals(fp.closed, False) try: self.assertEquals(open(x, 'rb').read(), HelperTestCase.contents) except: if os.path.isfile(x): os.unlink(x) raise
def test_save_file(self): fp = open(self.file_name, 'wb+') s = sol.SOL('hello') s.update({'name': 'value', 'spam': 'eggs'}) sol.save(s, fp) fp.seek(0) self.assertFalse(fp.closed) self.assertTrue(check_buffer(fp.read(), self.contents)) fp.close()
def test_save_name(self): s = sol.SOL('hello') s.update({'name': 'value', 'spam': 'eggs'}) sol.save(s, self.file_name) fp = open(self.file_name, 'rb') try: self.assertTrue(check_buffer(fp.read(), self.contents)) finally: fp.close()
def __init__(self, *args): if len(args) < 2: raise Framework.exceptions.FrameworkException('AMF.SOL() requires at least two arguments') #TODO: Paths for Linux & Windows sol_path = os.path.expanduser("~/Library/Preferences/Macromedia/Flash Player/#SharedObjects") subdir = [d for d in os.listdir(sol_path) if re.match("^[A-Z0-9]{8}$", d)][0] # hopefully there's only one... self._path = os.path.join(sol_path, subdir, *args) + '.sol' if os.path.exists(self._path): self._sol = sol.load(self._path) else: self._sol = sol.SOL(args[-1])
def test_save_name(self): s = sol.SOL('hello') s.update({'name': 'value', 'spam': 'eggs'}) sol.save(s, self.file_name) fp = open(self.file_name, 'rb') try: self.assertEquals(fp.read(), self.contents) except: fp.close() raise
def get_uid(self): if not GOT_PYAMF: if DEBUG: log('lso::get_uid: mising pyamf') return path = self.build_path(self.root, self.name) if DEBUG: log('lso::get_uid: path', path) uid = None try: if path is not None and os.path.isfile(path): lso = sol.load(path) if DEBUG: log('lso::get_uid: file found, try to load: path', path, 'data', lso) if lso.has_key('uid'): uid = lso['uid'] if DEBUG: log('lso::get_uid: successfullly loaded: uid', uid, 'path', path) elif DEBUG: log('lso::get_uid: file not found: path', path) except: if DEBUG: print_exc() if uid is None: uid = self.create_uid() if DEBUG: log('lso::get_uid: create new uid:', uid) if path is not None and uid is not None: try: d = os.path.dirname(path) if not os.path.isdir(d): os.mkdir(d) lso = sol.SOL(self.name) lso['uid'] = uid if DEBUG: log('lso::get_uid: save to file: path', path, 'data', lso) sol.save(lso, path) except: if DEBUG: print_exc() return uid
def test_create(self): s = sol.SOL('eggs') self.assertEqual(s, {}) self.assertEqual(s.name, 'eggs')