text
stringlengths
0
828
return json.dumps(obj, sort_keys=True, indent=4, separators=(',', ': '), ensure_ascii=False)"
4425,"def decode_jwt(input_text, secure_key):
""""""
Раскодирование строки на основе ключа
:param input_text: исходная строка
:param secure_key: секретный ключ
:return:
""""""
if input_text is None:
return None
encoded = (input_text.split("":"")[1]).encode('utf-8')
decoded = jwt.decode(encoded, secure_key)
return decoded['sub']"
4426,"def send_request(url, method, data,
args, params, headers, cookies, timeout, is_json, verify_cert):
""""""
Forge and send HTTP request.
""""""
## Parse url args
for p in args:
url = url.replace(':' + p, str(args[p]))
try:
if data:
if is_json:
headers['Content-Type'] = 'application/json'
data = json.dumps(data)
request = requests.Request(
method.upper(), url, data=data, params=params,
headers=headers, cookies=cookies
)
else:
request = requests.Request(
method.upper(), url, params=params, headers=headers,
cookies=cookies
)
## Prepare and send HTTP request.
session = requests.Session()
session.verify = verify_cert
r = session.send(request.prepare(), timeout=timeout)
session.close()
except requests.exceptions.Timeout:
return {
'data': {},
'cookies': CookieJar(),
'content_type': '',
'status': 0,
'is_json': False,
'timeout': True
}
try:
content_type = r.headers.get('Content-Type', 'application/json')
response = r.json()
isjson = True
except json.decoder.JSONDecodeError:
content_type = r.headers.get('Content-Type', 'text/html')
response = r.text
isjson = False
return {
'data': response,
'cookies': r.cookies,
'content_type': content_type,
'status': r.status_code,
'is_json': isjson,
'timeout': False
}"
4427,"def neighbors(self) -> List['Node']:
""""""
The list of neighbors of the node.
""""""
self._load_neighbors()
return [edge.source if edge.source != self else edge.target
for edge in self._neighbors.values()]"
4428,"def add_neighbor(self, edge: ""Edge"") -> None:
""""""
Adds a new neighbor to the node.
Arguments:
edge (Edge): The edge that would connect this node with its neighbor.
""""""
if edge is None or (edge.source != self and edge.target != self):
return
if edge.source == self:
other: Node = edge.target
elif edge.target == self:
other: Node = edge.source
else:
raise ValueError(""Tried to add a neighbor with an invalid edge."")
edge_key: Tuple(int, int) = edge.key
# The graph is considered undirected, check neighbor existence accordingly.