示例#1
0
文件: session.py 项目: dnessorga/LDP
def login(req, username, password):

    user = dms.username.get_by_id(username)
    if user and user.username==username:
        if user.password == password:
            if not sessions.has_key(username):
                sessions.add(username, req.connection.remote_addr[0])
    
            # establish random 20 character session_id.
            # 
            chars = string.letters + string.digits
            session_id = ''
            for x in range(20):
                session_id += whrandom.choice(chars)
            user.session_id = session_id
            user.save()
                    
            log(3, 'setting cookie')
            req.headers_out['Set-Cookie']='lampadas=' + session_id + '; path=/; expires=Wed, 09-Nov-2030 23:59:00 GMT'
            uri = URI('home' + referer_lang_ext(req))
            uri.base = '../../'
            return page_factory.page(uri)
        else:
            return "Wrong password"
    else:
        return "User not found"
示例#2
0
文件: session.py 项目: dnessorga/LDP
def logout(req, username):
    sessions.delete(username)

    user = dms.username.get_by_id(username)
    user.session_id = ''
    user.save()

    log(3, 'clearing cookie')
    req.headers_out['Set-Cookie']='lampadas=foo; path=/; expires=Wed, 09-Nov-1980 23:59:00 GMT'
    uri = URI('home' + referer_lang_ext(req))
    uri.base = '../../'
    return page_factory.page(uri)
示例#3
0
文件: HTML.py 项目: dnessorga/LDP
def main():
    import profile
    import pstats

    if len(sys.argv[1:]):
        profile_it = 0
        reps_flag = 0
        profile_reps = 100
        for arg in sys.argv[1:]:
            if reps_flag:
                profile_reps = int(arg)
                reps_flag = 0
            elif arg == '-p' or arg == '--profile':
                profile_it = 1
            elif arg == '-r' or arg == '--reps':
                reps_flag = 1
            elif profile_it > 0:
                print 'Profiling, ' + str(profile_reps) + ' repetitions...'
                page = page_factory.page(arg)
                profile.run(
                    'benchmark("' + arg + '", ' + str(profile_reps) + ')',
                    'profile_stats')
                p = pstats.Stats('profile_stats')
                p.sort_stats('time').print_stats()
            else:
                print page_factory.page(URI(arg))
    else:
        profile()
示例#4
0
文件: globals.py 项目: dnessorga/LDP
def referer_lang_ext(req):
    try:
        url = req.headers_in['referer']
    except KeyError:
        url = ''
    uri = URI(url)
    return uri.lang_ext
示例#5
0
def handler(req):

    log(3, 'handling request: ' + req.uri)
    uri = URI(req.uri)

    filename = config.file_dir + uri.path + '/' + uri.filename
    filename = filename.replace('//', '/')
    filename = filename.replace('//', '/')
    filename = filename.replace('//', '/')
    log(3, 'looking for file ' + filename)

    if os.path.isfile(filename):
        send_File(req, filename)
    else:
        log(3, 'Sending dynamic page: ' + req.uri)
        session = sessions.get_session(req)
        send_HTML(req, page_factory.page(uri))
    return apache.OK
示例#6
0
文件: UnitTest.py 项目: dnessorga/LDP
 def check_uri(self, url, result):
     uri = URI(url)
     u = (uri.protocol, uri.server, uri.port, uri.path, uri.lang_ext,
          uri.id, uri.code, uri.page_code, uri.parameter, uri.anchor)
     self.assertEqual((url, u), (url, result))
示例#7
0
文件: HTML.py 项目: dnessorga/LDP
 def page_exists(self, key):
     uri = URI(key)
     if uri.path == '' and dms.page.get_by_id(uri.code):
         return 1
     return
