def _updatePluginRegistry(registry, xml, should_purge, encoding=None): if should_purge: registry._plugin_types = [] registry._plugin_type_info = PersistentMapping() registry._plugins = PersistentMapping() # When PAS import is used in an extension profile, the plugin # registry will have been deleted (content import deletes by # default) but should_purge will be false; need to initialize # _plugins since PluginRegistry's constructor doesn't if registry._plugins is None: registry._plugins = PersistentMapping() pir = PluginRegistryImporter(registry, encoding) reg_info = pir.parseXML(xml) for info in reg_info['plugin_types']: iface = _resolveDottedName(info['interface']) # Avoid duplicate plugin types if iface not in registry._plugin_types: registry._plugin_types.append(iface) registry._plugin_type_info[iface] = { 'id': info['id'], 'title': info['title'], 'description': info['description'], } registry._plugins[iface] = tuple([x['id'] for x in info['plugins']])
def setDependentProducts(jar, productid, dep_ids): productid = str(productid) rd = _getCentralRefreshData(jar, 1) products = rd.get('products', None) if products is None: rd['products'] = products = PersistentMapping() product = products.get(productid, None) if product is None: products[productid] = product = PersistentMapping() product['dependent_products'] = tuple(map(str, dep_ids))
def fixArchetypesTool(portal, out): at = portal.archetype_tool if not hasattr(at, '_templates'): # They come in pairs at._templates = PersistentMapping() at._registeredTemplates = PersistentMapping() if not hasattr(at, 'catalog_map'): at.catalog_map = PersistentMapping() install_uidcatalog(out, portal)
def create_frozen_state(self, workflow, **parameters): """ create a 'frozen' state """ if 'frozen' not in workflow.states: workflow.states.addState('frozen') frozen_state = workflow.states['frozen'] default_mapping = workflow.states.objectValues()[0].permission_roles.copy() frozen_state.title = 'frozen' frozen_state.permission_roles = default_mapping frozen_state.group_roles = PersistentMapping() frozen_state.var_values = PersistentMapping() frozen_state.transitions = ()
def test_copy_of(self): # Verifies the functionality of zodb_copy(). ob1 = PersistentMapping() ob1._p_oid = 'xxx' self.assertEqual(ob1._p_oid, 'xxx') # Precondition ob1['fish'] = PersistentMapping() ob1['fish']['trout'] = 1 ob1['fish']['herring'] = 2 ob2 = zodb_copy(ob1) self.assert_(ob2 is not ob1) self.assert_(ob2['fish'] is not ob1['fish']) self.assert_(ob2._p_oid is None) self.assertEqual(list(ob2.keys()), ['fish']) self.assertEqual(len(ob2['fish'].keys()), 2)
def setPermission(self, permission, roles, REQUEST=None): """ Set a permission for this State. """ if self.state_permission_role_list_dict is None: self.state_permission_role_list_dict = PersistentMapping() self.state_permission_role_list_dict[permission] = tuple(roles)
def gettext(self, msgid, lang=None, default=None): """Returns the corresponding translation of msgid in Catalog.""" if not isinstance(msgid, basestring): raise TypeError('Only strings can be translated.') # saving everything unicode, utf-8 elif isinstance(msgid, str): msgid = force_to_unicode(msgid) if not lang: raise ValueError("No language provided for gettext") msgid = msgid.strip() # empty message is translated as empty message, regardless of lang if not msgid: return msgid # default `default translation` is the msgid itself if default is None: default = msgid if lang not in self.get_languages(): # we don't have that lang, thus we can't translate and won't add msg return default # Add it if it's not in the dictionary if not self._messages.has_key(msgid): self._messages[msgid] = PersistentMapping() notify(MessageAddEvent(self, msgid, lang, default)) if not self._messages[msgid].has_key(self._default_language): default_translation = collapse_whitespace(default) self._messages[msgid][self._default_language] = default_translation # translation may be blank (supposition), then-> default (usually msgid) in_catalog = self._messages[msgid].get(lang, '') return in_catalog or default
def get_po_header(self, lang): """ """ # For backwards compatibility if not hasattr(aq_base(self), '_po_headers'): self._po_headers = PersistentMapping() return self._po_headers.get(lang, empty_po_header)
def initCriteria(self): """ initialize the dictionary of import criteria for each bibliography type """ # this is a migration 0.8 -> 0.9 fix: if not shasattr(self, '_criteria'): self._criteria = PersistentMapping() bib_tool = getToolByName(self, 'portal_bibliography') has = self._criteria_names.has_key for bib_type in bib_tool.getBibliographyContentTypes(): bibname = bib_type['name'] self._criteria[bibname] = [ criteria for criteria in self._nonmeta_criteria ] #adds all meta_data as criteria for each bibliography type for field in bib_type['schema'].fields(): field_name = field.getName() if field_name in self._ignored_criteria: continue if not shasattr(field, 'is_duplicates_criterion'): continue if not field.is_duplicates_criterion: continue if has(field_name): self._criteria[bibname].append( self._criteria_names[field_name]) else: self._criteria[bibname].append(field_name) self._criteria[bibname].sort() self._criteria[bibname] = tuple(self._criteria[bibname])
def __init__(self, id, title, sourcelang, languages): self.id = id self.title = title # Language Manager data self._languages = tuple(languages) self._default_language = sourcelang # Here the message translations are stored self._messages = PersistentMapping() # Data for the PO files headers self._po_headers = PersistentMapping() for lang in self._languages: self._po_headers[lang] = empty_po_header
def test_export_import(self): root = PersistentMapping() test1 = TestObject() test1.strdata = '345' test1['a'] = 'b' test1['c'] = 'd' root['TestRoot'] = test1 test2 = TestObject() test2.leftover = 'oops' test2['true'] = 'undecided' root['TestRoot2'] = test2 oid = '' exporter = io.ExportImport(self.conf, self.conns) exporter.export_object(root, oid) importer = io.ExportImport(self.conf, self.conns) roota = importer.import_object(oid) self.assert_(root is not roota) self.assert_(root['TestRoot'] is not roota['TestRoot']) self.assert_(root['TestRoot2'] is not roota['TestRoot2']) self.assertEqual(root['TestRoot'].data, roota['TestRoot'].data) self.assertEqual(root['TestRoot2'].data, roota['TestRoot2'].data) self.assertEqual(root['TestRoot'].strdata, roota['TestRoot'].strdata) self.assertEqual(root['TestRoot2'].leftover, roota['TestRoot2'].leftover)
def manage_changeWorkflows( self, title, description, default_chain, props=None, REQUEST=None): """ Changes which workflows apply to objects of which type A chain equal to 'None' is empty we remove the entry. """ self.title = title self.description = description if props is None: props = REQUEST cbt = self._chains_by_type if cbt is None: self._chains_by_type = cbt = PersistentMapping() ti = self._listTypeInfo() # Set up the chains by type. for t in ti: id = t.getId() field_name = 'chain_%s' % id chain = props.get(field_name, DEFAULT_CHAIN).strip() if chain == 'None': if cbt.get(id, _MARKER) is not _MARKER: self.delChain(id) continue self.setChain(id, chain) # Set up the default chain. self.setDefaultChain(default_chain) if REQUEST is not None: return self.manage_main(REQUEST, manage_tabs_message='Changed.')
def copyPermMap(old): """bullet proof copy """ new = PersistentMapping() for k, v in old.items(): new[k] = v return new
def gettext(self, message, lang=None, add=None, default=None): """Returns the message translation from the database if available. If add=1, add any unknown message to the database. If a default is provided, use it instead of the message id as a translation for unknown messages. """ if not isinstance(message, basestring): raise TypeError('only strings can be translated, not: %r' % (message, )) if default is None: default = message message = message.strip() # BBB call get_message_key to support both (old) str key and # (new) unicode key. message = self.get_message_key(message) or to_unicode(message) # Add it if it's not in the dictionary if add is None: add = getattr(self, 'policy', self.POLICY_ADD_TRUE) if add != self.POLICY_ADD_FALSE and not self._messages.has_key( message) and message: if add == self.POLICY_ADD_LOG: LOG( 'New entry added to message catalog %s :' % self.id, INFO, '%s\n%s' % (message, ''.join(format_list(extract_stack()[:-1])))) self._messages[message] = PersistentMapping() # Get the string if self._messages.has_key(message): m = self._messages[message] if lang is None: # Builds the list of available languages # should the empty translations be filtered? available_languages = list(self._languages) # Imagine that the default language is 'en'. There is no # translation from 'en' to 'en' in the message catalog # The user has the preferences 'en' and 'nl' in that order # The next two lines make certain 'en' is shown, not 'nl' if not self._default_language in available_languages: available_languages.append(self._default_language) # Get the language! lang = lang_negotiator(available_languages) # Is it None? use the default if lang is None: lang = self._default_language if lang is not None: return m.get(lang) or default return default
def copyPermMap(old): """bullet proof copy """ new = PersistentMapping() for k, v in list(old.items()): nk = copy(k) nv = copy(v) new[k] = v return new
def getTreeIdList(self, htree=None): """ Return list of all tree ids """ if self._tree_list is None or len(self._tree_list.keys()) == 0: tree_list = self._getTreeIdList(htree=htree) self._tree_list = PersistentMapping() for tree in tree_list: self._tree_list[tree] = None return sorted(self._tree_list.keys())