Пример #1
0
 def get(self):
   post = db.get(db.Key(self.request.query_string))
   if (post.IsModeratable()):
     post.delete()
     #delete the memcached html for the parent thread
     memcache.delete('threadhtml' + str(post.ParentThread.key()))
   self.redirect('/messageboard/thread?' + str(post.ParentThread.key()))
Пример #2
0
    def post(self):
        code = self.request.get('code',None)
        img = self.request.get('img',"")

        # simple antispam
        if sum(x in code.lower() for x in ('href=', 'url=', 'link=')) > 2:
            self.redirect("/error")
            return

        if code.strip():
            hash = base64.b64encode(hashlib.sha1(code.strip()).digest()[:6], "-_")
            if not LogoProgram.all().filter('hash =', hash).get():
                program = LogoProgram()
                program.code = code
                program.hash = hash
                if img:
                    img = base64.b64decode(img)
                    img = images.Image(img)
                    img.resize(125, 125)
                    program.img = img.execute_transforms()
                else:
                    self.redirect("/error")
                    return
                program.put()
                memcache.set("program: %s" % hash, program)
                memcache.delete("recent_progs")
        else:
            hash = ""

        self.redirect("/%s" % hash)
Пример #3
0
	def get(self):
		category_key = self.request.get('id')
		category = db.get(category_key)
		category.reverse = True
		db.put(category)
		memcache.delete(category.getReviewPairsKey())
		self.redirect('category?id=' + category_key)
Пример #4
0
    def post(self, login_user=None, template_values={}):

        memcache.set('import_status', "Queued import task", time=30)

        # import or upload?
        action = self.request.get('action')
        assert action, "Import or upload? No action specified."

        upload_files = self.get_uploads('osmdata')
        try:
            blob_info = upload_files[0]
        except IndexError:
            memcache.set('%s_status' % action, "%s failed. Nothing found in blobstore." % action.title(), time=30)
            logging.warning("Could not find uploaded data in blobstore.")
            self.redirect('/update')

        # delete memory for confirmation walkthrough (see balsa_update)
        memcache.delete('update')
        memcache.delete('new')

        # start background process
        taskqueue.add(url='/%s/store' % action, queue_name='import',
                      params={'compressed': self.request.get('compressed', ""),
                              'action': action,
                              'osmdata': blob_info.key()})

        # redirect to update page which will show the current state of the data storage
        self.redirect('/update')
Пример #5
0
    def render_to_response(self, template, context=None, use_cache=False):
        """Renders the template and writes the result to the response."""

        if use_cache:
            # Use the request's path to store the contents.

            # WARNING: This could cause scary problems if you render
            # user-specific pages.
            # DO NOT use current_profile in a template rendered with use_cache=True.
            cache_key = self.request.path
            contents = memcache.get(cache_key)

            if not contents or 'flushcache' in self.request.arguments():
                contents = self.render_template(template, context)

                # If add() returns False, it means another request is already trying
                # to cache the page. No need to do anything here.
                if memcache.add('lock.%s' % cache_key, True):
                    memcache.set(cache_key, contents)
                    memcache.delete('lock.%s' % cache_key)

        else:
            contents = self.render_template(template, context)

        self.response.write(contents)
Пример #6
0
    def post(self):
        self.response.headers['Content-Type'] = 'application/json' 
        action = self.request.get("action")

        if action == "login":
            
            username = self.request.get('username') 
            password = self.request.get('password')

            self._handle_login(username=username, password=password)
 
        
        elif action == "logout":
            student_token = self.request.get('token')
            memcache.delete(student_token, namespace="teachers")
            self.response.write(json.dumps({'api':'ok'}))

        elif action == "register":
            self._handle_register()


        elif action == "debug":
            try:
                student_token = self.request.get('token')
                self.response.out.write("token " + student_token)
                student = memcache.get(student_token, "teachers")
                self.response.out.write(json.dumps(student))
                self.response.out.write("end")
            except:
                self.response.out.write("not logged in")
            pass
        else:
            raise RuntimeError("invalid request error.")
Пример #7
0
    def delete_all_sessions(cls):
        """
        Deletes all sessions and session data from the data store and memcache:

        NOTE: This is not fully developed. It also will not delete any cookie
        data as this does not work for each incoming request. Keep this in mind
        if you are using the cookie writer.
        """
        all_sessions_deleted = False
        all_data_deleted = False

        while not all_sessions_deleted:
            query = _AppEngineUtilities_Session.all()
            results = query.fetch(75)
            if len(results) is 0:
                all_sessions_deleted = True
            else:
                for result in results:
                    memcache.delete("sid-" + str(result.key()))
                    result.delete()

        while not all_data_deleted:
            query = _AppEngineUtilities_SessionData.all()
            results = query.fetch(75)
            if len(results) is 0:
                all_data_deleted = True
            else:
                for result in results:
                    result.delete()
