Did I find the right examples for you? yes no      Crawl my project      Python Jobs

All Samples(11)  |  Call(8)  |  Derive(0)  |  Import(3)
A simple wrapper around an anki.storage.Collection object.

This allows us to manage and refer to the collection, whether it's open or not. It
also provides a special "continuation passing" interface for executing functions
on the collection, which makes it easy to switch to a threading mode.

See ThreadingCollectionWrapper for a version that maintains a seperate thread for
interacting with the collection.

src/a/n/anki-sync-server-HEAD/AnkiServer/threading.py   anki-sync-server(Download)
import anki.storage
 
from AnkiServer.collection import CollectionWrapper, CollectionManager
 
from threading import Thread
    def __init__(self, path, setup_new_collection=None):
        self.path = path
        self.wrapper = CollectionWrapper(path, setup_new_collection)
 
        self._queue = Queue()

src/a/n/AnkiServer-2.0.5/AnkiServer/threading.py   AnkiServer(Download)
import anki.storage
 
from AnkiServer.collection import CollectionWrapper, CollectionManager
 
from threading import Thread
    def __init__(self, path, setup_new_collection=None):
        self.path = path
        self.wrapper = CollectionWrapper(path, setup_new_collection)
 
        self._queue = Queue()

src/a/n/anki-sync-server-HEAD/tests/test_collection.py   anki-sync-server(Download)
 
import AnkiServer
from AnkiServer.collection import CollectionWrapper, CollectionManager
 
class CollectionWrapperTest(unittest.TestCase):
    def test_lifecycle_real(self):
        """Testing common life-cycle with existing and non-existant collections. This
        test uses the real Anki objects and actually creates a new collection on disk."""
 
        wrapper = CollectionWrapper(self.collection_path)
 
        # open the same collection again (not a creation)
        wrapper = CollectionWrapper(self.collection_path)
        self.assertFalse(wrapper.opened())
        wrapper.open()
    def test_del(self):
        with mock.patch('anki.storage.Collection') as anki_storage_Collection:
            col = anki_storage_Collection.return_value
            wrapper = CollectionWrapper(self.collection_path)
            wrapper.open()
            setup_new_collection = MagicMock()
            self.assertFalse(os.path.exists(self.collection_path))
            wrapper = CollectionWrapper(self.collection_path, setup_new_collection)
            wrapper.open()
            anki_storage_Collection.assert_called_with(self.collection_path)