Esempio n. 1
0
    def get(self, code, format):
        if (code is None):
            logging.info("someone thinking about crafting a URL")
            MainView.render(self, 200, None, format)
            return

        ip = self.request.remote_addr 
        href = self.request.get('href').strip().encode('utf-8')
        title = self.request.get('title').strip().encode('utf-8')
        if (code == 'new') and (href is not None):
            try:
                u = Urly.find_or_create_by_href(href)
                if u is not None:
                    logging.info("creating urly by href: %s", str(href))
                    MainView.render(self, 200, u, format, href, title)
                else:
                    logging.info("error creating urly by href: %s", str(href))
                    MainView.render(self, 400, None, format, href)
            except db.BadValueError:
                # href parameter is bad
                logging.info("error with parameter")
                MainView.render(self, 400, None, format, href)
        else:
            u = Urly.find_by_code(str(code))
            if u is not None:
                logging.info("http://logg.ly/%s redirecting to %s for %s" % (code, u.href, ip))
                MainView.render(self, 200, u, format)
            else:
                logging.info("redirecting to loggly.com/%s" % code)
                self.redirect('http://www.loggly.com/%s' % code)
Esempio n. 2
0
    def get(self, code, format):
        
        server = "http://" + self.request.environ["HTTP_HOST"]+"/"
        
        logging.info("*** Server is %s" % server)
        
        if (code is None):
            logging.info("*** Code is None")
            MainView.render(self, 200, None, format)
            return

        logging.info("*** Code is %s" % code)    
        
        href = self.request.get('href').strip().encode('utf-8')
        title = self.request.get('title').strip().encode('utf-8')
        if (code == 'new') and (href is not None):
            logging.info("href is %s" % href)
            try:
                u = Urly.find_or_create_by_href(href)
                if u is not None:
                    logging.debug("Rendering with server %s" % server)
                    MainView.render(self, 200, u, format, href, title,server)
                else:
                    logging.error("Error creating urly by href: %s", str(href))
                    MainView.render(self, 400, None, format, href)
            except db.BadValueError:
                # href parameter is bad
                MainView.render(self, 400, None, format, href)
        else:
            u = Urly.find_by_code(str(code))
            if u is not None:
                MainView.render(self, 200, u, format,href,title,server)
            else:
                MainView.render(self, 404, None, format)
Esempio n. 3
0
 def get(self, code, format):
     if (code is None):
         MainView.render(self, 200, None, format)
         return
     
     base = self.request.get('href')
     params = self.request.arguments()
     for p in params:
         if (p != 'href') and (p != 'title'):
             base += '&'+str(p).strip()+'='+self.request.get(p).strip()
     href = base.strip().encode('utf-8')
     title = self.request.get('title').strip().encode('utf-8')
     if (code == 'new') and (href is not None):
         try:
             u = Urly.find_or_create_by_href(href)
             if u is not None:
                 MainView.render(self, 200, u, format, href, title)
             else:
                 logging.error("Error creating urly by href: %s", str(href))
                 MainView.render(self, 400, None, format, href)
         except db.BadValueError:
             # href parameter is bad
             MainView.render(self, 400, None, format, href)
     else:
         u = Urly.find_by_code(str(code))
         if u is not None:
             MainView.render(self, 200, u, format)
         else:
             MainView.render(self, 404, None, format)
Esempio n. 4
0
 def find_or_create_by_href(href):
     query = db.Query(Urly)
     query.filter('href =', href)
     u = query.get()
     if not u:
         u = Urly(href=href)
         u.put()
         u.save_in_cache()
     return u
Esempio n. 5
0
File: main.py Progetto: sevki/ur.ly
 def head(self, code, format):
     if (code is None):
         self.error(400)
     else:
         u = Urly.find_by_code(str(code))
         if u is not None:
             self.redirect(u.href)
         else:
             self.error(404)
Esempio n. 6
0
 def head(self, code, format):
     if (code is None):
         self.error(400)
     else:
         u = Urly.find_by_code(str(code))
         if u is not None:
             self.redirect(u.href)
         else:
             self.error(404)