Пример #8
0
 def post(self, id):
     if not users.get_current_user():
         self.response.set_status(401, "")
         return
     if len(id) > 0:
         entry = Package.get(id)
         if not entry:
             self.error(404)
             return
         entry.name = self.request.get('name'),
         entry.version = self.request.get("version"),
         entry.description = self.request.get("description"),
         entry.url = self.request.get("url"),
         entry.extractor = self.request.get("extractor"),
         entry.author = self.request.get("author"),
         entry.packer = users.get_current_user(),
         entry.requires = self.request.get("requires"),
         entry.installer = self.request.get("installer"),
         entry.installer_script = self.request.get("installer_script"),
     else:
         entry = Package(
             name=self.request.get('name'),
             version=self.request.get("version"),
             description=self.request.get("description"),
             url=self.request.get("url"),
             extractor=self.request.get("extractor"),
             author=self.request.get("author"),
             packer=users.get_current_user(),
             requires=self.request.get("requires"),
             installer=self.request.get("installer"),
             installer_script=self.request.get("installer_script"),
         )
     entry.put()
     memcache.delete("packages")
     self.redirect("/edit/%s" % (entry.key()))
Пример #9
0
	def get_doc(id):
		if googleUser.is_current_user_admin():
			memcache.delete(id)

		entry = memcache.get(id)
		if not entry:
			client = gdata.docs.client.DocsClient(source='yourCo-yourAppName-v1')
			client.ssl = True # Force all API requests through HTTPS
			client.http_client.debug = True # Set to True for debugging HTTP requests
			client.ClientLogin(settings.DOCS_EMAIL, settings.DOCS_PASS, client.source)

			entry = client.GetFileContent(
				'/feeds/download/documents/Export?id=%s&format=html' % id)
			memcache.add(id, entry)
		html = BeautifulStoneSoup(entry, convertEntities=BeautifulStoneSoup.HTML_ENTITIES)
		body = html.body.renderContents()
		style = html.style.prettify()
		return {
			'entry': entry,
			'title': html.head.title.text,
			'html': html,
			'body': body.replace('http:///', '/'),
			'style': style,
			'id': id,
			}
Пример #10
0
  def MemcacheWrappedDelete(cls, key_name=None, entity=None):
    """Delete an entity by key name and clear Memcache.

    Note: This only clears the entity cache. If MemcacheWrappedGet()
    with a prop_name kwarg has been used, a separate cache will exist
    for that property. This function will not delete that memcache.
    TODO(user): If this function were actually used anywhere
    we should have prop_name=[] here so that users can delete prop_name
    caches too.

    Args:
      key_name: str, key name of entity to fetch
      entity: db.Model entity
    Raises:
      ValueError: when neither entity nor key_name are supplied
    """
    if entity:
      key_name = entity.key().name()
    elif key_name:
      entity = cls.get_by_key_name(key_name)
    else:
      raise ValueError

    if entity:
      entity.delete()
    memcache_key = 'mwg_%s_%s' % (cls.kind(), key_name)
    memcache.delete(memcache_key)
Пример #11
0
 def POST(self):
     import opml
     x = web.input(importfile={})
     memcache.set(MEMC_ADV_ID, self.__url__, 86400)
     if 'importfile' in x:
         user = self.getcurrentuser()
         try:
             rsslist = opml.from_string(x.importfile.file.read())
         except Exception as e:
             return self.GET(str(e))
         
         for o in self.walkOutline(rsslist):
             title, url, isfulltext = o.text, urllib.unquote_plus(o.xmlUrl), o.isFulltext #isFulltext为非标准属性
             isfulltext = bool(isfulltext.lower() in ('true', '1'))
             if title and url:
                 rss = Feed.all().filter('book = ', user.ownfeeds).filter("url = ", url).get() #查询是否有重复的
                 if rss:
                     rss.title = title
                     rss.isfulltext = isfulltext
                     rss.put()
                 else:
                     Feed(title=title,url=url,book=user.ownfeeds,isfulltext=isfulltext,
                         time=datetime.datetime.utcnow()).put()
                         
         memcache.delete('%d.feedscount'%user.ownfeeds.key().id())
         raise web.seeother('/my')
     else:
         raise web.seeother('')
Пример #12
0
 def post(self):
   raw_img = self.request.get("img")
   if len(raw_img) == 0:
     logging.info('Image payload is empty')
     self.redirect('/problem/ERR_PAYLOAD_EMPTY')
     return
   if len(raw_img) > 1000000:
     logging.error('Image is too large')
     self.redirect('/problem/ERR_IMG_TOO_LARGE')
     return
   xi = ImageObject()
   xi.views = 0
   if users.get_current_user():
     xi.author = users.get_current_user()
   content = self.request.get("content")
   xi.content = validate_content(content)
   xi.full_text = strip_camel_case(content)
   try:
     xi.payload = db.Blob(raw_img)
     xi.thumbnail = create_thumbnail(xi)
     xi.put()
   except:
     payload = images.resize(raw_img, 640, 480)
     xi.payload = db.Blob(raw_img)
     xi.thumbnail = create_thumbnail(xi)
     xi.put()
   username = get_user()
   content_all_key = "%s_the_contents_all" % username
   content_key = "%s_the_contents" % username
   logging.info('Invalidating the memcache contents of %s %s', content_all_key, content_key)
   memcache.delete(content_all_key)
   memcache.delete(content_key)
   self.redirect('/user')
