rem stringlengths 0 322k | add stringlengths 0 2.05M | context stringlengths 8 228k |
|---|---|---|
doc = tidy.parseString(self.to_str(), indent=1, char_encoding='utf8', output_xhtml=1) new_body = str(doc) | new_body = tidy.parseString(new_body, indent=1, char_encoding='utf8', output_xhtml=1) new_body = str(new_body) | def edit(self, context): # XXX This code is ugly. We must: (1) write our own XML parser, with # support for fragments, and (2) use the commented code. |
resource_names = [ x for x in tests.get_resources() if x.endswith('.txt') ] | src = get_resource(docs_path) resource_names = [ x for x in src.get_resources() if x.endswith('.html') ] | def _load(self, resource): # Pre-process (load as unicode) Text.Text._load(self, resource) data = self._data del self._data # Extract the title and body lines = data.split('\n') self.title = lines[0] self.body = '\n'.join(lines[3:]) |
documents = [ Document(tests.get_resource(x)) for x in resource_names ] | documents = [] for name in resource_names[:120]: try: doc = Document(src.get_resource(name)) except: pass else: documents.append(doc) print len(documents) catalog = Catalog(fields=[('title', 'text', True, True), ('body', 'text', True, False)]) | def _load(self, resource): # Pre-process (load as unicode) Text.Text._load(self, resource) data = self._data del self._data # Extract the title and body lines = data.split('\n') self.title = lines[0] self.body = '\n'.join(lines[3:]) |
for document in documents: | for document in documents[:25]: | def profile_indexing(): for document in documents: catalog.index_document(document) |
row = Row(line) | row = self.row_class(line) | def _load_state(self, resource): data = resource.read() |
new_row = Row(row) | new_row = self.row_class(row) | def add_row(self, row): """Append new row. row -- list with new row values """ self.set_changed() new_row = Row(row) self.state.lines.append(new_row) |
copy.timestamp = None | copy.timestamp = datetime.now() copy.real_handler = None | def copy_handler(self): # Deep load if self.uri is not None: 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'): continu... |
dst = src.replace('/database/', '/database.bak/', 1) | dst = src.replace(a, b, 1) | def end_commit_on_success(self): target = self.target transaction = get_transaction() abspaths = [ str(x.uri.path) for x in transaction if x.uri.scheme == 'file' ] abspaths.sort() open('%s/state' % target, 'w').write('END') try: for src in abspaths: dst = src.replace('/database/', '/database.bak/', 1) if os.path.isdir(... |
return unicode(data[:2:-1], 'unicode_internal') | return unicode(data[:2][::-1], 'unicode_internal') | def decode_character(data): return unicode(data[:2:-1], 'unicode_internal') |
if not name.startswith('.'): handler = self.get_handler(segment) root = self.get_root() if isinstance(root, Root): if isinstance(handler, Folder): for x, context in handler.traverse2(): if x.real_handler is None: root.unindex_handler(x) else: context.skip = True else: root.unindex_handler(handler) if isinstance(handl... | if name.startswith('.') or name.endswith('.metadata'): return handler = self.get_handler(segment) root = self.get_root() if isinstance(root, Root): if isinstance(handler, Folder): for x, context in handler.traverse2(): if x.real_handler is None: root.unindex_handler(x) else: context.skip = True else: root.unindex_han... | def on_del_handler(self, segment): from root import Root |
if uri.path.is_relative(): return offset.resolve(uri.path) return uri | if not uri.scheme and not uri.authority: if uri.path.is_relative(): if uri.path or str(uri) == '.': return offset.resolve(uri.path) return URI.encode(uri) | def resolve_pointer(uri, offset): if uri.path.is_relative(): # XXX Here we loss the query and fragment. return offset.resolve(uri.path) return uri |
raise UserError, self.gettext(u'The name must be entered') | message = u'The name must be entered' return context.come_back(replace) | 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') |
raise UserError, self.gettext(message) handler_class = self.get_handler_class(class_id) | return context.come_back(message) handler_class = get_object_class(class_id) | 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') |
raise UserError, self.gettext(message) | return context.come_back(message) | 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') |
message = self.gettext(u'New resource added.') | message = u'New resource added.' | 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') |
comeback(message, goto=goto) | context.come_back(message, goto=goto) | 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') |
message = (u'The document name contains illegal characters,' u' choose another one.') raise UserError, self.gettext(message) | return context.come_back( u'The document name contains illegal characters,' u' choose another one.') | 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') |
raise UserError, self.gettext(message) | return context.come_back(message) | 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 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 path == '.': path = '' | def __str__(self): path = str(self.path) | |
def get_skeleton(self): return '<?xml version="1.0" encoding="UTF-8"?>\n' \ | def get_skeleton(self, title=''): data = '<?xml version="1.0" encoding="UTF-8"?>\n' \ | def get_skeleton(self): return '<?xml version="1.0" encoding="UTF-8"?>\n' \ '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"\n' \ ' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">\n' \ '<html xmlns="http://www.w3.org/1999/xhtml">\n' \ ' <head>\n' \ ' <meta http-equiv="Content-Type" content="text... |
' <title></title>\n' \ | ' <title>%(title)s</title>\n' \ | def get_skeleton(self): return '<?xml version="1.0" encoding="UTF-8"?>\n' \ '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"\n' \ ' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">\n' \ '<html xmlns="http://www.w3.org/1999/xhtml">\n' \ ' <head>\n' \ ' <meta http-equiv="Content-Type" content="text... |
if tests.has_resource('catalog'): tests.del_resource('catalog') | if tests.has_handler('catalog'): tests.del_handler('catalog') | def create_catalog(): print 'Creating catalog...', global catalog # Create and get a new empty index catalog = Catalog(fields=[('title', 'text', True, True), ('body', 'text', True, False)]) tests = get_handler('tests') if tests.has_resource('catalog'): tests.del_resource('catalog') tests.set_handler('catalog', catalog)... |
catalog_resource = tests.get_resource('catalog') | tests.save() catalog_resource = tests.resource.get_resource('catalog') | def create_catalog(): print 'Creating catalog...', global catalog # Create and get a new empty index catalog = Catalog(fields=[('title', 'text', True, True), ('body', 'text', True, False)]) tests = get_handler('tests') if tests.has_resource('catalog'): tests.del_resource('catalog') tests.set_handler('catalog', catalog)... |
elif option == 'bech': | elif option == 'bench': | def profile_search(): for word in ('forget', 'lion', 'hit'): catalog.search(body=word) |
type = schema[self.name]['type'] | type = DublinCore.datatypes[self.name] | def set_text(self, text, encoding='UTF-8'): text = text.strip() type = schema[self.name]['type'] if type is Unicode: self.value = type.decode(text, encoding) else: self.value = type.decode(text) |
version = "0.4.2", | version = "0.4.3", | 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" |
raise UserError, self.gettext(u'The document name contains illegal characters, choose another one.') | message = (u'The document name contains illegal characters,' u' choose another one.') raise UserError, self.gettext(message) | def upload_file(self, file=None, **kw): if file is None: raise UserError, self.gettext(u'The file must be entered') |
raise UserError, self.gettext(u'There is already another resource with this name.') | message = u'There is already another resource with this name.' raise UserError, self.gettext(message) | def upload_file(self, file=None, **kw): if file is None: raise UserError, self.gettext(u'The file must be entered') |
class RDFTestCase(TestCase): def test_parsing(self): resource = get_resource('test.rdf') handler = RDF(resource) | def setUp(self): # Load the scheme r = get_resource('es.xsd') doc = XML.Document(r) | |
XML.registry.set_namespace('http://www.lisa.org/tmx', self.schema) print"==========================================" | subject = u'http://www.example.org/index.html' self.assertEqual(handler.graph, {subject: [(u'title', u'The itools reference manual'), (u'description', u'')]}) | def setUp(self): # Load the scheme r = get_resource('es.xsd') doc = XML.Document(r) |
def test_simple(self): rr = get_resource('es.xml') doc = XML.Document(rr) | def setUp(self): # Load the scheme r = get_resource('es.xsd') doc = XML.Document(r) | |
content = 'msgid "Add"\n' \ 'msgstr "Aadir\\n"\n' po = parsers.PO(content) assert po.messages == {('Add',): ([], ['Aadir\n'])} | content = [" " " " " " 'msgid "Add"', 'msgstr "Anadir\\n"'] content = '\n'.join(content) po = parsers.PO content = memory.File(content) p = po.PO(content) assert p.messages[0].msgid == ['Add'] assert p.messages[0].msgstr[0] == 'Anadir\n' | def test_case1(self): """Test for newlines.""" content = 'msgid "Add"\n' \ 'msgstr "Aadir\\n"\n' |
po = parsers.PO(content) assert po.messages == {('Hello world',): ([], ['', 'Hola ', 'mundo'])} | po = parsers.PO content = memory.File(content) p = po.PO(content) assert p.messages[0].msgid == ['Hello world'] assert p.messages[0].msgstr == [u'', u'Hola ', u'mundo'] | def test_case2(self): """Test for multiple lines""" content = 'msgid "Hello world"\n' \ 'msgstr ""\n' \ '"Hola "\n' \ '"mundo"\n' |
po = parsers.PO(content) assert po.messages == {('test',): ([], ['Esto es una "prueba"'])} | p = parsers.PO.PO(memory.File(content)) assert p.messages[0].msgid == ['test'] assert p.messages[0].msgstr == [u'Esto es una "prueba"'] | def test_case3(self): """Test for double quotes.""" content = 'msgid "test"\n' \ 'msgstr "Esto es una \\"prueba\\""\n' |
po = parsers.PO(content) assert po.write() == content | p = parsers.PO.PO(memory.File(content)) assert p.messages[0].msgid == ['Hello'] assert p.messages[0].msgstr == [u'', u'Hola\n'] | def test_output(self): """Test output""" content = '# Comment\n' \ 'msgid "Hello"\n' \ 'msgstr ""\n' \ '"Hola\\n"\n' |
data = '<p>hello world</p>' xhtml = parsers.XHTML(data) messages = xhtml.get_messages() assert messages == [u'hello world'] | data = self.template % '<p>hello litle world</p>' data = memory.File(data) xhtml = parsers.XHTML.Document(data) messages = list(xhtml.get_messages()) assert messages == [u'hello litle world'] | def test_case1(self): """Test element content.""" data = '<p>hello world</p>' |
data = '<img alt="The beach" src="beach.jpg" />' xhtml = parsers.XHTML(data) messages = xhtml.get_messages() | data = self.template % '<img alt="The beach" src="beach.jpg" />' data = memory.File(data) xhtml = parsers.XHTML.Document(data) messages = list(xhtml.get_messages()) | def test_case2(self): """Test simple attribute.""" data = '<img alt="The beach" src="beach.jpg" />' |
data = '<html>\n' \ '<input type="text" name="id" />\n' \ '<input type="submit" value="Change" />\n' \ '</html>' xhtml = parsers.XHTML(data) messages = xhtml.get_messages() | data = self.template % """<input type="text" name="id" /> <input type="submit" value="Change" />""" data = memory.File(data) xhtml = parsers.XHTML.Document(data) messages = list(xhtml.get_messages()) | def test_case3(self): """Test complex attribute.""" data = '<html>\n' \ '<input type="text" name="id" />\n' \ '<input type="submit" value="Change" />\n' \ '</html>' |
html = '<p>hello world</p>' | html = self.template % '<p>hello world</p>' po = 'msgid "hello world"\n' \ 'msgstr "hola mundo"\n' p = parsers.PO.PO(memory.File(po)) html = memory.File(html) xhtml = parsers.XHTML.Document(html) html = xhtml.translate(p) html = memory.File(html) xhtml = parsers.XHTML.Document(html) data = list(xhtml.get_messages()... | def test_case4(self): """Test translation of an element content""" html = '<p>hello world</p>' po = 'msgid "hello world"\n' \ 'msgstr "hola mundo"' |
xhtml = parsers.XHTML(html) data = xhtml.translate(po) assert data == '<p>hola mundo</p>' | p = parsers.PO.PO(memory.File(po)) html = memory.File(html) xhtml = parsers.XHTML.Document(html) html = xhtml.translate(p) result = self.template % '<p>hola mundo </p>' assert html == result | def test_case4(self): """Test translation of an element content""" html = '<p>hello world</p>' po = 'msgid "hello world"\n' \ 'msgstr "hola mundo"' |
xhtml = parsers.XHTML(html) data = xhtml.translate(po) assert data == '<img src="beach.jpg" alt="La playa"></img>' | p = parsers.PO.PO(memory.File(po)) html = memory.File(html) xhtml = parsers.XHTML.Document(html) | def test_case5(self): """Test translation of an element content""" html = '<img alt="The beach" src="beach.jpg" />' po = 'msgid "The beach"\n' \ 'msgstr "La playa"' |
html = '<html>\n' \ '<input type="text" name="id" />\n' \ '<input type="submit" value="Change" />\n' \ '</html>' | html = self.template % '<input type="text" name="id"/>\n' \ '<input type="submit" value="Change"/>' | def test_case6(self): """Test translation of an element content""" html = '<html>\n' \ '<input type="text" name="id" />\n' \ '<input type="submit" value="Change" />\n' \ '</html>' po = 'msgid "Change"\n' \ 'msgstr "Cambiar"' |
xhtml = parsers.XHTML(html) data = xhtml.translate(po) assert data == '<html>\n' \ '<input type="text" name="id"></input>\n' \ '<input type="submit" value="Cambiar"></input>\n' \ '</html>' class HMLTestCase(TestCase): def test_case1(self): """Test element content.""" data = '<p>hello world</p>' html = parsers.HTML(... | p = parsers.PO.PO(memory.File(po)) html = memory.File(html) xhtml = parsers.XHTML.Document(html) html = xhtml.translate(p) result = self.template % '<input type="text" name="id"/>\n' \ '<input type="submit" value="Cambiar/">' assert html == result | def test_case6(self): """Test translation of an element content""" html = '<html>\n' \ '<input type="text" name="id" />\n' \ '<input type="submit" value="Change" />\n' \ '</html>' po = 'msgid "Change"\n' \ 'msgstr "Cambiar"' |
'mtime': str(self.resource.get_mtime().strftime('%Y%m%d%H%M%S')), | 'mtime': str(vfs.get_mtime(self.uri).strftime('%Y%m%d%H%M%S')), | def get_catalog_indexes(self): name = self.name abspath = self.get_abspath() get_property = self.get_metadata().get_property title = get_property('dc:title') |
if self.schema and self.columns: for line in self.state.lines: line = [ '"%s"' % self.schema[self.columns[i]].encode(value) for i, value in enumerate(line) ] | schema = self.schema columns = self.columns if schema and columns: datatypes = [ (i, schema[x]) for i, x in enumerate(columns) ] for row in self.state.lines: line = [ '"%s"' % datatype.encode(row[i]).replace('"', '""') for i, datatype in datatypes ] | def to_str(self, encoding='UTF-8'): lines = [] # When schema or columns (or both) are None there is plain # string to string conversion if self.schema and self.columns: for line in self.state.lines: line = [ '"%s"' % self.schema[self.columns[i]].encode(value) for i, value in enumerate(line) ] lines.append(','.join(line... |
line = [ '"%s"' % x.encode(encoding) for x in line ] | line = [ '"%s"' % x.encode(encoding).replace('"', '""') for x in line ] | def to_str(self, encoding='UTF-8'): lines = [] # When schema or columns (or both) are None there is plain # string to string conversion if self.schema and self.columns: for line in self.state.lines: line = [ '"%s"' % self.schema[self.columns[i]].encode(value) for i, value in enumerate(line) ] lines.append(','.join(line... |
original = str(path.resolve(filename[1:-4])) | original = path.resolve(filename[1:-4]) | def rollback(database): transaction = get_transaction() for reference in transaction: path = reference.path filename = path[-1].name marker = filename[-3:] original = str(path.resolve(filename[1:-4])) backup = str(path) if marker == 'tmp': remove(backup) elif marker == 'add': FileFS.remove(original) remove(backup) elif... |
print value | def Bool(value): print value yield str(int(value)), 0 | |
names = [ x.name for x in handlers if x.is_allowed_to_copy() ] | ac = self.get_access_control() names = [ x.name for x in handlers if ac.is_allowed_to_copy(context.user, x) ] | def copy(self, context): ids = context.get_form_values('ids') # 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() ] |
names = [ x.name for x in handlers if x.is_allowed_to_move() ] | ac = self.get_access_control() names = [ x.name for x in handlers if ac.is_allowed_to_move(context.user, x) ] | def cut(self, context): ids = context.get_form_values('ids') # 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() ] |
if node.name == 'script': | if node.name == 'script' or node.name == 'style': | def before(node, context): message = context.message if isinstance(node, XML.Raw): message.append(node.data) elif isinstance(node, XML.Element): # Skip <script> (XXX do the same with <style>??) if node.name == 'script': process_message(context) return True # Attributes for attribute in node.attributes: if node.is_trans... |
if not x.name.startswith('.'): | if isinstance(x, CatalogAware): | def after_set_handler(self, segment, handler, format=None, id=None, move=False, **kw): from root import Root |
mimetype = self.get_mimetype() | metadata = self.get_metadata() if metadata is None: mimetype = self.get_mimetype() else: mimetype = self.get_property('format') | def download(self): context = get_context() request, response = context.request, context.response |
path_to_icon = uri.Path('%s/' % name).resolve(path_to_icon) | path_to_icon = Path('%s/' % name).resolve(path_to_icon) | def browse_namespace(self, icon_size, sortby='title_or_name', sortorder='up', batchstart='0', batchsize='20', query={}, results=None): context = get_context() request = context.request |
path = uri.Path(selected_image) | path = Path(selected_image) | def browse_image(self, context): selected_image = context.get_form_value('selected_image') selected_index = None |
return uri.get_reference(';rename_form?%s' % ids_list) | return get_reference(';rename_form?%s' % ids_list) | def rename_form(self, context): ids = context.get_form_values('ids') # Filter names which the authenticated user is not allowed to move handlers = [ self.get_handler(x) for x in ids ] ac = self.get_access_control() names = [ x.name for x in handlers if ac.is_allowed_to_move(context.user, x) ] |
goto = uri.get_reference(';%s' % self.get_browse_view()) | goto = get_reference(';%s' % self.get_browse_view()) | def rename(self, context): names = context.get_form_value('names') new_names = context.get_form_value('new_names') # Process input data for i, old_name in enumerate(names): xxx, extension, language = FileName.decode(old_name) new_name = FileName.encode((new_names[i], extension, language)) new_name = checkid(new_name) i... |
goto = uri.get_reference(goto) | goto = get_reference(goto) | def upload_file(self, context): file = context.get_form_value('file') if file is None: return context.come_back(u'The file must be entered') |
data.append('Date: %s' % now.strftime("%a, %d %b %Y %H:%M:%S +0000")) | data.append('Date: %s' % HTTPDate.encode(now)) | def to_str(self): state = self.state |
return self.gettext(message) | return self.gettext(message).encode('utf-8') | def forbidden(self, context): message = (u'Access forbidden, you are not authorized to access' u' this resource.') return self.gettext(message) |
value = type.decode(value) | try: value = type.decode(value) except ValueError: warnings.warn('Unable to decode "%s"' % name) | 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, SimpleType): value = unicode(node.children) value = type.decode(value) elif issubclass(type, ComplexType): value = type.dec... |
languages = [ x.split('.')[-1] for x in self.resource.get_resource_names() | languages = [ x.split('.')[-1] for x in vfs.get_names(self.uri) | def _get_virtual_handler(self, segment): name = segment.name |
A budy block format is: | A busy block format is: | def _get_free_slot(self): """ Internal method that returns a free slot. If none exists a new one is allocated. |
- free slot (size - 1) | - free slot (size - 2) | def _get_free_slot(self): """ Internal method that returns a free slot. If none exists a new one is allocated. |
or path.endswith('/.') \ or path.endswith('/..') | or path.endswith('/.') | def normalize_path(path): """ Normalize the path (we don't use os.path because on Windows it converts forward slashes to back slashes). Examples: a//b/c : a/b/c a/./b/c : a/b/c a/b/c/../d : a/b/d /../a/b/c : /a/b/c """ if not isinstance(path, str) and not isinstance(path, unicode): raise TypeError, 'path must... |
self.del_handler('d%d' % doc_number) | self.del_handler('d%07d' % doc_number) | def _save(self): # Remove documents for doc_number in self.removed_documents: self.del_handler('d%d' % doc_number) self.removed_documents = [] # Add documents for doc_number, document in self.added_documents.items(): self.set_handler('d%d' % doc_number, document) self.added_documents = {} # Save indexes fields = self.g... |
self.set_handler('d%d' % doc_number, document) | self.set_handler('d%07d' % doc_number, document) | def _save(self): # Remove documents for doc_number in self.removed_documents: self.del_handler('d%d' % doc_number) self.removed_documents = [] # Add documents for doc_number, document in self.added_documents.items(): self.set_handler('d%d' % doc_number, document) self.added_documents = {} # Save indexes fields = self.g... |
document = self.get_handler('d%d' % doc_number) | document = self.get_handler('d%07d' % doc_number) | def unindex_document(self, doc_number): if doc_number in self.added_documents: document = self.added_documents.pop(doc_number) else: document = self.get_handler('d%d' % doc_number) self.removed_documents.append(doc_number) for name in document.resource.get_resource_names(): if name.startswith('i'): field = document.ge... |
doc_handler = self.get_handler('d%d' % doc_number) | doc_handler = self.get_handler('d%07d' % doc_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... |
base_path = request.get_header('X-Base-Path') | base_path = uri.Path(request.get_header('X-Base-Path')) | def __init__(self, request): self.request = request self.response = Response() |
request_uri.path = uri.Path('/%s%s' % (base_path,request_uri.path)) | diff_path = base_path.get_pathto(request_uri.path) request_uri.path = uri.Path('/%s' % diff_path) | def __init__(self, request): self.request = request self.response = Response() |
data = getattr(document, field_name) if callable(data): data = data() | if callable(field): data = field() else: data = field | def index_document(self, document): # Get the document number doc_number = self.get_new_document_number() # Add the document to 'self.documents' fields = {} # Update the search data structure (term dictionary) for field_name in self.indexed_fields: if hasattr(document, field_name): tree = self.indexed_fields[field_name... |
s.append(' %s="%s"' % (qname, str(value))) | datatype = schemas.get_datatype_by_uri(namespace, local_name) value = datatype.encode(value) s.append(' %s="%s"' % (qname, value)) | def process1(node, stack, repeat, encoding='UTF-8'): """ Process stl:if, stl:attributes and stl:content. """ # 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 [] ... |
return chr(byte) | return chr(value) | def encode_byte(value): return chr(byte) |
byte = decode_byte(data[i+1]) | byte = decode_byte(data[i]) | def decode_vint(data): byte = decode_byte(data[0]) x = byte & 0x7F i = 1 while byte & 0x80: byte = decode_byte(data[i+1]) x |= (byte & 0x7F) << (i * 7) i = i + 1 # Being a variable length value, it returns a tuple, where the first # item is the decoded value and the second one is the data that remains # to analyze. re... |
'meta_type:toto', | def external_edit(self, encoding=None, **kw): # XXX This code depends too much on Zope, while the ExternalEditor # client doesn't (using the HTTP+WebDAV protocol). # TODO extend the lock API of resources, and move the code below # playing with the Zope object to itools.resources.zope2. Think of an # implementation for ... | |
message = (u"You mistyped your actual password, " u"you account is not changed.") raise UserError, self.gettext(message) | return context.come_back(u"You mistyped your actual password, " u"your account is not changed.") | def edit_password(self, context): newpass = context.get_form_value('newpass') newpass2 = context.get_form_value('newpass2') password = context.get_form_value('password') user = context.user |
for handler in self: if handler.resource.get_mtime() is not None: handler.save() | try: for handler in self: if handler.resource.get_mtime() is not None: handler.save() except: self.rollback() raise self.clear() | def commit(self): # Event: before commit for handler in list(self): if hasattr(handler, 'before_commit'): handler.before_commit() |
self.clear() | def commit(self): # Event: before commit for handler in list(self): if hasattr(handler, 'before_commit'): handler.before_commit() | |
files.append(join(*path[1:])) | files.append(os.path.join(*path[1:])) | def fixed_import(name, globals={}, locals={}, fromlist=[]): if name.startswith('itools.'): name = name[7:] return pythons_import(name, globals, locals, fromlist) |
scripts = [ join(*['scripts', x]) for x in scripts ] | scripts = [ os.path.join(*['scripts', x]) for x in scripts ] | def fixed_import(name, globals={}, locals={}, fromlist=[]): if name.startswith('itools.'): name = name[7:] return pythons_import(name, globals, locals, fromlist) |
width = context.get_form_value('width') height = context.get_form_value('height') | width = context.get_form_value('width', 48) height = context.get_form_value('height', 48) | def icon48(self, context): width = context.get_form_value('width') height = context.get_form_value('height') |
atime = datetime.datetime.now() self.cache[key] = (handler, atime) | if is_virtual is False: atime = datetime.datetime.now() self.cache[key] = (handler, atime) | def get_handler(self, path): # Be sure path is a Path if not isinstance(path, uri.Path): path = uri.Path(path) |
stored.set_changed() | stored.save_state() | def index_document(self, document): # Mark as changed self.set_changed() |
self.timestamp = datetime.datetime.now() | container.timestamp = datetime.datetime.now() | def set_handler(self, path, handler, **kw): if not isinstance(path, uri.Path): path = uri.Path(path) |
self.timestamp = datetime.datetime.now() | container.timestamp = datetime.datetime.now() | def del_handler(self, path): if not isinstance(path, uri.Path): path = uri.Path(path) |
server.start() | if options.debug is True: server.start() else: server.start() def stop(parser, options, target): pid = open('%s/pid' % target).read() pid = int(pid) os.kill(pid, signal.SIGTERM) | def start(parser, options, target): # Load the config config = get_config(target) # Import the root class if is not the default if config.has_option('instance', 'root'): exec('import %s' % config.get('instance', 'root')) # Load the root handler database = get_database(target) root = get_root(database) root.name = roo... |
'-s', '--source', help='use the SOURCE directory to init the database') parser.add_option( | def pack(parser, options, target): database = get_database(target).database print 'Packing...', database.pack() print 'done.' | |
commands = {'init': (init, ['source', 'root', 'port']), 'start': (start, ['port']), | commands = {'init': (init, ['port', 'source', 'root']), 'start': (start, ['debug', 'port']), 'stop': (stop, []), | def pack(parser, options, target): database = get_database(target).database print 'Packing...', database.pack() print 'done.' |
if key not in allowed_options and value is not None: parser.error('the command "%s" does not accept the option -%s/--%s' % (command_name, key[0], key)) | if key not in allowed_options: if key == 'debug': if value is True: parser.error(error_message % (command_name, key[0], key)) elif value is not None: parser.error(error_message % (command_name, key[0], key)) | def pack(parser, options, target): database = get_database(target).database print 'Packing...', database.pack() print 'done.' |
return XHTML.Element.get_raw_closetag(self) | return XHTML.Element.get_closetag(self) def handle_start_element(self, ns_uri, prefix, name): return Element(prefix, name) | def get_closetag(self): if self.name in empty_elements: return '' return XHTML.Element.get_raw_closetag(self) |
return {'type': IO.Unicode} | return {'type': IO.String} | def get_attribute_schema(name): return {'type': IO.Unicode} |
if next >= subtotal: | if next >= total: | def __init__(self, objects, sortby=None, sortorder='up', batchstart=0, batchsize=0, getter=None, name='table'): # Get the parameters context = get_context() |
self.data = data | self.data = StringIO() self.data.write(data) | def __init__(self, data): self.data = data self.ctime = self.mtime = datetime.now() |
data = self.data | def __setitem__(self, index, value): data = self.data if isinstance(index, slice): # XXX So far 'step' is not supported start, stop = index.start, index.stop else: start, stop = index, index + 1 self.data = data[:start] + value + data[stop:] self.mtime = datetime.now() | |
start, stop = index.start, index.stop else: start, stop = index, index + 1 self.data = data[:start] + value + data[stop:] | index = index.start self.data.seek(index) self.data.write(value) | def __setitem__(self, index, value): data = self.data if isinstance(index, slice): # XXX So far 'step' is not supported start, stop = index.start, index.stop else: start, stop = index, index + 1 self.data = data[:start] + value + data[stop:] self.mtime = datetime.now() |
self.data = self.data[:start] + value + self.data[stop:] | rest = self[stop:] self.data.seek(start) self.data.truncate() self.data.write(value) self.data.write(rest) | def __setslice__(self, start, stop, value): self.data = self.data[:start] + value + self.data[stop:] self.mtime = datetime.now() |
self.data += value | self.data.seek(0, 2) self.data.write(value) | def append(self, value): self.data += value |
return self.data | self.data.seek(0) return self.data.read() | def get_data(self): return self.data |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.