class progressBarGlue: _css = util.resource_filename('nevow.taglibrary', "progressBar.css") _js = util.resource_filename('nevow.taglibrary', "progressBar.js") fileCSS = static.Data(_css, 'text/css') fileJS = static.Data(_js, 'text/javascript') fileGlue = ( t.link(rel='stylesheet', type_='text/css', href='/progressBar.css'), t.script(type_='text/javascript', src='/progressBar.js') ) inlineCSS = t.style(type_='text/css')[ t.xml(file(_css).read()) ] inlineJS = t.inlineJS(file(_js).read()) inlineGlue = inlineJS, inlineCSS
def locateChild(self, ctx, segs): md5 = segs[0] db = theGlobal["database"] FM = data.FileMeta # for now, everyone gets access to everyone else's files # TODO - implement permissions on files? _filter = A.AND(FM.md5==unicode(md5)) fileitem = db.findFirst(FM, _filter) if fileitem is None: return None, () if len(segs) > 1 and segs[1] == 'thumb': return static.Data(fileitem.thumbnail.data, 'image/png'), () else: mimeType = fileitem.mimeType.encode('utf-8') return static.Data(fileitem.data.data, mimeType), ()
def getResource( self, ctx, key, segments ): """ Return an Resource that contains the image, either a file from the resource manager, or a data object from the convertible. """ if segments[0] == self.FROM_RESOURCE_MANAGER: # Resource manager can provide a path so return a static.File # instance that points to the file rm = iformal.IForm( ctx ).resourceManager (mimetype, path, fileName) = rm.getResourcePath( segments[1] ) inevow.IRequest(ctx).setHeader('Cache-Control', 'no-cache, must-revalidate, no-store') return static.Data(file(path).read(), str(mimetype)), () elif segments[0] == self.FROM_CONVERTIBLE: # The convertible can provide a file like object so create a # static.Data instance with the data from the convertible. def _( result ): mimetype, filelike, fileName = result data = filelike.read() filelike.close() return static.Data( data, mimetype ), [] d = defer.maybeDeferred( self.convertibleFactory(self.original).fromType, segments[1], context=ctx ) d.addCallback( _ ) return d else: return None
def resourceFactory(self, fileName): """ Retrieve a possibly L{inevow.IResource} which will render the contents of C{fileName}. """ f = open(fileName, 'rb') js = f.read() return static.Data(js, 'text/javascript')
def deliverWampSecret(ctx, segments): # filename = segments[1].decode('utf-8') # FIXME: compare filename to ID+".secret" # for now all url under /secret returns the secret # TODO: make beautifull message in case of exception # while loading secret (if empty or dont exist) secret = LoadWampSecret(_WampSecret) return static.Data(secret, 'application/octet-stream'), ()
def locateChild(self, ctx, segments): """ Retrieve an L{inevow.IResource} to render the contents of the given module. """ if len(segments) != 2: return NotFound hashCode, moduleName = segments cachedModule = self.getModule(moduleName) return static.Data(cachedModule.fileContents, 'text/javascript', expires=(60 * 60 * 24 * 365 * 5)), []
def child_album_css(self, ctx): style = self.template['css'] if self.template['type'] == "html": for name, data in self.template['options'].items(): key = "" if self.album_info[ 'serialized_template_options'] and self.album_info[ 'serialized_template_options'].has_key(name): key = self.album_info['serialized_template_options'][name] else: key = data['default'] style += "%s\n" % data['values'][key] return static.Data(style, "text/css")
def redirectAfterPost(aspects): redirectAfterPost = request.getComponent(iformless.IRedirectAfterPost, None) if redirectAfterPost is None: ref = request.getHeader('referer') or '' else: ## Use the redirectAfterPost url ref = str(redirectAfterPost) from nevow import url refpath = url.URL.fromString(ref) magicCookie = str(now()) refpath = refpath.replace('_nevow_carryover_', magicCookie) _CARRYOVER[magicCookie] = C = tpc.Componentized() for k, v in aspects.iteritems(): C.setComponent(k, v) request.redirect(str(refpath)) from nevow import static return static.Data('You posted a form to %s' % bindingName, 'text/plain'), ()
class componentGlue(object): _js = """ livetags = new Object(); function delComponent(name) { o = livetags[name]; if(o) { if(o.del) { o.del(); } livetags[name] = null; } } """ fileJS = static.Data(_js, 'text/javascript') inlineGlue = t.script(type_='text/javascript')[ t.xml(_js) ] fileGlue = t.script(type_='text/javascript', src='/componentGlue.js')
def redirectAfterPost(aspects): hand = aspects.get(inevow.IHand) refpath = None if hand is not None: if isinstance(hand, Page): refpath = url.here if 'freeform_hand' not in inevow.IRequest(ctx).prepath: refpath = refpath.child('freeform_hand') if isinstance(hand, (url.URL, url.URLOverlay)): refpath, hand = hand, None if refpath is None: redirectAfterPost = request.getComponent( iformless.IRedirectAfterPost, None) if redirectAfterPost is None: ref = request.getHeader('referer') if ref: refpath = url.URL.fromString(ref) else: refpath = url.here else: warnings.warn( "[0.5] IRedirectAfterPost is deprecated. Return a URL instance from your autocallable instead.", DeprecationWarning, 2) ## Use the redirectAfterPost url ref = str(redirectAfterPost) refpath = url.URL.fromString(ref) if hand is not None or aspects.get( iformless.IFormErrors) is not None: magicCookie = '%s%s%s' % (now(), request.getClientIP(), random.random()) refpath = refpath.replace('_nevow_carryover_', magicCookie) _CARRYOVER[magicCookie] = C = tpc.Componentized() for k, v in aspects.items(): C.setComponent(k, v) destination = flat.flatten(refpath, ctx) request.redirect(destination) from nevow import static return static.Data('You posted a form to %s' % bindingName, 'text/plain'), ()
.nevow-inline-table-cell { display: table-cell; } </html:style> <html:span class="nevow-inline-table"> <html:span class="nevow-inline-table-row"> <html:span class="nevow-inline-table-cell" xbl:inherits="style"> <children/> </html:span> </html:span> </html:span> </content> </binding> </bindings> """ blocks_child = static.Data(mozBinding, 'text/xml; name="inline-block.xml"') class _Blocks(object): def __init__(self, tag, className): self.tag = tag self.className = className def __call__(self, **kw): """Make and return a new block. If height or width is specified, they may be of any css-supported measurement format, such as '200px' or '50%'. If height or width is not specified, the block will "shrink wrap". Interesting experiment: kw arguments to __call__ are treated like css style key value pairs. For example, block(color='blue', background_color='red') will translate
def child_album_js(self, ctx): return static.Data(self.template['script'], "text/javascript")
def locateChild(self, ctx, segments): if segments[0] == 'fs': data = IImages(self.store).getOne(segments[1].decode('utf-8')) return static.Data(data.image, 'image/jpeg'), () return super(Root, self).locateChild(ctx, segments)
def _(result): mimetype, filelike, fileName = result data = filelike.read() filelike.close() return static.Data(data, mimetype), []
def childFactory(self, ctx, name): avatarData = avatar.AvatarCache().getAvatarData(name) return static.Data(avatarData, "image/png")