desc stringlengths 3 26.7k | decl stringlengths 11 7.89k | bodies stringlengths 8 553k |
|---|---|---|
'True if \'self.result\' is an instance of \'self.wsgi_file_wrapper\''
| def result_is_file(self):
| wrapper = self.wsgi_file_wrapper
return ((wrapper is not None) and isinstance(self.result, wrapper))
|
'True if client can accept status and headers'
| def client_is_modern(self):
| return (self.environ['SERVER_PROTOCOL'].upper() != 'HTTP/0.9')
|
'Log the \'exc_info\' tuple in the server log
Subclasses may override to retarget the output or change its format.'
| def log_exception(self, exc_info):
| try:
from traceback import print_exception
stderr = self.get_stderr()
print_exception(exc_info[0], exc_info[1], exc_info[2], self.traceback_limit, stderr)
stderr.flush()
finally:
exc_info = None
|
'Log current error, and send error output to client if possible'
| def handle_error(self):
| self.log_exception(sys.exc_info())
if (not self.headers_sent):
self.result = self.error_output(self.environ, self.start_response)
self.finish_response()
|
'WSGI mini-app to create error output
By default, this just uses the \'error_status\', \'error_headers\',
and \'error_body\' attributes to generate an output page. It can
be overridden in a subclass to dynamically generate diagnostics,
choose an appropriate message for the user\'s preferred language, etc.
Note, howeve... | def error_output(self, environ, start_response):
| start_response(self.error_status, self.error_headers[:], sys.exc_info())
return [self.error_body]
|
'Override in subclass to buffer data for send to client
It\'s okay if this method actually transmits the data; BaseHandler
just separates write and flush operations for greater efficiency
when the underlying system actually has such a distinction.'
| def _write(self, data):
| raise NotImplementedError
|
'Override in subclass to force sending of recent \'_write()\' calls
It\'s okay if this method is a no-op (i.e., if \'_write()\' actually
sends the data.'
| def _flush(self):
| raise NotImplementedError
|
'Override in subclass to return suitable \'wsgi.input\''
| def get_stdin(self):
| raise NotImplementedError
|
'Override in subclass to return suitable \'wsgi.errors\''
| def get_stderr(self):
| raise NotImplementedError
|
'Override in subclass to insert CGI variables in \'self.environ\''
| def add_cgi_vars(self):
| raise NotImplementedError
|
'Serve a POST request.
This is only implemented for CGI scripts.'
| def do_POST(self):
| if self.is_cgi():
self.run_cgi()
else:
self.send_error(501, 'Can only POST to CGI scripts')
|
'Version of send_head that support CGI scripts'
| def send_head(self):
| if self.is_cgi():
return self.run_cgi()
else:
return SimpleHTTPServer.SimpleHTTPRequestHandler.send_head(self)
|
'Test whether self.path corresponds to a CGI script.
Returns True and updates the cgi_info attribute to the tuple
(dir, rest) if self.path requires running a CGI script.
Returns False otherwise.
If any exception is raised, the caller should assume that
self.path was rejected as invalid and act accordingly.
The default ... | def is_cgi(self):
| collapsed_path = _url_collapse_path(self.path)
dir_sep = collapsed_path.find('/', 1)
(head, tail) = (collapsed_path[:dir_sep], collapsed_path[(dir_sep + 1):])
if (head in self.cgi_directories):
self.cgi_info = (head, tail)
return True
return False
|
'Test whether argument path is an executable file.'
| def is_executable(self, path):
| return executable(path)
|
'Test whether argument path is a Python script.'
| def is_python(self, path):
| (head, tail) = os.path.splitext(path)
return (tail.lower() in ('.py', '.pyw'))
|
'Execute a CGI script.'
| def run_cgi(self):
| (dir, rest) = self.cgi_info
path = ((dir + '/') + rest)
i = path.find('/', (len(dir) + 1))
while (i >= 0):
nextdir = path[:i]
nextrest = path[(i + 1):]
scriptdir = self.translate_path(nextdir)
if os.path.isdir(scriptdir):
(dir, rest) = (nextdir, nextrest)
... |
'Override this method to support alternative .mo formats.'
| def _parse(self, fp):
| unpack = struct.unpack
filename = getattr(fp, 'name', '')
self._catalog = catalog = {}
self.plural = (lambda n: int((n != 1)))
buf = fp.read()
buflen = len(buf)
magic = unpack('<I', buf[:4])[0]
if (magic == self.LE_MAGIC):
(version, msgcount, masteridx, transidx) = unpack('<4I', ... |
'Return the next item from the iterator. When exhausted, raise StopIteration'
| @abstractmethod
def next(self):
| raise StopIteration
|
'Construct an instance of the class from any iterable input.
Must override this method if the class constructor signature
does not accept an iterable for an input.'
| @classmethod
def _from_iterable(cls, it):
| return cls(it)
|
'Return True if two sets have a null intersection.'
| def isdisjoint(self, other):
| for value in other:
if (value in self):
return False
return True
|
'Compute the hash value of a set.
Note that we don\'t define __hash__: not all sets are hashable.
But if you define a hashable set type, its __hash__ should
call this function.
This must be compatible __eq__.
All sets ought to compare equal if they contain the same
elements, regardless of how they are implemented, and
... | def _hash(self):
| MAX = sys.maxint
MASK = ((2 * MAX) + 1)
n = len(self)
h = (1927868237 * (n + 1))
h &= MASK
for x in self:
hx = hash(x)
h ^= (((hx ^ (hx << 16)) ^ 89869747) * 3644798167)
h &= MASK
h = ((h * 69069) + 907133923)
h &= MASK
if (h > MAX):
h -= (MASK + 1)
... |
'Add an element.'
| @abstractmethod
def add(self, value):
| raise NotImplementedError
|
'Remove an element. Do not raise an exception if absent.'
| @abstractmethod
def discard(self, value):
| raise NotImplementedError
|
'Remove an element. If not a member, raise a KeyError.'
| def remove(self, value):
| if (value not in self):
raise KeyError(value)
self.discard(value)
|
'Return the popped value. Raise KeyError if empty.'
| def pop(self):
| it = iter(self)
try:
value = next(it)
except StopIteration:
raise KeyError
self.discard(value)
return value
|
'This is slow (creates N new iterators!) but effective.'
| def clear(self):
| try:
while True:
self.pop()
except KeyError:
pass
|
'D.get(k[,d]) -> D[k] if k in D, else d. d defaults to None.'
| def get(self, key, default=None):
| try:
return self[key]
except KeyError:
return default
|
'D.iterkeys() -> an iterator over the keys of D'
| def iterkeys(self):
| return iter(self)
|
'D.itervalues() -> an iterator over the values of D'
| def itervalues(self):
| for key in self:
(yield self[key])
|
'D.iteritems() -> an iterator over the (key, value) items of D'
| def iteritems(self):
| for key in self:
(yield (key, self[key]))
|
'D.keys() -> list of D\'s keys'
| def keys(self):
| return list(self)
|
'D.items() -> list of D\'s (key, value) pairs, as 2-tuples'
| def items(self):
| return [(key, self[key]) for key in self]
|
'D.values() -> list of D\'s values'
| def values(self):
| return [self[key] for key in self]
|
'D.pop(k[,d]) -> v, remove specified key and return the corresponding value.
If key is not found, d is returned if given, otherwise KeyError is raised.'
| def pop(self, key, default=__marker):
| try:
value = self[key]
except KeyError:
if (default is self.__marker):
raise
return default
else:
del self[key]
return value
|
'D.popitem() -> (k, v), remove and return some (key, value) pair
as a 2-tuple; but raise KeyError if D is empty.'
| def popitem(self):
| try:
key = next(iter(self))
except StopIteration:
raise KeyError
value = self[key]
del self[key]
return (key, value)
|
'D.clear() -> None. Remove all items from D.'
| def clear(self):
| try:
while True:
self.popitem()
except KeyError:
pass
|
'D.update([E, ]**F) -> None. Update D from mapping/iterable E and F.
If E present and has a .keys() method, does: for k in E: D[k] = E[k]
If E present and lacks .keys() method, does: for (k, v) in E: D[k] = v
In either case, this is followed by: for k, v in F.items(): D[k] = v'
| def update(*args, **kwds):
| if (not args):
raise TypeError("descriptor 'update' of 'MutableMapping' object needs an argument")
self = args[0]
args = args[1:]
if (len(args) > 1):
raise TypeError(('update expected at most 1 arguments, got %d' % len(args)))
if args:
... |
'D.setdefault(k[,d]) -> D.get(k,d), also set D[k]=d if k not in D'
| def setdefault(self, key, default=None):
| try:
return self[key]
except KeyError:
self[key] = default
return default
|
'S.index(value) -> integer -- return first index of value.
Raises ValueError if the value is not present.'
| def index(self, value):
| for (i, v) in enumerate(self):
if (v == value):
return i
raise ValueError
|
'S.count(value) -> integer -- return number of occurrences of value'
| def count(self, value):
| return sum((1 for v in self if (v == value)))
|
'S.insert(index, object) -- insert object before index'
| @abstractmethod
def insert(self, index, value):
| raise IndexError
|
'S.append(object) -- append object to the end of the sequence'
| def append(self, value):
| self.insert(len(self), value)
|
'S.reverse() -- reverse *IN PLACE*'
| def reverse(self):
| n = len(self)
for i in range((n // 2)):
(self[i], self[((n - i) - 1)]) = (self[((n - i) - 1)], self[i])
|
'S.extend(iterable) -- extend sequence by appending elements from the iterable'
| def extend(self, values):
| for v in values:
self.append(v)
|
'S.pop([index]) -> item -- remove and return item at index (default last).
Raise IndexError if list is empty or index is out of range.'
| def pop(self, index=(-1)):
| v = self[index]
del self[index]
return v
|
'S.remove(value) -- remove first occurrence of value.
Raise ValueError if the value is not present.'
| def remove(self, value):
| del self[self.index(value)]
|
'This tests the improved concurrency with pysqlite 2.3.4. You needed
to roll back con2 before you could commit con1.'
| def CheckLocking(self):
| if (sqlite.sqlite_version_info < (3, 2, 2)):
return
self.cur1.execute('create table test(i)')
self.cur1.execute('insert into test(i) values (5)')
try:
self.cur2.execute('insert into test(i) values (5)')
self.fail('should have raised an Op... |
'Checks if cursors on the connection are set into a "reset" state
when a rollback is done on the connection.'
| def CheckRollbackCursorConsistency(self):
| con = sqlite.connect(':memory:')
cur = con.cursor()
cur.execute('create table test(x)')
cur.execute('insert into test(x) values (5)')
cur.execute('select 1 union select 2 union select 3')
con.rollback()
try:
cur.fetchall()
self.fail('Int... |
'Can the connection be used as a context manager at all?'
| def CheckContextManager(self):
| with self.con:
pass
|
'Is a commit called in the context manager?'
| def CheckContextManagerCommit(self):
| with self.con:
self.con.execute("insert into test(c) values ('foo')")
self.con.rollback()
count = self.con.execute('select count(*) from test').fetchone()[0]
self.assertEqual(count, 1)
|
'Is a rollback called in the context manager?'
| def CheckContextManagerRollback(self):
| global did_rollback
self.assertEqual(did_rollback, False)
try:
with self.con:
self.con.execute('insert into test(c) values (4)')
self.con.execute('insert into test(c) values (4)')
except sqlite.IntegrityError:
pass
self.assertEqual(did_... |
'Checks if the row object is iterable'
| def CheckSqliteRowIter(self):
| self.con.row_factory = sqlite.Row
row = self.con.execute('select 1 as a, 2 as b').fetchone()
for col in row:
pass
|
'Checks if the row object can be converted to a tuple'
| def CheckSqliteRowAsTuple(self):
| self.con.row_factory = sqlite.Row
row = self.con.execute('select 1 as a, 2 as b').fetchone()
t = tuple(row)
self.assertEqual(t, (row['a'], row['b']))
|
'Checks if the row object can be correctly converted to a dictionary'
| def CheckSqliteRowAsDict(self):
| self.con.row_factory = sqlite.Row
row = self.con.execute('select 1 as a, 2 as b').fetchone()
d = dict(row)
self.assertEqual(d['a'], row['a'])
self.assertEqual(d['b'], row['b'])
|
'Checks if the row object compares and hashes correctly'
| def CheckSqliteRowHashCmp(self):
| self.con.row_factory = sqlite.Row
row_1 = self.con.execute('select 1 as a, 2 as b').fetchone()
row_2 = self.con.execute('select 1 as a, 2 as b').fetchone()
row_3 = self.con.execute('select 1 as a, 3 as b').fetchone()
self.assertEqual(row_1, row_1... |
'Checks if the row object can act like a sequence'
| def CheckSqliteRowAsSequence(self):
| self.con.row_factory = sqlite.Row
row = self.con.execute('select 1 as a, 2 as b').fetchone()
as_tuple = tuple(row)
self.assertEqual(list(reversed(row)), list(reversed(as_tuple)))
self.assertIsInstance(row, Sequence)
|
'Register two different collation functions under the same name.
Verify that the last one is actually used.'
| def CheckCollationRegisterTwice(self):
| con = sqlite.connect(':memory:')
con.create_collation('mycoll', cmp)
con.create_collation('mycoll', (lambda x, y: (- cmp(x, y))))
result = con.execute("\n select x from (select 'a' as x union select 'b' as x) order by ... |
'Register a collation, then deregister it. Make sure an error is raised if we try
to use it.'
| def CheckDeregisterCollation(self):
| con = sqlite.connect(':memory:')
con.create_collation('mycoll', cmp)
con.create_collation('mycoll', None)
try:
con.execute("select 'a' as x union select 'b' as x order by x collate mycoll")
self.fail('should have raised an OperationalErr... |
'Test that the progress handler is invoked once it is set.'
| def CheckProgressHandlerUsed(self):
| con = sqlite.connect(':memory:')
progress_calls = []
def progress():
progress_calls.append(None)
return 0
con.set_progress_handler(progress, 1)
con.execute('\n create table foo(a, b)\n ... |
'Test that the opcode argument is respected.'
| def CheckOpcodeCount(self):
| con = sqlite.connect(':memory:')
progress_calls = []
def progress():
progress_calls.append(None)
return 0
con.set_progress_handler(progress, 1)
curs = con.cursor()
curs.execute('\n create table foo (a, b)\n ... |
'Test that returning a non-zero value stops the operation in progress.'
| def CheckCancelOperation(self):
| con = sqlite.connect(':memory:')
progress_calls = []
def progress():
progress_calls.append(None)
return 1
con.set_progress_handler(progress, 1)
curs = con.cursor()
self.assertRaises(sqlite.OperationalError, curs.execute, 'create table bar (a, b)')
|
'Test that setting the progress handler to None clears the previously set handler.'
| def CheckClearHandler(self):
| con = sqlite.connect(':memory:')
action = []
def progress():
action.append(1)
return 0
con.set_progress_handler(progress, 1)
con.set_progress_handler(None, 1)
con.execute('select 1 union select 2 union select 3').fetchall()
self.assertEqual(len(action), 0... |
'A commit should also work when no changes were made to the database.'
| def CheckCommitAfterNoChanges(self):
| self.cx.commit()
self.cx.commit()
|
'A rollback should also work when no changes were made to the database.'
| def CheckRollbackAfterNoChanges(self):
| self.cx.rollback()
self.cx.rollback()
|
'pysqlite does not know the rowcount of SELECT statements, because we
don\'t fetch all rows after executing the select statement. The rowcount
has thus to be -1.'
| def CheckRowcountSelect(self):
| self.cu.execute('select 5 union select 6')
self.assertEqual(self.cu.rowcount, (-1))
|
'Checks if fetchmany works with keyword arguments'
| def CheckFetchmanyKwArg(self):
| self.cu.execute('select name from test')
res = self.cu.fetchmany(size=100)
self.assertEqual(len(res), 1)
|
'Checks whether converter names are cut off at \'(\' characters'
| def CheckNumber2(self):
| self.cur.execute('insert into test(n2) values (5)')
value = self.cur.execute('select n2 from test').fetchone()[0]
self.assertEqual(type(value), float)
|
'Assures that the declared type is not used when PARSE_DECLTYPES
is not set.'
| def CheckDeclTypeNotUsed(self):
| self.cur.execute('insert into test(x) values (?)', ('xxx',))
self.cur.execute('select x from test')
val = self.cur.fetchone()[0]
self.assertEqual(val, 'xxx')
|
'cursor.description should at least provide the column name(s), even if
no row returned.'
| def CheckCursorDescriptionNoRow(self):
| self.cur.execute('select * from test where 0 = 1')
self.assertEqual(self.cur.description[0][0], 'x')
|
'pysqlite would crash with older SQLite versions unless
a workaround is implemented.'
| def CheckWorkaroundForBuggySqliteTransferBindings(self):
| self.con.execute('create table foo(bar)')
self.con.execute('drop table foo')
self.con.execute('create table foo(bar)')
|
'pysqlite used to segfault with SQLite versions 3.5.x. These return NULL
for "no-operation" statements'
| def CheckEmptyStatement(self):
| self.con.execute('')
|
'With pysqlite 2.4.0 you needed to use a string or a APSW connection
object for opening database connections.
Formerly, both bytestrings and unicode strings used to work.
Let\'s make sure unicode strings work in the future.'
| def CheckUnicodeConnect(self):
| con = sqlite.connect(u':memory:')
con.close()
|
'pysqlite until 2.4.1 did not rebuild the row_cast_map when recompiling
a statement. This test exhibits the problem.'
| def CheckTypeMapUsage(self):
| SELECT = 'select * from foo'
con = sqlite.connect(':memory:', detect_types=sqlite.PARSE_DECLTYPES)
con.execute('create table foo(bar timestamp)')
con.execute('insert into foo(bar) values (?)', (datetime.datetime.now(),))
con.execute(SELECT)
con.execute('drop tabl... |
'See issue 3312.'
| def CheckRegisterAdapter(self):
| self.assertRaises(TypeError, sqlite.register_adapter, {}, None)
|
'See issue 3312.'
| def CheckSetIsolationLevel(self):
| con = sqlite.connect(':memory:')
self.assertRaises(UnicodeEncodeError, setattr, con, 'isolation_level', u'\xe9')
|
'Verifies that cursor methods check whether base class __init__ was
called.'
| def CheckCursorConstructorCallCheck(self):
| class Cursor(sqlite.Cursor, ):
def __init__(self, con):
pass
con = sqlite.connect(':memory:')
cur = Cursor(con)
try:
cur.execute('select 4+5').fetchall()
self.fail('should have raised ProgrammingError')
except sqlite.ProgrammingError:
pass
... |
'Verifies that connection methods check whether base class __init__ was
called.'
| def CheckConnectionConstructorCallCheck(self):
| class Connection(sqlite.Connection, ):
def __init__(self, name):
pass
con = Connection(':memory:')
try:
cur = con.cursor()
self.fail('should have raised ProgrammingError')
except sqlite.ProgrammingError:
pass
except:
self.fail('should h... |
'Verifies that subclassed cursor classes are correctly registered with
the connection object, too. (fetch-across-rollback problem)'
| def CheckCursorRegistration(self):
| class Connection(sqlite.Connection, ):
def cursor(self):
return Cursor(self)
class Cursor(sqlite.Cursor, ):
def __init__(self, con):
sqlite.Cursor.__init__(self, con)
con = Connection(':memory:')
cur = con.cursor()
cur.execute('create table foo(x)')
... |
'Verifies that creating a connection in autocommit mode works.
2.5.3 introduced a regression so that these could no longer
be created.'
| def CheckAutoCommit(self):
| con = sqlite.connect(':memory:', isolation_level=None)
|
'Verifies that running a PRAGMA statement that does an autocommit does
work. This did not work in 2.5.3/2.5.4.'
| def CheckPragmaAutocommit(self):
| cur = self.con.cursor()
cur.execute('create table foo(bar)')
cur.execute('insert into foo(bar) values (5)')
cur.execute('pragma page_size')
row = cur.fetchone()
|
'See http://bugs.python.org/issue7478
It was possible to successfully register callbacks that could not be
hashed. Return codes of PyDict_SetItem were not checked properly.'
| def CheckSetDict(self):
| class NotHashable:
def __call__(self, *args, **kw):
pass
def __hash__(self):
raise TypeError()
var = NotHashable()
self.assertRaises(TypeError, self.con.create_function, var)
self.assertRaises(TypeError, self.con.create_aggregate, var)
self.assertRaises(TypeEr... |
'Call a connection with a non-string SQL request: check error handling
of the statement constructor.'
| def CheckConnectionCall(self):
| self.assertRaises(sqlite.Warning, self.con, 1)
|
'http://bugs.python.org/issue10811
Recursively using a cursor, such as when reusing it from a generator led to segfaults.
Now we catch recursive cursor usage and raise a ProgrammingError.'
| def CheckRecursiveCursorUse(self):
| con = sqlite.connect(':memory:')
cur = con.cursor()
cur.execute('create table a (bar)')
cur.execute('create table b (baz)')
def foo():
cur.execute('insert into a (bar) values (?)', (1,))
(yield 1)
with self.assertRaises(sqlite.ProgrammingError):
... |
'http://bugs.python.org/issue14720
The microsecond parsing of convert_timestamp() should pad with zeros,
since the microsecond string "456" actually represents "456000".'
| def CheckConvertTimestampMicrosecondPadding(self):
| con = sqlite.connect(':memory:', detect_types=sqlite.PARSE_DECLTYPES)
cur = con.cursor()
cur.execute('CREATE TABLE t (x TIMESTAMP)')
cur.execute("INSERT INTO t (x) VALUES ('2012-04-04 15:06:00.456')")
cur.execute("INSERT INTO t (x) VALUES ('2012-04-04 ... |
'Return true if (and only if) cookie should be accepted from server.
Currently, pre-expired cookies never get this far -- the CookieJar
class deletes such cookies itself.'
| def set_ok(self, cookie, request):
| raise NotImplementedError()
|
'Return true if (and only if) cookie should be returned to server.'
| def return_ok(self, cookie, request):
| raise NotImplementedError()
|
'Return false if cookies should not be returned, given cookie domain.'
| def domain_return_ok(self, domain, request):
| return True
|
'Return false if cookies should not be returned, given cookie path.'
| def path_return_ok(self, path, request):
| return True
|
'Constructor arguments should be passed as keyword arguments only.'
| def __init__(self, blocked_domains=None, allowed_domains=None, netscape=True, rfc2965=False, rfc2109_as_netscape=None, hide_cookie2=False, strict_domain=False, strict_rfc2965_unverifiable=True, strict_ns_unverifiable=False, strict_ns_domain=DomainLiberal, strict_ns_set_initial_dollar=False, strict_ns_set_path=False):
| self.netscape = netscape
self.rfc2965 = rfc2965
self.rfc2109_as_netscape = rfc2109_as_netscape
self.hide_cookie2 = hide_cookie2
self.strict_domain = strict_domain
self.strict_rfc2965_unverifiable = strict_rfc2965_unverifiable
self.strict_ns_unverifiable = strict_ns_unverifiable
self.stri... |
'Return the sequence of blocked domains (as a tuple).'
| def blocked_domains(self):
| return self._blocked_domains
|
'Set the sequence of blocked domains.'
| def set_blocked_domains(self, blocked_domains):
| self._blocked_domains = tuple(blocked_domains)
|
'Return None, or the sequence of allowed domains (as a tuple).'
| def allowed_domains(self):
| return self._allowed_domains
|
'Set the sequence of allowed domains, or None.'
| def set_allowed_domains(self, allowed_domains):
| if (allowed_domains is not None):
allowed_domains = tuple(allowed_domains)
self._allowed_domains = allowed_domains
|
'If you override .set_ok(), be sure to call this method. If it returns
false, so should your subclass (assuming your subclass wants to be more
strict about which cookies to accept).'
| def set_ok(self, cookie, request):
| _debug(' - checking cookie %s=%s', cookie.name, cookie.value)
assert (cookie.name is not None)
for n in ('version', 'verifiability', 'name', 'path', 'domain', 'port'):
fn_name = ('set_ok_' + n)
fn = getattr(self, fn_name)
if (not fn(cookie, request)):
return F... |
'If you override .return_ok(), be sure to call this method. If it
returns false, so should your subclass (assuming your subclass wants to
be more strict about which cookies to return).'
| def return_ok(self, cookie, request):
| _debug(' - checking cookie %s=%s', cookie.name, cookie.value)
for n in ('version', 'verifiability', 'secure', 'expires', 'port', 'domain'):
fn_name = ('return_ok_' + n)
fn = getattr(self, fn_name)
if (not fn(cookie, request)):
return False
return True
|
'Return a list of cookies to be returned to server.'
| def _cookies_for_request(self, request):
| cookies = []
for domain in self._cookies.keys():
cookies.extend(self._cookies_for_domain(domain, request))
return cookies
|
'Return a list of cookie-attributes to be returned to server.
like [\'foo="bar"; $Path="/"\', ...]
The $Version attribute is also added when appropriate (currently only
once per request).'
| def _cookie_attrs(self, cookies):
| cookies.sort(key=(lambda arg: len(arg.path)), reverse=True)
version_set = False
attrs = []
for cookie in cookies:
version = cookie.version
if (not version_set):
version_set = True
if (version > 0):
attrs.append(('$Version=%s' % version))
if... |
'Add correct Cookie: header to request (urllib2.Request object).
The Cookie2 header is also added unless policy.hide_cookie2 is true.'
| def add_cookie_header(self, request):
| _debug('add_cookie_header')
self._cookies_lock.acquire()
try:
self._policy._now = self._now = int(time.time())
cookies = self._cookies_for_request(request)
attrs = self._cookie_attrs(cookies)
if attrs:
if (not request.has_header('Cookie')):
request... |
'Return list of tuples containing normalised cookie information.
attrs_set is the list of lists of key,value pairs extracted from
the Set-Cookie or Set-Cookie2 headers.
Tuples are name, value, standard, rest, where name and value are the
cookie name and value, standard is a dictionary containing the standard
cookie-att... | def _normalized_cookie_tuples(self, attrs_set):
| cookie_tuples = []
boolean_attrs = ('discard', 'secure')
value_attrs = ('version', 'expires', 'max-age', 'domain', 'path', 'port', 'comment', 'commenturl')
for cookie_attrs in attrs_set:
(name, value) = cookie_attrs[0]
max_age_set = False
bad_cookie = False
standard = {}
... |
'Return sequence of Cookie objects extracted from response object.'
| def make_cookies(self, response, request):
| headers = response.info()
rfc2965_hdrs = headers.getheaders('Set-Cookie2')
ns_hdrs = headers.getheaders('Set-Cookie')
rfc2965 = self._policy.rfc2965
netscape = self._policy.netscape
if (((not rfc2965_hdrs) and (not ns_hdrs)) or ((not ns_hdrs) and (not rfc2965)) or ((not rfc2965_hdrs) and (not ne... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.