Пример #13
0
def end_recording(status, firepython_set_extension_data=None):
  """Stop recording RPC traces and save all traces to memcache.

  This resets the global 'recorder' variable to None.

  Args:
    status: HTTP Status, a 3-digit integer.
    firepython_set_extension_data: Optional function to be called
      to pass the recorded data to FirePython.
  """
  global recorder
  rec = recorder
  recorder = None
  if config.DEBUG:
    logging.debug('Cleared recorder')
  if rec is not None:
    try:
      rec.record_http_status(status)
      rec.save()





      if (firepython_set_extension_data and
          (os.getenv('SERVER_SOFTWARE', '').startswith('Dev') or
           users.is_current_user_admin())):
        logging.info('Passing data to firepython')
        firepython_set_extension_data('appengine_appstats', rec.json())
    finally:
      memcache.delete(lock_key(), namespace=config.KEY_NAMESPACE)
Пример #14
0
def sync_add_image(request, uid):
    logging.info("Add image for gift with key: %s" % uid)
    mem_key = 'sync/add_image/%s' % uid
    img_url = memcache.get(mem_key)
    if img_url:
        memcache.delete(mem_key)
        img = urlfetch.fetch(img_url)
        if img.status_code == 200:
            thumb = img.content
            gift = Gift.get_by_id(uid)
            if gift:
                title = gift.name.replace('"', '"')
                thumb_img = ThumbImage()
                content_type = 'image/jpeg'
                thumb_img.add_new_thumb(blob_img=thumb, thumb_size=(700, 700,),
                                        title=title, content_type=content_type)
                thumb_img.add_new_thumb(blob_img=thumb, thumb_size=(400, 400, ),
                                        title=title, content_type=content_type)
                thumb_img.add_new_thumb(blob_img=thumb, thumb_size=(200, 200, ),
                                        title=title, content_type=content_type)
                thumb_img.add_new_thumb(blob_img=thumb, thumb_size=(100, 100, ),
                                        title=title, content_type=content_type)
                if not gift.thumbs.count():
                    thumb_img.main_gift = gift
                thumb_img.gift = gift
                thumb_img.put()
    return render_json_response({'api_msg': 'Ok', 'api_success': True})
Пример #15
0
def end_recording(status, firepython_set_extension_data=None):
    """Stop recording RPC traces and save all traces to memcache.

  This clears the recorder set for this request in 'recorder_proxy'.

  Args:
    status: HTTP Status, a 3-digit integer.
    firepython_set_extension_data: Optional function to be called
      to pass the recorded data to FirePython.
  """
    rec = recorder_proxy.get_for_current_request()
    recorder_proxy.clear_for_current_request()
    if config.DEBUG:
        logging.debug("Cleared recorder")
    if rec is not None:
        try:
            rec.record_http_status(status)
            rec.save()

            if firepython_set_extension_data and (
                os.getenv("SERVER_SOFTWARE", "").startswith("Dev") or users.is_current_user_admin()
            ):
                logging.info("Passing data to firepython")
                firepython_set_extension_data("appengine_appstats", rec.json())
        finally:
            memcache.delete(lock_key(), namespace=config.KEY_NAMESPACE)
Пример #16
0
    def post(self):
        E_username = str(self.request.get('username'))
        E_password = self.request.get('password')

        username = valid_username(E_username)
        if not username:
            name_error = "That's not a valid username,"
        else:
            name_error = ''

        password = valid_pass(E_password)
        if not password:
            pass_error = "That wasn't a valid password."
        else:
            pass_error = ''

        if not (username and password):
            self.write_form(name_error, pass_error, '',  E_username)
        else:
            entry = db.GqlQuery("select * from Users where username=:1 limit 1", E_username).get()
            if entry:
                name = logged_in(self)
                if name and '*' in name: # delete guest user if current
                    c = db.GqlQuery("select * from Users where username=:1", name).get()
                    c.delete()
                    memcache.delete(name + '_loginhash')
                stored_hash = str(entry.password)
                if valid_hash(E_username, E_password, stored_hash):
                    make_session(self, E_username, E_password)
                    self.redirect("/welcome")
                else:
                    self.write_form('', 'Incorrect password', '', E_username)
            else:
                self.write_form('', '', "Don't know you, %s. Have you signed up?" % E_username, E_username)
Пример #17
0
	def get(self):
		exp = datetime.date.today() + datetime.timedelta(days = -1)
		name = logged_in(self)
		if name:
			memcache.delete(name + '_loginhash')
			self.response.headers.add_header('Set-Cookie', "user_id=; expires='%s';path=/" % exp.strftime("%a, %d-%b-%Y 23:59:59 GMT"))
		self.redirect("/")