示例#8
0
def document(req,
             title='',
             short_title='',
             pub_status_code='',
             type_code='',
             topic_code='',
             username='',
             maintained='',
             maintainer_wanted='',
             lang='',
             review_status_code='',
             tech_review_status_code='',
             pub_date='',
             last_update='',
             tickle_date='',
             isbn='',
             encoding='',
             rating='',
             format_code='',
             dtd_code='',
             license_code='',
             copyright_holder='',
             sk_seriesid='',
             abstract='',
             short_desc='',
             collection_code='',
             columns={},
             layout='compact'):
    """
    Returns the results of a document search.
    """

    # Read session state
    sessions.get_session(req)

    uri = URI(req.uri)
    page = dms.page.get_by_id('doctable')

    # serve search results by manually replacing the
    # doctable here instead of during the regular call.
    # It's a bit ugly, but works.

    # We store and restore the contents to avoid doing
    # a copy.deepcopy() which I haven't tested but imagine to
    # be rather expensive. -- DCM
    save_page = page.page[uri.lang]
    table = tables.doctable(uri,
                            title=title,
                            short_title=short_title,
                            pub_status_code=pub_status_code,
                            type_code=type_code,
                            topic_code=topic_code,
                            username=username,
                            maintained=maintained,
                            maintainer_wanted=maintainer_wanted,
                            lang=lang,
                            review_status_code=review_status_code,
                            tech_review_status_code=tech_review_status_code,
                            pub_date=pub_date,
                            last_update=last_update,
                            tickle_date=tickle_date,
                            isbn=isbn,
                            encoding=encoding,
                            rating=rating,
                            format_code=format_code,
                            dtd_code=dtd_code,
                            license_code=license_code,
                            copyright_holder=copyright_holder,
                            sk_seriesid=sk_seriesid,
                            abstract=abstract,
                            short_desc=short_desc,
                            collection_code=collection_code,
                            layout=layout,
                            show_search=1)

    page.page[uri.lang] = page.page[uri.lang].replace('|tabdocs|', table)
    uri = URI('doctable' + referer_lang_ext(req))
    uri.base = '../../'
    html = page_factory.build_page(page, uri)

    # Restore the original page
    page.page[uri.lang] = save_page
    return html
示例#9
0
文件: search.py 项目: Fat-Zer/LDP
def document(req,
             title='',
             short_title='',
             pub_status_code='',
             type_code='',
             topic_code='',
             username='',
             maintained='',
             maintainer_wanted='',
             lang='',
             review_status_code='',
             tech_review_status_code='',
             pub_date='',
             last_update='',
             tickle_date='',
             isbn='',
             encoding='',
             rating='',
             format_code='',
             dtd_code='',
             license_code='',
             copyright_holder='',
             sk_seriesid='',
             abstract='',
             short_desc='',
             collection_code='',
             columns={},
             layout='compact'
             ):
    """
    Returns the results of a document search.
    """

    # Read session state
    sessions.get_session(req)

    uri = URI(req.uri)
    page = dms.page.get_by_id('doctable')

    # serve search results by manually replacing the
    # doctable here instead of during the regular call.
    # It's a bit ugly, but works.

    # We store and restore the contents to avoid doing
    # a copy.deepcopy() which I haven't tested but imagine to
    # be rather expensive. -- DCM
    save_page = page.page[uri.lang]
    table = tables.doctable(uri, 
                            title                   = title,
                            short_title             = short_title,
                            pub_status_code         = pub_status_code,
                            type_code               = type_code,
                            topic_code              = topic_code,
                            username                = username,
                            maintained              = maintained,
                            maintainer_wanted       = maintainer_wanted,
                            lang                    = lang,
                            review_status_code      = review_status_code,
                            tech_review_status_code = tech_review_status_code,
                            pub_date                = pub_date,
                            last_update             = last_update,
                            tickle_date             = tickle_date,
                            isbn                    = isbn,
                            encoding                = encoding,
                            rating                  = rating,
                            format_code             = format_code,
                            dtd_code                = dtd_code,
                            license_code            = license_code,
                            copyright_holder        = copyright_holder,
                            sk_seriesid             = sk_seriesid,
                            abstract                = abstract,
                            short_desc              = short_desc,
                            collection_code         = collection_code,
                            layout                  = layout,
                            show_search             = 1)

    page.page[uri.lang] = page.page[uri.lang].replace('|tabdocs|', table)
    uri = URI('doctable' + referer_lang_ext(req))
    uri.base = '../../'
    html = page_factory.build_page(page, uri)
    
    # Restore the original page
    page.page[uri.lang] = save_page
    return html