예제 #1
0
 def __init__(self, resturl, method, params, data=None):
     self.app = grailutil.get_grailapp()
     self.args = (resturl, method, params, data)
     self.state = WAIT
     self.h = None
     self.reader_callback = None
     self.app.sq.request_socket(self, self.open)
예제 #2
0
def convert_to_url(urn):
    prefs = grailutil.get_grailapp().prefs
    urn = str.lower(urn)
    m = _reference_rx.match(urn)
    if m:
        type, number = m.group(1, 2)
        vars = {"type": type, "number": int(number)}
        which = "document-template"
    else:
        m = _draft_rx.match(urn)
        if m:
            draft = m.group(1)
            draft, format = os.path.splitext(draft)
            if format and format[0] == ".":
                format = format[1:]
            format = format or "txt"
            which = "internet-draft-template"
            vars = {"draft": draft, "format": format}
        else:
            m = _meeting_rx.match(urn)
            if not m:
                raise ValueError("not a valid ietf URN")
            wgbofname = m.group(2)
            try:
                date = _number_to_date[int(m.group(1))]
            except KeyError:
                raise ValueError("unknown IETF meeting number: " + m.group(1))
            which = "meeting-template"
            vars = {"date": date, "wg": wgbofname}
    return prefs.Get(PREF_GROUP, which) % vars
def isPILAllowed():
    """Return true iff PIL should be used by the caller."""
    global _pil_allowed
    if _pil_allowed is None:
        app = grailutil.get_grailapp()
        _pil_allowed = (app.prefs.GetBoolean("browser", "enable-pil")
                        and pil_installed())
    return _pil_allowed
 def checkapi(self, *args):
     if not self.callback:
         print("*** checkapi -- too late ***")
         if self.fno >= 0:
             fno = self.fno
             self.fno = -1
             tkinter.deletefilehandler(fno)
         return
     try:
         self.callback()  # Call via function pointer
     except:
         if self.context and self.context.app:
             app = self.context.app
         else:
             app = grailutil.get_grailapp()
         app.exception_dialog("in BaseReader")
         self.kill()
예제 #5
0
    def __init__(self,
                 master,
                 app=None,
                 width=None,
                 height=None,
                 geometry=None):
        self.master = master
        if not app:
            app = grailutil.get_grailapp()
        prefs = app.prefs
        self.app = app

        if not width: width = prefs.GetInt('browser', 'default-width')
        if not height: height = prefs.GetInt('browser', 'default-height')

        self.create_widgets(width=width, height=height, geometry=geometry)
        self.root.iconname('Grail')
        app.add_browser(self)
예제 #6
0
 def handle_meta(self, errcode, errmsg, headers):
     if not self.handle_meta_prelim(errcode, errmsg, headers):
         return
     # now save:
     self.stop()
     try:
         self.save_file = open(self.__filename, "wb")
     except IOError as msg:
         self.context.error_dialog(IOError, msg)
         return
     #
     # add to history without destroying any title already known:
     #
     history = grailutil.get_grailapp().global_history
     title, when = history.lookup_url(self.url)
     history.remember_url(self.url, title or '')
     #
     Reader.TransferDisplay(self.last_context, self.__filename, self)
예제 #7
0
 def getreply(self, file):
     self.file = file
     line = self.file.readline()
     if self.debuglevel > 0: print('reply:', repr(line))
     if replyprog.match(line) < 0:
         # Not an HTTP/1.0 response.  Fall back to HTTP/0.9.
         # Push the data back into the file.
         self.file.seek(-len(line), 1)
         self.headers = {}
         app = grailutil.get_grailapp()
         c_type, c_encoding = app.guess_type(self.selector)
         if c_encoding:
             self.headers['content-encoding'] = c_encoding
         # HTTP/0.9 sends HTML by default
         self.headers['content-type'] = c_type or "text/html"
         return 200, "OK", self.headers
     errcode, errmsg = replyprog.group(1, 2)
     errcode = int(errcode)
     errmsg = str.strip(errmsg)
     self.headers = email.Message(self.file, 0)
     return errcode, errmsg, self.headers
예제 #8
0
 def __init__(self, url, method, params):
     from urllib import url2pathname, pathname2url
     self.url = url
     self.redirect = None
     pathname = url2pathname(url)
     if not os.path.isabs(pathname):
         try:
             pwd = os.getcwd()
         except os.error:
             pass
         else:
             pathname = os.path.expanduser(pathname)
             pathname = os.path.join(pwd, pathname)
             pathname = os.path.normpath(pathname)
             self.redirect = 1
     self.pathname = pathname
     self.url = "file:" + pathname2url(pathname)
     self.method = method
     self.params = params
     self.headers = {}
     try:
         stats = os.stat(self.pathname)
     except (IOError, os.error, AttributeError):
         pass
     else:
         self.headers['content-length'] = str(stats[ST_SIZE])
         self.headers['last-modified'] = ht_time.unparse(stats[ST_MTIME])
     if os.path.isdir(self.pathname):
         self.format_directory()
     else:
         self.fp = open(self.pathname, 'rb')  # May raise IOError!
         app = grailutil.get_grailapp()
         ctype, cencoding = app.guess_type(self.pathname)
         if ctype: self.headers['content-type'] = ctype
         if cencoding: self.headers['content-encoding'] = cencoding
     self.state = META
 def __init__(self, url, method, params, data=None):
     null_access.__init__(self, url, method, params)
     # when a form's action is a mail URL, the data field will be
     # non-None.  In that case, initialize the dialog with the data
     # contents
     toplevel = MailDialog(grailutil.get_grailapp().root, url, data)
예제 #10
0
"""

import re
import regsub

import ftplib
from urllib import unquote, splithost, splitport, splituser, \
     splitpasswd, splitattr, splitvalue, quote
from urllib import urljoin
import email
from utils.Assert import Assert
from utils import grailutil
import socket

app = grailutil.get_grailapp()  # app.guess_type(url)

# Stages
META = 'META'
DATA = 'DATA'
EOF = 'EOF'
DONE = 'DONE'

LISTING_HEADER = """<HTML>
<HEAD><TITLE>FTP Directory: %(url)s</TITLE></HEAD>
<BODY>
<H1>FTP Directory: %(url)s</H1>
<PRE>"""

LISTING_TRAILER = """</PRE>
</BODY>