File: mark_safe_secure.py

package info (click to toggle)
bandit 1.7.10-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,864 kB
  • sloc: python: 19,727; makefile: 23; sh: 14
file content (75 lines) | stat: -rw-r--r-- 2,184 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import os
from django.utils import safestring

safestring.mark_safe('<b>secure</b>')
safestring.SafeText('<b>secure</b>')
safestring.SafeUnicode('<b>secure</b>')
safestring.SafeString('<b>secure</b>')
safestring.SafeBytes('<b>secure</b>')

my_secure_str = '<b>Hello World</b>'
safestring.mark_safe(my_secure_str)

my_secure_str, _ = ('<b>Hello World</b>', '')
safestring.mark_safe(my_secure_str)

also_secure_str = my_secure_str
safestring.mark_safe(also_secure_str)


def try_secure():
    try:
        my_secure_str = 'Secure'
    except Exception:
        my_secure_str = 'Secure'
    else:
        my_secure_str = 'Secure'
    finally:
        my_secure_str = 'Secure'
    safestring.mark_safe(my_secure_str)


def format_secure():
    safestring.mark_safe('<b>{}</b>'.format('secure'))
    my_secure_str = 'secure'
    safestring.mark_safe('<b>{}</b>'.format(my_secure_str))
    safestring.mark_safe('<b>{} {}</b>'.format(my_secure_str, 'a'))
    safestring.mark_safe('<b>{} {}</b>'.format(*[my_secure_str, 'a']))
    safestring.mark_safe('<b>{b}</b>'.format(b=my_secure_str))  # nosec TODO
    safestring.mark_safe('<b>{b}</b>'.format(**{'b': my_secure_str}))  # nosec TODO
    my_secure_str = '<b>{}</b>'.format(my_secure_str)
    safestring.mark_safe(my_secure_str)


def percent_secure():
    safestring.mark_safe('<b>%s</b>' % 'secure')
    my_secure_str = 'secure'
    safestring.mark_safe('<b>%s</b>' % my_secure_str)
    safestring.mark_safe('<b>%s %s</b>' % (my_secure_str, 'a'))
    safestring.mark_safe('<b>%(b)s</b>' % {'b': my_secure_str})  # nosec TODO


def with_secure(path):
    with open(path) as f:
        safestring.mark_safe('Secure')


def loop_secure():
    my_secure_str = ''

    for i in range(ord(os.urandom(1))):
        my_secure_str += ' Secure'
    safestring.mark_safe(my_secure_str)
    while ord(os.urandom(1)) % 2 == 0:
        my_secure_str += ' Secure'
    safestring.mark_safe(my_secure_str)


def all_secure_case():
    if ord(os.urandom(1)) % 2 == 0:
        my_secure_str = 'Secure'
    elif ord(os.urandom(1)) % 2 == 0:
        my_secure_str = 'Secure'
    else:
        my_secure_str = 'Secure'
    safestring.mark_safe(my_secure_str)