Mercurial > p > roundup > code
comparison roundup/roundupdb.py @ 5488:52cb53eedf77
reworked random number use
prefer secrets module from Python 3.6+, random.SystemRandom and finally plain random
| author | Christof Meerwald <cmeerw@cmeerw.org> |
|---|---|
| date | Sat, 04 Aug 2018 22:40:16 +0100 |
| parents | 3afda04c96a1 |
| children | 725266c03eab |
comparison
equal
deleted
inserted
replaced
| 5487:ce171c81d823 | 5488:52cb53eedf77 |
|---|---|
| 18 | 18 |
| 19 """Extending hyperdb with types specific to issue-tracking. | 19 """Extending hyperdb with types specific to issue-tracking. |
| 20 """ | 20 """ |
| 21 __docformat__ = 'restructuredtext' | 21 __docformat__ = 'restructuredtext' |
| 22 | 22 |
| 23 import re, os, smtplib, socket, time, random | 23 import re, os, smtplib, socket, time |
| 24 import base64, mimetypes | 24 import base64, mimetypes |
| 25 import os.path | 25 import os.path |
| 26 import logging | 26 import logging |
| 27 from email import encoders | 27 from email import encoders |
| 28 from email.parser import FeedParser | 28 from email.parser import FeedParser |
| 37 from roundup.hyperdb import iter_roles | 37 from roundup.hyperdb import iter_roles |
| 38 | 38 |
| 39 from roundup.mailer import Mailer, MessageSendError, encode_quopri, \ | 39 from roundup.mailer import Mailer, MessageSendError, encode_quopri, \ |
| 40 nice_sender_header | 40 nice_sender_header |
| 41 | 41 |
| 42 from roundup.anypy.strings import s2u | 42 from roundup.anypy.strings import b2s, s2u |
| 43 import roundup.anypy.random_ as random_ | |
| 43 | 44 |
| 44 try: | 45 try: |
| 45 import pyme, pyme.core | 46 import pyme, pyme.core |
| 46 # gpgme_check_version() must have been called once in a programm | 47 # gpgme_check_version() must have been called once in a programm |
| 47 # to initialise some subsystems of gpgme. | 48 # to initialise some subsystems of gpgme. |
| 419 | 420 |
| 420 # make up a messageid if there isn't one (web edit) | 421 # make up a messageid if there isn't one (web edit) |
| 421 if not messageid: | 422 if not messageid: |
| 422 # this is an old message that didn't get a messageid, so | 423 # this is an old message that didn't get a messageid, so |
| 423 # create one | 424 # create one |
| 424 messageid = "<%s.%s.%s%s@%s>"%(time.time(), random.random(), | 425 messageid = "<%s.%s.%s%s@%s>"%(time.time(), |
| 425 self.classname, issueid, | 426 b2s(base64.b32encode(random_.token_bytes(10))), |
| 426 self.db.config.MAIL_DOMAIN) | 427 self.classname, issueid, self.db.config['MAIL_DOMAIN']) |
| 427 if msgid is not None: | 428 if msgid is not None: |
| 428 messages.set(msgid, messageid=messageid) | 429 messages.set(msgid, messageid=messageid) |
| 429 | 430 |
| 430 # compose title | 431 # compose title |
| 431 cn = self.classname | 432 cn = self.classname |
