Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
""" This module contains essential stuff that should've come with Python itself ;)
It also contains functions (or functionality) which is in Python versions higher than 2.5 which used to be the lowest version supported by Scrapy.
"""
"""The SGMLParser that comes with Python has a bug in the convert_charref() method. This is the same class with the bug fixed"""
"""This method fixes a bug in Python's SGMLParser.""" try: n = int(name) except ValueError: return if not 0 <= n <= 127 : # ASCII ends at 127, not 255 return return self.convert_codepoint(n)
"""flatten(sequence) -> list
Returns a single, flat list which contains all elements retrieved from the sequence and all recursively contained sub-sequences (iterables).
Examples: >>> [1, 2, [3,4], (5,6)] [1, 2, [3, 4], (5, 6)] >>> flatten([[[1,2,3], (42,None)], [4,5], [6], 7, (8,9,10)]) [1, 2, 3, 42, None, 4, 5, 6, 7, 8, 9, 10]"""
else:
"""efficient function to uniquify a list preserving item order"""
"""Return the unicode representation of text in the given encoding. Unlike .encode(encoding) this function can be applied directly to a unicode object without the risk of double-decoding problems (which can happen if you don't use the default 'ascii' encoding) """
else:
"""Return the str representation of text in the given encoding. Unlike .encode(encoding) this function can be applied directly to a str object without the risk of double-decoding problems (which can happen if you don't use the default 'ascii' encoding) """
else:
""" This function does a reverse search in a text using a regular expression given in the attribute 'pattern'. Since the re module does not provide this functionality, we have to find for the expression into chunks of text extracted from the end (for the sake of efficiency). At first, a chunk of 'chunk_size' kilobytes is extracted from the end, and searched for the pattern. If the pattern is not found, another chunk is extracted, and another search is performed. This process continues until a match is found, or until the whole file is read. In case the pattern wasn't found, None is returned, otherwise it returns a tuple containing the start position of the match, and the ending (regarding the entire text). """ yield (text[offset:], offset)
return None
"""Decorator to cache the result of a method (without arguments) using a weak reference to its object """ def new_method(self, *args, **kwargs):
"""Return True if the given text is considered binary, or false otherwise, by looking for binary bytes at their chars """
"""Return the argument name list of a callable""" else: raise TypeError('%s is not callable' % type(func))
"""Compare two objects attributes""" # not attributes given return False by default
# support callables like itemgetter else: # check that objects has attribute return False # compare object attributes # all attributes equal
"""Return a (new) dict with the unicode keys (and values if, keys_only is False) of the given dict converted to strings. `dct_or_tuples` can be a dict or a list of tuples, like any dict constructor supports. """
"""Return True if the given path can be written (if it exists) or created (if it doesn't exist) """ if os.path.exists(path): return os.access(path, os.W_OK) else: return os.access(os.path.dirname(path), os.W_OK)
"""Set attribute value, but only if it's not already set. Similar to setdefault() for dicts. """ if not hasattr(obj, name): setattr(obj, name, value) |