Beispiel #1
0
def View(env, resp):
    '''View is the 'main page' of the forum.

    It displays the submission form and the previously posted messages.
    '''
    print('View Function Called')
    bleach.clean('<script>')
    bleach.clean('</script>')
    bleach.clean('<script></script>')
    # get posts from database
    posts = forumdb.GetAllPosts()

    bleach.clean(u'<script>')
    bleach.clean(u'</script>')
    bleach.clean(u'<script></script>')
    bleach.clean(posts)
    u'an &lt;script&gt;evil()&lt;/script&gt; example'
    bleach.clean(u'<script>')
    bleach.clean(u'</script>')
    bleach.clean(u'<script></script>')
    print('bl-3')
    # send results
    headers = [('Content-type', 'text/html')]
    resp('200 OK', headers)
    return [HTML_WRAP % ''.join(POST % p for p in posts)]
Beispiel #2
0
def View(env, resp):
    '''View is the 'main page' of the forum.
    It displays the submission form and the previously posted messages.
    '''
    # get posts from database
    posts = forumdb.GetAllPosts()
    # send results
    headers = [('Content-type', 'text/html')]
    resp('200 OK', headers)
    return [HTML_WRAP % ''.join(POST % p for p in posts)]
def View(env, resp):
    '''View is the 'main page' of the forum.

    It displays the submission form and the previously posted messages.
    '''
    # get posts from database
    posts = forumdb.GetAllPosts()

    # sanitize output
    postsBleached = [{
        'content': str(bleach.clean(post['content'])),
        'time': str(post['time'])
    } for post in posts]

    # send results
    headers = [('Content-type', 'text/html')]
    resp('200 OK', headers)
    return [HTML_WRAP % ''.join(POST % p for p in postsBleached)]
Beispiel #4
0
def View(env, resp):
    '''View is the 'main page' of the forum.

    It displays the submission form and the previously posted messages.
    '''
    # get posts from database
    posts = forumdb.GetAllPosts()
    d = {}
    for each in posts:
        child_idx = each['post_id']
        parent_idx = each['reply_id']
        if parent_idx in d:
            d[parent_idx].append(child_idx)
        else:
            d[parent_idx] = [child_idx]
    posts = {each['post_id']: each for each in posts}

    def robot(curr_idx, d, posts):
        if curr_idx not in d:
            ans = POST_0 % posts[curr_idx] + POST_1 % posts[curr_idx]
            return ans
        temp = POST_0 % posts[curr_idx]
        for nxt_idx in d[curr_idx]:
            temp += robot(nxt_idx, d, posts)

        temp += POST_1 % posts[curr_idx]
        return temp

    ans = ''
    if len(d) != 0 and len(d[0]) != 0:
        for i in d[0]:
            ans += robot(i, d, posts)
    # send results
    headers = [('Content-type', 'text/html')]
    resp('200 OK', headers)
    return [HTML_WRAP % (ans, )]