First commit

This commit is contained in:
Egor 2023-07-21 01:06:53 +03:00
commit a0add49372
13 changed files with 328 additions and 0 deletions

153
.gitignore vendored Normal file
View file

@ -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/

8
.idea/.gitignore vendored Normal file
View file

@ -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

10
.idea/Lab3.iml Normal file
View file

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/venv" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View file

@ -0,0 +1,13 @@
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="PyUnresolvedReferencesInspection" enabled="true" level="WARNING" enabled_by_default="true">
<option name="ignoredIdentifiers">
<list>
<option value="list.__getitem__" />
<option value="str.replace" />
</list>
</option>
</inspection_tool>
</profile>
</component>

View file

@ -0,0 +1,6 @@
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>

4
.idea/misc.xml Normal file
View file

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.9 (Lab3)" project-jdk-type="Python SDK" />
</project>

8
.idea/modules.xml Normal file
View file

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/Lab3.iml" filepath="$PROJECT_DIR$/.idea/Lab3.iml" />
</modules>
</component>
</project>

23
dop1.py Normal file
View file

@ -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("Ничего не найдено")

18
dop1_test.py Normal file
View file

@ -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()

21
dop2.py Normal file
View file

@ -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('Недостаточно аргументов')

19
dop2_test.py Normal file
View file

@ -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()

30
smiley.py Normal file
View file

@ -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())))

15
smiley_test.py Normal file
View file

@ -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()