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): 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 get_str(self): if not self.str: self.str = ht_time.unparse(self.secs) return self.str
def __init__(self, master, context, class_="DocumentInfo"): root = tktools.make_toplevel(master, class_=class_, title="Document Info") self.root = root self.app = context.app page_title = context.page.title() if page_title: root.title("Document Info: " + page_title) destroy = self.destroy for seq in ("<Alt-W>", "<Alt-w>", "<Return>"): root.bind(destroy) root.protocol("WM_DELETE_WINDOW", destroy) frame, self.__topfr, botfr = tktools.make_double_frame(root) # # Info display # url = context.page.url() scheme, netloc, path, params, query, fragment = urlparse.urlparse(url) url = urlparse.urlunparse((scheme, netloc, path, '', '', '')) self.add_label_field("Title", page_title or "(unknown)", "title") self.add_label_field("URI", url, "uri") if fragment: self.add_label_field("Fragment", fragment, "fragment") headers = context.get_headers() if headers.has_key("date") and type(headers["date"]) is type(self): self.add_label_field("", "(Loaded from local cache.)", "cached") items = headers.items() items.sort() s = "" for k, v in items: if k == 'date' and type(v) is type(self): import ht_time v = ht_time.unparse(v.get_secs()) s = "%s%s:\t%s\n" % (s, k, v) stretch = self.add_text_field("Response headers", s, "headers") if query: query = string.translate(query, FIELD_BREAKER) stretch = stretch or \ self.add_text_field("Query fields", query, "query") postdata = context.get_postdata() if postdata: postdata = string.translate(postdata, FIELD_BREAKER) stretch = stretch or \ self.add_text_field("POST fields", postdata, "postdata") # # Bottom button # fr = Tkinter.Frame(botfr, borderwidth=1, relief=Tkinter.SUNKEN) fr.pack() btn = Tkinter.Button(fr, text="OK", command=destroy) # '2m' is the value from the standard Tk 'tk_dialog' command btn.pack(padx='2m', pady='2m') btn.focus_set() # del self.__topfr # loose the reference tktools.set_transient(root, master) root.update_idletasks() reqwidth = root.winfo_reqwidth() reqheight = root.winfo_reqheight() root.minsize(reqwidth, reqheight) if not stretch: root.maxsize(reqwidth, reqheight)
def __init__(self, master, context, class_="DocumentInfo"): root = tktools.make_toplevel(master, class_=class_, title="Document Info") self.root = root self.app = context.app page_title = context.page.title() if page_title: root.title("Document Info: " + page_title) destroy = self.destroy for seq in ("<Alt-W>", "<Alt-w>", "<Return>"): root.bind(destroy) root.protocol("WM_DELETE_WINDOW", destroy) frame, self.__topfr, botfr = tktools.make_double_frame(root) # # Info display # url = context.page.url() scheme, netloc, path, params, query, fragment = urlparse.urlparse(url) url = urlparse.urlunparse((scheme, netloc, path, '', '', '')) self.add_label_field("Title", page_title or "(unknown)", "title") self.add_label_field("URI", url, "uri") if fragment: self.add_label_field("Fragment", fragment, "fragment") headers = context.get_headers() if headers.has_key("date") and type(headers["date"]) is type(self): self.add_label_field("", "(Loaded from local cache.)", "cached") items = headers.items() items.sort() s = "" for k, v in items: if k == 'date' and type(v) is type(self): import ht_time v = ht_time.unparse(v.get_secs()) s = "%s%s:\t%s\n" % (s, k, v) stretch = self.add_text_field("Response headers", s, "headers") if query: query = string.translate(query, FIELD_BREAKER) stretch = stretch or \ self.add_text_field("Query fields", query, "query") postdata = context.get_postdata() if postdata: postdata = string.translate(postdata, FIELD_BREAKER) stretch = stretch or \ self.add_text_field("POST fields", postdata, "postdata") # # Bottom button # fr = Tkinter.Frame(botfr, borderwidth=1, relief=Tkinter.SUNKEN) fr.pack() btn = Tkinter.Button(fr, text="OK", command=destroy) # '2m' is the value from the standard Tk 'tk_dialog' command btn.pack(padx='2m', pady='2m') btn.focus_set() # del self.__topfr # lose the reference tktools.set_transient(root, master) root.update_idletasks() reqwidth = root.winfo_reqwidth() reqheight = root.winfo_reqheight() root.minsize(reqwidth, reqheight) if not stretch: root.maxsize(reqwidth, reqheight)