__copyright__ = "Copyright © Stichting SciPost (SciPost Foundation)"
__license__ = "AGPL v3"
import hashlib
import random
import string
[docs]def random_arxiv_identifier_with_version_number(version_nr='0'):
return random_arxiv_identifier_without_version_number() + 'v' + str(version_nr)
[docs]def random_arxiv_identifier_without_version_number():
return random_digits(4) + "." + random_digits(5)
[docs]def random_scipost_journal():
return random.choice((
'SciPostPhys',
'SciPostPhysLectNotes',
'SciPostPhysProc',
'SciPostMath',
'SciPostChem',
))
[docs]def random_external_journal_abbrev():
return random.choice((
'Ann. Phys.',
'Phys. Rev. A',
'Phys. Rev. B',
'Phys. Rev. C',
'Phys. Rev. Lett.',
'Europhys. Lett.',
'J. Math. Anal. Appl.',
'Nat. Phys.'
'J. Phys. A',
'J. Stat. Phys.',
'J. Stat. Mech.',
'J. Math. Phys.',
'Lett. Math. Phys.',
'Sov. Phys. JETP',
'Sov. Phys. JETP',
'Nucl. Phys. B',
'Adv. Phys.'
))
[docs]def random_pub_number():
return '%i.%i.%s' % (random.randint(1, 9), random.randint(1, 9), random_digits(3))
[docs]def random_scipost_doi():
return '10.21468/%s.%s' % (random_scipost_journal(), random_pub_number())
[docs]def random_scipost_report_doi_label():
return 'SciPost.Report.%s' % random_digits(4)
[docs]def random_external_doi():
"""
Return a fake/random doi as if all journal abbrev and pub_number are separated by `.`, which
can be helpfull for testing purposes.
"""
journal = random.choice((
'PhysRevA',
'PhysRevB',
'PhysRevC',
'PhysRevLett',
'nature'
'S0550-3213(01)',
'1742-5468',
'0550-3213(96)'
))
return '10.%s/%s.%s' % (random_digits(5), journal, random_pub_number())
[docs]def random_digits(n):
return "".join(random.choice(string.digits) for _ in range(n))
[docs]def generate_orcid():
return '{}-{}-{}-{}'.format(
random_digits(4),
random_digits(4),
random_digits(4),
random_digits(4),
)
[docs]def filter_keys(dictionary, keys_to_keep):
# Field is empty if not on model.
return {key: dictionary.get(key, "") for key in keys_to_keep}
[docs]def get_new_secrets_key(salt='', salt2=''):
key = salt or generate_orcid()
for i in range(5):
key += random.choice(string.ascii_letters)
key = key.encode('utf8')
return hashlib.sha1(key + salt2.encode('utf8')).hexdigest()