commit a0add49372c65b5b658613572a9362d1eba1eb92 Author: erius Date: Fri Jul 21 01:06:53 2023 +0300 First commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..06109db --- /dev/null +++ b/.gitignore @@ -0,0 +1,153 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ +cover/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +.pybuilder/ +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +# For a library or package, you might want to ignore these files since the code is +# intended to run in multiple environments; otherwise, check them in: +# .python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# poetry +# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. +# This is especially recommended for binary packages to ensure reproducibility, and is more +# commonly ignored for libraries. +# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control +#poetry.lock + +# pdm +# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. +#pdm.lock +# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it +# in version control. +# https://pdm.fming.dev/#use-with-ide +.pdm.toml + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# pytype static type analyzer +.pytype/ + +# Cython debug symbols +cython_debug/ diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/Lab3.iml b/.idea/Lab3.iml new file mode 100644 index 0000000..74d515a --- /dev/null +++ b/.idea/Lab3.iml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..fc76246 --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,13 @@ + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..cd75bde --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..0152fa7 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/dop1.py b/dop1.py new file mode 100644 index 0000000..0724992 --- /dev/null +++ b/dop1.py @@ -0,0 +1,23 @@ +# Дополнительное задание №1 +# Номер в ИСУ: 316304 +# Вариант: 2 + +import re +from smiley import get_args + +regex = [re.compile('ВТ\W*\s+(?:\w+\W+){,4}ИТМО'), re.compile('\W+')] + + +def parse(text): + result = re.findall(regex[0], text) + result = [re.sub(regex[1], ' ', s) for s in result] + return result + + +if __name__ == '__main__': + out = parse(get_args()) + print("Результат работы:") + for n, i in enumerate(out): + print(str(n + 1) + ') ' + str(i)) + if len(out) == 0: + print("Ничего не найдено") diff --git a/dop1_test.py b/dop1_test.py new file mode 100644 index 0000000..b3238ab --- /dev/null +++ b/dop1_test.py @@ -0,0 +1,18 @@ +import unittest +from dop1 import parse + + +class MyTestCase(unittest.TestCase): + def test_dop1(self): + self.assertEqual(parse('А ты знал, что ВТ - лучшая кафедра в ИТМО?'), ['ВТ лучшая кафедра в ИТМО']) + self.assertEqual(parse('А ты знал, что ВТ - лучшая\nкафедра в ИТМО?'), ['ВТ лучшая кафедра в ИТМО']) + self.assertEqual(parse('А ты знал, что ВТ - лучшая крутая супер пупер кафедра в ИТМО?'), []) + self.assertEqual(parse('ВТ ИТМО ВТ ИТМО'), ['ВТ ИТМО ВТ ИТМО']) + self.assertEqual(parse('ВТИТМО'), []) + self.assertEqual(parse('ВТ.ИТМО'), []) + self.assertEqual(parse('ВТ ИТМО'), ['ВТ ИТМО']) + self.assertEqual(parse('А ты знал, что ВТ - лучшая кафедра в ИТМО?\nДа да, ВТ - самая крутая кафедра в ИТМО'), ['ВТ лучшая кафедра в ИТМО', 'ВТ самая крутая кафедра в ИТМО']) + + +if __name__ == '__main__': + unittest.main() diff --git a/dop2.py b/dop2.py new file mode 100644 index 0000000..99dd004 --- /dev/null +++ b/dop2.py @@ -0,0 +1,21 @@ +# Дополнительное задание №2 +# Номер в ИСУ: 316304 +# Вариант: 0 + +import re +import sys + +regex = re.compile('[\w.]+@(\w+\.\w+)') + + +def get_email_server(text): + match = re.match(regex, text) + return 'Fail!' if match is None else match.group(1) + + +if __name__ == '__main__': + args = sys.argv + if len(args) > 1: + print('Почтовый сервер: ' + get_email_server(args[1])) + else: + print('Недостаточно аргументов') diff --git a/dop2_test.py b/dop2_test.py new file mode 100644 index 0000000..0e14cf0 --- /dev/null +++ b/dop2_test.py @@ -0,0 +1,19 @@ +import unittest +from dop2 import get_email_server + + +class MyTestCase(unittest.TestCase): + def test_dop2(self): + self.assertEqual(get_email_server('students.spam@yandex.ru'), 'yandex.ru') + self.assertEqual(get_email_server('mail@gmail.com'), 'gmail.com') + self.assertEqual(get_email_server('example@example.com'), 'example.com') + self.assertEqual(get_email_server('example@example'), 'Fail!') + self.assertEqual(get_email_server('example example'), 'Fail!') + self.assertEqual(get_email_server('@example.com'), 'Fail!') + self.assertEqual(get_email_server('example@example.'), 'Fail!') + self.assertEqual(get_email_server('example@.com'), 'Fail!') + self.assertEqual(get_email_server(''), 'Fail!') + + +if __name__ == '__main__': + unittest.main() diff --git a/smiley.py b/smiley.py new file mode 100644 index 0000000..5c0c82d --- /dev/null +++ b/smiley.py @@ -0,0 +1,30 @@ +# Смайлики +# Номер в ИСУ: 316304 +# Вариант: 402 (=-O) + +import sys + +smiley = '=-0' + + +def smiley_count(text): + return text.count(smiley) + + +def get_args(): + args = sys.argv + if len(args) > 1: + txt = '' + for file_name in args[1:]: + try: + txt += open(file_name).read() + except FileNotFoundError: + print('Файл ' + file_name + ' не найден!') + else: + print('Введите текст (Ctrl+D или Ctrl+Z - конец текста):') + txt = sys.stdin.read() + return txt + + +if __name__ == '__main__': + print('Найдено смайликов: ' + str(smiley_count(get_args()))) diff --git a/smiley_test.py b/smiley_test.py new file mode 100644 index 0000000..ccc69f0 --- /dev/null +++ b/smiley_test.py @@ -0,0 +1,15 @@ +import unittest +from smiley import smiley_count + + +class MyTestCase(unittest.TestCase): + def test_smiley(self): + self.assertEqual(smiley_count('Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus convallis.'), 0) + self.assertEqual(smiley_count('Lorem ipsum dolor sit amet =-0, consectetur adipiscing elit =-0. Phasellus convallis. =-0'), 3) + self.assertEqual(smiley_count('Lorem ipsum dolor sit amet =- 0, consectetur adipiscing elit =\n-0. Phasellus convallis.\n=-0'), 1) + self.assertEqual(smiley_count(''), 0) + self.assertEqual(smiley_count('=-0=-0=-0=--=0-=-009=-'), 4) + + +if __name__ == '__main__': + unittest.main()