Пример #18
0
 def get(self, one_num):
     if 'Referer' in self.request.headers:
         go = self.request.headers['Referer']
     else:
         go = '/'
     member = CheckAuth(self)
     t = self.request.get('t')
     if member:
         if str(member.created_ts) == str(t):
             one = GetKindByNum('Member', int(one_num))
             if one is not False:
                 if one.num != member.num:
                     q = db.GqlQuery("SELECT * FROM MemberBookmark WHERE one = :1 AND member_num = :2", one, member.num)
                     if q.count() > 0:
                         bookmark = q[0]
                         bookmark.delete()
                         member = db.get(member.key())
                         member.favorited_members = member.favorited_members - 1
                         member.put()
                         memcache.set('Member_' + str(member.num), member, 86400)
                         n = 'r/m' + str(one.num) + '/m' + str(member.num)
                         memcache.delete(n)
                         one = db.get(one.key())
                         one.followers_count = one.followers_count - 1
                         one.put()
                         memcache.set('Member_' + str(one.num), one, 86400)
                         memcache.set('Member::' + str(one.username_lower), one, 86400)
     self.redirect(go)
Пример #19
0
  def post(self):
    """Adds a new builder status message."""

    # Check if this is a delete builder request.
    delete_builder = self.request.get('delete')
    if delete_builder:
      BuilderStatus.delete_builder(delete_builder)
    else:
      message = self.request.get('message')
      builder_name = self.request.get('builder_name')
      # If an entry with the builder_name already exists then delete it first.
      BuilderStatus.delete_builder(builder_name)

      # Add a new BuilderStatus entry.
      BuilderStatus(username=self.user.email(),
                    builder_name=builder_name,
                    message=message).put()

    # Flush the cache.
    memcache.flush_all()
    memcache.delete('builder_statuses')
    # Wait for a second before accessing the memcache again (in case there is a
    # propagation delay).
    time.sleep(1)
    # Set template values and load the template.
    self._handle()
Пример #20
0
	def get(self):
		if not self.is_login:
			self.redirect(users.create_login_url(self.request.uri))

		action=self.param('action')

		if action=='stop':
			memcache.delete("imt")
			#OptionSet.remove('wpimport_data')
			self.write('"ok"')
			return

		imt=memcache.get('imt')
		#imt=OptionSet.getValue('wpimport_data')
		if imt and imt.cur_do:
			process=100-math.ceil(imt.count()*100/imt.total)
			if imt.cur_do[0]=='cat':
				msg="importing category '%s'"%imt.cur_do[1]['name']
			elif imt.cur_do[0]=='entry':
				msg="importing entry '%s'"%imt.cur_do[1]['title']
			else:
				msg="start importing..."
			self.write(simplejson.dumps((process,msg,not process==100)))
		else:
			self.write(simplejson.dumps((-1,"Have no data to import!",False)))
Пример #21
0
 def stop(self):
   self.active = False
   game_slugs = get_game_slugs()
   
   if self.slug in game_slugs:
     game_slugs.remove(self.slug)
     memcache.set('game_slugs', game_slugs)
   
   
   serialized_status = memcache.get_multi(self.status_ids,
                                          key_prefix='status')
   
   # Just copying my status_ids list to make some changes localy
   missing_status_ids = list(self.status_ids)
   for status_id, status in serialized_status.iteritems():
     deserialized_status = deserialize(status)
     deserialized_status.player.leave_game(self)
     missing_status_ids.remove(status_id)
   
   # Taking the missing status in database
   if missing_status_ids:
     missing_status = Status.get(missing_status_ids)
     for status in missing_status:
       status.player.leave_game(self)
   
   memcache.delete('game'+self.slug)
   self.status_ids = []
   self.put()
Пример #22
0
 def clear(cls):
     charCache = memcache.get(cls._charCacheName)
     if not charCache: return
     
     for char in charCache:
         cls.deleteCache(char)
     memcache.delete(cls._charCacheName)
Пример #23
0
    def test_get_and_put_cached(self):
        storage = appengine.StorageByKeyName(
            appengine.CredentialsModel, 'foo', 'credentials', cache=memcache)

        self.assertEqual(None, storage.get())
        self.credentials.set_store(storage)

        http = http_mock.HttpMock(data=BASIC_RESP)
        self.credentials._refresh(http)
        credmodel = appengine.CredentialsModel.get_by_key_name('foo')
        self.assertEqual(BASIC_TOKEN, credmodel.credentials.access_token)

        # Now remove the item from the cache.
        memcache.delete('foo')

        # Check that getting refreshes the cache.
        credentials = storage.get()
        self.assertEqual(BASIC_TOKEN, credentials.access_token)
        self.assertNotEqual(None, memcache.get('foo'))

        # Deleting should clear the cache.
        storage.delete()
        credentials = storage.get()
        self.assertEqual(None, credentials)
        self.assertEqual(None, memcache.get('foo'))

        # Verify mock.
        self._verify_basic_refresh(http)
Пример #24
0
    def post(self):
        user = check_privileged(self)
        if not user:
            return

        # basic template values
        template_values = {
            'action': self.request.uri,
            'pages': page.DbPage.all(),
            'displays': display.Display.all()
        }

        p = self._get_page()
        if p:
            template_values['page'] = p
            form = PageForm(instance=p, data=self.request.POST.mixed())
        else:
            form = PageForm(data=self.request.POST.mixed())

        if form.is_valid():
            form.save()

            # force udpate of serials
            # TODO only do this if the page has/had a serial display
            memcache.delete('serials')

        template_values['form'] = form

        self.response.out.write(template.render('static/admin_pages.html', template_values))
