Browse Source

Adds type hints in user class methods

Adrien Panay 7 years ago
parent
commit
d16f97badf
1 changed files with 8 additions and 5 deletions
  1. 8 5
      tracim/tracim/model/auth.py

+ 8 - 5
tracim/tracim/model/auth.py View File

14
 from datetime import datetime
14
 from datetime import datetime
15
 from hashlib import md5
15
 from hashlib import md5
16
 from hashlib import sha256
16
 from hashlib import sha256
17
+from typing import TYPE_CHECKING
17
 
18
 
18
 from sqlalchemy import Column
19
 from sqlalchemy import Column
19
 from sqlalchemy import ForeignKey
20
 from sqlalchemy import ForeignKey
32
 from tracim.model import DBSession
33
 from tracim.model import DBSession
33
 from tracim.model import DeclarativeBase
34
 from tracim.model import DeclarativeBase
34
 from tracim.model import metadata
35
 from tracim.model import metadata
36
+if TYPE_CHECKING:
37
+    from tracim.model.data import Workspace
35
 
38
 
36
 __all__ = ['User', 'Group', 'Permission']
39
 __all__ = ['User', 'Group', 'Permission']
37
 
40
 
174
         return DBSession.query(cls).filter_by(email=username).first()
177
         return DBSession.query(cls).filter_by(email=username).first()
175
 
178
 
176
     @classmethod
179
     @classmethod
177
-    def _hash_password(cls, cleartext_password):
180
+    def _hash_password(cls, cleartext_password: str) -> str:
178
         salt = sha256()
181
         salt = sha256()
179
         salt.update(os.urandom(60))
182
         salt.update(os.urandom(60))
180
         salt = salt.hexdigest()
183
         salt = salt.hexdigest()
204
         self._password = self._hash_password(cleartext_password)
207
         self._password = self._hash_password(cleartext_password)
205
         self.update_webdav_digest_auth(cleartext_password)
208
         self.update_webdav_digest_auth(cleartext_password)
206
 
209
 
207
-    def _get_password(self):
210
+    def _get_password(self) -> str:
208
         """Return the hashed version of the password."""
211
         """Return the hashed version of the password."""
209
         return self._password
212
         return self._password
210
 
213
 
225
                                                descriptor=property(_get_hash_digest,
228
                                                descriptor=property(_get_hash_digest,
226
                                                                    _set_hash_digest))
229
                                                                    _set_hash_digest))
227
 
230
 
228
-    def update_webdav_digest_auth(self, cleartext_password) -> None:
231
+    def update_webdav_digest_auth(self, cleartext_password: str) -> None:
229
         self.webdav_left_digest_response_hash \
232
         self.webdav_left_digest_response_hash \
230
             = '{username}:/:{cleartext_password}'.format(
233
             = '{username}:/:{cleartext_password}'.format(
231
                 username=self.email,
234
                 username=self.email,
232
                 cleartext_password=cleartext_password,
235
                 cleartext_password=cleartext_password,
233
             )
236
             )
234
 
237
 
235
-    def validate_password(self, cleartext_password):
238
+    def validate_password(self, cleartext_password: str) -> bool:
236
         """
239
         """
237
         Check the password against existing credentials.
240
         Check the password against existing credentials.
238
 
241
 
253
                 self.update_webdav_digest_auth(cleartext_password)
256
                 self.update_webdav_digest_auth(cleartext_password)
254
         return result
257
         return result
255
 
258
 
256
-    def get_display_name(self, remove_email_part=False):
259
+    def get_display_name(self, remove_email_part: bool=False) -> str:
257
         """
260
         """
258
         Get a name to display from corresponding member or email.
261
         Get a name to display from corresponding member or email.
259
 
262