Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/ShExBy/shex_roo.../lib64/python3....
File: weakref.py
"""Weak reference support for Python.
[0] Fix | Delete
[1] Fix | Delete
This module is an implementation of PEP 205:
[2] Fix | Delete
[3] Fix | Delete
http://www.python.org/dev/peps/pep-0205/
[4] Fix | Delete
"""
[5] Fix | Delete
[6] Fix | Delete
# Naming convention: Variables named "wr" are weak reference objects;
[7] Fix | Delete
# they are called this instead of "ref" to avoid name collisions with
[8] Fix | Delete
# the module-global ref() function imported from _weakref.
[9] Fix | Delete
[10] Fix | Delete
from _weakref import (
[11] Fix | Delete
getweakrefcount,
[12] Fix | Delete
getweakrefs,
[13] Fix | Delete
ref,
[14] Fix | Delete
proxy,
[15] Fix | Delete
CallableProxyType,
[16] Fix | Delete
ProxyType,
[17] Fix | Delete
ReferenceType,
[18] Fix | Delete
_remove_dead_weakref)
[19] Fix | Delete
[20] Fix | Delete
from _weakrefset import WeakSet, _IterationGuard
[21] Fix | Delete
[22] Fix | Delete
import _collections_abc # Import after _weakref to avoid circular import.
[23] Fix | Delete
import sys
[24] Fix | Delete
import itertools
[25] Fix | Delete
[26] Fix | Delete
ProxyTypes = (ProxyType, CallableProxyType)
[27] Fix | Delete
[28] Fix | Delete
__all__ = ["ref", "proxy", "getweakrefcount", "getweakrefs",
[29] Fix | Delete
"WeakKeyDictionary", "ReferenceType", "ProxyType",
[30] Fix | Delete
"CallableProxyType", "ProxyTypes", "WeakValueDictionary",
[31] Fix | Delete
"WeakSet", "WeakMethod", "finalize"]
[32] Fix | Delete
[33] Fix | Delete
[34] Fix | Delete
class WeakMethod(ref):
[35] Fix | Delete
"""
[36] Fix | Delete
A custom `weakref.ref` subclass which simulates a weak reference to
[37] Fix | Delete
a bound method, working around the lifetime problem of bound methods.
[38] Fix | Delete
"""
[39] Fix | Delete
[40] Fix | Delete
__slots__ = "_func_ref", "_meth_type", "_alive", "__weakref__"
[41] Fix | Delete
[42] Fix | Delete
def __new__(cls, meth, callback=None):
[43] Fix | Delete
try:
[44] Fix | Delete
obj = meth.__self__
[45] Fix | Delete
func = meth.__func__
[46] Fix | Delete
except AttributeError:
[47] Fix | Delete
raise TypeError("argument should be a bound method, not {}"
[48] Fix | Delete
.format(type(meth))) from None
[49] Fix | Delete
def _cb(arg):
[50] Fix | Delete
# The self-weakref trick is needed to avoid creating a reference
[51] Fix | Delete
# cycle.
[52] Fix | Delete
self = self_wr()
[53] Fix | Delete
if self._alive:
[54] Fix | Delete
self._alive = False
[55] Fix | Delete
if callback is not None:
[56] Fix | Delete
callback(self)
[57] Fix | Delete
self = ref.__new__(cls, obj, _cb)
[58] Fix | Delete
self._func_ref = ref(func, _cb)
[59] Fix | Delete
self._meth_type = type(meth)
[60] Fix | Delete
self._alive = True
[61] Fix | Delete
self_wr = ref(self)
[62] Fix | Delete
return self
[63] Fix | Delete
[64] Fix | Delete
def __call__(self):
[65] Fix | Delete
obj = super().__call__()
[66] Fix | Delete
func = self._func_ref()
[67] Fix | Delete
if obj is None or func is None:
[68] Fix | Delete
return None
[69] Fix | Delete
return self._meth_type(func, obj)
[70] Fix | Delete
[71] Fix | Delete
def __eq__(self, other):
[72] Fix | Delete
if isinstance(other, WeakMethod):
[73] Fix | Delete
if not self._alive or not other._alive:
[74] Fix | Delete
return self is other
[75] Fix | Delete
return ref.__eq__(self, other) and self._func_ref == other._func_ref
[76] Fix | Delete
return False
[77] Fix | Delete
[78] Fix | Delete
def __ne__(self, other):
[79] Fix | Delete
if isinstance(other, WeakMethod):
[80] Fix | Delete
if not self._alive or not other._alive:
[81] Fix | Delete
return self is not other
[82] Fix | Delete
return ref.__ne__(self, other) or self._func_ref != other._func_ref
[83] Fix | Delete
return True
[84] Fix | Delete
[85] Fix | Delete
__hash__ = ref.__hash__
[86] Fix | Delete
[87] Fix | Delete
[88] Fix | Delete
class WeakValueDictionary(_collections_abc.MutableMapping):
[89] Fix | Delete
"""Mapping class that references values weakly.
[90] Fix | Delete
[91] Fix | Delete
Entries in the dictionary will be discarded when no strong
[92] Fix | Delete
reference to the value exists anymore
[93] Fix | Delete
"""
[94] Fix | Delete
# We inherit the constructor without worrying about the input
[95] Fix | Delete
# dictionary; since it uses our .update() method, we get the right
[96] Fix | Delete
# checks (if the other dictionary is a WeakValueDictionary,
[97] Fix | Delete
# objects are unwrapped on the way out, and we always wrap on the
[98] Fix | Delete
# way in).
[99] Fix | Delete
[100] Fix | Delete
def __init__(self, other=(), /, **kw):
[101] Fix | Delete
def remove(wr, selfref=ref(self), _atomic_removal=_remove_dead_weakref):
[102] Fix | Delete
self = selfref()
[103] Fix | Delete
if self is not None:
[104] Fix | Delete
if self._iterating:
[105] Fix | Delete
self._pending_removals.append(wr.key)
[106] Fix | Delete
else:
[107] Fix | Delete
# Atomic removal is necessary since this function
[108] Fix | Delete
# can be called asynchronously by the GC
[109] Fix | Delete
_atomic_removal(self.data, wr.key)
[110] Fix | Delete
self._remove = remove
[111] Fix | Delete
# A list of keys to be removed
[112] Fix | Delete
self._pending_removals = []
[113] Fix | Delete
self._iterating = set()
[114] Fix | Delete
self.data = {}
[115] Fix | Delete
self.update(other, **kw)
[116] Fix | Delete
[117] Fix | Delete
def _commit_removals(self):
[118] Fix | Delete
l = self._pending_removals
[119] Fix | Delete
d = self.data
[120] Fix | Delete
# We shouldn't encounter any KeyError, because this method should
[121] Fix | Delete
# always be called *before* mutating the dict.
[122] Fix | Delete
while l:
[123] Fix | Delete
key = l.pop()
[124] Fix | Delete
_remove_dead_weakref(d, key)
[125] Fix | Delete
[126] Fix | Delete
def __getitem__(self, key):
[127] Fix | Delete
if self._pending_removals:
[128] Fix | Delete
self._commit_removals()
[129] Fix | Delete
o = self.data[key]()
[130] Fix | Delete
if o is None:
[131] Fix | Delete
raise KeyError(key)
[132] Fix | Delete
else:
[133] Fix | Delete
return o
[134] Fix | Delete
[135] Fix | Delete
def __delitem__(self, key):
[136] Fix | Delete
if self._pending_removals:
[137] Fix | Delete
self._commit_removals()
[138] Fix | Delete
del self.data[key]
[139] Fix | Delete
[140] Fix | Delete
def __len__(self):
[141] Fix | Delete
if self._pending_removals:
[142] Fix | Delete
self._commit_removals()
[143] Fix | Delete
return len(self.data)
[144] Fix | Delete
[145] Fix | Delete
def __contains__(self, key):
[146] Fix | Delete
if self._pending_removals:
[147] Fix | Delete
self._commit_removals()
[148] Fix | Delete
try:
[149] Fix | Delete
o = self.data[key]()
[150] Fix | Delete
except KeyError:
[151] Fix | Delete
return False
[152] Fix | Delete
return o is not None
[153] Fix | Delete
[154] Fix | Delete
def __repr__(self):
[155] Fix | Delete
return "<%s at %#x>" % (self.__class__.__name__, id(self))
[156] Fix | Delete
[157] Fix | Delete
def __setitem__(self, key, value):
[158] Fix | Delete
if self._pending_removals:
[159] Fix | Delete
self._commit_removals()
[160] Fix | Delete
self.data[key] = KeyedRef(value, self._remove, key)
[161] Fix | Delete
[162] Fix | Delete
def copy(self):
[163] Fix | Delete
if self._pending_removals:
[164] Fix | Delete
self._commit_removals()
[165] Fix | Delete
new = WeakValueDictionary()
[166] Fix | Delete
with _IterationGuard(self):
[167] Fix | Delete
for key, wr in self.data.items():
[168] Fix | Delete
o = wr()
[169] Fix | Delete
if o is not None:
[170] Fix | Delete
new[key] = o
[171] Fix | Delete
return new
[172] Fix | Delete
[173] Fix | Delete
__copy__ = copy
[174] Fix | Delete
[175] Fix | Delete
def __deepcopy__(self, memo):
[176] Fix | Delete
from copy import deepcopy
[177] Fix | Delete
if self._pending_removals:
[178] Fix | Delete
self._commit_removals()
[179] Fix | Delete
new = self.__class__()
[180] Fix | Delete
with _IterationGuard(self):
[181] Fix | Delete
for key, wr in self.data.items():
[182] Fix | Delete
o = wr()
[183] Fix | Delete
if o is not None:
[184] Fix | Delete
new[deepcopy(key, memo)] = o
[185] Fix | Delete
return new
[186] Fix | Delete
[187] Fix | Delete
def get(self, key, default=None):
[188] Fix | Delete
if self._pending_removals:
[189] Fix | Delete
self._commit_removals()
[190] Fix | Delete
try:
[191] Fix | Delete
wr = self.data[key]
[192] Fix | Delete
except KeyError:
[193] Fix | Delete
return default
[194] Fix | Delete
else:
[195] Fix | Delete
o = wr()
[196] Fix | Delete
if o is None:
[197] Fix | Delete
# This should only happen
[198] Fix | Delete
return default
[199] Fix | Delete
else:
[200] Fix | Delete
return o
[201] Fix | Delete
[202] Fix | Delete
def items(self):
[203] Fix | Delete
if self._pending_removals:
[204] Fix | Delete
self._commit_removals()
[205] Fix | Delete
with _IterationGuard(self):
[206] Fix | Delete
for k, wr in self.data.items():
[207] Fix | Delete
v = wr()
[208] Fix | Delete
if v is not None:
[209] Fix | Delete
yield k, v
[210] Fix | Delete
[211] Fix | Delete
def keys(self):
[212] Fix | Delete
if self._pending_removals:
[213] Fix | Delete
self._commit_removals()
[214] Fix | Delete
with _IterationGuard(self):
[215] Fix | Delete
for k, wr in self.data.items():
[216] Fix | Delete
if wr() is not None:
[217] Fix | Delete
yield k
[218] Fix | Delete
[219] Fix | Delete
__iter__ = keys
[220] Fix | Delete
[221] Fix | Delete
def itervaluerefs(self):
[222] Fix | Delete
"""Return an iterator that yields the weak references to the values.
[223] Fix | Delete
[224] Fix | Delete
The references are not guaranteed to be 'live' at the time
[225] Fix | Delete
they are used, so the result of calling the references needs
[226] Fix | Delete
to be checked before being used. This can be used to avoid
[227] Fix | Delete
creating references that will cause the garbage collector to
[228] Fix | Delete
keep the values around longer than needed.
[229] Fix | Delete
[230] Fix | Delete
"""
[231] Fix | Delete
if self._pending_removals:
[232] Fix | Delete
self._commit_removals()
[233] Fix | Delete
with _IterationGuard(self):
[234] Fix | Delete
yield from self.data.values()
[235] Fix | Delete
[236] Fix | Delete
def values(self):
[237] Fix | Delete
if self._pending_removals:
[238] Fix | Delete
self._commit_removals()
[239] Fix | Delete
with _IterationGuard(self):
[240] Fix | Delete
for wr in self.data.values():
[241] Fix | Delete
obj = wr()
[242] Fix | Delete
if obj is not None:
[243] Fix | Delete
yield obj
[244] Fix | Delete
[245] Fix | Delete
def popitem(self):
[246] Fix | Delete
if self._pending_removals:
[247] Fix | Delete
self._commit_removals()
[248] Fix | Delete
while True:
[249] Fix | Delete
key, wr = self.data.popitem()
[250] Fix | Delete
o = wr()
[251] Fix | Delete
if o is not None:
[252] Fix | Delete
return key, o
[253] Fix | Delete
[254] Fix | Delete
def pop(self, key, *args):
[255] Fix | Delete
if self._pending_removals:
[256] Fix | Delete
self._commit_removals()
[257] Fix | Delete
try:
[258] Fix | Delete
o = self.data.pop(key)()
[259] Fix | Delete
except KeyError:
[260] Fix | Delete
o = None
[261] Fix | Delete
if o is None:
[262] Fix | Delete
if args:
[263] Fix | Delete
return args[0]
[264] Fix | Delete
else:
[265] Fix | Delete
raise KeyError(key)
[266] Fix | Delete
else:
[267] Fix | Delete
return o
[268] Fix | Delete
[269] Fix | Delete
def setdefault(self, key, default=None):
[270] Fix | Delete
try:
[271] Fix | Delete
o = self.data[key]()
[272] Fix | Delete
except KeyError:
[273] Fix | Delete
o = None
[274] Fix | Delete
if o is None:
[275] Fix | Delete
if self._pending_removals:
[276] Fix | Delete
self._commit_removals()
[277] Fix | Delete
self.data[key] = KeyedRef(default, self._remove, key)
[278] Fix | Delete
return default
[279] Fix | Delete
else:
[280] Fix | Delete
return o
[281] Fix | Delete
[282] Fix | Delete
def update(self, other=None, /, **kwargs):
[283] Fix | Delete
if self._pending_removals:
[284] Fix | Delete
self._commit_removals()
[285] Fix | Delete
d = self.data
[286] Fix | Delete
if other is not None:
[287] Fix | Delete
if not hasattr(other, "items"):
[288] Fix | Delete
other = dict(other)
[289] Fix | Delete
for key, o in other.items():
[290] Fix | Delete
d[key] = KeyedRef(o, self._remove, key)
[291] Fix | Delete
for key, o in kwargs.items():
[292] Fix | Delete
d[key] = KeyedRef(o, self._remove, key)
[293] Fix | Delete
[294] Fix | Delete
def valuerefs(self):
[295] Fix | Delete
"""Return a list of weak references to the values.
[296] Fix | Delete
[297] Fix | Delete
The references are not guaranteed to be 'live' at the time
[298] Fix | Delete
they are used, so the result of calling the references needs
[299] Fix | Delete
to be checked before being used. This can be used to avoid
[300] Fix | Delete
creating references that will cause the garbage collector to
[301] Fix | Delete
keep the values around longer than needed.
[302] Fix | Delete
[303] Fix | Delete
"""
[304] Fix | Delete
if self._pending_removals:
[305] Fix | Delete
self._commit_removals()
[306] Fix | Delete
return list(self.data.values())
[307] Fix | Delete
[308] Fix | Delete
[309] Fix | Delete
class KeyedRef(ref):
[310] Fix | Delete
"""Specialized reference that includes a key corresponding to the value.
[311] Fix | Delete
[312] Fix | Delete
This is used in the WeakValueDictionary to avoid having to create
[313] Fix | Delete
a function object for each key stored in the mapping. A shared
[314] Fix | Delete
callback object can use the 'key' attribute of a KeyedRef instead
[315] Fix | Delete
of getting a reference to the key from an enclosing scope.
[316] Fix | Delete
[317] Fix | Delete
"""
[318] Fix | Delete
[319] Fix | Delete
__slots__ = "key",
[320] Fix | Delete
[321] Fix | Delete
def __new__(type, ob, callback, key):
[322] Fix | Delete
self = ref.__new__(type, ob, callback)
[323] Fix | Delete
self.key = key
[324] Fix | Delete
return self
[325] Fix | Delete
[326] Fix | Delete
def __init__(self, ob, callback, key):
[327] Fix | Delete
super().__init__(ob, callback)
[328] Fix | Delete
[329] Fix | Delete
[330] Fix | Delete
class WeakKeyDictionary(_collections_abc.MutableMapping):
[331] Fix | Delete
""" Mapping class that references keys weakly.
[332] Fix | Delete
[333] Fix | Delete
Entries in the dictionary will be discarded when there is no
[334] Fix | Delete
longer a strong reference to the key. This can be used to
[335] Fix | Delete
associate additional data with an object owned by other parts of
[336] Fix | Delete
an application without adding attributes to those objects. This
[337] Fix | Delete
can be especially useful with objects that override attribute
[338] Fix | Delete
accesses.
[339] Fix | Delete
"""
[340] Fix | Delete
[341] Fix | Delete
def __init__(self, dict=None):
[342] Fix | Delete
self.data = {}
[343] Fix | Delete
def remove(k, selfref=ref(self)):
[344] Fix | Delete
self = selfref()
[345] Fix | Delete
if self is not None:
[346] Fix | Delete
if self._iterating:
[347] Fix | Delete
self._pending_removals.append(k)
[348] Fix | Delete
else:
[349] Fix | Delete
del self.data[k]
[350] Fix | Delete
self._remove = remove
[351] Fix | Delete
# A list of dead weakrefs (keys to be removed)
[352] Fix | Delete
self._pending_removals = []
[353] Fix | Delete
self._iterating = set()
[354] Fix | Delete
self._dirty_len = False
[355] Fix | Delete
if dict is not None:
[356] Fix | Delete
self.update(dict)
[357] Fix | Delete
[358] Fix | Delete
def _commit_removals(self):
[359] Fix | Delete
# NOTE: We don't need to call this method before mutating the dict,
[360] Fix | Delete
# because a dead weakref never compares equal to a live weakref,
[361] Fix | Delete
# even if they happened to refer to equal objects.
[362] Fix | Delete
# However, it means keys may already have been removed.
[363] Fix | Delete
l = self._pending_removals
[364] Fix | Delete
d = self.data
[365] Fix | Delete
while l:
[366] Fix | Delete
try:
[367] Fix | Delete
del d[l.pop()]
[368] Fix | Delete
except KeyError:
[369] Fix | Delete
pass
[370] Fix | Delete
[371] Fix | Delete
def _scrub_removals(self):
[372] Fix | Delete
d = self.data
[373] Fix | Delete
self._pending_removals = [k for k in self._pending_removals if k in d]
[374] Fix | Delete
self._dirty_len = False
[375] Fix | Delete
[376] Fix | Delete
def __delitem__(self, key):
[377] Fix | Delete
self._dirty_len = True
[378] Fix | Delete
del self.data[ref(key)]
[379] Fix | Delete
[380] Fix | Delete
def __getitem__(self, key):
[381] Fix | Delete
return self.data[ref(key)]
[382] Fix | Delete
[383] Fix | Delete
def __len__(self):
[384] Fix | Delete
if self._dirty_len and self._pending_removals:
[385] Fix | Delete
# self._pending_removals may still contain keys which were
[386] Fix | Delete
# explicitly removed, we have to scrub them (see issue #21173).
[387] Fix | Delete
self._scrub_removals()
[388] Fix | Delete
return len(self.data) - len(self._pending_removals)
[389] Fix | Delete
[390] Fix | Delete
def __repr__(self):
[391] Fix | Delete
return "<%s at %#x>" % (self.__class__.__name__, id(self))
[392] Fix | Delete
[393] Fix | Delete
def __setitem__(self, key, value):
[394] Fix | Delete
self.data[ref(key, self._remove)] = value
[395] Fix | Delete
[396] Fix | Delete
def copy(self):
[397] Fix | Delete
new = WeakKeyDictionary()
[398] Fix | Delete
with _IterationGuard(self):
[399] Fix | Delete
for key, value in self.data.items():
[400] Fix | Delete
o = key()
[401] Fix | Delete
if o is not None:
[402] Fix | Delete
new[o] = value
[403] Fix | Delete
return new
[404] Fix | Delete
[405] Fix | Delete
__copy__ = copy
[406] Fix | Delete
[407] Fix | Delete
def __deepcopy__(self, memo):
[408] Fix | Delete
from copy import deepcopy
[409] Fix | Delete
new = self.__class__()
[410] Fix | Delete
with _IterationGuard(self):
[411] Fix | Delete
for key, value in self.data.items():
[412] Fix | Delete
o = key()
[413] Fix | Delete
if o is not None:
[414] Fix | Delete
new[o] = deepcopy(value, memo)
[415] Fix | Delete
return new
[416] Fix | Delete
[417] Fix | Delete
def get(self, key, default=None):
[418] Fix | Delete
return self.data.get(ref(key),default)
[419] Fix | Delete
[420] Fix | Delete
def __contains__(self, key):
[421] Fix | Delete
try:
[422] Fix | Delete
wr = ref(key)
[423] Fix | Delete
except TypeError:
[424] Fix | Delete
return False
[425] Fix | Delete
return wr in self.data
[426] Fix | Delete
[427] Fix | Delete
def items(self):
[428] Fix | Delete
with _IterationGuard(self):
[429] Fix | Delete
for wr, value in self.data.items():
[430] Fix | Delete
key = wr()
[431] Fix | Delete
if key is not None:
[432] Fix | Delete
yield key, value
[433] Fix | Delete
[434] Fix | Delete
def keys(self):
[435] Fix | Delete
with _IterationGuard(self):
[436] Fix | Delete
for wr in self.data:
[437] Fix | Delete
obj = wr()
[438] Fix | Delete
if obj is not None:
[439] Fix | Delete
yield obj
[440] Fix | Delete
[441] Fix | Delete
__iter__ = keys
[442] Fix | Delete
[443] Fix | Delete
def values(self):
[444] Fix | Delete
with _IterationGuard(self):
[445] Fix | Delete
for wr, value in self.data.items():
[446] Fix | Delete
if wr() is not None:
[447] Fix | Delete
yield value
[448] Fix | Delete
[449] Fix | Delete
def keyrefs(self):
[450] Fix | Delete
"""Return a list of weak references to the keys.
[451] Fix | Delete
[452] Fix | Delete
The references are not guaranteed to be 'live' at the time
[453] Fix | Delete
they are used, so the result of calling the references needs
[454] Fix | Delete
to be checked before being used. This can be used to avoid
[455] Fix | Delete
creating references that will cause the garbage collector to
[456] Fix | Delete
keep the keys around longer than needed.
[457] Fix | Delete
[458] Fix | Delete
"""
[459] Fix | Delete
return list(self.data)
[460] Fix | Delete
[461] Fix | Delete
def popitem(self):
[462] Fix | Delete
self._dirty_len = True
[463] Fix | Delete
while True:
[464] Fix | Delete
key, value = self.data.popitem()
[465] Fix | Delete
o = key()
[466] Fix | Delete
if o is not None:
[467] Fix | Delete
return o, value
[468] Fix | Delete
[469] Fix | Delete
def pop(self, key, *args):
[470] Fix | Delete
self._dirty_len = True
[471] Fix | Delete
return self.data.pop(ref(key), *args)
[472] Fix | Delete
[473] Fix | Delete
def setdefault(self, key, default=None):
[474] Fix | Delete
return self.data.setdefault(ref(key, self._remove),default)
[475] Fix | Delete
[476] Fix | Delete
def update(self, dict=None, /, **kwargs):
[477] Fix | Delete
d = self.data
[478] Fix | Delete
if dict is not None:
[479] Fix | Delete
if not hasattr(dict, "items"):
[480] Fix | Delete
dict = type({})(dict)
[481] Fix | Delete
for key, value in dict.items():
[482] Fix | Delete
d[ref(key, self._remove)] = value
[483] Fix | Delete
if len(kwargs):
[484] Fix | Delete
self.update(kwargs)
[485] Fix | Delete
[486] Fix | Delete
[487] Fix | Delete
class finalize:
[488] Fix | Delete
"""Class for finalization of weakrefable objects
[489] Fix | Delete
[490] Fix | Delete
finalize(obj, func, *args, **kwargs) returns a callable finalizer
[491] Fix | Delete
object which will be called when obj is garbage collected. The
[492] Fix | Delete
first time the finalizer is called it evaluates func(*arg, **kwargs)
[493] Fix | Delete
and returns the result. After this the finalizer is dead, and
[494] Fix | Delete
calling it just returns None.
[495] Fix | Delete
[496] Fix | Delete
When the program exits any remaining finalizers for which the
[497] Fix | Delete
atexit attribute is true will be run in reverse order of creation.
[498] Fix | Delete
By default atexit is true.
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function