def link_wiki(self,label,wikiname,wikianame): name = wikiname.replace(' ','_') path = misc.normpath(name) if label: label = label.replace('_',' ') else: label = name self.w.link_wiki(label,path+aname)
def test_normpath(): eq_(misc.normpath('////'),'') eq_(misc.normpath('.'),'.') eq_(misc.normpath('hoge/hoge'),'hoge/hoge') eq_(misc.normpath('hoge/../hoge'),'hoge') eq_(misc.normpath('../../hoge'),'../../hoge') eq_(misc.normpath('hoge/../../hoge'),'../hoge') eq_(misc.normpath('/hoge/hoge/.'),'hoge/hoge')
def cmd_upload(self, ri): if not self.wikifile.exist: raise exceptions.NotFound() if ri.is_spam or not config.EDITABLE: return self.text_wrapper(text_access_denied) if not ri.is_valid_host: return self.page_attach(ri) filename = "unkown" message = "unkown error" success = False if not ri.files: message = "no file." else: item = ri.files["file"] filename = os.path.basename(misc.normpath(item.filename.replace("\\", "/"))).lower() ext = os.path.splitext(filename)[1] path = misc.join(self.wikifile.path, "../" + filename) wa = self.head.get_file(path) if not config.MIME_MAP.has_key(ext): message = "%s: file type not supported" % filename else: temp = misc.read_fs_file(item.stream, config.MAX_ATTACH_SIZE) if not temp: message = "%s: too big file. maximum attach size = %s" % (filename, config.MAX_ATTACH_SIZE) else: temp.seek(0) success = not not wa.write(temp.read(), ri.user, "attach file uploaded", ext == ".txt") if not success: message = "commit error." if not success: ri.log("cmd_upload: file=%s message=%s" % (filename, message)) return self.renderer_wrapper(views.uploaded_body(success, message))