def get_secs(self): if not self.secs: try: self.secs = ht_time.parse(self.str) except: # if there is a parsing error, we bail self.secs = 0 return self.secs
def handle_meta(self, errcode, errmsg, headers): if not self.handle_meta_prelim(errcode, errmsg, headers): return # This updates the attributes in the bookmarks database. try: bkmks = self.last_context.app.bookmarks_controller except AttributeError: pass else: last_modified = None if headers.has_key("last-modified"): try: last_modified = ht_time.parse(headers["last-modified"]) except ValueError: pass bkmks.record_visit(self.url, last_modified) content_encoding, transfer_encoding = get_encodings(headers) if headers.has_key('content-type'): content_type = headers['content-type'] if ';' in content_type: content_type = string.strip( content_type[:string.index(content_type, ';')]) else: content_type, encoding = self.app.guess_type(self.url) if not content_encoding: content_encoding = encoding real_content_type = content_type or "unknown" real_content_encoding = content_encoding if (transfer_encoding and not transfer_decoding_wrappers.has_key(transfer_encoding)) \ or (content_encoding and not content_decoding_wrappers.has_key(content_encoding)): # XXX provisional hack -- change content type to octet stream content_type = "application/octet-stream" transfer_encoding = None content_encoding = None if not content_type: content_type = "text/plain" # Last resort guess only istext = content_type and content_type[:5] == 'text/' \ and not (content_encoding or transfer_encoding) if self.show_source and istext: content_type = 'text/plain' parserclass = self.find_parser_extension(content_type) if not parserclass and istext: if content_type != 'text/plain': # still need to check for text/plain parserclass = self.find_parser_extension('text/plain') if not parserclass: parserclass = TextParser if not parserclass: # Don't know how to display this. # First consult mailcap. import mailcap global caps if not caps: caps = mailcap.getcaps() if caps: plist = [] # XXX Should be taken from Content-type header command, entry = mailcap.findmatch( caps, content_type, 'view', "/dev/null", plist) if command: # Retrieve to temporary file. import tempfile self.save_mailcap = command self.save_filename = tempfile.mktemp() self.save_content_type = content_type self.save_plist = plist self.save_file = open(self.save_filename, "wb") # remember the original click location self.app.global_history.remember_url(self.url) self.viewer.remove_temp_tag(histify=1) return # No relief from mailcap either. # Ask the user whether and where to save it. # Stop the transfer, and restart when we're ready. context = self.last_context # TBD: hack so that Context.rmreader() doesn't call # Viewer.remove_temp_tag(). We'll call that later # explicitly once we know whether the file has been saved # or not. context.source = None self.stop() context.message("Wait for save dialog...") encoding = '' if real_content_encoding: encoding = real_content_encoding + "ed " if encoding[:2] == "x-": encoding = encoding[2:] encoding_label = "MIME type: %s%s" % (encoding, real_content_type) import FileDialog fd = FileDialog.SaveFileDialog(context.root) label = Label(fd.top, text=encoding_label) label.pack(before=fd.filter) # give it a default filename on which save within the # current directory urlasfile = string.splitfields(self.url, '/') fn = fd.go(default=urlasfile[-1], key="save") if not fn: # User canceled. Stop the transfer. self.viewer.remove_temp_tag() return self.viewer.remove_temp_tag(histify=1) self.app.global_history.remember_url(self.url) # Prepare to save. # Always save in binary mode. try: self.save_file = open(fn, "wb") except IOError, msg: context.error_dialog(IOError, msg) return TransferDisplay(context, fn, self) return