This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
from pyramid.config import Configurator | |
from pyramid.response import Response | |
from jinja2 import FileSystemLoader,Template,Environment | |
from wsgiref.simple_server import make_server | |
env = Environment(loader=FileSystemLoader('HTML')) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Задание: | |
1. Create a class/mapping for this table, call the class Network | |
CREATE TABLE network ( | |
network_id INTEGER PRIMARY KEY, | |
name VARCHAR(100) NOT NULL, | |
) | |
2. emit Base.metadata.create_all(engine) to create the table | |
3. commit a few Network objects to the database: | |
Network(name='net1'), Network(name='net2') | |
----------------------------------------------------------------------------- |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Задание: | |
Produce these expressions using "user_table.c.fullname", | |
"user_table.c.id", and "user_table.c.username": | |
1. user.fullname = 'ed' | |
2. user.fullname = 'ed' AND user.id > 5 | |
3. user.username = 'edward' OR (user.fullname = 'ed' AND user.id > 5) | |
---------------------------------------------------------------------- | |
Код: | |
from sqlalchemy import create_engine, MetaData |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Задание: | |
1. Write a Table construct corresponding to this CREATE TABLE statement. | |
engine = create_engine("sqlite://some.db") | |
metadata.create_all(engine) | |
network_id INTEGER PRIMARY KEY, | |
name VARCHAR(100) NOT NULL, | |
created_at DATETIME NOT NULL, | |
owner_id INTEGER, | |
FOREIGN KEY owner_id REFERENCES user(id) | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Задание: | |
Assuming this table: | |
CREATE TABLE employee ( | |
emp_id INTEGER PRIMARY KEY, | |
emp_name VARCHAR(30) | |
} | |
And using the "engine.execute()" method to invoke a statement: | |
1. Execute an INSERT statement that will insert the row with emp_name='dilbert'. | |
The primary key column can be omitted so that it is generated automatically. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Запрос: | |
from webob import Request | |
req = Request.blank('/post') | |
req.host = 'httpbin.org/post' | |
req.accept = 'multipart/form-data' | |
req.http_version = 'HTTP/1.1' | |
req.method = 'POST' | |
req.text = 'firstname: Olga\nlastname: Umutbaeva\ngroup: FO-350005\nmessage: Hurray!\nmyimg: img' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Запрос 1: | |
from webob import Request, Response | |
req = Request.blank('/ip') | |
req.host = 'httpbin.org' | |
req.accept = '*/*' | |
req.http_version = 'HTTP/1.1' | |
print(req) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Запрос: | |
from webob import Request, Response | |
req = Request.blank('/wiki/stranica') | |
req.host = 'ru.wikipedia.org' | |
req.accept = 'text/html' | |
req.headers['connection'] = 'close' | |
req.user_agent = 'Mozilla/5.0 (X11; U; Linux i686; ru; rv:1.9b5)' | |
req.http_version = 'HTTP/1.1' | |
print(req) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1. Запускаем в терминале файл SWGI.py (название моего файла, в котором хранится код). | |
Сам код выглядет так: | |
class WsgiTopBottomMiddleware(object): | |
def __init__(self, app): | |
self.app = app | |
self.assets = [ | |
'app.js', | |
'react.js', | |
'leaflet.js', | |
'D3.js', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
В терминале ввели команду 'ifconfig', далее команду 'sudo tcpdump -X -i enp0s3host httpbin.org and port 80' | |
Во втором терминале открыли файлик с кодом: | |
#!/usr/bin/python | |
#codin: utf8 | |
import requests | |
response = requests.post("http://httpbin.org/post", data={"github": "Olisss", "Name": "Olga", "Surname": "Umutbaeva"}) | |
print(response.headers) | |
И получили ответ: | |
NewerOlder