Hostnames are composed of series of labels concatenated with dots, as are all domain names. For example, "en.wikipedia.org" is a hostname. Each label must be between 1 and 63 characters long, and the entire hostname (including the delimiting dots but not a trailing dot) has a maximum of 253 ASCII characters.
The Internet standards for protocols mandate that component hostname labels may contain only the ASCII letters 'a' through 'z' (in a case-insensitive manner), the digits '0' through '9', and the hyphen ('-'). The original specification of hostnames in RFC 952, mandated that labels could not start with a digit or with a hyphen, and must not end with a hyphen. However, a subsequent specification (RFC 1123) permitted hostname labels to start with digits. No other symbols, punctuation characters, or white space are permitted.
students = [
{
'first_name': 'Иван',
'last_name': 'Иванов',
'grades': {
'math': 3,
'chemistry': 5,
'literature': 4
}
},
{
'first_name': 'Пётр',
'last_name': 'Петров',
'grades': {
'math': 5,
'chemistry': 4,
'literature': 3
}
}
]
class LimitedImageField(ImageField):
def __init__(self, *args, **kwargs):
self.max_upload_size = kwargs.pop('max_upload_size', None)
self.min_dim = kwargs.pop('min_dim', None)
self.max_dim = kwargs.pop('max_dim', None)
if not self.max_upload_size:
self.max_upload_size = settings.FILE_UPLOAD_MAX_MEMORY_SIZE
super(LimitedImageField, self).__init__(*args, **kwargs)
def clean(self, *args, **kwargs):
data = super(LimitedImageField, self).clean(*args, **kwargs)
try:
img_file = data.file
if img_file.size > self.max_upload_size:
err_msg = 'Размер файла не должен превышать {}'.format(filesizeformat(self.max_upload_size))
raise forms.ValidationError(err_msg)
w, h = get_image_dimensions(img_file)
if self.min_dim:
if (w < self.min_dim[0]) or (h < self.min_dim[1]):
err_msg = 'Разрешение изображения не должно быть меньше, чем {}x{}'.format(*self.min_dim)
raise forms.ValidationError(err_msg)
if self.max_dim:
if (w > self.max_dim[0]) or (h > self.max_dim[1]):
err_msg = 'Разрешение изображения не должно превышать {}x{}'.format(*self.max_dim)
raise forms.ValidationError(err_msg)
except AttributeError:
pass
return data
image = LimitedImageField('Изображение', min_dim=(100, 100), max_dim=(300, 300),
help_text='Разрешение от 100x100 до 300х300')
class A:
def __init__(self, name='default'):
self._name = name
@property
def name(self):
return self._name
@name.setter
def name(self, value):
self._name = value
a = A()
print(a.name)
a.name = 'test'
from datetime import datetime
d1 = datetime(2018, 12, 15, 13)
d2 = datetime(2018, 12, 15, 18)
delta = d2 - d1
print(delta.seconds)