예제 #1
0
def parse_text_plain(*args, **kw):
    headers = args[0].context.get_headers()
    ctype = headers.get('content-type')
    if ctype:
        ctype, opts = grailutil.conv_mimetype(ctype)
        if opts.get('format'):
            how = string.lower(opts['format'])
            if how == "flowed":
                from . import FlowingText
                return apply(FlowingText.FlowingTextParser, args, kw)
    return apply(Reader.TextParser, args, kw)
예제 #2
0
        context.error_dialog(IOError, msg)
        return
    content_encoding, transfer_encoding = Reader.get_encodings(infp.info())
    try:
        ctype = infp.info()['content-type']
    except KeyError:
        ctype, encoding = context.app.guess_type(url)
        if not content_encoding:
            content_encoding = encoding
    if not ctype:
        MaybePrintDialog(context, url, title, infp)
        return
    if not Reader.support_encodings(content_encoding, transfer_encoding):
        # create an alert of some sort....
        return
    ctype, ctype_params = grailutil.conv_mimetype(ctype)
    mod = context.app.find_type_extension("printing.filetypes", ctype)
    if ctype != "application/postscript" and not mod.parse:
        context.error_dialog(
            "Unprintable document",
            "No printing support is available for the %s media type." % ctype)
        return
    RealPrintDialog(context, url, title, infp, ctype)


class MaybePrintDialog:

    UNKNOWN_TYPE_MESSAGE = \
"""No MIME type is known for this
document.  It will be printed as
plain text if you elect to continue."""