当前位置: 首页>>代码示例>>Python>>正文


Python AttachFile._access_file方法代码示例

本文整理汇总了Python中MoinMoin.action.AttachFile._access_file方法的典型用法代码示例。如果您正苦于以下问题:Python AttachFile._access_file方法的具体用法?Python AttachFile._access_file怎么用?Python AttachFile._access_file使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MoinMoin.action.AttachFile的用法示例。


在下文中一共展示了AttachFile._access_file方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: raw_file

# 需要导入模块: from MoinMoin.action import AttachFile [as 别名]
# 或者: from MoinMoin.action.AttachFile import _access_file [as 别名]
def raw_file(pagename, request):
    import shutil

    filename, fpath = AttachFile._access_file(pagename, request)
    if not filename: return # error msg already sent in _access_file

    # get mimetype
    type, enc = mimetypes.guess_type(filename)
    if not type:
        type = "application/octet-stream"

    # send header
    request.http_headers([
        "Content-Type: %s" % type,
        "Content-Length: %d" % os.path.getsize(fpath),
        # TODO: fix the encoding here, plain 8 bit is not allowed according to the RFCs
        # There is no solution that is compatible to IE except stripping non-ascii chars
    ])

    # send data
    shutil.copyfileobj(open(fpath, 'rb'), request, 8192)

    raise MoinMoinNoFooter
开发者ID:130s,项目名称:roswiki,代码行数:25,代码来源:RawFile.py

示例2: execute

# 需要导入模块: from MoinMoin.action import AttachFile [as 别名]
# 或者: from MoinMoin.action.AttachFile import _access_file [as 别名]
def execute(pagename, request):
    _ = request.getText
    if not request.user or not request.user.isSuperUser():
        msg = _('Only superuser is allowed to use this action.')
        request.theme.add_msg(msg, "error")
        request.page.send_page()
        return ''
    fmt = request.html_formatter
    language_setup_page = 'LanguageSetup'
    not_translated_system_pages = 'not_translated_system_pages.zip'
    files = AttachFile._get_files(request, language_setup_page)
    if not files:
        msg = _('No page packages found.')
        request.theme.add_msg(msg, "error")
        request.page.send_page()
        return ''
    wiki_languages = list(set([lang_file.split('--')[0] for lang_file in files]) - set(['00_needs_fixing.zip']))
    wiki_languages.sort()

    lang = request.values.get('language') or 'English'
    target = request.values.get('target') or ''
    msg = ''
    # if target is given it tries to install the package.
    if target:
        dummy_pagename, dummy_target, targetpath = AttachFile._access_file(language_setup_page, request)
        package = packages.ZipPackage(request, targetpath)
        if package.isPackage():
            if package.installPackage():
                msg = _("Attachment '%(filename)s' installed.") % {'filename': target}
            else:
                msg = _("Installation of '%(filename)s' failed.") % {'filename': target}
        else:
            msg = _('The file %s is not a MoinMoin package file.') % target


    data = TupleDataset()
    data.columns = [
           Column('page package', label=_('page package')),
           Column('action', label=_('install')),
        ]

    label_install = _("install")
    for pageset_name in i18n.strings.pagesets:
        attachment = "%s--%s.zip" % (lang, pageset_name)
        # not_translated_system_pages are in english
        if attachment.endswith(not_translated_system_pages):
            attachment = 'English_not_translated_system_pages.zip'
        install_link = ''
        querystr = {'action': 'language_setup', 'target': attachment, 'language': lang}
        if AttachFile.exists(request, language_setup_page, attachment):
            install_link = request.page.link_to(request, label_install, querystr=querystr)
        data.addRow((pageset_name, install_link))

    table = DataBrowserWidget(request)
    table.setData(data)
    page_table = ''.join(table.format(method='GET'))

    fmt = request.formatter
    lang_links = [request.page.link_to_raw(request, _lang,
                                        querystr={'action': 'language_setup',
                                                  'language': _lang,
                                                  'pageset': pageset_name, })
                  for _lang in wiki_languages]

    lang_selector = u''.join([fmt.paragraph(1), _("Choose:"), ' ', ' '.join(lang_links), fmt.paragraph(0)])

    title = _("Install language packs for '%s'") % wikiutil.escape(lang)
    request.theme.add_msg(msg, "info")
    request.theme.send_title(title, page=request.page, pagename=pagename)
    request.write(request.formatter.startContent("content"))
    request.write(lang_selector)
    request.write(page_table)
    request.write(request.formatter.endContent())
    request.theme.send_footer(pagename)
    request.theme.send_closing_html()
