How to use the persistent.dict.PersistentDict function in persistent

To help you get started, we’ve selected a few persistent examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github collective / collective.easyslider / collective / easyslider / settings.py View on Github external
# XXX for things like plone.app.event, traversers
            # are not adaptable so we need to look at the parent here
            self.context = aq_parent(context)
            annotations = IAnnotations(self.context)

        self._metadata = annotations.get('collective.easyslider', None)
        if self._metadata is None:
            self._metadata = PersistentDict()
            annotations['collective.easyslider'] = self._metadata

        ctx = aq_inner(context)
        rootctx = getToolByName(ctx, 'portal_url').getPortalObject()
        rootannotations = IAnnotations(rootctx)
        self._rootmetadata = rootannotations.get('collective.easyslider', None)
        if self._rootmetadata is None:
            self._rootmetadata = PersistentDict()
            rootannotations['collective.easyslider'] = self._rootmetadata
github mgedmin / zodbbrowser / src / zodbbrowser / state.py View on Github external
def listItems(self):
        # Now this is tricky: we want to construct a small object graph using
        # old state pickles without ever calling __setstate__ on a real
        # Persistent object, as _that_ would poison ZODB in-memory caches
        # in a nasty way (LP #487243).
        container = OrderedContainer()
        container.__setstate__(self.state)
        if isinstance(container._data, PersistentDict):
            old_data_state = IObjectHistory(container._data).loadState(self.tid)
            container._data = PersistentDict()
            container._data.__setstate__(old_data_state)
        if isinstance(container._order, PersistentList):
            old_order_state = IObjectHistory(container._order).loadState(self.tid)
            container._order = PersistentList()
            container._order.__setstate__(old_order_state)
        return container.items()
github collective / rapido.plone / rapido / plone / database.py View on Github external
def set_watcher(self, path):
        annotations = IAnnotations(self)
        if ANNOTATION_KEY not in annotations:
            annotations[ANNOTATION_KEY] = PersistentDict()
        annotations[ANNOTATION_KEY]["watch_path"] = path
github enkore / borgcube / src / borgcube / core / models.py View on Github external
# hex archive id -> Archive
        self.archives = OOBTree()
        # client hostname -> Client
        self.clients = OOBTree()

        # job number -> Job
        # note: this tree is the canonical source of job numbers.
        self.jobs = NumberTree()
        # job state (str) -> NumberTree
        self.jobs_by_state = PersistentDefaultDict(factory=LOBTree)

        self.schedules = PersistentList()

        self.trigger_ids = OOBTree()

        self.ext = PersistentDict()
github castlecms / castle.cms / castle / cms / lead.py View on Github external
def find_image_in_annotation(data):
    if type(data) in (dict, PersistentMapping, PersistentDict):
        for field_name in ('content', 'video', 'image', 'images', 'audio'):
            if field_name not in data:
                continue
            val = data[field_name]
            if not val:
                continue
            if isinstance(data, list):
                val = val[0]
            if not isinstance(val, basestring):
                continue
            val = val.strip()
            if '<' in val:
                # possible html...
                return find_image_in_html(val)
            else:
                im = uuidToObject(val)
github plone / Products.Archetypes / Products / Archetypes / cache.py View on Github external
def getOrCreateCache(self):
        ann = IAnnotations(self.instance)
        transforms_cache = ann.setdefault(self.key, PersistentDict())
        field_cache = transforms_cache.setdefault(self.field.getName(),
                                                  PersistentDict())
        return field_cache
github plone / Products.CMFPlone / Products / CMFPlone / browser / syndication / settings.py View on Github external
def __init__(self, context):
        self.context = context
        self.annotations = IAnnotations(context)
        self.needs_saving = False

        self._metadata = self.annotations.get(FEED_SETTINGS_KEY, None)
        if self._metadata is None:
            self._metadata = PersistentDict()
            self.needs_saving = True

        registry = getUtility(IRegistry)
        self.site_settings = registry.forInterface(ISiteSyndicationSettings,
                                                   check=False)
github plomino / Plomino / Products / CMFPlomino / PlominoReplicationManager.py View on Github external
docid = node.getAttribute('id').encode('ascii')
        lastmodified = DateTime(node.getAttribute('lastmodified'))
        doc = self.createDocument(docid)

        # restore items
        itemnode = node.getElementsByTagName("params")[0]
        #result, method = xmlrpclib.loads(node.firstChild.toxml())
        result, method = xmlrpclib.loads(itemnode.toxml().encode('utf-8'))
        items = result[0]
        for k in items.keys():
            # convert xmlrpclib.DateTime into DateTime
            if items[k].__class__.__name__ == 'DateTime':
                items[k] = StringToDate(
                        items[k].value[:19],
                        format="%Y-%m-%dT%H:%M:%S")
        doc.items = PersistentDict(items)

        # restore files
        for fnode in node.getElementsByTagName("attachment"):
            filename = str(fnode.getAttribute('id'))
            contenttype = str(fnode.getAttribute('contenttype'))
            doc.setfile(
                    fnode.firstChild.data.decode('base64'),
                    filename=filename,
                    overwrite=True,
                    contenttype=contenttype)
        doc.save(onSaveEvent=False)
        doc.plomino_modification_time = lastmodified
github castlecms / castle.cms / castle / cms / browser / content / __init__.py View on Github external
def add_tmp_upload(self, obj, info):
        annotations = IAnnotations(obj)
        if '_tmp_files' not in annotations:
            annotations['_tmp_files'] = PersistentDict()
        tmp_files = annotations['_tmp_files']

        # cleanup old ones
        for tmp_id, item in [(k, v) for k, v in tmp_files.items()]:
            if (time.time() - item['uploaded']) > (1 * 60 * 60):
                del tmp_files[tmp_id]
        info['uploaded'] = time.time()
        tmp_files[info['field_name']] = info
github eea / eea.daviz / eea / daviz / app / handler.py View on Github external
def set_json(self, value):
        """ Set json dict
        """
        anno = IAnnotations(self.context)
        anno[ANNO_JSON] = PersistentDict(value)