Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions 1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import re


def email_parse(email):
if '@' not in email:
raise ValueError('email don`t have - @')
elif '.' not in email:
raise ValueError('email don`t have - .')
di = {}
all = re.findall(r'[a-zA-Z1-9]*', email)
di['username'] = all[0]
di['domain'] = all[2]
print(di)


email = 'someone@geekbrains.ru'
email_parse(email)
22 changes: 22 additions & 0 deletions 2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import re


li_result = []
with open('nginx_logs.txt', 'r') as file:
for line in file:
# print(line)
ip4 = re.search(r'^\d+.\d+.\d+.\d+', line)
ip6 = re.match(r'([0-9A-Za-z]{1,4}:){7}[0-9A-Za-z]{1,4}', line)
ip = ip4 if ip4 else ip6
if ip:
date = re.search(r'\[.*\]', line).group()[1:-2]
method = re.search(r'"[A-Z]{3}', line).group()[1:]
load = re.search(r'/downloads/product_\d', line).group()
req_res = re.findall(r' [0-9]{1,3}', line)
request = req_res[0]
responce = req_res[1]
line_res = (ip.group(), date, method, load, request, responce)
li_result.append(line_res)

print(li_result) # ...('79.136.114.202', '04/Jun/2015:07:06:35 +0000',
# '"GET', '/downloads/product_1', ' 404', ' 334')]
29 changes: 29 additions & 0 deletions 3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from functools import wraps


def type_logger(func):

@wraps(func)
def wrap_func(*args):
new_li = []
z = func(*args)
for i in z:
new_li.append((i, type(i)))
return new_li
return wrap_func


@type_logger
def calc_cube(*args):
'''get args in cube'''
li = []
if type(args) == list or type(args) == tuple:
for a in args:
li.append(int(a)**3)
else:
li = int(args)**3
return li


a = calc_cube(5, 54, 3)
print(a)
30 changes: 30 additions & 0 deletions 4.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from functools import wraps


def val_checker(func):

@wraps(func)
def wrap_args(*args):
check_argv = args
for i in check_argv:
if i < 0:
raise ValueError('Error - value less zero')
res = func(check_argv)
return res
return wrap_args


@val_checker
def calc_cube(*args):
'''get args in cube'''
li = []
if type(args) == list or type(args) == tuple:
for a in args:
li.append(int(a)**3)
else:
li = int(args)**3
return li


res = calc_cube(1, -3, 4)
print(res)
Loading