modulitiz-mini 2.6.0__py311-none-any.whl → 2.6.1__py311-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,84 +1,84 @@
1
- from cryptography.hazmat.backends import default_backend
2
- from cryptography.hazmat.primitives import hashes
3
- from cryptography.hazmat.primitives import serialization
4
- from cryptography.hazmat.primitives.asymmetric import padding
5
- from cryptography.hazmat.primitives.asymmetric import rsa
6
- from cryptography.hazmat.primitives.asymmetric.rsa import RSAPrivateKey
7
- from cryptography.hazmat.primitives.asymmetric.rsa import RSAPublicKey
8
-
9
- from modulitiz_micro.ModuloStringhe import ModuloStringhe
10
-
11
-
12
- class ModuloRsa(object):
13
- DEFAULT_HASH_TYPE=hashes.SHA256()
14
- KEY_SIZE=4096
15
-
16
- NOMEFILE_PUBLIC_KEY="public.key"
17
- NOMEFILE_PRIVATE_KEY="private.key"
18
-
19
- def __init__(self):
20
- self.publicKey:RSAPublicKey|None=None
21
- self.privateKey:RSAPrivateKey|None=None
22
-
23
- def generateKeys(self):
24
- self.privateKey = rsa.generate_private_key(
25
- public_exponent=65537, key_size=self.KEY_SIZE, backend=default_backend()
26
- )
27
- self.publicKey = self.privateKey.public_key()
28
-
29
- #
30
- # save
31
- #
32
- def savePublicKey(self,nomefile=NOMEFILE_PUBLIC_KEY):
33
- pem = self.publicKey.public_bytes(
34
- encoding=serialization.Encoding.PEM,
35
- format=serialization.PublicFormat.SubjectPublicKeyInfo
36
- )
37
- with open(nomefile, 'wb') as fp:
38
- fp.write(pem)
39
-
40
- def savePrivateKey(self, nomefile=NOMEFILE_PRIVATE_KEY):
41
- pem = self.privateKey.private_bytes(
42
- encoding=serialization.Encoding.PEM,
43
- format=serialization.PrivateFormat.TraditionalOpenSSL,
44
- encryption_algorithm=serialization.NoEncryption()
45
- )
46
- with open(nomefile, 'wb') as fp:
47
- fp.write(pem)
48
-
49
- #
50
- # read
51
- #
52
- def readPublicKey(self,nomefile=NOMEFILE_PUBLIC_KEY):
53
- with open(nomefile, "rb") as fp:
54
- pem=fp.read()
55
- self.publicKey = serialization.load_pem_public_key(pem, backend=default_backend())
56
-
57
- def readPrivateKey(self,nomefile=NOMEFILE_PRIVATE_KEY):
58
- with open(nomefile, "rb") as fp:
59
- pem=fp.read()
60
- self.privateKey = serialization.load_pem_private_key(pem, password=None, backend=default_backend())
61
-
62
-
63
- def encrypt(self,messaggio):
64
- encryptedMsg = self.publicKey.encrypt(
65
- messaggio.encode(ModuloStringhe.CODIFICA_UTF8),
66
- self.__generatePadding()
67
- )
68
- return encryptedMsg
69
-
70
- def decrypt(self,encryptedMsg):
71
- originalMessage = self.privateKey.decrypt(
72
- encryptedMsg,
73
- self.__generatePadding()
74
- ).decode(ModuloStringhe.CODIFICA_UTF8)
75
- return originalMessage
76
-
77
- def __generatePadding(self):
78
- hashType=self.DEFAULT_HASH_TYPE
79
- paddingObj=padding.OAEP(
80
- mgf=padding.MGF1(algorithm=hashType),
81
- algorithm=hashType,
82
- label=None
83
- )
84
- return paddingObj
1
+ from cryptography.hazmat.backends import default_backend
2
+ from cryptography.hazmat.primitives import hashes
3
+ from cryptography.hazmat.primitives import serialization
4
+ from cryptography.hazmat.primitives.asymmetric import padding
5
+ from cryptography.hazmat.primitives.asymmetric import rsa
6
+ from cryptography.hazmat.primitives.asymmetric.rsa import RSAPrivateKey
7
+ from cryptography.hazmat.primitives.asymmetric.rsa import RSAPublicKey
8
+
9
+ from modulitiz_micro.ModuloStringhe import ModuloStringhe
10
+
11
+
12
+ class ModuloRsa(object):
13
+ DEFAULT_HASH_TYPE=hashes.SHA256()
14
+ KEY_SIZE=4096
15
+
16
+ NOMEFILE_PUBLIC_KEY="public.key"
17
+ NOMEFILE_PRIVATE_KEY="private.key"
18
+
19
+ def __init__(self):
20
+ self.publicKey:RSAPublicKey|None=None
21
+ self.privateKey:RSAPrivateKey|None=None
22
+
23
+ def generateKeys(self):
24
+ self.privateKey = rsa.generate_private_key(
25
+ public_exponent=65537, key_size=self.KEY_SIZE, backend=default_backend()
26
+ )
27
+ self.publicKey = self.privateKey.public_key()
28
+
29
+ #
30
+ # save
31
+ #
32
+ def savePublicKey(self,nomefile=NOMEFILE_PUBLIC_KEY):
33
+ pem = self.publicKey.public_bytes(
34
+ encoding=serialization.Encoding.PEM,
35
+ format=serialization.PublicFormat.SubjectPublicKeyInfo
36
+ )
37
+ with open(nomefile, 'wb') as fp:
38
+ fp.write(pem)
39
+
40
+ def savePrivateKey(self, nomefile=NOMEFILE_PRIVATE_KEY):
41
+ pem = self.privateKey.private_bytes(
42
+ encoding=serialization.Encoding.PEM,
43
+ format=serialization.PrivateFormat.TraditionalOpenSSL,
44
+ encryption_algorithm=serialization.NoEncryption()
45
+ )
46
+ with open(nomefile, 'wb') as fp:
47
+ fp.write(pem)
48
+
49
+ #
50
+ # read
51
+ #
52
+ def readPublicKey(self,nomefile=NOMEFILE_PUBLIC_KEY):
53
+ with open(nomefile, "rb") as fp:
54
+ pem=fp.read()
55
+ self.publicKey = serialization.load_pem_public_key(pem, backend=default_backend())
56
+
57
+ def readPrivateKey(self,nomefile=NOMEFILE_PRIVATE_KEY):
58
+ with open(nomefile, "rb") as fp:
59
+ pem=fp.read()
60
+ self.privateKey = serialization.load_pem_private_key(pem, password=None, backend=default_backend())
61
+
62
+
63
+ def encrypt(self,messaggio):
64
+ encryptedMsg = self.publicKey.encrypt(
65
+ messaggio.encode(ModuloStringhe.CODIFICA_UTF8),
66
+ self.__generatePadding()
67
+ )
68
+ return encryptedMsg
69
+
70
+ def decrypt(self,encryptedMsg):
71
+ originalMessage = self.privateKey.decrypt(
72
+ encryptedMsg,
73
+ self.__generatePadding()
74
+ ).decode(ModuloStringhe.CODIFICA_UTF8)
75
+ return originalMessage
76
+
77
+ def __generatePadding(self):
78
+ hashType=self.DEFAULT_HASH_TYPE
79
+ paddingObj=padding.OAEP(
80
+ mgf=padding.MGF1(algorithm=hashType),
81
+ algorithm=hashType,
82
+ label=None
83
+ )
84
+ return paddingObj
@@ -1,20 +1,20 @@
1
- """
2
- python manage.py collectstatic
3
- python manage.py runserver 0.0.0.0:80
4
- """
5
-
6
- from modulitiz_micro.ModuloStringhe import ModuloStringhe
7
-
8
-
9
- class ModuloDjango(object):
10
- @staticmethod
11
- def isLocalhost(request)->bool:
12
- return ModuloStringhe.contains(request.path, 'localhost') or ModuloStringhe.contains(request.path, '127.0.0.1')
13
-
14
- @classmethod
15
- def init_modelmap(cls,request,pageTitle:str)->dict:
16
- modelMap = {
17
- 'page_title': pageTitle,
18
- 'is_localhost': cls.isLocalhost(request)
19
- }
20
- return modelMap
1
+ """
2
+ python manage.py collectstatic
3
+ python manage.py runserver 0.0.0.0:80
4
+ """
5
+
6
+ from modulitiz_micro.ModuloStringhe import ModuloStringhe
7
+
8
+
9
+ class ModuloDjango(object):
10
+ @staticmethod
11
+ def isLocalhost(request)->bool:
12
+ return ModuloStringhe.contains(request.path, 'localhost') or ModuloStringhe.contains(request.path, '127.0.0.1')
13
+
14
+ @classmethod
15
+ def init_modelmap(cls,request,pageTitle:str)->dict:
16
+ modelMap = {
17
+ 'page_title': pageTitle,
18
+ 'is_localhost': cls.isLocalhost(request)
19
+ }
20
+ return modelMap
@@ -1,10 +1,10 @@
1
- class MyMiddleware(object):
2
-
3
- def __init__(self, getResponse):
4
- self.getResponse = getResponse
5
-
6
- def __call__(self, request):
7
- response = self.getResponse(request)
8
- # allow iframe tag to be loaded
9
- response['X-Frame-Options'] = 'SAMEORIGIN'
10
- return response
1
+ class MyMiddleware(object):
2
+
3
+ def __init__(self, getResponse):
4
+ self.getResponse = getResponse
5
+
6
+ def __call__(self, request):
7
+ response = self.getResponse(request)
8
+ # allow iframe tag to be loaded
9
+ response['X-Frame-Options'] = 'SAMEORIGIN'
10
+ return response
@@ -1,132 +1,132 @@
1
- """
2
- Django settings.
3
-
4
- Generated by 'django-admin startproject' using Django 3.0.8.
5
-
6
- For more information on this file, see
7
- https://docs.djangoproject.com/en/3.0/topics/settings/
8
-
9
- For the full list of settings and their values, see
10
- https://docs.djangoproject.com/en/3.0/ref/settings/
11
- """
12
-
13
- import os
14
-
15
- from modulitiz_micro.rete.ModuloNetworking import ModuloNetworking
16
-
17
- # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
18
- BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
19
-
20
-
21
- # Quick-start development settings - unsuitable for production
22
- # See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/
23
-
24
- ALLOWED_HOSTS = ['localhost', '127.0.0.1', ModuloNetworking.getLocalIp()]
25
-
26
-
27
- # Application definition
28
-
29
- INSTALLED_APPS = [
30
- 'django.contrib.admin',
31
- 'django.contrib.auth',
32
- 'django.contrib.contenttypes',
33
- 'django.contrib.sessions',
34
- 'django.contrib.messages',
35
- 'django.contrib.staticfiles',
36
- ]
37
-
38
- MIDDLEWARE = [
39
- 'django.middleware.security.SecurityMiddleware',
40
- 'django.contrib.sessions.middleware.SessionMiddleware',
41
- 'django.middleware.common.CommonMiddleware',
42
- 'django.middleware.csrf.CsrfViewMiddleware',
43
- 'django.contrib.auth.middleware.AuthenticationMiddleware',
44
- 'django.contrib.messages.middleware.MessageMiddleware',
45
- 'django.middleware.clickjacking.XFrameOptionsMiddleware',
46
- # custom
47
- 'modulitiz_mini.django.MyMiddleware.MyMiddleware'
48
- ]
49
-
50
- ROOT_URLCONF = 'testwebsite.urls'
51
-
52
- TEMPLATE_DIRS = [
53
- os.path.join(BASE_DIR,'progetto1','templates')
54
- ]
55
-
56
- TEMPLATES = [
57
- {
58
- 'BACKEND': 'django.template.backends.django.DjangoTemplates',
59
- 'DIRS': TEMPLATE_DIRS,
60
- 'APP_DIRS': True,
61
- 'OPTIONS': {
62
- 'context_processors': [
63
- 'django.template.context_processors.debug',
64
- 'django.template.context_processors.request',
65
- 'django.contrib.auth.context_processors.auth',
66
- 'django.contrib.messages.context_processors.messages',
67
- ],
68
- },
69
- },
70
- ]
71
-
72
- WSGI_APPLICATION = 'testwebsite.wsgi.application'
73
-
74
-
75
- # Database
76
- # https://docs.djangoproject.com/en/3.0/ref/settings/#databases
77
-
78
- DATABASES = {
79
- 'default': {
80
- 'ENGINE': 'django.db.backends.sqlite3',
81
- 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
82
- }
83
- }
84
-
85
-
86
- # Password validation
87
- # https://docs.djangoproject.com/en/3.0/ref/settings/#auth-password-validators
88
-
89
- AUTH_PASSWORD_VALIDATORS = [
90
- {
91
- 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
92
- },
93
- {
94
- 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
95
- },
96
- {
97
- 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
98
- },
99
- {
100
- 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
101
- },
102
- ]
103
-
104
-
105
- # Internationalization
106
- # https://docs.djangoproject.com/en/3.0/topics/i18n/
107
-
108
- LANGUAGE_CODE = 'en-us'
109
-
110
- TIME_ZONE = 'UTC'
111
-
112
- USE_I18N = True
113
-
114
- USE_L10N = True
115
-
116
- USE_TZ = True
117
-
118
-
119
- # Static files (CSS, JavaScript, Images)
120
- # https://docs.djangoproject.com/en/3.0/howto/static-files/
121
- STATIC_URL = '/static/'
122
- STATICFILES_DIRS = [
123
- os.path.normpath(os.path.join(BASE_DIR,'static'))
124
- ]
125
-
126
-
127
-
128
-
129
-
130
-
131
-
132
-
1
+ """
2
+ Django settings.
3
+
4
+ Generated by 'django-admin startproject' using Django 3.0.8.
5
+
6
+ For more information on this file, see
7
+ https://docs.djangoproject.com/en/3.0/topics/settings/
8
+
9
+ For the full list of settings and their values, see
10
+ https://docs.djangoproject.com/en/3.0/ref/settings/
11
+ """
12
+
13
+ import os
14
+
15
+ from modulitiz_micro.rete.ModuloNetworking import ModuloNetworking
16
+
17
+ # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
18
+ BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
19
+
20
+
21
+ # Quick-start development settings - unsuitable for production
22
+ # See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/
23
+
24
+ ALLOWED_HOSTS = ['localhost', '127.0.0.1', ModuloNetworking.getLocalIp()]
25
+
26
+
27
+ # Application definition
28
+
29
+ INSTALLED_APPS = [
30
+ 'django.contrib.admin',
31
+ 'django.contrib.auth',
32
+ 'django.contrib.contenttypes',
33
+ 'django.contrib.sessions',
34
+ 'django.contrib.messages',
35
+ 'django.contrib.staticfiles',
36
+ ]
37
+
38
+ MIDDLEWARE = [
39
+ 'django.middleware.security.SecurityMiddleware',
40
+ 'django.contrib.sessions.middleware.SessionMiddleware',
41
+ 'django.middleware.common.CommonMiddleware',
42
+ 'django.middleware.csrf.CsrfViewMiddleware',
43
+ 'django.contrib.auth.middleware.AuthenticationMiddleware',
44
+ 'django.contrib.messages.middleware.MessageMiddleware',
45
+ 'django.middleware.clickjacking.XFrameOptionsMiddleware',
46
+ # custom
47
+ 'modulitiz_mini.django.MyMiddleware.MyMiddleware'
48
+ ]
49
+
50
+ ROOT_URLCONF = 'testwebsite.urls'
51
+
52
+ TEMPLATE_DIRS = [
53
+ os.path.join(BASE_DIR,'progetto1','templates')
54
+ ]
55
+
56
+ TEMPLATES = [
57
+ {
58
+ 'BACKEND': 'django.template.backends.django.DjangoTemplates',
59
+ 'DIRS': TEMPLATE_DIRS,
60
+ 'APP_DIRS': True,
61
+ 'OPTIONS': {
62
+ 'context_processors': [
63
+ 'django.template.context_processors.debug',
64
+ 'django.template.context_processors.request',
65
+ 'django.contrib.auth.context_processors.auth',
66
+ 'django.contrib.messages.context_processors.messages',
67
+ ],
68
+ },
69
+ },
70
+ ]
71
+
72
+ WSGI_APPLICATION = 'testwebsite.wsgi.application'
73
+
74
+
75
+ # Database
76
+ # https://docs.djangoproject.com/en/3.0/ref/settings/#databases
77
+
78
+ DATABASES = {
79
+ 'default': {
80
+ 'ENGINE': 'django.db.backends.sqlite3',
81
+ 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
82
+ }
83
+ }
84
+
85
+
86
+ # Password validation
87
+ # https://docs.djangoproject.com/en/3.0/ref/settings/#auth-password-validators
88
+
89
+ AUTH_PASSWORD_VALIDATORS = [
90
+ {
91
+ 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
92
+ },
93
+ {
94
+ 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
95
+ },
96
+ {
97
+ 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
98
+ },
99
+ {
100
+ 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
101
+ },
102
+ ]
103
+
104
+
105
+ # Internationalization
106
+ # https://docs.djangoproject.com/en/3.0/topics/i18n/
107
+
108
+ LANGUAGE_CODE = 'en-us'
109
+
110
+ TIME_ZONE = 'UTC'
111
+
112
+ USE_I18N = True
113
+
114
+ USE_L10N = True
115
+
116
+ USE_TZ = True
117
+
118
+
119
+ # Static files (CSS, JavaScript, Images)
120
+ # https://docs.djangoproject.com/en/3.0/howto/static-files/
121
+ STATIC_URL = '/static/'
122
+ STATICFILES_DIRS = [
123
+ os.path.normpath(os.path.join(BASE_DIR,'static'))
124
+ ]
125
+
126
+
127
+
128
+
129
+
130
+
131
+
132
+
@@ -1,9 +1,9 @@
1
- from abc import ABC
2
-
3
- class AbstractPdf(ABC):
4
-
5
- def __init__(self):
6
- self.pdfObj=None
7
-
8
- def close(self):
9
- self.pdfObj.close()
1
+ from abc import ABC
2
+
3
+ class AbstractPdf(ABC):
4
+
5
+ def __init__(self):
6
+ self.pdfObj=None
7
+
8
+ def close(self):
9
+ self.pdfObj.close()
@@ -1,27 +1,27 @@
1
- import pypdf
2
-
3
- from modulitiz_micro.eccezioni.EccezioneRuntime import EccezioneRuntime
4
- from modulitiz_mini.files.pdf.AbstractPdf import AbstractPdf
5
-
6
-
7
- class ReadPdf(AbstractPdf):
8
-
9
- def __init__(self,filename:str):
10
- super().__init__()
11
- self.filename=filename
12
- self.pdfObj=pypdf.PdfReader(open(filename,"rb"))
13
-
14
- def getNumPages(self)->int:
15
- return len(self.pdfObj.pages)
16
-
17
- def getPage(self,pageNum:int):
18
- """
19
- Read a page from a pdf file.
20
- :param pageNum: pages start with 0 and including extremes.
21
- """
22
- pageNum-=1
23
- maxPages=self.getNumPages()
24
- # check if page exist
25
- if pageNum<0 or pageNum>=maxPages:
26
- raise EccezioneRuntime("Page number {0} not exists.".format(pageNum))
27
- return self.pdfObj.pages[pageNum]
1
+ import pypdf
2
+
3
+ from modulitiz_micro.eccezioni.EccezioneRuntime import EccezioneRuntime
4
+ from modulitiz_mini.files.pdf.AbstractPdf import AbstractPdf
5
+
6
+
7
+ class ReadPdf(AbstractPdf):
8
+
9
+ def __init__(self,filename:str):
10
+ super().__init__()
11
+ self.filename=filename
12
+ self.pdfObj=pypdf.PdfReader(open(filename,"rb"))
13
+
14
+ def getNumPages(self)->int:
15
+ return len(self.pdfObj.pages)
16
+
17
+ def getPage(self,pageNum:int):
18
+ """
19
+ Read a page from a pdf file.
20
+ :param pageNum: pages start with 0 and including extremes.
21
+ """
22
+ pageNum-=1
23
+ maxPages=self.getNumPages()
24
+ # check if page exist
25
+ if pageNum<0 or pageNum>=maxPages:
26
+ raise EccezioneRuntime("Page number {0} not exists.".format(pageNum))
27
+ return self.pdfObj.pages[pageNum]
@@ -1,14 +1,14 @@
1
- import pypdf
2
-
3
- from modulitiz_mini.files.pdf.AbstractPdf import AbstractPdf
4
-
5
-
6
- class WritePdf(AbstractPdf):
7
-
8
- def __init__(self):
9
- super().__init__()
10
- self.pdfObj=pypdf.PdfWriter()
11
-
12
- def write(self,filename:str):
13
- with open(filename,"wb") as outStream:
14
- self.pdfObj.write(outStream)
1
+ import pypdf
2
+
3
+ from modulitiz_mini.files.pdf.AbstractPdf import AbstractPdf
4
+
5
+
6
+ class WritePdf(AbstractPdf):
7
+
8
+ def __init__(self):
9
+ super().__init__()
10
+ self.pdfObj=pypdf.PdfWriter()
11
+
12
+ def write(self,filename:str):
13
+ with open(filename,"wb") as outStream:
14
+ self.pdfObj.write(outStream)