rem stringlengths 0 322k | add stringlengths 0 2.05M | context stringlengths 8 228k |
|---|---|---|
if self.has_attribute(namespaces.xhtml, 'type'): return self.get_attribute(namespaces.xhtml, 'type') == 'submit' | if self.has_attribute(Namespace.class_uri, 'type'): return self.get_attribute(Namespace.class_uri, 'type') == 'submit' | def is_translatable(self, attribute_name): # Attributes if self.name == 'img' and attribute_name == 'alt': return True if self.name == 'input' and attribute_name == 'value': if self.has_attribute(namespaces.xhtml, 'type'): return self.get_attribute(namespaces.xhtml, 'type') == 'submit' return False |
if isinstance(namespace, dict): | elif isinstance(namespace, dict): | def lookup(namespace, name): """ Looks for a variable in a namespace (an instance, a mapping, etc..) """ if hasattr(namespace, 'stl_lookup'): return namespace.stl_lookup(name) if isinstance(namespace, dict): if name in namespace: return namespace[name] try: value = getattr(namespace, name) except AttributeError: # XX... |
try: value = getattr(namespace, name) except AttributeError: try: value = namespace[name] except KeyError: raise STLNameError, 'name "%s" not found in the namespace' % name return value | elif hasattr(namespace, name): return getattr(namespace, name) raise STLNameError, 'name "%s" not found in the namespace' % name | def lookup(namespace, name): """ Looks for a variable in a namespace (an instance, a mapping, etc..) """ if hasattr(namespace, 'stl_lookup'): return namespace.stl_lookup(name) if isinstance(namespace, dict): if name in namespace: return namespace[name] try: value = getattr(namespace, name) except AttributeError: # XX... |
version = "0.5.0", | version = "0.5.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" |
if user_id in self.get_property(rolename): | if user_id in self.get_property(role): | def user_has_role(self, user_id, *roles): """ Return True if the given user has any of the the given roles, False otherwise. """ for role in roles: if user_id in self.get_property(rolename): return True return False |
if not document.is_allowed_to_view(): | ac = document.get_access_control() if not ac.is_allowed_to_view(user, document): | def tasks_list(self, context): root = context.root |
assert str(path) == 'a/b/c/' | self.assertEqual(str(path), 'a/b/c/') | def test_simplenorm(self): """ Test the simple path normalization: |
assert str(path) == 'a/b/d' | self.assertEqual(str(path), 'a/b/d') | def test_backnorm(self): """ Test the normalization 'a/../b' = 'b' """ path = uri.Path('a/b/c/../d') assert str(path) == 'a/b/d' |
assert str(path) == '/a/b/c' | self.assertEqual(str(path), '/a/b/c') | def test_absnorm(self): """ Test the normalization '/..' = '/' """ path = uri.Path('/../../a/b/c') assert str(path) == '/a/b/c' |
assert str(path) == '../../a/b/c' | self.assertEqual(str(path), '../../a/b/c') | def test_relnorm(self): """ Check that '../' = '../' """ path = uri.Path('../../a//.//b/c') assert str(path) == '../../a/b/c' |
assert ref.scheme == 'http' assert ref.authority == 'example.com' assert ref.path == '/a/b/c' assert ref.query == 'query' assert ref.fragment == 'fragment' | self.assertEqual(ref.scheme, 'http') self.assertEqual(ref.authority, 'example.com') self.assertEqual(ref.path, '/a/b/c') self.assertEqual(ref.query, 'query') self.assertEqual(ref.fragment, 'fragment') | def test_full(self): ref = 'http://example.com/a/b/c?query#fragment' ref = uri.Reference(ref) assert ref.scheme == 'http' assert ref.authority == 'example.com' assert ref.path == '/a/b/c' assert ref.query == 'query' assert ref.fragment == 'fragment' |
assert bool(ref.scheme) is False assert ref.authority == 'example.com' assert ref.path == '/a/b' | self.assertEqual(bool(ref.scheme), False) self.assertEqual(ref.authority, 'example.com') self.assertEqual(ref.path, '/a/b') | def test_network(self): ref = '//example.com/a/b' ref = uri.Reference(ref) assert bool(ref.scheme) is False assert ref.authority == 'example.com' assert ref.path == '/a/b' |
assert bool(ref.scheme) is False assert bool(ref.authority) is False assert ref.path == '/a/b/c' | self.assertEqual(bool(ref.scheme), False) self.assertEqual(bool(ref.authority), False) self.assertEqual(ref.path, '/a/b/c') | def test_path(self): ref = '/a/b/c' ref = uri.Reference(ref) assert bool(ref.scheme) is False assert bool(ref.authority) is False assert ref.path == '/a/b/c' |
assert bool(ref.scheme) is False assert bool(ref.authority) is False assert len(ref.path) == 0 assert ref.query == 'query' | self.assertEqual(bool(ref.scheme), False) self.assertEqual(bool(ref.authority), False) self.assertEqual(len(ref.path), 0) self.assertEqual(ref.query, 'query') | def test_query(self): ref = '?query' ref = uri.Reference(ref) assert bool(ref.scheme) is False assert bool(ref.authority) is False assert len(ref.path) == 0 assert ref.query == 'query' |
def test(self): | def test_standard(self): | def test(self): failure = 0 for reference, expected in [('g:h', 'g:h'), ('g', 'http://a/b/c/g'), ('./g', 'http://a/b/c/g'), ('g/', 'http://a/b/c/g/'), ('/g', 'http://a/g'), ('//g', 'http://g'), ('?y', 'http://a/b/c/?y'), ('g?y', 'http://a/b/c/g?y'), ('#s', 'http://a/b/c/d;p?q#s'), ('g#s', 'http://a/b/c/g#s'), ('g?y#s',... |
('', 'http://a/b/c/'), | ('.', 'http://a/b/c/'), | def test(self): failure = 0 for reference, expected in [('g:h', 'g:h'), ('g', 'http://a/b/c/g'), ('./g', 'http://a/b/c/g'), ('g/', 'http://a/b/c/g/'), ('/g', 'http://a/g'), ('//g', 'http://g'), ('?y', 'http://a/b/c/?y'), ('g?y', 'http://a/b/c/g?y'), ('#s', 'http://a/b/c/d;p?q#s'), ('g#s', 'http://a/b/c/g#s'), ('g?y#s',... |
assert x == expected | self.assertEqual(x, expected) | def test(self): failure = 0 for reference, expected in [('g:h', 'g:h'), ('g', 'http://a/b/c/g'), ('./g', 'http://a/b/c/g'), ('g/', 'http://a/b/c/g/'), ('/g', 'http://a/g'), ('//g', 'http://g'), ('?y', 'http://a/b/c/?y'), ('g?y', 'http://a/b/c/g?y'), ('#s', 'http://a/b/c/d;p?q#s'), ('g#s', 'http://a/b/c/g#s'), ('g?y#s',... |
port = 8000 | port = 8080 | def __init__(self, root, address='127.0.0.1', port=None, access_log=None, error_log=None, pid_file=None): if port is None: port = 8000 # The application's root self.pool = Pool(root) # The address and port the server will listen to self.address = address self.port = port # The access and error logs if access_log is not... |
handler = self._get_handler(segment) if handler is None: raise ValueError, '%s not found' % segment | if self.has_resource(name): resource = self.get_resource(name) handler = self._get_handler(segment, resource) else: 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) |
def _get_handler(self, segment): if self.has_resource(segment.name): resource = self.get_resource(segment.name) | def _get_handler(self, segment, resource): from itools.handlers import database mimetype = database.guess_mimetype(segment.name, resource) return database.get_handler(resource, mimetype) | def _get_handler(self, segment): if self.has_resource(segment.name): resource = self.get_resource(segment.name) |
from itools.handlers import database mimetype = database.guess_mimetype(segment.name, resource) return database.get_handler(resource, mimetype) | def _get_handler(self, segment): if self.has_resource(segment.name): resource = self.get_resource(segment.name) | |
return None | def _get_virtual_handler(self, segment): """ This method must return a handler for the given segment, or raise the exception LookupError. We know there is not a resource with the given name, this method is used to return 'virtual' handlers. """ raise LookupError, 'the resource "%s" does not exist' % segment.name | def _get_handler(self, segment): if self.has_resource(segment.name): resource = self.get_resource(segment.name) |
state.children = [] | children = [] | def _load_state(self, resource): state = self.state state.encoding = 'UTF-8' state.document_type = None state.children = [] |
state.children.append(element) | children.append(element) | def _load_state(self, resource): state = self.state state.encoding = 'UTF-8' state.document_type = None state.children = [] |
state.children.append(comment) | children.append(comment) | def _load_state(self, resource): state = self.state state.encoding = 'UTF-8' state.document_type = None state.children = [] |
state.children.append(value) | children.append(value) for element in children: if isinstance(element, Element) and element.name == 'html': state.root_element = element break else: schema = elements_schema.get('html', {'type': BlockElement}) element_class = schema['type'] element = element_class('html') element.children = children state.root_ele... | def _load_state(self, resource): state = self.state state.encoding = 'UTF-8' state.document_type = None state.children = [] |
s = [] | data = [] | def to_str(self, encoding='UTF-8'): s = [] # The declaration if self.state.document_type is not None: s.append('<!%s>' % self.state.document_type) # The children for child in self.state.children: if isinstance(child, unicode): s.append(child.encode(encoding)) else: s.append(child.to_str(encoding)) return ''.join(s) |
s.append('<!%s>' % self.state.document_type) for child in self.state.children: if isinstance(child, unicode): s.append(child.encode(encoding)) else: s.append(child.to_str(encoding)) return ''.join(s) | data.append('<!%s>' % self.state.document_type) data.append(self.get_root_element().to_str(encoding)) | def to_str(self, encoding='UTF-8'): s = [] # The declaration if self.state.document_type is not None: s.append('<!%s>' % self.state.document_type) # The children for child in self.state.children: if isinstance(child, unicode): s.append(child.encode(encoding)) else: s.append(child.to_str(encoding)) return ''.join(s) |
def get_root_element(self): for child in self.state.children: if isinstance(child, Element): return child | return ''.join(data) | def to_str(self, encoding='UTF-8'): s = [] # The declaration if self.state.document_type is not None: s.append('<!%s>' % self.state.document_type) # The children for child in self.state.children: if isinstance(child, unicode): s.append(child.encode(encoding)) else: s.append(child.to_str(encoding)) return ''.join(s) |
language = node.get_attribute('lang') | language = str(node.get_attribute('lang')) | 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 = unicode(node.children) value = value.encode('utf8') try: value = type... |
print 'COMMIT' | def commit(self, username='', note=''): if not self: return | |
try: if self.schema[self.columns[i]].index == True: if self.state.indexes[i] is None: self.state.indexes[i] = {} if self.state.indexes[i].has_key(value): self.state.indexes[i][value].append(row_index) else: self.state.indexes[i][value] = [row_index] except: pass | if self.schema[self.columns[i]].index is True: if indexes[i] is None: indexes[i] = {} index = indexes[i] if value in index: index[value].append(row_index) else: index[value] = [row_index] | def _index_row(self, row, row_index): """Index one line""" for i, value in enumerate(row): try: if self.schema[self.columns[i]].index == True: if self.state.indexes[i] is None: self.state.indexes[i] = {} if self.state.indexes[i].has_key(value): self.state.indexes[i][value].append(row_index) else: self.state.indexes[i][... |
res = ' ' + lines[0] | res = lines[0] | def fold_line(line): """ Fold the unfolded line over 75 characters. """ i = 1 lines = line.split(' ') res = ' ' + lines[0] size = len(res) while i < len(lines): # Still less than 75c if size+len(lines[i]) <= 75: res = res + ' ' + lines[i] size = size + 1 + len(lines[i]) i = i + 1 # More than 75c, insert new line else: ... |
raise SyntaxError, 'unexpected character (%s)' % c | raise SyntaxError, "unexpected character '%s' (%s)" % (c, ord(c)) | def parse(cls, property, encoding='UTF-8'): """ Parse content line property splitting it into 2 parts: name | [parameters]value """ c, lexeme = property[0], '' # Test first character of name if not c.isalnum() and c != '-': raise SyntaxError, 'unexpected character (%s)' % c # Test if property contains ':' if not ':' in... |
xmlns = get_namespace(xmlns_uri) | xmlns = get_namespace(None) | def start_element_handler(self, name, attrs): # Parse the element name: namespace_uri, name and prefix n = name.count(' ') if n == 2: namespace_uri, name, prefix = name.split() elif n == 1: prefix = None namespace_uri, name = name.split() else: prefix = None namespace_uri = None |
value = namespace.get_attribute('xmlns', name, value) | value = xmlns.get_attribute('xmlns', name, value) | def start_element_handler(self, name, attrs): # Parse the element name: namespace_uri, name and prefix n = name.count(' ') if n == 2: namespace_uri, name, prefix = name.split() elif n == 1: prefix = None namespace_uri, name = name.split() else: prefix = None namespace_uri = None |
format = '%W' if cls.get_first_day() == 1 else '%U' week_number = Unicode.encode(c_date.strftime(format)) day, xxx = monthrange(c_date.year, 1) if day in (1,2,3): week_number = str(int(week_number) + 1) if len(week_number) == 1: week_number = '0%s' % week_number current_week = cls.gettext(u'Week ') + week_number | def add_selector_ns(cls, c_date, method, namespace): # Set header used to navigate into time # Week, current date is first showed week + 1 tmp_date = c_date - timedelta(7) current_week = cls.gettext(u'Week ') current_week = current_week + Unicode.encode(tmp_date.strftime('%U')) previous_week = ";%s?date=%s" % (method, ... | |
current_week = cls.gettext(u'Week ') current_week = current_week + Unicode.encode(tmp_date.strftime('%U')) | def add_selector_ns(cls, c_date, method, namespace): # Set header used to navigate into time # Week, current date is first showed week + 1 tmp_date = c_date - timedelta(7) current_week = cls.gettext(u'Week ') current_week = current_week + Unicode.encode(tmp_date.strftime('%U')) previous_week = ";%s?date=%s" % (method, ... | |
tmp_date = c_date - timedelta(30) | delta = 31 if c_date.month != 1: xxx, delta = monthrange(c_date.year, c_date.month - 1) tmp_date = c_date - timedelta(delta) | def add_selector_ns(cls, c_date, method, namespace): # Set header used to navigate into time # Week, current date is first showed week + 1 tmp_date = c_date - timedelta(7) current_week = cls.gettext(u'Week ') current_week = current_week + Unicode.encode(tmp_date.strftime('%U')) previous_week = ";%s?date=%s" % (method, ... |
tmp_date = c_date + timedelta(30) | xxx, delta = monthrange(c_date.year, c_date.month) tmp_date = c_date + timedelta(delta) | def add_selector_ns(cls, c_date, method, namespace): # Set header used to navigate into time # Week, current date is first showed week + 1 tmp_date = c_date - timedelta(7) current_week = cls.gettext(u'Week ') current_week = current_week + Unicode.encode(tmp_date.strftime('%U')) previous_week = ";%s?date=%s" % (method, ... |
tmp_date = c_date - timedelta(365) | date_before = date(c_date.year, 2, 28) date_after = date(c_date.year, 3, 1) delta = 365 if (isleap(c_date.year - 1) and c_date <= date_before) \ or (isleap(c_date.year) and c_date > date_before): delta = 366 tmp_date = c_date - timedelta(delta) | def add_selector_ns(cls, c_date, method, namespace): # Set header used to navigate into time # Week, current date is first showed week + 1 tmp_date = c_date - timedelta(7) current_week = cls.gettext(u'Week ') current_week = current_week + Unicode.encode(tmp_date.strftime('%U')) previous_week = ";%s?date=%s" % (method, ... |
tmp_date = c_date + timedelta(365) | delta = 365 if (isleap(c_date.year) and c_date <= date_before) \ or (isleap(c_date.year +1) and c_date >= date_after): delta = 366 tmp_date = c_date + timedelta(delta) | def add_selector_ns(cls, c_date, method, namespace): # Set header used to navigate into time # Week, current date is first showed week + 1 tmp_date = c_date - timedelta(7) current_week = cls.gettext(u'Week ') current_week = current_week + Unicode.encode(tmp_date.strftime('%U')) previous_week = ";%s?date=%s" % (method, ... |
def days_of_week_ns(cls, date, num=None, ndays=7): | def days_of_week_ns(cls, date, num=None, ndays=7, c_date=None): | def days_of_week_ns(cls, date, num=None, ndays=7): ns_days = [] for index in range(ndays): ns = {} ns['name'] = cls.gettext(cls.days[date.weekday()]) ns['nday'] = None if num: ns['nday'] = date.day ns_days.append(ns) date = date + timedelta(1) return ns_days |
namespace['days_of_week'] = self.days_of_week_ns(start, num=True) | namespace['days_of_week'] = self.days_of_week_ns(start, True, 7, c_date) | def weekly_view(self, context): context = get_context() root = context.root |
class Stat_special_char(Char): def __init__(self, text): self.text = text.upper().swapcase() | def test_french_very_sort(self): text = u"""Les dclarations du prsident Vladimir Poutine""" p = oracle.Language(text) print ('test_french_very_sort', p.percent()) | def __init__(self, language, lexeme=''): self.language = language self.lexeme = lexeme |
def stat_special_char(self): """ return percent of special char for specific language """ stat = {} for lang in language: n = 0 for special_char in lang[2]: n = n + self.text.count(special_char) if len(self.text) != 0: percent = (n*4000)/len(self.text) percent = min (100, percent) else: percent = 0 stat[lang[0]] = per... | def test_english_short(self): text = """The French, too, paid much attention to French-German reconciliation and interpreted the ceremonies as a celebration of European integration and peace.""" p = oracle.Language(text) print ('test_english_short', p.percent()) | def stat_special_char(self): """ return percent of special char for specific language """ stat = {} for lang in language: n = 0 for special_char in lang[2]: n = n + self.text.count(special_char) if len(self.text) != 0: percent = (n*4000)/len(self.text) percent = min (100, percent) else: percent = 0 stat[lang[0]] = per... |
class Token: def __init__(self, id, lexeme=''): self.id = id self.lexeme = lexeme | if __name__ == '__main__': unittest.main() | def stat_special_char(self): """ return percent of special char for specific language """ stat = {} for lang in language: n = 0 for special_char in lang[2]: n = n + self.text.count(special_char) if len(self.text) != 0: percent = (n*4000)/len(self.text) percent = min (100, percent) else: percent = 0 stat[lang[0]] = per... |
class Select_token(Token): def __init__(self, text): self.text = text for i in rubbish_punctuation: self.text = self.text.replace(i , ' ') for i in keeping_punctuation: self.text = self.text.replace(i , ' '+i+' ') self.index = 0 def get_token(self): """ return only word with latin char or keeping_punctuation """ lexe... | def __init__(self, id, lexeme=''): self.id = id self.lexeme = lexeme | |
request_uri = deepcopy(request.uri) request_uri.path = uri.Path('/' + request_uri.query['REAL_PATH']) | real_path = request_uri.query.pop('REAL_PATH') request_uri = deepcopy(request_uri) request_uri.path = uri.Path('/' + real_path) | def __init__(self, request): self.request = request self.response = Response() |
path = request_uri.path | path = request.uri.path | def __init__(self, request): self.request = request self.response = Response() |
- itools.csv | def get_data_files(self): """Generate list of '(package,src_dir,build_dir,filenames)' tuples""" data = [] if not self.packages: return data for package in self.packages: # Locate package source directory src_dir = self.get_package_dir(package) | |
version = "0.11.0", | version = "0.12.0", | def get_data_files(self): """Generate list of '(package,src_dir,build_dir,filenames)' tuples""" data = [] if not self.packages: return data for package in self.packages: # Locate package source directory src_dir = self.get_package_dir(package) |
endswith_slash = path.endswith('/') | endswith_slash = 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... |
if not isinstance(path, Path): path = Path(path) return self.__class__(list(self) + list(path)) | raise NotImplementedError, \ 'paths can not be added, use resolve2 instead' | def __add__(self, path): if not isinstance(path, Path): path = Path(path) return self.__class__(list(self) + list(path)) |
return urlunsplit((self.scheme, str(self.authority), str(self.path), | path = str(self.path) if path == '.': path = '' return urlunsplit((self.scheme, str(self.authority), path, | def __str__(self): return urlunsplit((self.scheme, str(self.authority), str(self.path), str(self.query), self.fragment)) |
for resource_name in self.get_resource_names(path): yield self.get_resource(resource_name) | resource = self.get_resource(path) for name in resource._get_resource_names(): yield resource.get_resource(name) | def get_resources(self, path='.'): for resource_name in self.get_resource_names(path): yield self.get_resource(resource_name) |
parameters.append('; max-Age=%s' % cookie.max_age) | parameters.append('; max-age=%s' % cookie.max_age) | def to_str(self): state = self.state |
value = ' '.join(value) | value = u' '.join(value) | def index_document(self, document): self.set_changed() # Create the document to index doc_number = self.documents.n_documents catalog_document = Document(doc_number) |
css_class = 'busy' | css_class = 'cal_busy' | def get_ns_calendar(self, calendar, c_date, cal_fields, shown_fields, timetables, method='browse_calendar', show_conflicts=False): calendar_url = self.get_pathto(calendar) args = 'date=%s&method=%s' % (Date.encode(c_date), method) new_url = '%s/;edit_event_form?%s' % (calendar_url, args) |
request_uri.path = uri.Path('/%s' % diff_path) | if request_uri.path.endswith_slash: request_uri.path = uri.Path('/%s/' % diff_path) else: request_uri.path = uri.Path('/%s' % diff_path) | def __init__(self, request): self.request = request self.response = Response() |
return str(self) != normalize_path(str(other)) | if isinstance(other, str): other = Path(other) return str(self) != str(other) | def __ne__(self, other): return str(self) != normalize_path(str(other)) |
return str(self) == normalize_path(str(other)) | if isinstance(other, str): other = Path(other) return str(self) == str(other) | def __eq__(self, other): return str(self) == normalize_path(str(other)) |
buffer.write(u' %s="%s"' % (qname, unicode(value))) | namespace = namespaces.get_namespace(namespace) schema = namespace.get_attribute_schema(local_name) type = schema['type'] buffer.write(u' %s="%s"' % (qname, type.to_unicode(value))) | def open_tag(node): # The open tag buffer.write(u'<%s' % node.qname) # The attributes for namespace, local_name, value in node.get_attributes(): if node.is_translatable(local_name): value = value.strip() if value: value = catalog.get_msgstr(value) or value qname = node.get_attribute_qname(namespace, local_name) buffer.... |
author = config.get_value('author_name'), | author = author_name, | def setup(description='', classifiers=[]): from __init__ import __version__ try: from itools.resources import get_resource from handlers.config import Config except ImportError: # Are we trying to install itools? # XXX This is ugly, because Python does not support relative imports start_local_import() from resources im... |
handler_class = here.get_handler_class(uri) | handler_class = self.get_handler_class(uri) | def _get_handler(self, segment, uri): handler_class = here.get_handler_class(uri) return handler_class(uri) |
reference = self.uri.resolve2(reference) | reference = self.uri.resolve(reference) | def redirect(self, reference, status=302): reference = self.uri.resolve2(reference) self.response.redirect(reference, status) |
self.encoding = self.guess_encoding(data) | self.encoding = 'utf-8' | def new(self, data=u''): self.data = data self.encoding = self.guess_encoding(data) |
if isinstance(self, WorkflowAware): state = self.workflow_state | if isinstance(object, WorkflowAware): state = object.workflow_state | def is_allowed_to_view(self, user, object): # Objects with workflow from workflow import WorkflowAware if isinstance(self, WorkflowAware): state = self.workflow_state # Anybody can see public objects if state == 'public': return True |
dialect = csv.Sniffer().sniff(data[:1000]) | if data: dialect = csv.Sniffer().sniff(data[:1000]) reader = csv.reader(data.splitlines(), dialect) else: reader = csv.reader(data.splitlines()) | def parse(data, schema=None): encoding = Text.guess_encoding(data) dialect = csv.Sniffer().sniff(data[:1000]) if schema is None: for line in csv.reader(data.splitlines(), dialect): yield [ unicode(x, encoding) for x in line ] else: for line in csv.reader(data.splitlines(), dialect): yield [ schema[i].decode(value) for ... |
for line in csv.reader(data.splitlines(), dialect): | for line in reader: | def parse(data, schema=None): encoding = Text.guess_encoding(data) dialect = csv.Sniffer().sniff(data[:1000]) if schema is None: for line in csv.reader(data.splitlines(), dialect): yield [ unicode(x, encoding) for x in line ] else: for line in csv.reader(data.splitlines(), dialect): yield [ schema[i].decode(value) for ... |
['about', 'license']] | ['about', 'license'], ['catalog_form', 'check_groups']] | def get_subviews(self, name): views = [['browse_thumbnails', 'browse_list'], ['general_form', 'languages_form'], ['about', 'license']] for subviews in views: if name in subviews: return subviews return Group.get_subviews(self, name) |
catalog_form__label__ = u'Catalog' | catalog_form__label__ = u'Maintenance' catalog_form__sublabel__ = u'Update Catalog' | def join(self, username, password, password2, **kw): users = self.get_handler('users') error = users.new_user(username, password, password2) |
check_groups__access__ = 'is_admin' check_groups__label__ = u'Maintenance' check_groups__sublabel__ = u'Check Groups' def check_groups(self): namespace = {} groups = [] root_users = self.get_handler('users').get_usernames() for path in self.get_groups(): group = self.get_handler(path) group_users = group.get_usernames... | def update_catalog(self): # Initialize a new empty catalog t0 = time() tmp_path = tempfile.mkdtemp() tmp_folder = get_handler(tmp_path) tmp_folder.set_handler('catalog', Catalog(fields=self._catalog_fields)) tmp_folder.save_state() catalog_resource = tmp_folder.resource.get_resource('catalog') catalog = Catalog(catalog... | |
return unicode(value) | return unicode(value).replace(u'&', u'&') | def to_unicode(cls, value): return unicode(value) |
If 'self' and 'path' are absolute, a relative path 'x' is returned so self.resolve(x) = path. | Returns the relative path from 'self' to 'path'. This operation is the complement of 'resolve2'. So, if 'x = a.get_pathto(b)', then 'b = a.resolve2(x)'. | def get_pathto(self, path): """ If 'self' and 'path' are absolute, a relative path 'x' is returned so self.resolve(x) = path. """ if not isinstance(path, Path): path = Path(path) |
class HeadElement(Element): | class HeadElement(BlockElement): | def get_closetag(self): if self.name in parser.empty_elements: return '' return XHTML.Element.get_closetag(self) |
stack.append(Element(None, value)) | schema = elements_schema.get(value, {'type': BlockElement}) element_class = schema['type'] stack.append(element_class(None, value)) | def _load(self, resource): self._encoding = 'UTF-8' self.document_type = None self.children = [] |
lines = self._data.splitlines() | state = self.state lines = state.data.splitlines() | def _load_state(self, resource=None): # Load the resource as a unicode string Text._load_state(self, resource) # Split the raw data in lines. lines = self._data.splitlines() # Append None to signal the end of the data. lines.append(None) # Free the un-needed data structure, 'self._data' del self._data |
del self._data | del state.data | def _load_state(self, resource=None): # Load the resource as a unicode string Text._load_state(self, resource) # Split the raw data in lines. lines = self._data.splitlines() # Append None to signal the end of the data. lines.append(None) # Free the un-needed data structure, 'self._data' del self._data |
self.tasks = [] | state.tasks = [] | def _load_state(self, resource=None): # Load the resource as a unicode string Text._load_state(self, resource) # Split the raw data in lines. lines = self._data.splitlines() # Append None to signal the end of the data. lines.append(None) # Free the un-needed data structure, 'self._data' del self._data |
self.tasks.append(task) | state.tasks.append(task) | def _load_state(self, resource=None): # Load the resource as a unicode string Text._load_state(self, resource) # Split the raw data in lines. lines = self._data.splitlines() # Append None to signal the end of the data. lines.append(None) # Free the un-needed data structure, 'self._data' del self._data |
for task in self.tasks: | for task in self.state.tasks: | def to_unicode(self, encoding=None): lines = [] for task in self.tasks: lines.append(u'title:%s' % task.title) description = u'description:%s' % task.description description = textwrap.wrap(description) lines.append(description[0]) for line in description[1:]: lines.append(u' %s' % line) lines.append(u'state:%s' % task... |
self.tasks.append(task) | self.state.tasks.append(task) | def add_task(self, title, description): task = Task(title, description) self.tasks.append(task) |
for id, task in enumerate(self.tasks): | for id, task in enumerate(self.state.tasks): | def show_open_tasks(self): for id, task in enumerate(self.tasks): if task.state == 'open': print 'Task #%d: %s' % (id, task.title) print print textwrap.fill(task.description) print print |
task = self.tasks[id] | task = self.state.tasks[id] | def close_task(self, id): task = self.tasks[id] task.state = u'closed' |
return list(cls.options) | return [dict(option) for option in cls.options] | def get_options(cls): return list(cls.options) |
metadata_name = '.%s.metadata' % self.name | metadata_name = '%s.metadata' % self.name | def get_metadata(self): if self.real_handler is not None: return self.real_handler.get_metadata() |
version = "0.6.3", | version = "0.6.4", | 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" |
if getattr(datatype, 'index', False): | if getattr(datatype, 'index', None) is not None: | def _index_init(self): """Initialize csv values index list""" for column in self.columns: datatype = self.schema[column] if getattr(datatype, 'index', False): indexes.append(Index()) else: indexes.append(None) |
if isinstance(reference, uri.Reference): | if isinstance(reference, Reference): | def remove(reference): if isinstance(reference, uri.Reference): path = str(reference.path) elif isinstance(reference, uri.Path): path = str(path) |
elif isinstance(reference, uri.Path): | elif isinstance(reference, Path): | def remove(reference): if isinstance(reference, uri.Reference): path = str(reference.path) elif isinstance(reference, uri.Path): path = str(path) |
control = Handler.gettext('%(start)s-%(end)s of %(total)s') \ | control = Handler.gettext(u'%(start)s-%(end)s of %(total)s') \ | def batch_control(self): """Return a dict. as {'total', 'previous', 'next', 'control'}""" context = get_context() request = context.request |
if not results: | if results is None: | 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 |
email = context.get_form_value('ikaaro:email') users = self.get_handler('users') error = users.new_user(email, password, password2) message = self.gettext(u'Thanks for register, please log in') message = quote(message.encode('utf8')) goto = ';login_form?username=%s&message=%s' % (email, message) return uri.get_refere... | if password != password2: message = u'The passwords do not match.' return context.come_back(message) user = users.set_user(email, password) message = u'Thanks for register, please log in' goto = ';login_form?username=%s' % email return context.come_back(message, goto=goto) | def register(self, context): password = context.get_form_value('password') password2 = context.get_form_value('password2') email = context.get_form_value('ikaaro:email') |
response = self.GET(context) content_length = response.get_content_length() response.set_header('content-length', content_length) response.set_body(None) return response | status, body = self.GET(context) if isinstance(body, str): response = context.response response.set_header('content-length', len(body)) body = None return status, body | def HEAD(self, context): if context.method == 'HEAD': context.method = 'GET' response = self.GET(context) content_length = response.get_content_length() response.set_header('content-length', content_length) response.set_body(None) return response |
key, value = x.split('=', 1) | if '=' in x: key, value = x.split('=', 1) else: key, value = x, None | def __init__(self, query): # XXX Right now when we find more than one value with the same # name we store all values as a list, otherwise it will be a # singleton. to Look http://docs.python.org/lib/node472.html # and maybe implement something similar. if query: for x in query.split('&'): x = urllib.unquote_plus(x) if ... |
return '&'.join([ '%s=%s' % (k, urllib.quote_plus(v)) for k, v in self.items() ]) | line = [] for key, value in self.items(): if value is None: line.append(key) else: line.append('%s=%s' % (key, urllib.quote_plus(value))) return '&'.join(line) | def __str__(self): return '&'.join([ '%s=%s' % (k, urllib.quote_plus(v)) for k, v in self.items() ]) |
def test_varsion(self): | def test_version(self): | def test_varsion(self): value = '20050217' encoded_value = IO.encode_version(value) self.assertEqual(IO.decode_version(encoded_value), value) |
if ('http-equiv', 'Content-Type') in attrs: for attribute_name, attribute_value in attrs: if attribute_name == 'content': encoding = attribute_value.split(';')[-1].strip()[8:] self.encoding = encoding break | is_content_type = False for attribute_name, attribute_value in attrs: if attribute_name == 'http-equiv': if attribute_value.lower() == 'content-type': is_content_type = True elif attribute_name == 'content': content_value = attribute_value if is_content_type is True: self.encoding = attribute_value.split(';')[-1].strip... | def handle_starttag(self, name, attrs): line_number = self.getpos()[0] |
body = root.after_traverse(context, body) | body = context.root.after_traverse(context, body) | def POST(self, context): request, response = context.request, context.response # Not a safe method context.commit = True # Traverse status, method = self.traverse(context) # Call the method body = method(context) if isinstance(body, str): # Post-process (used to wrap the body in a skin) body = root.after_traverse(conte... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.