Пример #25
0
    def _respond(self, path, obj={}, xml=False, search={}):
        """ draw the html and add it to the response then decide to add to or flush the cashe if admin"""
        
        opt = {
            "appname": self._conf.APP_NAME,
            "blog_name": self._conf.BLOG,
            "fb_app_id": self._conf.FB_APP_ID,
            "can_edit": self._req.sesh().can_edit(),
            "authed": self._req.sesh().authorised(),
            "authfor": self._req.sesh().user_name(),
            "url": self._req.spath(query=False),
            "search": search 
        }

        if self._req.ext() == 'xml' or xml:
            path = "rss"
            self._req.set_header('Content-Type', 'application/rss+xml')

        html = self._req.draw(path=path, obj=obj, opt=opt)

        # if an admin hits the page then clear this out of the cache
        if self._conf.CACHE:
            # if an admin hits the page then clear this out of the cache
            if self._req.sesh().can_edit():
                memcache.delete(self._req.get_cache_key())
            else:
                if not memcache.add(self._req.get_cache_key(), html, 3600):   #3600 = 1 hour 
                    logging.error("MEMCACHE MISTAKE")
Пример #26
0
def flush(model, filter):
  """Removes the data for the current user from the memcache.
  """

  memcache_key = key(model, filter)
  # pylint: disable=E1101
  memcache.delete(memcache_key)
Пример #27
0
 def post(self):
     try:
         self.store_poll()
         memcache.delete('INDEX_HTML')
         self.redirect('/')
     except:
         self.response.out.write('Error: ' + str(sys.exc_info()))
Пример #28
0
def create_event(title, summary, information, start_date, end_date, start_time, end_time, attendance, location, email):
    event = event_info()
    event.populate(
        title=title,
        summary=summary,
        information=information,
        start_date=start_date,
        end_date=end_date,
        start_time=start_time,
        end_time=end_time,
        attendance=attendance,
        location=location,
        featured=False,
        votes=0,
        user=email,
    )
    # event_number = event_number,)

    ##event.key = ndb.Key(event_info, event_number)
    event.put()

    memcache.delete("events")
    memcache.set(event.key.urlsafe(), event, namespace="event")

    return event.key.urlsafe()
Пример #29
0
 def flush_cache():
   """Flushes the memcache key used by this datamodel."""
   memcache.flush_all()
   memcache.delete(IS_STOPPED_MEMCACHE_KEY)
   # Wait for a second before accessing the memcache again (in case there is a
   # propagation delay).
   time.sleep(1)
Пример #30
0
 def delete(cls, key, namespace=None):
     """Deletes an item from memcache if memcache is enabled."""
     if CAN_USE_MEMCACHE.value:
         CACHE_DELETE.inc()
         if not namespace:
             namespace = appengine_config.DEFAULT_NAMESPACE_NAME
         memcache.delete(key, namespace=namespace)
Пример #31
0
 def put(self):
     Setting.cached_exercises_date(str(datetime.datetime.now()))
     memcache.delete(Exercise._EXERCISES_COUNT_KEY, namespace=App.version)
     db.Model.put(self)
Пример #32
0
 def delete(self, *args, **kwargs):
     """Ensure tags memcache entries are purged when one is delete."""
     # TODO(user): extend BaseModel so such memcache cleanup is reusable.
     memcache.delete(self.ALL_TAGS_MEMCACHE_KEY)
     return super(Tag, self).delete(*args, **kwargs)
Пример #33
0
 def put(self, *args, **kwargs):
     """Ensure tags memcache entries are purged when a new one is created."""
     memcache.delete(self.ALL_TAGS_MEMCACHE_KEY)
     return super(Tag, self).put(*args, **kwargs)
Пример #34
0
                    'MemcacheWrappedGet: failure to memcache.set(%s, ...): %s',
                    memcache_key, str(e))
        else:
            if prop_name:
                output = cached
            else:
                try:
                    output = db.model_from_protobuf(cached)
                except Exception, e:  # pylint: disable=broad-except
                    # NOTE(user): I copied this exception trap style from
                    # google.appengine.datastore.datatstore_query.  The notes indicate
                    # that trapping this exception by the class itself is problematic
                    # due to differences between the Python and SWIG'd exception
                    # classes.
                    output = None
                    memcache.delete(memcache_key)
                    if e.__class__.__name__ == 'ProtocolBufferDecodeError':
                        logging.warning('Invalid protobuf at key %s', key_name)
                    elif retry:
                        logging.exception(
                            'Unexpected exception in MemcacheWrappedGet')
                    if not retry:
                        return cls.MemcacheWrappedGet(
                            key_name,
                            prop_name=prop_name,
                            memcache_secs=memcache_secs,
                            retry=True)
                    else:
                        return cls.get_by_key_name(key_name)

        return output
Пример #35
0
def delete_memcached_api_key_list():
  key_name = "MASTERDATA_API_KEYS"
  memcache.delete(key_name)
Пример #36
0
def clearMemcacheKeyMasterData(master_code):
  memcache.delete(getMemcacheKeyMasterData(master_code))
