本文整理汇总了Python中BTrees.IIBTree.IISet.insert方法的典型用法代码示例。如果您正苦于以下问题:Python IISet.insert方法的具体用法?Python IISet.insert怎么用?Python IISet.insert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BTrees.IIBTree.IISet
的用法示例。
在下文中一共展示了IISet.insert方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testFixed1843
# 需要导入模块: from BTrees.IIBTree import IISet [as 别名]
# 或者: from BTrees.IIBTree.IISet import insert [as 别名]
def testFixed1843(self):
from BTrees.IIBTree import IISet
t = IISet()
t.insert(1)
# This one used to fail to raise the TypeError when it occurred.
self.assertRaises(TypeError, t.keys, "")
# This one used to segfault.
self.assertRaises(TypeError, t.keys, 0, "")
示例2: get
# 需要导入模块: from BTrees.IIBTree import IISet [as 别名]
# 或者: from BTrees.IIBTree.IISet import insert [as 别名]
def get(self, pattern):
""" Query the lexicon for words matching a pattern."""
# single word pattern produce a slicing problem below.
# Because the splitter throws away single characters we can
# return an empty tuple here.
if len(pattern)==1: return ()
wc_set = [self.multi_wc, self.single_wc]
digrams = []
globbing = 0
for i in range(len(pattern)):
if pattern[i] in wc_set:
globbing = 1
continue
if i == 0:
digrams.insert(i, (self.eow + pattern[i]) )
digrams.append((pattern[i] + pattern[i+1]))
else:
try:
if pattern[i+1] not in wc_set:
digrams.append( pattern[i] + pattern[i+1] )
except IndexError:
digrams.append( (pattern[i] + self.eow) )
if not globbing:
result = self._lexicon.get(pattern, None)
if result is None:
return ()
return (result, )
## now get all of the intsets that contain the result digrams
result = None
for digram in digrams:
result=union(result, self._digrams.get(digram, None))
if not result:
return ()
else:
## now we have narrowed the list of possible candidates
## down to those words which contain digrams. However,
## some words may have been returned that match digrams,
## but do not match 'pattern'. This is because some words
## may contain all matching digrams, but in the wrong
## order.
expr = re.compile(self.createRegex(pattern))
words = []
hits = IISet()
for x in result:
if expr.match(self._inverseLex[x]):
hits.insert(x)
return hits
示例3: AccountingFolder
# 需要导入模块: from BTrees.IIBTree import IISet [as 别名]
# 或者: from BTrees.IIBTree.IISet import insert [as 别名]
class AccountingFolder(BaseFolder, BrowserDefaultMixin):
"""
"""
security = ClassSecurityInfo()
implements(interfaces.IAccountingFolder)
meta_type = 'AccountingFolder'
_at_rename_after_creation = True
schema = AccountingFolder_schema
##code-section class-header #fill in your manual code here
##/code-section class-header
# Methods
# Manually created methods
def __init__(self, oid, **kwargs):
BaseFolder.__init__(self, oid, **kwargs)
self._closing_transfers = IISet()
security.declareProtected(permissions.View, 'getAccountingRoot')
def getAccountingRoot(self):
''' Return 'self' as accounting root
'''
return self
def displayContentsTab(self):
""" Hide contents tab
"""
return False
def registerClosingDate(self, date):
""" register closing transfer date
"""
# strip time before insert
date = int(DateTime(date.Date()))
self._closing_transfers.insert(date)
def getClosingDates(self):
""" return all registered closing dates
"""
return self._closing_transfers
示例4: nearResultSets
# 需要导入模块: from BTrees.IIBTree import IISet [as 别名]
# 或者: from BTrees.IIBTree.IISet import insert [as 别名]
def nearResultSets(sets, index, distance=5, bidirectional=1):
""" perform near search on results sets """
# One resultset consists of an IISet() or documentIds and
# tuple whose first element is the word (from LexiconLookup())
# First we perform an intersection to get the documentIds of
# those documents that contain all the words
docids = intersectResultSets(sets).docIds()
# Now we determine for every document the positions of all
# the words inside the document. Then we compare all the positions
# to determine neighbourship
words = []
for set in sets:
for word in set.words().keys():
words.append(word)
res_docids = IISet()
for docId in docids:
# the posMap is a list of tuples(word,IISet[positions])
posMap = index.positionsFromDocumentLookup(docId, words)
if bidirectional:
if len(posMap.checkPositionMapBidirectional(distance)) > 0:
res_docids.insert(docId)
else:
if len(posMap.checkPositionMapUnidirectional(distance)) > 0:
res_docids.insert(docId)
d = {}
for w in words: d[w] = 1.0
return ResultSet(res_docids, d)
示例5: Article
# 需要导入模块: from BTrees.IIBTree import IISet [as 别名]
# 或者: from BTrees.IIBTree.IISet import insert [as 别名]
class Article(Posting):
""" """
security = ClassSecurityInfo()
meta_type ='Article'
icon ='misc_/Zch/posting_img'
security.declarePrivate('__init__')
def __init__(self, id):
Posting.__init__(self, id)
self.ids =IISet() #Article has sub ids.
security.declareProtected(View, 'relative_path')
def relative_path(self):
return self.id
security.declareProtected(View, 'index_html')
def index_html(self,REQUEST):
""" Zch article main page (the read more page) """
return self.article_html(self,REQUEST)
security.declareProtected(ManageZch, 'postingValues')
def postingValues(self):
""" return all replies """
return self.data_map(self.ids)
security.declareProtected(View, 'comment_list_size')
def comment_list_size(self, start=0, size=0):
""" returns comment items """
if start:
start = int(start)
else:
start = 0
if size:
size = int(size)
else:
size = 0
# Adjust start to tnum
if start == 1:
start = 2
if size:
size = size-1
# Convert to ids[] index number
if start:
start = start -2
if size == 0:
ids = [id for id in self.ids][start:]
else:
ids = [id for id in self.ids][start:start+size]
else:
if size == 0:
ids = [id for id in self.ids][:]
else:
ids = [id for id in self.ids][size*-1:]
return self.data_map(ids)
security.declareProtected(View, 'comment_list_from_to')
def comment_list_from_to(self, from_tnum=0, to_tnum=0):
""" returns comment items """
from_tnum = int(from_tnum)
to_tnum = int(to_tnum)
ids = [id for id in self.ids if (from_tnum == 0 or int(self.data[id].tnum) >= from_tnum) and (to_tnum == 0 or int(self.data[id].tnum) <= to_tnum)]
return self.data_map(ids)
security.declareProtected(AddCommentZch, 'addPosting')
def addPosting(self, file='', REQUEST=None,RESPONSE=None):
""" add a Comment """
index=1
id=self.createId()
msg=Comment(id, self.id)
err, sage = msg.__of__(self)._validation(REQUEST,RESPONSE,'delete attachment',file)
if err:
return err
# Set thread number.
msg.tnum = str(len(self.ids) + 2)
if sage==0:
self.modified=id
self.ids.insert(id)
self.data[id]=msg
if index:
msg.__of__(self).index()
if RESPONSE:
return self.showMessage(self, REQUEST=REQUEST,
title='Comment Posted',
message ='Your reply has been posted',
action=self.absolute_url()
)
return id
security.declareProtected(View, 'recent_entry')
#.........这里部分代码省略.........
示例6: get
# 需要导入模块: from BTrees.IIBTree import IISet [as 别名]
# 或者: from BTrees.IIBTree.IISet import insert [as 别名]
def get(self, key, default=None):
"""Return the matched word against the key."""
r=IISet()
wid=self._lexicon.get(key, default)
if wid is not None: r.insert(wid)
return r
示例7: search
# 需要导入模块: from BTrees.IIBTree import IISet [as 别名]
# 或者: from BTrees.IIBTree.IISet import insert [as 别名]
def search(self, path, default_level=0, depth=-1, navtree=0,
navtree_start=0):
"""
path is either a string representing a
relative URL or a part of a relative URL or
a tuple (path,level).
level >= 0 starts searching at the given level
level < 0 not implemented yet
"""
if isinstance(path, basestring):
startlevel = default_level
else:
startlevel = int(path[1])
path = path[0]
absolute_path = isinstance(path, basestring) and path.startswith('/')
comps = filter(None, path.split('/'))
orig_comps = [''] + comps[:]
# Optimization - avoid using the root set
# as it is common for all objects anyway and add overhead
# There is an assumption about catalog/index having
# the same container as content
if default_level == 0:
indexpath = list(filter(None, self.getPhysicalPath()))
while min(len(indexpath), len(comps)):
if indexpath[0] == comps[0]:
del indexpath[0]
del comps[0]
startlevel += 1
else:
break
if len(comps) == 0:
if depth == -1 and not navtree:
return IISet(self._unindex.keys())
# Make sure that we get depth = 1 if in navtree mode
# unless specified otherwise
orig_depth = depth
if depth == -1:
depth = 0 or navtree
# Optimized navtree starting with absolute path
if absolute_path and navtree and depth == 1 and default_level==0:
set_list = []
# Insert root element
if navtree_start >= len(orig_comps):
navtree_start = 0
# create a set of parent paths to search
for i in range(len(orig_comps), navtree_start, -1):
parent_path = '/'.join(orig_comps[:i])
parent_path = parent_path and parent_path or '/'
try:
set_list.append(self._index_parents[parent_path])
except KeyError:
pass
return multiunion(set_list)
# Optimized breadcrumbs
elif absolute_path and navtree and depth == 0 and default_level==0:
item_list = IISet()
# Insert root element
if navtree_start >= len(orig_comps):
navtree_start = 0
# create a set of parent paths to search
for i in range(len(orig_comps), navtree_start, -1):
parent_path = '/'.join(orig_comps[:i])
parent_path = parent_path and parent_path or '/'
try:
item_list.insert(self._index_items[parent_path])
except KeyError:
pass
return item_list
# Specific object search
elif absolute_path and orig_depth == 0 and default_level == 0:
try:
return IISet([self._index_items[path]])
except KeyError:
return IISet()
# Single depth search
elif absolute_path and orig_depth == 1 and default_level == 0:
# only get objects contained in requested folder
try:
return self._index_parents[path]
except KeyError:
return IISet()
# Sitemaps, relative paths, and depth queries
elif startlevel >= 0:
pathset = None # Same as pathindex
navset = None # For collecting siblings along the way
depthset = None # For limiting depth
if navtree and depth and \
self._index.has_key(None) and \
self._index[None].has_key(startlevel):
#.........这里部分代码省略.........
示例8: checkCatalog
# 需要导入模块: from BTrees.IIBTree import IISet [as 别名]
# 或者: from BTrees.IIBTree.IISet import insert [as 别名]
def checkCatalog(path,indexes):
""" perform some consistency checks on a ZCatalog instance"""
root = Zope2.app()
try:
catalog = root.unrestrictedTraverse(path)
except AttributeError:
print 'Error: catalog object not found'
sys.exit(1)
# get Catalog instance
_cat = catalog._catalog
# check Catalog internal BTrees
l_data = list(_cat.data.keys())
l_data.sort()
l_uids = list(_cat.uids.values())
l_uids.sort()
l_paths = list(_cat.data.keys())
l_paths.sort()
print "Checking catalog internal BTrees"
print "\tINFO: Mapping data: %d entries" % len(l_data)
print "\tINFO: Mapping uids: %d entries" % len(l_uids)
print "\tINFO: Mapping paths: %d entries" % len(l_paths)
if l_data == l_uids:
print "\tOK: Mapping data equals Mapping uids"
else:
print "\tERR: Mapping data does not equal Mapping uids"
if l_data == l_paths:
print "\tOK: Mapping data equals Maaping paths"
else:
print "\tERR: Mapping data does not equal Maaping paths"
# check BTrees of indexes
for id,idx in _cat.indexes.items():
if indexes and not idx.meta_type in indexes: continue
print "Checking index '%s' (type: %s)" % (id, idx.meta_type)
if idx.meta_type in ['FieldIndex','KeywordIndex']:
# check forward entries
RIDS = IISet()
for key, rids in idx._index.items():
if isinstance(rids,IntType):
RIDS.insert( rids )
else:
map(RIDS.insert , rids.keys())
diff = difference(RIDS, IISet(_cat.data.keys()))
if len(diff)!=0:
print '\tERR: Problem with forward entries'
print '\tERR: too much forward entries:', diff
else:
print '\tOK: Forward entries (%d entries)' % (len(RIDS))
elif idx.meta_type in ['PathIndex']:
RIDS = IISet()
for rids in map(None,idx._index.values()):
map(RIDS.insert , rids.values()[0])
diff = difference(RIDS, IISet(_cat.data.keys()))
if len(diff)!=0:
print '\tERR: Problem with forward entries'
print '\tERR: too much forward entries:', diff
else:
print '\tOK: Forward entries (%d entries)' % (len(RIDS))
if idx.meta_type in ['FieldIndex','KeywordIndex','PathIndex']:
# check backward entries
RIDS = IISet(idx._unindex.keys())
diff = difference(RIDS, IISet(_cat.data.keys()))
if len(diff)!=0:
print '\tERR: Problem with backward entries'
print '\tERR: too much backward entries:', diff
else:
print '\tOK: Backward entries (%d entries)' % (len(RIDS))
示例9: languageindex_search
# 需要导入模块: from BTrees.IIBTree import IISet [as 别名]
# 或者: from BTrees.IIBTree.IISet import insert [as 别名]
def languageindex_search(self, language, fallback=True, res=None):
main, sub = splitLanguage(language)
if main not in self._index:
return None
if fallback:
# Search in sorted order, specific sub tag first, None second
subs = list(self._index[main].keys())
subs.sort()
if sub in subs:
subs.remove(sub)
subs.insert(0, sub)
else:
subs = [sub]
if not fallback and res is not None:
# We do not support any optimization when fallback is enabled.
#
# TODO: The core loop is not in C here. Casual benchmarks suggest this
# is still more effecient than trying to move it to C. The problem is
# that we only have an IISet of docids as an input. We need to filter
# this per language. The available index structures we have are:
#
# IndexEntry objects used as entries. Complex objects storing docid,
# main and sub languages and UID of the canonical. Their hash and
# compare function uses the canonical UID.
#
# self._index
# An OOBTreeSet structure per language. In the outermost nodes we have
# OOBTree's per language. Useful to get all items in a language.
# Otherwise useless, as we would have to compare the docid attribute
# of the object in the tree against our wanted set, requiring a full
# loop over all items.
#
# self._unindex
# An IOBTree of docid to entry. Better to match our docid wanted set,
# but we would still have to compare the language code to the entry
# object itself.
#
# self._sortindex
# An IOBTree of docid to language tag. Looks like the best candidate
# for us, as we can compare the language directly as a simple string
# comparision.
#
# One thing to keep in mind, is that once we get a wanted set, this
# will usually have gone through a path query already. This means
# we will almost always already have matching set and won't filter
# out any item at all. So the edge-case of a 100% match is actually
# the most common one for us.
#
# Casual benchmarks show that trying to construct an IOBTree from the
# wanted set and intersecting it with the sortindex is still slower
# than having the core loop in Python code.
tag = lang_tag(main, sub)
result = IISet()
for r in res:
lang = self._sortindex.get(r)
if lang == tag:
result.insert(r)
return result
result = OOSet()
for sublanguage in subs:
result = oo_union(result, self._index[main][sublanguage])
return IISet(entry.docid for entry in result)
示例10: ZchSite
# 需要导入模块: from BTrees.IIBTree import IISet [as 别名]
# 或者: from BTrees.IIBTree.IISet import insert [as 别名]
#.........这里部分代码省略.........
security.declareProtected(ManageZch, 'postingValues')
postingValues = article_list
security.declareProtected(View, 'tpId')
def tpId(self):
return self.id
security.declareProtected(View, 'tpURL')
def tpURL(self):
return self.id
security.declareProtected(View, 'this')
def this(self):
return self
security.declareProtected(View, 'site_url')
def site_url(self):
# """ url of the Zch main page """
return self.absolute_url()
security.declareProtected(View, 'has_items')
def has_items(self):
return len(self.ids)
security.declareProtected(View, 'item_count')
def item_count(self):
return len(self.data)
security.declareProtected(AddArticleZch, 'addPosting')
def addPosting(self,file='',REQUEST=None,RESPONSE=None, index=1):
""" add an article """
id=self.createId()
msg=Article(id)
err, sage = msg.__of__(self)._validation(REQUEST,RESPONSE,'delete attachment',file)
if err:
return err
# Set thread number.
msg.tnum = '1'
self.ids.insert(id)
self.data[id]=msg
if index:
msg.__of__(self).index()
if RESPONSE:
return self.showMessage(self, REQUEST=REQUEST,
title='Article Posted',
message ='Your article has been posted',
action=self.absolute_url()
)
return id
security.declareProtected(View, 'search')
def search(self,REQUEST):
""" fulfill a search request """
if REQUEST.has_key('op') and REQUEST['op']=='articles':
REQUEST.set('meta_type','Article')
sr=self.__call__(REQUEST)
rc=len(sr)
return self.showSearchResults(self,REQUEST,search_results=sr,
result_count=rc)
security.declareProtected(ManageZch, 'manage_edit')
def manage_edit(self, REQUEST=None, fileattache=0):
""" edit Zch options """
self.fileattache = fileattache
if REQUEST is not None:
return REQUEST.RESPONSE.redirect(REQUEST['HTTP_REFERER'])
security.declareProtected(ManageZch, 'manage_delete')
def manage_delete(self,ids=[],REQUEST=None):
""" delete selected articles from a Zch site """
ids=map(atoi, ids)
for id in ids:
self.delItem(id)
if REQUEST is not None:
return REQUEST.RESPONSE.redirect(REQUEST['HTTP_REFERER'])
security.declarePrivate('list_skelton')
def list_skelton(self):
skelton = []
for item in os.listdir(os.path.join(package_home(globals()), 'skelton')):
skelton.append(item)
return skelton
# Searchable interface
security.declareProtected(View, '__call__')
def __call__(self, REQUEST=None, internal=0, **kw):
brains = apply(self.searchResults,(REQUEST,),kw)
if internal:
return map(lambda x: x.getObject(), brains)
return brains
示例11: search
# 需要导入模块: from BTrees.IIBTree import IISet [as 别名]
# 或者: from BTrees.IIBTree.IISet import insert [as 别名]
def search(self, path, default_level=0, depth=-1, navtree=0,
navtree_start=0):
"""
path is either a string representing a
relative URL or a part of a relative URL or
a tuple (path,level).
level >= 0 starts searching at the given level
level < 0 not implemented yet
"""
if isinstance(path, basestring):
startlevel = default_level
else:
startlevel = int(path[1])
path = path[0]
absolute_path = isinstance(path, basestring) and path.startswith('/')
comps = filter(None, path.split('/'))
orig_comps = [''] + comps[:]
if depth > 0:
raise ValueError, "Can't do depth searches anymore"
if not comps:
comps = ['dmd']
startlevel = 1
elif comps[0] == 'zport':
comps = comps[1:]
elif comps[0] != 'dmd':
raise ValueError, "Depth searches must start with 'dmd'"
startlevel = len(comps)
#startlevel = len(comps)-1 if len(comps) > 1 else 1
if len(comps) == 0:
if depth == -1 and not navtree:
return IISet(self._unindex.keys())
# Make sure that we get depth = 1 if in navtree mode
# unless specified otherwise
orig_depth = depth
if depth == -1:
depth = 0 or navtree
# Optimized navtree starting with absolute path
if absolute_path and navtree and depth == 1 and default_level==0:
set_list = []
# Insert root element
if navtree_start >= len(orig_comps):
navtree_start = 0
# create a set of parent paths to search
for i in range(len(orig_comps), navtree_start, -1):
parent_path = '/'.join(orig_comps[:i])
parent_path = parent_path and parent_path or '/'
try:
set_list.append(self._index_parents[parent_path])
except KeyError:
pass
return multiunion(set_list)
# Optimized breadcrumbs
elif absolute_path and navtree and depth == 0 and default_level==0:
item_list = IISet()
# Insert root element
if navtree_start >= len(orig_comps):
navtree_start = 0
# create a set of parent paths to search
for i in range(len(orig_comps), navtree_start, -1):
parent_path = '/'.join(orig_comps[:i])
parent_path = parent_path and parent_path or '/'
try:
item_list.insert(self._index_items[parent_path])
except KeyError:
pass
return item_list
# Specific object search
elif absolute_path and orig_depth == 0 and default_level == 0:
try:
return IISet([self._index_items[path]])
except KeyError:
return IISet()
# Single depth search
elif absolute_path and orig_depth == 1 and default_level == 0:
# only get objects contained in requested folder
try:
return self._index_parents[path]
except KeyError:
return IISet()
# Sitemaps, relative paths, and depth queries
elif startlevel >= 0:
pathset = None # Same as pathindex
navset = None # For collecting siblings along the way
depthset = None # For limiting depth
if navtree and depth and \
self._index.has_key(None) and \
self._index[None].has_key(startlevel):
navset = self._index[None][startlevel]
#.........这里部分代码省略.........