Esempio n. 7
0
 def get(self, format):
     url = self.request.get('url').strip()
     if url is not None:
         try:
             valid = Urly.validate_url(url)
             if valid:
                 u = Urly.find_or_create_by_url(url)
                 if u is not None:
                     MainView.render(self, 200, u, format)
                 else:
                     logging.error("Error creating urly by url: %s", str(url))
                     MainView.render(self, 400, None, format, url)
             else:
                 logging.error("Error creating urly by url: %s", str(url))
                 MainView.render(self, 400, None, format, url)
         except db.BadValueError:
             # url parameter is bad
             MainView.render(self, 400, None, format, url)
     else:
         self.redirect('/')
Esempio n. 8
0
    def find_by_code(code):
        try:
            u = memcache.get(code)
        except:
            # http://code.google.com/p/googleappengine/issues/detail?id=417
            logging.error("Urly.find_by_code() memcached error")
            u = None

        if u is not None:
            logging.info("Urly.find_by_code() cache HIT: %s", str(code))
            return u

        logging.info("Urly.find_by_code() cache MISS: %s", str(code))
        aid = Urly.code_to_id(code)
        try:
            u = Urly.get_by_id(int(aid))
            if u is not None:
                u.save_in_cache()
            return u
        except db.BadValueError:
            return None
Esempio n. 9
0
 def get(self, code, format):
     if (code is None):
         MainView.render(self, 200, None, format)
         user = users.get_current_user()
         if user: self.response.out.write("<a href=\"" + users.create_logout_url('/') + "\">Logout</a>")
         return
     
     u = Urly.find_by_code(str(code))
     if u is not None:
         MainView.render(self, 200, u, format, preview=True)
     else:
         MainView.render(self, 404, None, format)
Esempio n. 10
0
    def find_by_code(code):
        try:
            u = memcache.get(code)
        except:
            # http://code.google.com/p/googleappengine/issues/detail?id=417
            logging.error("Urly.find_by_code() memcached error")
            u = None
        
        if u is not None:
            logging.info("Urly.find_by_code() cache HIT: %s", str(code))
            return u        

        logging.info("Urly.find_by_code() cache MISS: %s", str(code))
        aid = Urly.code_to_id(code)
        try:
            u = Urly.get_by_id(int(aid))
            if u is not None:
                u.save_in_cache()
            return u
        except db.BadValueError:
            return None
Esempio n. 11
0
 def find_or_create_by_href(href):
     query = db.Query(Urly)
     query.filter('href =', href)
     u = query.get()
     if not u:
         u = Urly(href=href)
         u.put()
         u.save_in_cache()
     return u
Esempio n. 12
0
File: main.py Progetto: sevki/ur.ly
    def get(self, code, format):
        if (code is None):
            MainView.render(self, 200, None, format)
            return

        href = self.request.get('href').strip().encode('utf-8')
        title = self.request.get('title').strip().encode('utf-8')
        if (code == 'new') and (href is not None):
            try:
                u = Urly.find_or_create_by_href(href)
                if u is not None:
                    MainView.render(self, 200, u, format, href, title)
                else:
                    logging.error("Error creating urly by href: %s", str(href))
                    MainView.render(self, 400, None, format, href)
            except db.BadValueError:
                # href parameter is bad
                MainView.render(self, 400, None, format, href)
        else:
            u = Urly.find_by_code(str(code))
            if u is not None:
                MainView.render(self, 200, u, format)
            else:
                MainView.render(self, 404, None, format)
Esempio n. 13
0
    def get(self, code, format):
        if code is None:
            MainView.render(self, 200, None, format)
            return

        href = self.request.get("href").strip().encode("utf-8")
        title = self.request.get("title").strip().encode("utf-8")
        if (code == "new") and (href is not None):
            try:
                u = Urly.find_or_create_by_href(href)
                if u is not None:
                    MainView.render(self, 200, u, format, href, title)
                else:
                    logging.error("Error creating urly by href: %s", str(href))
                    MainView.render(self, 400, None, format, href)
            except db.BadValueError:
                # href parameter is bad
                MainView.render(self, 400, None, format, href)
        else:
            u = Urly.find_by_code(str(code))
            if u is not None:
                MainView.render(self, 200, u, format)
            else:
                MainView.render(self, 404, None, format)