Пример #37
0
 def clear_memcache(self):
     memcache.delete(UserExercise.get_key_for_user(self.user))
Пример #38
0
def delete_token(unique_key):
    # Clear from memcache.
    memcache.delete(unique_key)
    # Clear from the datastore.
    Token(key_name=unique_key).delete()
Пример #39
0
 def removecache(self):
     memcache.delete('/')
     memcache.delete('/' + self.link)
     memcache.delete('/sitemap')
     memcache.delete('blog.postcount')
     g_blog.tigger_action("clean_post_cache", self)
Пример #40
0
 def get(self):
   """Render the main page."""
   # Get the flash message and delete it.
   message = memcache.get(key=self.userid)
   memcache.delete(key=self.userid)
   self._render_template(message)
Пример #41
0
 def invalidate_user_fb_id(user_fb_id):
     memcache.delete(user_fb_id, namespace=USER_FB_ID_NAMESPACE)
Пример #42
0
 def delete(self, raw_token):
     s = datamodel.UserToken.get_by_key_name(raw_token)
     if s:
         memcache.delete('token_request:%s' % s.value)
         s.delete()
Пример #43
0
    def post(self):
        if not self.current_user:
            args = dict(user=self.current_user, logout_url=LOGOUT_URL)
            self.response.out.write(
                template.render('templates/index.html', args))
            return

        try:
            query = db.Query(Crush)
            query.filter('id =', self.current_user.id)
            query.order('created')

            results = query.fetch(11)
            orig_crushes = [x.crush for x in results]

            names = self.request.POST.getall('c')
            orig = self.request.POST.getall('o')

            # First handle deletion
            for crush in orig_crushes:
                if crush not in names:
                    crushkey = self.current_user.id + ':' + crush
                    c = Crush.get_by_key_name(crushkey)
                    if c:
                        logging.info('deleting crush %s from cache and store' %
                                     (crushkey))
                        c.delete()
                        mc.delete(crushkey, namespace='crushes')

            # Now add anything new
            d = DNDRemoteLookup()
            # TODO not necessary to lookup names that were already in there (even though we memcache lookups)
            dndnames = d.lookup(names, CLASS_YEAR)
            new_crushes = []
            comments = []
            i = 0
            for name in names:
                if name == '':
                    i += 1
                    continue

                # Check if it's already there
                crushkeyname = self.current_user.id + ':' + name
                c = mc.get(crushkeyname, namespace='crushes')

                if c != None or Crush.get_by_key_name(crushkeyname):
                    # We also checked that it's in db in case it got evicted from cache
                    if c:
                        logging.info('Found preexisting crush in cache')
                    else:
                        logging.info('Found preexisting crush in store')

                    # Was already validated, so no need to check in dndnames
                    comments.append('')
                    new_crushes.append(name)
                else:
                    # Crush doesn't already exist
                    if len(dndnames[name]) == 0:
                        # No good
                        comments.append(
                            'DND couldn\'t find anyone named "%s" in your year'
                            % (cgi.escape(name)))
                        new_crushes.append('')
                    elif len(dndnames[name]) == 1:
                        # New crush
                        resolved_name = dndnames[name][0]
                        crushkeyname = self.current_user.id + ':' + resolved_name
                        c = Crush(key_name=crushkeyname,
                                  id=self.current_user.id,
                                  crush=resolved_name)
                        c.put()
                        mc.set(crushkeyname, True, namespace='crushes')
                        comments.append('Saved')
                        new_crushes.append(resolved_name)
                    else:
                        # Unspecific - let them choose
                        links = ['<a href="#" onClick="document.getElementById(\'c%d\').value=\'%s\';return false;">%s</a>' \
                                 % (i,x,x) for x in dndnames[name]]
                        comments.append('Did you mean: ' + ', '.join(links))
                        new_crushes.append('')
                i += 1

            self.render_main(crushes=new_crushes, comments=comments)

        except DeadlineExceededError:
            self.response.clear()
            self.response.set_status(500)
            self.response.out.write(
                'The operation could not be completed in time.  Try again or contact technical assistance.'
            )
Пример #44
0
def invalidate_cache():
    if not memcache.delete("frontpage"):
        logging.error("Memcache delete failed on frontpage")
    taskqueue.add(url='/', method="GET")
