Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from string import ascii_lowercase, digits
- # здесь объявляйте классы TextInput и PasswordInput
- class TextInput:
- CHARS = "абвгдеёжзийклмнопрстуфхцчшщьыъэюя " + ascii_lowercase
- CHARS_CORRECT = CHARS + CHARS.upper() + digits
- def __init__(self,name,size =10):
- if self.check_name(name):
- self.name = name
- self.size = size
- def get_html(self):
- return f"<p class='login'>{self.name}: <input type='text' size={self.size} />"
- @classmethod
- def check_name(cls, name):
- if 3 > len(name) or len(name) > 50:
- raise ValueError("некорректное поле name")
- for char in name:
- if char not in cls.CHARS_CORRECT:
- raise ValueError("некорректное поле name")
- return True
- class PasswordInput:
- CHARS = "абвгдеёжзийклмнопрстуфхцчшщьыъэюя " + ascii_lowercase
- CHARS_CORRECT = CHARS + CHARS.upper() + digits
- def __init__(self, name, size = 10):
- if self.check_name(name):
- self.name = name
- self.size = size
- def get_html(self):
- return f"<p class='password'>{self.name}: <input type='text' size={self.size} />"
- @classmethod
- def check_name(cls, name):
- if 3 > len(name) or len(name) > 50:
- raise ValueError("некорректное поле name")
- for char in name:
- if char not in cls.CHARS_CORRECT:
- raise ValueError("некорректное поле name")
- return True
- class FormLogin:
- def __init__(self, lgn, psw):
- self.login = lgn
- self.password = psw
- def render_template(self):
- return "\n".join(['<form action="#">', self.login.get_html(), self.password.get_html(), '</form>'])
- # эти строчки не менять
- login = FormLogin(TextInput("Логин"), PasswordInput("Пароль"))
- html = login.render_template()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement