rem stringlengths 0 322k | add stringlengths 0 2.05M | context stringlengths 8 228k |
|---|---|---|
def save_state(self): base = vfs.open(self.uri) | def _save_state(self, uri): base = vfs.open(uri) | def save_state(self): base = vfs.open(self.uri) tree_file = base.open('tree') docs_file = base.open('docs') try: # Removed terms for term in self.removed_terms: # XXX pass # Added terms for term in self.added_terms: documents = self.added_terms[term] self._index.index_term(tree_file, docs_file, term, documents) # Clean... |
msgstr = msgstr.replace('&', '&') | def f(match): x = match.group(0) if x.endswith(';'): return x return "&" + x[1:] msgstr = re.sub("&[\w;]*", f, msgstr) | def process_message(context): # Get the message to process and set a new message in the context message = context.message context.message = i18n.segment.Message() # Normalize the message message.normalize() # Left strip if message: x = message[0] if isinstance(x, unicode) and x.strip() == u'': del message[0] context.bu... |
yield line, reader.line_no | yield line | def parse(data, n_columns=None): """ This method is a generator that returns one CSV row at a time. To do the job it wraps the standard Python's csv parser. """ # Find out the dialect if data: lines = data.splitlines() dialect = sniffer.sniff('\n'.join(lines[:10])) # Fix the fucking sniffer dialect.doublequote = True i... |
create_catalog() load_documents() t0 = time() profile_indexing() t1 = time() print t1 - t0 | if len(sys.argv) == 2: option = sys.argv[1] else: option = None | def profile_search(): for word in ('forget', 'lion', 'hit'): catalog.search(body=word) |
if option == 'profile': create_catalog() load_documents() profile.run('profile_indexing()') elif option == 'bech': create_catalog() load_documents() t0 = time() profile_indexing() t1 = time() print t1 - t0 else: print "This script expects only one of the two options: 'profile'" \ " or 'bench'." | def profile_search(): for word in ('forget', 'lion', 'hit'): catalog.search(body=word) | |
self.resources[name] = File(data) | self.resources[name] = File(data, name=name) | def _set_file_resource(self, name, resource): data = resource.get_data() self.resources[name] = File(data) self.mtime = datetime.now() |
self.resources[name] = Folder() | self.resources[name] = Folder(name=name) | def _set_folder_resource(self, name, resource): self.resources[name] = Folder() self.mtime = datetime.now() |
usernames = [ x for x in self.get_handler_names() if not x.startswith('.') ] | usernames = [ x for x in self.get_handler_names() if not x.endswith('.metadata') ] | def get_usernames(self): """ Return all users name. """ usernames = [ x for x in self.get_handler_names() if not x.startswith('.') ] return frozenset(usernames) |
def to_str(self, encoding='UTF-8'): data = [] if self.document_type is not None: data.append('<!%s>' % self.document_type) data.append(self.get_root_element().to_str(encoding)) return ''.join(data) | def header_to_str(self, encoding='UTF-8'): if self.document_type is None: return '' return '<!%s>' % self.document_type | def to_str(self, encoding='UTF-8'): data = [] # The declaration if self.document_type is not None: data.append('<!%s>' % self.document_type) # The document itself data.append(self.get_root_element().to_str(encoding)) |
yield unicode(value), 0 | if isinstance(value, list) or isinstance(value, Set): for x in value: yield unicode(x), 0 else: yield unicode(value), 0 | def Keyword(value): if value: yield unicode(value), 0 |
stored_field = self.get_handler('d%d/s%d' % (doc_number, field.number)) | if doc_number in self.added_documents: doc_handler = self.added_documents[doc_number] else: doc_handler = self.get_handler('d%d' % doc_number) stored_field = doc_handler.get_handler('s%d' %field.number) | def search(self, query=None, **kw): # Build the query if it is passed through keyword parameters if query is None: for key, value in kw.items(): atom = Query.Simple(key, value) if query is None: query = atom else: query = Query.Complex(query, 'and', atom) # Check wether there is a query at all if query is None: raise V... |
handler = self.get_handler(name) root = self.get_site_root() languages = root.get_property('ikaaro:website_languages') handler.set_property('dc:title', title, languages[0]) | handler.set_property('dc:title', title, language) | def new_resource(self, context): class_id = context.get_form_value('class_id') name = context.get_form_value('name') title = context.get_form_value('dc:title') |
def f(x): expr = Expression(x.group(1)) | match = subs_expr_solo.match(data) if match is not None: expr = Expression(match.group(1)) | def f(x): expr = Expression(x.group(1)) value = expr.evaluate(stack, repeat_stack) if isinstance(value, unicode): return value.encode(encoding) return str(value) |
return subs_expr.sub(f, data) def encode_attribute(namespace, local_name, value, encoding='UTF-8'): datatype = schemas.get_datatype_by_uri(namespace, local_name) if issubclass(datatype, Boolean): if value == 'False': return None if bool(value) is True: return local_name elif value is not None: | def repl(match): expr = Expression(match.group(1)) value = expr.evaluate(stack, repeat_stack) if value is None: return '' | def f(x): expr = Expression(x.group(1)) value = expr.evaluate(stack, repeat_stack) if isinstance(value, unicode): return value.encode(encoding) return str(value) |
value = value.encode(encoding) else: value = str(value) return XMLAttribute.encode(value) return None | return value.encode(encoding) return str(value) return subs_expr.sub(repl, data) | def encode_attribute(namespace, local_name, value, encoding='UTF-8'): datatype = schemas.get_datatype_by_uri(namespace, local_name) if issubclass(datatype, Boolean): # XXX This representation of boolean attributes is specfic to HTML if value == 'False': return None if bool(value) is True: return local_name elif value i... |
value = substitute(value, stack, repeat, encoding) value = encode_attribute(namespace, local_name, value, encoding) if value is not None: s.append(' %s="%s"' % (qname, value)) | datatype = schemas.get_datatype_by_uri(namespace, local_name) if issubclass(datatype, Boolean): value = substitute_boolean(value, stack, repeat, encoding) if value is True: s.append(' %s="%s"' % (qname, local_name)) else: value = substitute(value, stack, repeat, encoding) if value is not None: value = XMLAttribute.enc... | def process1(node, stack, repeat, encoding='UTF-8'): """ Process "stl:if" and variable substitution. """ # Remove the element if the given expression evaluates to false if node.has_attribute(stl_uri, 'if'): stl_expression = node.get_attribute(stl_uri, 'if') if not stl_expression.evaluate(stack, repeat): return [] # Pr... |
Each slot is made of: - position (4 bytes) - next position (4 bytes) | The rest of the file is split into variable size blocks. A block maybe busy or free. A free block starts with a header: - number of slots [uint32] (excluding the header, maybe 0 or more) - next free block [link] A busy block stars with the header: - number of slots [uint32] So, the minimal size for a block, free o... | def _get_document_slot(self, slot_number, document_number): """ Searches and returns the slot number for the given document, starting from the given base slot. If it is not found None is returned. """ r = self.resource while True: base = 12 + slot_number * 16 x = IO.decode_uint32(r[base:base+4]) if x == document_number... |
def _get_free_slot(self): """ Returns the slot number of a free slot, allocates a new one if needed. """ state = self.state r = self.resource if state.first_empty is None: slot_number = state.number_of_slots state.number_of_slots += 1 r[4:8] = IO.encode_uint32(state.number_of_slots) else: slot_number = state.first_emp... | def _load_state(self, resource): state = self.state # The header state.version = IO.decode_version(resource[:4]) state.number_of_slots = IO.decode_uint32(resource[4:8]) state.first_empty = IO.decode_link(resource[8:12]) | |
while pos_slot_n is not None: pos_slot = 12 + pos_slot_n * 8 position = IO.decode_uint32(posi_rsrc[pos_slot:pos_slot+4]) documents.add(position) pos_slot_n = IO.decode_link(posi_rsrc[pos_slot+4:pos_slot+8]) | pos_slot = 12 + pos_slot_n * 4 data = posi_rsrc[pos_slot+4:pos_slot+4+(frequency*4)] i = 0 while i < frequency: documents.add(IO.decode_uint32(data[i:i+4])) i += 1 | def load_documents(self): # Initialize data structure self.documents = {} |
+ IO.encode_uint32(len(doc_positions)) | + IO.encode_uint32(frq) | def _index_term(self, term, documents): """ Indexes the given term. The parameter 'documents' is a mapping from document number to list of positions: |
for position in doc_positions: p_r = docs_rsrc[doc_slot+8:doc_slot+12] f_n = posi_handler._get_free_slot() f_b = 12 + f_n * 8 posi_rsrc[f_b:f_b+4] = IO.encode_uint32(position) posi_rsrc[f_b+4:f_b+8] = p_r docs_rsrc[doc_slot+8:doc_slot+12] = IO.encode_link(f_n) | free_block_n = posi_handler.state.first_empty previous_block_n = None while free_block_n is not None: free_block = 12 + free_block_n * 4 n = IO.decode_uint32(posi_rsrc[free_block:free_block+4]) if frq < n: new_free_block_n = free_block_n + frq + 1 new_free_block = 12 + new_free_block_n * 4 next_free_block_r = posi_rsr... | def _index_term(self, term, documents): """ Indexes the given term. The parameter 'documents' is a mapping from document number to list of positions: |
posi_rsrc = self.root.posi_handler.resource | posi_handler = self.root.posi_handler posi_rsrc = posi_handler.resource | def _unindex_term(self, word, documents): """ Un-indexes the given term. The parameter 'documents' is a list with the numbers of the documents that must be un-indexed. """ if word: if self.children is None: self.load_children() |
f_e = posi_rsrc[8:12] p_r = docs_rsrc[docs_slot+8:docs_slot+12] posi_rsrc[8:12] = p_r p_n = IO.decode_link(p_r) p_b = 12 + p_n * 8 pn_r = posi_rsrc[p_b+4:p_b+8] pn_n = IO.decode_link(pn_r) while pn_n is not None: p_n = pn_n p_b = 12 + p_n * 8 pn_r = posi_rsrc[p_b+4:p_b+8] pn_n = IO.decode_link(pn_r) posi_rsrc[p_b+8:p_... | new_free_block_r = docs_rsrc[docs_slot+8:docs_slot+12] new_free_block_n = IO.decode_link(new_free_block_r) new_free_block = 12 + new_free_block_n * 4 frq = IO.decode_uint32(posi_rsrc[new_free_block:new_free_block+4]) first_free_block_r = posi_rsrc[8:12] posi_rsrc[new_free_block:new_free_block+8] = ( IO.encode_uint32(fr... | def _unindex_term(self, word, documents): """ Un-indexes the given term. The parameter 'documents' is a list with the numbers of the documents that must be un-indexed. """ if word: if self.children is None: self.load_children() |
'if-modified-since': HTTPDate, | 'if-modified-since': If_Modified_Since, | def encode(value): return '; '.join([ '%s="%s"' % (name, value) for name, value in value.items() ]) |
def load(self, resource=None): | def _load(self, resource): | def load(self, resource=None): # XXX Clean the cache. # # This has a very negative performance impact; for example, if you # create a new resource into a folder, the folder's modification # time will change, then it will be re-loaded the next time; if the # handler has a lot of content, it will be cleaned, even if it i... |
Handler.load(self, resource) def _load(self, resource): | for name in self.resource.get_resource_names(): self.cache[name] = None | def load(self, resource=None): # XXX Clean the cache. # # This has a very negative performance impact; for example, if you # create a new resource into a folder, the folder's modification # time will change, then it will be re-loaded the next time; if the # handler has a lot of content, it will be cleaned, even if it i... |
return self.resource._get_resource_names() | return self.cache.keys() | def _get_handler_names(self): return self.resource._get_resource_names() |
def _del_handler(self, segment): self.resource.del_resource(segment) | self.cache[name] = None self.timestamp = datetime.datetime.now() def _del_handler(self, name): self.resource.del_resource(name) del self.cache[name] self.timestamp = datetime.datetime.now() | def _set_handler(self, name, handler): self.resource.set_resource(name, handler.resource) |
key = str(segment) resource_names = [ x for x in self.resource.get_resource_names() if x not in self.removed_handlers ] | def get_handler(self, path): # Be sure path is a Path if not isinstance(path, uri.Path): path = uri.Path(path) | |
elif name in resource_names: if key in self.cache: handler, atime = self.cache[key] if handler.is_outdated(): handler.load() | else: if name in self.cache and name not in self.removed_handlers: handler = self.cache[name] if handler is None: resource = self.resource.get_resource(name) handler = self._get_handler(segment, resource) handler.parent = self handler.name = segment.name self.cache[name] = handler else: if handler.is_outdated(): ... | def get_handler(self, path): # Be sure path is a Path if not isinstance(path, uri.Path): path = uri.Path(path) |
resource = self.resource.get_resource(name) handler = self._get_handler(segment, resource) | if name in self.cache: del self.cache[name] handler = self._get_virtual_handler(segment) | def get_handler(self, path): # Be sure path is a Path if not isinstance(path, uri.Path): path = uri.Path(path) |
atime = datetime.datetime.now() self.cache[key] = (handler, atime) else: if key in self.cache: del self.cache[key] handler = self._get_virtual_handler(segment) handler.parent = self handler.name = segment.name | def get_handler(self, path): # Be sure path is a Path if not isinstance(path, uri.Path): path = uri.Path(path) | |
container.timestamp = datetime.datetime.now() | def set_handler(self, path, handler, **kw): if not isinstance(path, uri.Path): path = uri.Path(path) | |
container.timestamp = datetime.datetime.now() | def del_handler(self, path): if not isinstance(path, uri.Path): path = uri.Path(path) | |
iindex.save() | iindex._save(iindex.resource) iindex.timestamp = iindex.resource.get_mtime() | def _save(self, resource): # Remove documents for doc_number in self.removed_documents: name = 'd%07d' % doc_number resource.del_resource(name) del self.cache[name] self.removed_documents = [] # Add documents for doc_number, document in self.added_documents.items(): if document.has_changed(): document.save() name = 'd%... |
method = handler.get_method(method_name) if method is None: if user is None: method = root.login_form | try: method = handler.get_method(method_name) except: server.log_error() response.set_status(500) method = root.internal_server_error else: if method is None: if user is None: method = root.login_form else: method = root.forbidden | def handle_request(connection, server): # Build the request object resource = File(connection) try: request = Request(resource) except BadRequest, exception: request = None request_line = exception.args[0] else: # Keep here (though redundant) to be used later in the access log request_line = request.state.request_line ... |
method = root.forbidden else: mtime = getattr(handler, '%s__mtime__' % method_name, None) if mtime is not None: mtime = mtime().replace(microsecond=0) response.set_header('last-modified', mtime) if request.method == 'GET': if request.has_header('if-modified-since'): msince = request.get_header('if-modified-since') if m... | mtime = getattr(handler, '%s__mtime__' % method_name, None) if mtime is not None: mtime = mtime().replace(microsecond=0) response.set_header('last-modified', mtime) if request.method == 'GET': if request.has_header('if-modified-since'): msince = request.get_header('if-modified-since') if mtime <= msince: response.set_... | def handle_request(connection, server): # Build the request object resource = File(connection) try: request = Request(resource) except BadRequest, exception: request = None request_line = exception.args[0] else: # Keep here (though redundant) to be used later in the access log request_line = request.state.request_line ... |
self._encoding = charset[len('charset='):] | self.encoding = charset[len('charset='):] | def next_entry(self): # Initialize entry information id, comments, msgid, msgstr, fuzzy = None, [], [], [], False # Parse entry state = 0 for m in self.next_line(): line_type, value, line_number = m # Syntactic and semantic analysis if state == 0: # Wait for an entry if line_type == EOF: return elif line_type == BLANK:... |
def _load_state(self, resource): | def _load_state_from_file(self, file): | def _load_state(self, resource): """ A PO file is made of entries, where entries are separated by one or more blank lines. Each entry consists of a msgid and a msgstr, optionally preceded by comments; if there are comments at the end of the entry they are ignored. So, an entry looks like: |
data = resource.read() | data = file.read() | def _load_state(self, resource): """ A PO file is made of entries, where entries are separated by one or more blank lines. Each entry consists of a msgid and a msgstr, optionally preceded by comments; if there are comments at the end of the entry they are ignored. So, an entry looks like: |
name, type, language = FileName.decode(name) | short_name, type, language = FileName.decode(name) | def upload_file(self, context): file = context.get_form_value('file') if file is None: raise UserError, self.gettext(u'The file must be entered') |
name = FileName.encode((name, type, language)) | name = FileName.encode((short_name, type, language)) | def upload_file(self, context): file = context.get_form_value('file') if file is None: raise UserError, self.gettext(u'The file must be entered') |
if kw.has_key('add_and_return'): | if context.has_form_value('add_and_return'): | def upload_file(self, context): file = context.get_form_value('file') if file is None: raise UserError, self.gettext(u'The file must be entered') |
documents.setdefault(doc_number, 0) documents[doc_number] += len(positions) | if doc_number in documents: documents[doc_number] |= positions else: documents[doc_number] = positions | def search_word(self, word): state = self.state |
edit_password_form__access__ = 'is_self_or_superuser' | edit_password_form__access__ = 'is_allowed_to_edit' | def edit_account(self, context): title = context.get_form_value('dc:title') email = context.get_form_value('email') password = context.get_form_value('password') |
def edit_password_form(self): context = get_context() | def edit_password_form(self, context): | def edit_password_form(self): context = get_context() user = context.user |
edit_password__access__ = 'is_self_or_superuser' def edit_password(self, newpass, newpass2, password='', **kw): context = get_context() | edit_password__access__ = 'is_allowed_to_edit' def edit_password(self, context): newpass = context.get_form_value('newpass') newpass2 = context.get_form_value('newpass2') password = context.get_form_value('password') | def edit_password_form(self): context = get_context() user = context.user |
context = get_context() | def edit_password(self, newpass, newpass2, password='', **kw): context = get_context() user = context.user | |
return ''.join(message.msgstr) | msgstr = ''.join(message.msgstr) if msgstr: return msgstr | def get_translation(self, msgid): message = self.state.messages.get(msgid) if message and not message.fuzzy: return ''.join(message.msgstr) return msgid |
root = Zope.app() | root = get_context().request.zope_request['PARENTS'][-1] | def _get_object(self): root = Zope.app() return root.unrestrictedTraverse(self._path) |
class ComplexType(object): | class ComplexType(XML.Element): | ## def decode(cls, value): |
def __init__(self, **kw): schema = self.schema for key, value in kw.items(): if key in schema: self.set_property(key, value) | def __init__(self, **kw): schema = self.schema for key, value in kw.items(): if key in schema: self.set_property(key, value) | |
property = cls() | property = cls(None, None) | def decode(cls, node): schema = cls.schema property = cls() for node in node.get_elements(): name = node.name # Decode the value if name in schema: type, default = schema[name] if issubclass(type, ComplexType): value = type.decode(node) else: value = XML.Children.encode(node.children) value = value.encode('utf8') try: ... |
self._deep_load() | if self.uri is not None: self._deep_load() | def copy_handler(self): # Deep load self._deep_load() # Create and initialize the instance cls = self.__class__ copy = object.__new__(cls) copy.uri = None copy.timestamp = None # Copy the state for name in cls.__slots__: if name in ('uri', 'timestamp', 'parent', 'name', 'real_handler'): continue value = getattr(self, n... |
if user is None: return self.get_handler('ui/aruni') theme = user.get_property('ikaaro:user_theme') | if user is not None: theme = user.get_property('ikaaro:user_theme') if theme not in themes: theme = themes[0] | def get_skin(self): context = get_context() |
if '.%s' % data[-1] in mimetypes.types_map: | if '.%s' % data[-1].lower() in mimetypes.types_map: | def decode(cls, data): data = data.split('.') |
self.lock = thread.allocate_lock() | self.lock = Lock() | def __init__(self, root): self.lock = thread.allocate_lock() self.pool = [root] |
print 'Listen port %s' % self.port while True: try: connection, client_address = ear.accept() except socket.error: continue except: ear.close() if self.access_log is not None: self.access_log.close() if self.error_log is not None: self.error_log.close() break else: thread.start_new_thread(handle_request, (connection, ... | try: while True: try: connection, client_address = ear.accept() except socket.error: continue thread = Thread(target=handle_request, args=(connection, self)) thread.start() except: ear.close() if self.access_log is not None: self.access_log.close() if self.error_log is not None: self.error_log.close() | def start(self): if self.pid_file is not None: pid = os.getpid() open(self.pid_file, 'w').write(str(pid)) |
base = vfs.open(self.uri) tree_file = base.open('tree') docs_file = base.open('docs') | if self.uri is None: tree_file = None docs_file = None else: base = vfs.open(self.uri) tree_file = base.open('tree') docs_file = base.open('docs') | def search_word(self, word): # Search in the data structure base = vfs.open(self.uri) tree_file = base.open('tree') docs_file = base.open('docs') try: documents = self._index.search_word(tree_file, docs_file, word) finally: tree_file.close() docs_file.close() |
tree_file.close() docs_file.close() | if self.uri is not None: tree_file.close() docs_file.close() | def search_word(self, word): # Search in the data structure base = vfs.open(self.uri) tree_file = base.open('tree') docs_file = base.open('docs') try: documents = self._index.search_word(tree_file, docs_file, word) finally: tree_file.close() docs_file.close() |
base = vfs.open(self.uri) tree_file = base.open('tree') docs_file = base.open('docs') | def search_range(self, left, right): # Search in the data structure base = vfs.open(self.uri) tree_file = base.open('tree') docs_file = base.open('docs') try: documents = self._index.search_range(tree_file, docs_file, left, right) finally: tree_file.close() docs_file.close() | |
tree_file.close() docs_file.close() | if self.uri is not None: tree_file.close() docs_file.close() | def search_range(self, left, right): # Search in the data structure base = vfs.open(self.uri) tree_file = base.open('tree') docs_file = base.open('docs') try: documents = self._index.search_range(tree_file, docs_file, left, right) finally: tree_file.close() docs_file.close() |
sniffer = csv.Sniffer() dialect = sniffer.sniff('\n'.join(data)) | if data: sniffer = csv.Sniffer() dialect = sniffer.sniff('\n'.join(data)) | def _load(self): Text._load(self) |
self.lines = [] for line in csv.reader(data, dialect): line = [ unicode(x, self._encoding) for x in line ] self.lines.append(line) | self.lines = [] for line in csv.reader(data, dialect): line = [ unicode(x, self._encoding) for x in line ] self.lines.append(line) else: self.lines = [] | def _load(self): Text._load(self) |
response = context.response | def handle_request(connection, server): # Build the request object resource = File(connection) try: request = Request(resource) except BadRequest, exception: request = None request_line = exception.args[0] else: # Keep here (though redundant) to be used later in the access log request_line = request.state.request_line ... | |
reference = self.uri.resolve(reference) | reference = self.uri.resolve2(reference) | def redirect(self, reference, status=302): reference = self.uri.resolve(reference) self.response.redirect(reference, status) |
version = "0.6.0", | version = "0.6.1", | def build_module(self, module, module_file, package): if isinstance(package, str): package = package.split('.') elif not isinstance(package, (list, tuple)): raise TypeError, \ "'package' must be a string (dot-separated), list, or tuple" |
id = ''.join(msgid) | def next_entry(self): # Initialize entry information id, comments, msgid, msgstr, fuzzy = None, [], [], [], False # Parse entry state = 0 for m in self.next_line(): line_type, value, line_number = m # Syntactic and semantic analysis if state == 0: # Wait for an entry if line_type == EOF: return elif line_type == BLANK:... | |
transaction.commit(username, note) if request.method == 'LOCK' or request.method == 'UNLOCK': from transaction import get as get_zodb_transaction zodb_transaction = get_zodb_transaction() zodb_transaction.setUser(username, '') zodb_transaction.note(note) zodb_transaction.commit() | try: transaction.commit(username, note) except: server.log_error() transaction.rollback() response.set_status(500) response_body = root.internal_server_error() else: if request.method == 'LOCK' or request.method == 'UNLOCK': from transaction import get as get_zodb_transaction zodb_transaction = get_zodb_transaction(... | def handle_request(connection, server): # Build the request object resource = File(connection) try: request = Request(resource) except BadRequest, exception: request = None request_line = exception.args[0] else: # Keep here (though redundant) to be used later in the access log request_line = request.state.request_line ... |
node = self.tree | node = self.root | def unindex_term(self, tree_file, docs_file, word, documents): """ Un-indexes the given term. The parameter 'documents' is a list with the numbers of the documents that must be un-indexed. """ # Get the node node = self.tree for c in word: if node.children is None: node.load_children(tree_file) # Next node = node.child... |
node.load_documents() | node.load_documents(tree_file, docs_file) | def unindex_term(self, tree_file, docs_file, word, documents): """ Un-indexes the given term. The parameter 'documents' is a list with the numbers of the documents that must be un-indexed. """ # Get the node node = self.tree for c in word: if node.children is None: node.load_children(tree_file) # Next node = node.child... |
del self.documents[doc_number] | del node.documents[doc_number] | def unindex_term(self, tree_file, docs_file, word, documents): """ Un-indexes the given term. The parameter 'documents' is a list with the numbers of the documents that must be un-indexed. """ # Get the node node = self.tree for c in word: if node.children is None: node.load_children(tree_file) # Next node = node.child... |
tree_file.seek(node.slot * 16 + 4) | tree_file.seek(node.block * 16 + 4) | def unindex_term(self, tree_file, docs_file, word, documents): """ Un-indexes the given term. The parameter 'documents' is a list with the numbers of the documents that must be un-indexed. """ # Get the node node = self.tree for c in word: if node.children is None: node.load_children(tree_file) # Next node = node.child... |
pass | documents = self.removed_terms[term] self._index.unindex_term(tree_file, docs_file, term, documents) | def _save_state(self, uri): base = vfs.open(uri) tree_file = base.open('tree') docs_file = base.open('docs') try: # Removed terms for term in self.removed_terms: # XXX pass # Added terms for term in self.added_terms: documents = self.added_terms[term] self._index.index_term(tree_file, docs_file, term, documents) # Clea... |
if isinstance(value, int): value = str(value) | def process1(self, node, stack, repeat): """ Process stl:if, stl:ifnot, stl:attributes and stl:content. """ attrs = node.attributes stl_uri = 'http://xml.itools.org/namespaces/stl' stl_attrs = attrs.namespaces.get(stl_uri, {}) | |
return self.get_start_tag() + self.get_content() + self.get_end_tag() | return self.get_start_tag() \ + self.get_content(encoding) \ + self.get_end_tag() | def to_unicode(self, encoding='UTF-8'): return self.get_start_tag() + self.get_content() + self.get_end_tag() |
if len(path) == 0: return '.' | def __str__(self): path = '' if self.startswith_slash: path = '/' path += '/'.join([ str(x) for x in self ]) if self.endswith_slash: path += '/' if len(path) == 0: return '.' return path | |
if path == '.': path = '' | def __str__(self): path = str(self.path) if path == '.': path = '' reference = urlunsplit((self.scheme, str(self.authority), path, str(self.query), self.fragment)) if reference == '': if self.fragment is not None: return '#' return '.' return reference | |
if request.uri.path.endswith_slash: | if context.uri.path.endswith_slash: | def handle_request(self, connection): # Build the request object resource = File(connection) try: request = Request(resource) except BadRequest, exception: request = None request_line = exception.args[0] except: self.log_error() request = None request_line = 'XXX' else: # Keep here (though redundant) to be used later i... |
goto = copy(request.uri) | goto = copy(context.uri) | def handle_request(self, connection): # Build the request object resource = File(connection) try: request = Request(resource) except BadRequest, exception: request = None request_line = exception.args[0] except: self.log_error() request = None request_line = 'XXX' else: # Keep here (though redundant) to be used later i... |
context = Context(request) set_context(context) | def handle_request(self, connection): # Build the request object resource = File(connection) try: request = Request(resource) except BadRequest, exception: request = None request_line = exception.args[0] except: self.log_error() request = None request_line = 'XXX' else: # Keep here (though redundant) to be used later i... | |
def _index_term(self, word, doc_number, position): | def _index_term(self, word, doc_number, positions): | def _index_term(self, word, doc_number, position): if word: prefix, suffix = word[0], word[1:] if prefix in self.children: subtree = self.children[prefix] else: # Get an empty slot free_slot_n = self.root.tree_handler._get_free_slot() # Update data structure on memory subtree = self.children[prefix] = Tree(self.root, f... |
subtree._index_term(suffix, doc_number, position) | subtree._index_term(suffix, doc_number, positions) | def _index_term(self, word, doc_number, position): if word: prefix, suffix = word[0], word[1:] if prefix in self.children: subtree = self.children[prefix] else: # Get an empty slot free_slot_n = self.root.tree_handler._get_free_slot() # Update data structure on memory subtree = self.children[prefix] = Tree(self.root, f... |
positions = self.documents[doc_number] positions.append(position) | aux = self.documents[doc_number] aux.extend(positions) positions = aux | def _index_term(self, word, doc_number, position): if word: prefix, suffix = word[0], word[1:] if prefix in self.children: subtree = self.children[prefix] else: # Get an empty slot free_slot_n = self.root.tree_handler._get_free_slot() # Update data structure on memory subtree = self.children[prefix] = Tree(self.root, f... |
frequency = len(positions) | def _index_term(self, word, doc_number, position): if word: prefix, suffix = word[0], word[1:] if prefix in self.children: subtree = self.children[prefix] else: # Get an empty slot free_slot_n = self.root.tree_handler._get_free_slot() # Update data structure on memory subtree = self.children[prefix] = Tree(self.root, f... | |
self.documents[doc_number] = positions = [position] | self.documents[doc_number] = positions | def _index_term(self, word, doc_number, position): if word: prefix, suffix = word[0], word[1:] if prefix in self.children: subtree = self.children[prefix] else: # Get an empty slot free_slot_n = self.root.tree_handler._get_free_slot() # Update data structure on memory subtree = self.children[prefix] = Tree(self.root, f... |
frequency = 1 | frequency = len(positions) | def _index_term(self, word, doc_number, position): if word: prefix, suffix = word[0], word[1:] if prefix in self.children: subtree = self.children[prefix] else: # Get an empty slot free_slot_n = self.root.tree_handler._get_free_slot() # Update data structure on memory subtree = self.children[prefix] = Tree(self.root, f... |
for position in positions: self._index_term(term, doc_number, position) | self._index_term(term, doc_number, positions) | def _save(self): # Removed terms for term, documents in self.removed_terms.keys(): for doc_number in documents: self._unindex_term(term, doc_number) self.removed_terms = {} # Added terms for term, documents in self.removed_terms.keys(): for doc_number, positions in documents.keys(): for position in positions: self._ind... |
def _index_term(self, word, doc_number, position): | def _index_term(self, word, doc_number, positions): | def _index_term(self, word, doc_number, position): prefix, suffix = word[0], word[1:] if prefix in self.children: subtree = self.children[prefix] else: # Get an empty slot slot_number = self.tree_handler._get_free_slot() subtree = self.children[prefix] = Tree(self, slot_number) # Update resource r = self.tree_handler.r... |
subtree._index_term(suffix, doc_number, position) | subtree._index_term(suffix, doc_number, positions) | def _index_term(self, word, doc_number, position): prefix, suffix = word[0], word[1:] if prefix in self.children: subtree = self.children[prefix] else: # Get an empty slot slot_number = self.tree_handler._get_free_slot() subtree = self.children[prefix] = Tree(self, slot_number) # Update resource r = self.tree_handler.r... |
return apply(x, self.parameters) else: return self.end(x) def end(self, value): """ Call the object at the end of the traversal to get the value, if it is callable. """ if callable(value): | x = apply(x, self.parameters) elif callable(x): | def evaluate(self, stack, repeat): if self.repeat: stack = repeat |
value = value() | x = x() | def end(self, value): """ Call the object at the end of the traversal to get the value, if it is callable. """ if callable(value): try: value = value() except AttributeError, error_value: # XXX "callable" could return true even if the object is not # callable (see Python's documentation). # # This happens, for example,... |
return value | return x | def end(self, value): """ Call the object at the end of the traversal to get the value, if it is callable. """ if callable(value): try: value = value() except AttributeError, error_value: # XXX "callable" could return true even if the object is not # callable (see Python's documentation). # # This happens, for example,... |
def N_(message, language=None): """ Used to markup a string for translation but without translating it, this is known as deferred translations. """ return message | def gettext(cls, message, language=None, domain=None): if domain is None: domain = cls.class_domain | |
path = str(context.path[1:]) | path = self.get_abspath() | def copy(self, ids=[], **kw): # Filter names which the authenticated user is not allowed to copy handlers = [ self.get_handler(x) for x in ids ] names = [ x.name for x in handlers if x.is_allowed_to_copy() ] |
context.set_cookie('ikaaro_cp', cp) | context.set_cookie('ikaaro_cp', cp, path='/') | def copy(self, ids=[], **kw): # Filter names which the authenticated user is not allowed to copy handlers = [ self.get_handler(x) for x in ids ] names = [ x.name for x in handlers if x.is_allowed_to_copy() ] |
path = str(context.path[1:]) | path = self.get_abspath() | def cut(self, ids=[], **kw): # Filter names which the authenticated user is not allowed to move handlers = [ self.get_handler(x) for x in ids ] names = [ x.name for x in handlers if x.is_allowed_to_move() ] |
context.set_cookie('ikaaro_cp', cp) | context.set_cookie('ikaaro_cp', cp, path='/') | def cut(self, ids=[], **kw): # Filter names which the authenticated user is not allowed to move handlers = [ self.get_handler(x) for x in ids ] names = [ x.name for x in handlers if x.is_allowed_to_move() ] |
self.encoding = attribute_value.split(';')[-1].strip()[8:] | self.encoding = content_value.split(';')[-1].strip()[8:] | def handle_starttag(self, name, attrs): line_number = self.getpos()[0] |
self.body = uri.generic.Query.decode(body) | self.body = Query.decode(body) | def non_blocking_load(self, read): """ Loads the request state from in non-blocking mode. Aimed at sockets, it works for files too. """ buffer = '' # Read the first line while True: data = read(512) data_size = len(data) # Check there is some data, if not we abort the request, something # may be wrong. if data_size == ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.