Пример #45
0
    def post(self):
        (forum, siteroot,
         tmpldir) = forum_siteroot_tmpldir_from_url(self.request.path_info)
        if not forum or forum.is_disabled:
            return self.redirect("/forum/")
        if self.request.get('Cancel'):
            return self.redirect(siteroot)

        ip = get_remote_ip()
        if ip in BANNED_IPS:
            return self.redirect(siteroot)

        self.send_cookie()

        vals = [
            'TopicId', 'num1', 'num2', 'Captcha', 'Subject', 'Message',
            'Remember', 'Email', 'Name', 'Url'
        ]
        (topic_id, num1, num2, captcha, subject, message, remember_me, email,
         name, homepage) = req_get_vals(self.request, vals)
        message = to_unicode(message)

        remember_me = True
        if remember_me == "": remember_me = False
        rememberChecked = ""
        if remember_me: rememberChecked = "checked"

        validCaptcha = True
        try:
            captcha = int(captcha)
            num1 = int(num1)
            num2 = int(num2)
        except ValueError:
            validCaptcha = False

        homepage = sanitize_homepage(homepage)
        tvals = {
            'siteroot': siteroot,
            'forum': forum,
            'num1': num1,
            'num2': num2,
            'num3': int(num1) + int(num2),
            "prevCaptcha": captcha,
            "prevSubject": subject,
            "prevMessage": message,
            "rememberChecked": rememberChecked,
            "prevEmail": email,
            "prevUrl": homepage,
            "prevName": name,
            "prevTopicId": topic_id,
            "log_in_out": get_log_in_out(siteroot + "post")
        }

        # validate captcha and other values
        errclass = None
        if not validCaptcha or (captcha != (num1 + num2)):
            errclass = 'captcha_class'
        if not message: errclass = "message_class"
        if not name: errclass = "name_class"
        if not valid_email(email): errclass = "email_class"
        # first post must have subject
        if not topic_id and not subject: errclass = "subject_class"

        # sha.new() doesn't accept Unicode strings, so convert to utf8 first
        message_utf8 = message.encode('UTF-8')
        s = sha.new(message_utf8)
        sha1_digest = s.hexdigest()

        duppost = Post.gql("WHERE sha1_digest = :1", sha1_digest).get()
        if duppost: errclass = "message_class"

        if errclass:
            tvals[errclass] = "error"
            tmpl = os.path.join(tmpldir, "post.html")
            return self.template_out(tmpl, tvals)

        # get user either by google user id or cookie. Create user objects if don't
        # already exist
        existing_user = False
        user_id = users.get_current_user()
        if user_id:
            user = FofouUser.gql("WHERE user = :1", user_id).get()
            if not user:
                #logging.info("Creating new user for '%s'" % str(user_id))
                user = FofouUser(user=user_id,
                                 remember_me=remember_me,
                                 email=email,
                                 name=name,
                                 homepage=homepage)
                user.put()
            else:
                existing_user = True
                #logging.info("Found existing user for '%s'" % str(user_id))
        else:
            cookie = self.get_cookie_val()
            user = FofouUser.gql("WHERE cookie = :1", cookie).get()
            if not user:
                #logging.info("Creating new user for cookie '%s'" % cookie)
                user = FofouUser(cookie=cookie,
                                 remember_me=remember_me,
                                 email=email,
                                 name=name,
                                 homepage=homepage)
                user.put()
            else:
                existing_user = True
                #logging.info("Found existing user for cookie '%s'" % cookie)

        if existing_user:
            need_update = False
            if user.remember_me != remember_me:
                user.remember_me = remember_me
                need_update = True
            if user.email != email:
                user.email = email
                need_update = True
            if user.name != name:
                user.name = name
                need_update = True
            if user.homepage != homepage:
                user.homepage = homepage
                need_update = True
            if need_update:
                #logging.info("User needed an update")
                user.put()

        if not topic_id:
            topic = Topic(forum=forum, subject=subject, created_by=name)
            topic.put()
        else:
            topic = db.get(db.Key.from_path('Topic', int(topic_id)))
            #assert forum.key() == topic.forum.key()
            topic.ncomments += 1
            topic.put()

        user_ip_str = get_remote_ip()
        p = Post(topic=topic,
                 forum=forum,
                 user=user,
                 user_ip=0,
                 user_ip_str=user_ip_str,
                 message=message,
                 sha1_digest=sha1_digest,
                 user_name=name,
                 user_email=email,
                 user_homepage=homepage)
        p.put()
        memcache.delete(rss_memcache_key(forum))
        clear_topics_memcache(forum)
        if topic_id:
            self.redirect(siteroot + "topic?id=" + str(topic_id))
        else:
            self.redirect(siteroot)
Пример #46
0
 def invalidate(key):
     memcache.delete(key)
Пример #47
0
def clear_forums_memcache():
    memcache.delete(FORUMS_MEMCACHE_KEY)
