· 7 years ago · Oct 27, 2018, 04:06 PM
1from flask import request
2from flask import FLASK
3import BaseHTTPServer
4import socket
5
6import time
7
8class Client:
9 __socket = 0
10
11 def __init__(self, hostage, port, timeout=None):
12 self.__socket = socket.create_connection((hostage, port), timeout)
13
14 def receive(self):
15 if request.method == "GET":
16 login = request.form['login']
17 email = request.form['email']
18 password = request.form['password']
19 phone = request.form['phone']
20 fname = request.form['fname']
21 lname = request.form['lname']
22 if len(phone) <= 12 and len(phone) >= 11:
23 self.incorrect_input(self)
24 return False
25 self.__socket.sendall((' '.join(login, email, phone, fname,
26 lname, password)).encode('utf-8')
27 main_server_answer = (self.__socket.recv(1024)).decode('utf-8')
28
29 def incorrect_input(self):
30 print("Incorrect")
31
32 def correctness_check(self, email, phone):
33 first = True
34 for cur_elem in phone:
35 if (not first and (not ('0' <= cur_elem and cur_elem <= '9') or cur_elem == '+')):
36 self.incorrect_input(self)
37 return False;
38 first = False
39
40 domens = ['mail.ru', 'yandex.ru', 'bk.ru', 'list.ru', 'gmail.com']
41
42 special_symb = -1
43 for i in range(len(email)):
44 if ('0' <= email[i] and email[i] <= '9') or \
45 ('A' <= email[i] and 'Z' <= email[i]) or \
46 ('a' <= email[i] and 'z' <= email[i]) or \
47 (email[i] in {'!', '#', '$', '%', '&',
48 '*', '+', '-', '/', '=', '?', '^', '_', '`', '{', '|', '}', '~'}):
49 pass
50 elif email[i] == '@':
51 special_symb = i + 1
52 break
53 else:
54 self.incorrect_input(self)
55 return False
56 if special_symb <= 0 or email[special_symb:len(email)] not in domens:
57 self.incorrect_input(self)
58 return False
59 return True
60
61 def send(self, data):
62 pass