开发者ID:IvanLogvinov,项目名称:soar,代码行数:77,代码来源:language_setup.py

示例3: _do_diff

# 需要导入模块: from MoinMoin.action import AttachFile [as 别名]
# 或者: from MoinMoin.action.AttachFile import _access_file [as 别名]
def _do_diff(pagename, request):
    # return attachment list
    _ = request.getText

    form = values_to_form(request.values)

    att1 = form.get('att1', [''])[0]
    att2 = form.get('att2', [''])[0]
    sort = form.get('sort', ['normal'])[0]

    if (not (att1 and att2) or not 
        (AttachFile.exists(request, pagename, att1) and 
         AttachFile.exists(request, pagename, att2))):
        AttachFile.error_msg(pagename, request, 
                             _('Could not diff, attachments not selected or nonexisting'))
        return

    form['target'] = [att1]
    request.values = CombinedMultiDict([MultiDict(form)])
    pagename, filename, fpath = AttachFile._access_file(pagename, request)

    att1data = open(fpath, 'r').read()

    form['target'] = [att2]
    request.values = CombinedMultiDict([MultiDict(form)])
    pagename, filename, fpath = AttachFile._access_file(pagename, request)
    att2data = open(fpath, 'r').read()

    if sort == 'sort':
        att1data = '\n'.join(sorted(att1data.split('\n')))
        att2data = '\n'.join(sorted(att2data.split('\n')))
    elif sort == 'uniq':
        att1data = '\n'.join(sorted(set(att1data.split('\n'))))
        att2data = '\n'.join(sorted(set(att2data.split('\n'))))
    elif sort == 'cnt':
        att1tmp = list()
        for line in sorted(set(att1data.split('\n'))):
            if not line:
                continue
            att1tmp.append("%s %s" % (att1data.count(line), line))
        att2tmp = list()
        for line in sorted(set(att2data.split('\n'))):
            if not line:
                continue
            att2tmp.append("%s %s" % (att2data.count(line), line))
        att1data = '\n'.join(att1tmp)
        att2data = '\n'.join(att2tmp)

    # Use user interface language for this generated page
    request.setContentLanguage(request.lang)
    request.theme.send_title(_('Diff of %s and %s') % (att1, att2), 
                             pagename=pagename)
    request.write('<div id="content">\n') # start content div

    if request.user.show_fancy_diff:
        from MoinMoin.util import diff_html
        request.write(request.formatter.rawHTML(diff_html.diff(request, 
                                                               att1data, 
                                                               att2data)))
    else:
        from MoinMoin.util import diff_text
        lines = diff_text.diff(att1data.split("\n"), att2data.split("\n"))

        request.write(request.formatter.preformatted(1))
        for line in lines:
                if line[0] == "@":
                    request.write(request.formatter.rule(1))
                request.write(request.formatter.text(line + '\n'))
        request.write(request.formatter.preformatted(0))

    AttachFile.send_uploadform(pagename, request)
    request.write('</div>\n') # end content div
    request.theme.send_footer(pagename)
    request.theme.send_closing_html()
开发者ID:graphingwiki,项目名称:graphingwiki,代码行数:76,代码来源:AttachFile.py


注:本文中的MoinMoin.action.AttachFile._access_file方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。