def main(): try: if os.environ['REQUEST_METHOD'] != 'POST': # Forbidden raise Forbidden user = users.get_current_user() if user == None: raise Forbidden form = cgi.FieldStorage() r_id = form.getfirst("id") r_token = form.getfirst("token") r_action = form.getfirst("action") if r_action != 'del': raise Forbidden page = models.Page.get_by_key_name('K' + r_id) if page is None or page.public < 0: raise NotFound if not users.is_current_user_admin() and page.owner != user: raise Forbidden if r_token != tools.token(page, user): raise Forbidden page.public = -1 page.put() tools.redirect('/my') except Forbidden: tools.printError( "Forbidden", "You've just tried to do some evil thing. We didn't expect that of you." ) except NotFound: tools.printError("Not found", "We think you are playing unfair.")
def main(): try: args = cgi.FieldStorage() r_id = args.getfirst("id") cookies = Cookie.SimpleCookie(os.environ['HTTP_COOKIE']) r_token = cookies['anonymous_token'].value user = users.get_current_user() if not user: raise Forbidden page = models.Page.get_by_key_name('K' + r_id) if page is None: raise NotFound(id) if page.public != 0: raise Forbidden if not isAnonymous(page.owner): raise Forbidden if r_token != tools.token(page, page.owner): raise Forbidden page.public = 1 page.owner = user page.put() tools.redirect('/' + page.key().name()[1:]) except Forbidden: tools.printError( "Forbidden", "You've just tried to do some evil thing. We didn't expect that of you." ) except NotFound: tools.printError("Not found", "We think you are playing unfair.")
def main(): if os.environ['REQUEST_METHOD'] != 'POST': # Forbidden tools.redirect('/') exit() form = cgi.FieldStorage() r_url = form.getfirst("r_url") r_content = form.getfirst("r_content") r_type = form.getfirst("r_type") r_url = unicode(r_url, 'utf-8') if r_url else None r_content = r_content if r_content else None r_type = unicode(r_type, 'utf-8') if r_type else None if not r_url or r_url == 'http://': # url not passed tools.redirect('/') exit() if not r_url.startswith('http://') and not r_url.startswith('https://'): r_url = 'http://'+r_url try: if not r_content or not r_type: r_content, r_type, r_url = fetch(r_url) except DownloadFail, e: tools.printError('Download error', 'Sorry, we couldn\'t access to address you provided. Please try again in a few seconds.') tools.logException() exit()
def main(): try: args = cgi.FieldStorage() r_id = args.getfirst("id") cookies = Cookie.SimpleCookie(os.environ['HTTP_COOKIE']) r_token = cookies['anonymous_token'].value user = users.get_current_user() if not user: raise Forbidden page = models.Page.get_by_key_name('K'+r_id) if page is None: raise NotFound(id) if page.public != 0: raise Forbidden if not isAnonymous(page.owner): raise Forbidden if r_token != tools.token(page, page.owner): raise Forbidden page.public = 1 page.owner = user page.put() tools.redirect('/'+page.key().name()[1:]) except Forbidden: tools.printError("Forbidden", "You've just tried to do some evil thing. We didn't expect that of you.") except NotFound: tools.printError("Not found", "We think you are playing unfair.")
def main(): try: if os.environ['REQUEST_METHOD'] != 'POST': # Forbidden raise Forbidden if users.get_current_user() == None: raise Forbidden form = cgi.FieldStorage() r_id = form.getfirst("id") r_token = form.getfirst("token") r_action = form.getfirst("action") if r_action != 'del': raise Forbidden page = models.Page.get_by_key_name('K'+r_id) if page is None or page.public < 0: raise NotFound if not users.is_current_user_admin() and page.owner != users.get_current_user(): raise Forbidden if r_token != tools.token(page): raise Forbidden page.public = -1 page.put() tools.redirect('/my') except Forbidden: tools.printError("Forbidden", "You've just tried to do some evil thing. We didn't expect that of you.") except NotFound: tools.printError("Not found", "We think you are playing unfair.")
def main(): if os.environ['REQUEST_METHOD'] != 'POST': # Forbidden tools.redirect('/') exit() form = cgi.FieldStorage() r_url = form.getfirst("r_url") r_content = form.getfirst("r_content") r_type = form.getfirst("r_type") r_url = unicode(r_url, 'utf-8') if r_url else None r_content = r_content if r_content else None r_type = unicode(r_type, 'utf-8') if r_type else None verified = False if not r_url or r_url == 'http://': # url not passed tools.redirect('/') exit() if not r_url.startswith('http://') and not r_url.startswith('https://'): r_url = 'http://'+r_url user = users.get_current_user() public = 1 if user is not None else 0 if user: owner = user else: owner = generateAnonymous() try: if not r_content or not r_type: r_content, r_type, r_url = fetch(r_url) verified = True except DownloadFail, e: tools.printError('Download error', 'Sorry, we couldn\'t access to address you provided. Please try again in a few seconds.') tools.logException() exit()
''' for stability, calculate ordinate of fit values''' from uncertainties import ufloat import numpy y = ["-113.161522564 +/- 24.1559875092", "26.3560023073 +/- 50.4099140061", "-69.3503185589 +/- 56.7122509259", "-115.105245988 +/- 56.0641568581", "-22.1584551362 +/- 32.2763627437", "-50.4901873138 +/- 18.9218106161"] means = [] weights = [] for i in y: means.append( ufloat(i).nominal_value) weights.append( ufloat(i).std_dev()**2) val, error = numpy.average( numpy.array( means ) , weights = numpy.array( weights ) ,returned = True) error = 1. / numpy.sqrt( error ) from tools import printError printError( val, error)