Пример #48
0
    def post(self):
        if not auth(self.request):
            self.response.set_status(403)
            return

        builder = self.request.get('builder')
        log = self.request.get('log').encode('utf-8')

        loghash = ''
        if len(log) > 0:
            loghash = hashlib.sha256(log).hexdigest()
            l = CompressedLog(key_name=loghash)
            l.log = bz2.compress(log)
            l.put()

        date = parseDate(self.request.get('date'))
        user = self.request.get('user').encode('utf8')
        desc = self.request.get('desc').encode('utf8')
        node = self.request.get('node')
        parenthash = self.request.get('parent')
        if not validNode(node) or not validNode(parenthash) or date is None:
            logging.error("Not valid node ('%s') or bad date (%s %s)", node,
                          date, self.request.get('date'))
            self.response.set_status(500)
            return

        q = Commit.all()
        q.filter('node =', parenthash)
        parent = q.get()
        if parent is None:
            logging.error('Cannot find parent %s of node %s' %
                          (parenthash, node))
            self.response.set_status(404)
            return
        parentnum, _ = parent.key().name().split('-', 1)
        nodenum = int(parentnum, 16) + 1

        key_name = '%08x-%s' % (nodenum, node)

        def add_build():
            n = Commit.get_by_key_name(key_name)
            if n is None:
                n = Commit(key_name=key_name)
                n.num = nodenum
                n.node = node
                n.parentnode = parenthash
                n.user = user
                n.date = date
                n.desc = desc
            s = '%s`%s' % (builder, loghash)
            for i, b in enumerate(n.builds):
                if b.split('`', 1)[0] == builder:
                    n.builds[i] = s
                    break
            else:
                n.builds.append(s)
            n.put()

        db.run_in_transaction(add_build)

        key = 'hw-%s' % builder
        hw = Highwater.get_by_key_name(key)
        if hw is None:
            hw = Highwater(key_name=key)
        hw.commit = node
        hw.put()
        memcache.delete(key)
        memcache.delete('hw')

        def mark_sent():
            n = Commit.get_by_key_name(key_name)
            n.fail_notification_sent = True
            n.put()

        n = Commit.get_by_key_name(key_name)
        if loghash and not failed(parent,
                                  builder) and not n.fail_notification_sent:
            subject = const.mail_fail_subject % (builder, desc.split("\n")[0])
            path = os.path.join(os.path.dirname(__file__), 'fail-notify.txt')
            body = template.render(
                path, {
                    "builder": builder,
                    "node": node[:12],
                    "user": user,
                    "desc": desc,
                    "loghash": loghash
                })
            mail.send_mail(sender=const.mail_from,
                           reply_to=const.mail_fail_reply_to,
                           to=const.mail_fail_to,
                           subject=subject,
                           body=body)
            db.run_in_transaction(mark_sent)

        self.response.set_status(200)
Пример #49
0
 def release(self):
     memcache.delete(self.name, namespace="whooshlocks")
Пример #50
0
def clear_topics_memcache(forum):
    memcache.delete(topics_memcache_key(forum))
Пример #51
0
 def post(self):
     memcache.delete(self.request.get('mac'))
     self.redirect('/%s' % base64.b64encode(','.join(
         [self.request.get('mac'),
          self.request.get('redirect')])))
Пример #52
0
    def get(self):
        path = self.request.path

        # Remove string after "_" if redirected from basic-authed link
        path_parts = path.split("_")
        path = path_parts[0]
        if len(path_parts) >= 2:
            key_auth = path_parts[1]
        else:
            key_auth = None

        if not path or len(path) < 1 or path[0] != "/":
            self.response.set_status(404)
            return
        key_name = path[1:]
        entry = models.ApkEntry.get_by_key_name(key_name)
        if not entry:
            self.response.set_status(404)
            return

        # if the path was postfixed w/ "_" + key_auth random string
        if key_auth != None:
            user_ip = memcache.get(key_auth)
            if user_ip == self.request.remote_addr:
                memcache.delete(key_auth)
                self.respond_apk(entry)
                return
            else:
                self.response.set_status(404)
                return

        if not entry.ipaddrs and not entry.accounts and not entry.basic_id:
            # public available if both empty
            self.respond_apk(entry)
            return

        if entry.ipaddrs:
            if self.is_ip_allowed(entry):
                self.respond_apk(entry)
                return

        if entry.accounts:
            cur_user = users.get_current_user()
            if cur_user:
                if self.is_user_allowed(entry, cur_user):
                    self.respond_apk(entry)
                    return
            self.redirect(users.create_login_url(self.request.path))
            return

        if entry.basic_id:
            if self.is_basicAuthorized(entry):
                # A file cannot be downloaded from Android device if
                # it is protected by Basic authentication directly.
                # So, after authenticated, redirect to a different address
                # that allows only the IP address cached here.
                # self.respond_apk(entry) is what is not working here.
                auth_key = self.gen_key(32)
                user_ip = self.request.remote_addr
                # Set expiration time a little long to 60 sec, because
                # user must start downloadeing before it expires.
                memcache.set(auth_key, user_ip, 60)
                self.redirect(self.request.url + "_" + auth_key)
                return
            else:
                self.response.set_status(401)
                self.response.headers[
                    'WWW-Authenticate'] = 'Basic realm="BasicTest"'
                return

        self.response.set_status(404)
Пример #53
0
 def delete_memcache(self):
     memcache.delete(self.get_memcache_keyname())
Пример #54
0
 def delete_file(self, name):
     memcache.delete(name, namespace="DatastoreFile")
     return DatastoreFile.get_by_key_name(name).delete()
Пример #55
0
def flushBlogPagesCache():
    memcache.delete("blog_pages_key")
Пример #56
0
 def _expire_conversation(self):
     memcache.delete(self._convo_mckey())
Пример #57
0
def flushTagList():
    memcache.delete("blog_tagList_key")
Пример #58
0
 def add_memcache(self, test):
     memcache_keyname = self.get_memcache_keyname(test)
     memcache.delete(memcache_keyname)
     memcache.add(memcache_keyname, self, settings.STATS_USERTEST_TIMEOUT)
Пример #59
0
def flushCPedialog():
    memcache.delete("blog_cpedialog_key")
Пример #60
0
def flushRecentReactions():
    memcache.delete("blog_recentReactions_key")