示例#1
0
文件: feeds.py 项目: erwan/firenomics
    def GET(self, path):
        if path == '/xml/comments':
            comments = db.GqlQuery("SELECT * FROM Comment ORDER BY created DESC LIMIT 20")
            web.header('Content-Type', 'application/rss+xml')
            return render.comments(comments)
        else:
            if web.ctx.env.get('HTTP_USER_AGENT',"").find("FeedBurner") == -1:
                return web.Redirect("http://feeds.feedburner.com/overstimulate")

            articles = db.GqlQuery("SELECT * FROM Article WHERE created > :1 ORDER BY created DESC LIMIT 10", datetime.datetime(2008, 04, 25))
            web.header('Content-Type', 'application/rss+xml')
            return render.feed(articles)
示例#2
0
        def f(*args, **keywords):
            remotePassword = None
            remoteUser = None
            try:
                b64text = web.ctx.env["HTTP_AUTHORIZATION"][6:]
                plainText = b64decode(b64text)
                remoteUser, remotePassword = plainText.split(":")
            except:
                pass

            if remoteUser and remotePassword and verify(remoteUser, remotePassword, realm):
                return func(*args, **keywords)
            else:
                web.ctx.status = "401 UNAUTHORIZED"
                web.header("WWW-Authenticate", 'Basic realm="%s"' % web.websafe(realm))
                return notAuthenticatedFunc(realm, remoteUser, remotePassword, redirectURL)
示例#3
0
 def GET(self):
     posts = db.GqlQuery("SELECT * FROM Post order by created desc")
     web.header('Content-Type', 'text/xml')
     return render_no_layout.forum_feed(posts, base=None)
示例#4
0
    def POST(self, key=None):
        web.debug("hi: %s" % key)
        send_welcome = False
        json = simplejson.loads(web.input().data)

        if key and key != '':
            profile = Profile.get(key)

            if profile:
                sig = web.input().sig
                data = web.data()
                expected = md5.new(data + profile.secret).hexdigest()
                if sig != expected:
                    web.ctx.status = "401 Unauthorized"
                    return "Invalid Signature"
            else:
                send_welcome = 410

        else:
            send_welcome = 200

        if send_welcome:
            secret_uuid = uuid.uuid4()
            profile = Profile(secret=secret_uuid.hex)

        profile.version = json['system']['version']
        profile.os = json['system']['OS']
        profile.platform = json['system']['name']
        profile.put()

        web.debug("profile: %s" % profile)

        # Build a dictionary of the current extensions
        profile_extensions = profile.profileextension_set.fetch(100)

        px_dict = {}
        for e in profile_extensions:
            px_dict[e.extension.mid] = e
        web.debug(px_dict)

        local_extensions = json['extensions']
        for mid in local_extensions:
            local_extension = local_extensions[mid]
            web.debug("processing " + mid)
            key = db.Key.from_path('Extension', mid)
            extension = Extension.get(key)
            if not extension:
                web.debug("new extension: " + mid)
                extension = Extension(key_name=mid)
                extension.mid = mid
                extension.name = local_extension['name']
                extension.updateRDF = local_extension['updateRDF']
                extension.description = local_extension['description']
                extension.creator = local_extension['creator']
                extension.homepageURL = local_extension['homepageURL']
                extension.developers = local_extension['developers']
                extension.translators = local_extension['translators']
                extension.contributors = local_extension['contributors']
                extension.put()
            if px_dict.has_key(mid):
                web.debug("user had extension " + mid)
                px_dict[mid].version = local_extension['version']
                px_dict[mid].put()
                del px_dict[mid]
            else:
                web.debug("user did not have extension " + mid)
                px = ProfileExtension()
                px.extension = extension
                px.version = local_extension['version']
                px.profile = profile
                px.put()

        # Delete any user extensions from the database that weren't in the update
        for px in px_dict:
            web.debug("user no longer has extension " + mid)
            px_dict[px].delete()

        web.debug("profile key: %s" % profile.key())

        if send_welcome:
            web.ctx.status = "%s New Profile" % send_welcome
            web.header('Content-Type', 'text/x-json')
            return simplejson.dumps({'profile': str(profile.key()), 'secret': profile.secret})
        else:
            web.ctx.status = "200 OK"
            return "KTHXBAI"