コード例 #1
0
def application(environ, start_response):
    startTime = time.time()
    host = environ['HTTP_HOST']

    #req.write("Heeello World!"+req.uri)
    #qs = environ["QUERY_STRING"]
    ua = environ["HTTP_USER_AGENT"]
    print "BROWSER****", ua
    iev = ieVersion(ua)
    print "VERSION", iev
    print "CLOAKING", constants.nowCloaking
    constants.ieVersion = iev
    ruri = environ["REQUEST_URI"]
    print "DISPATCH ruri = " + str(ruri)
    prsu = urlparse.urlparse(ruri)
    qs = prsu.query
    nocloak = False
    if qs:
        qsp = urlparse.parse_qs(qs)
        print "QS", qs, "QSP", qsp
        nocloak = qsp.get('nocloak', False)  #for debugging
    print "PRSU", prsu
    print "ZZZZ"
    path = prsu.path
    if host == "imagediver.org":
        redir = redirect.get(path, None)
        if redir:
            return redirectResponse("http://s3.imagediver.org" + path,
                                    start_response)

    if iev:
        if iev < 7:
            webin = WebInput(path, qs, None, None, 0)
            webout = emitUnsupportedBrowserPage(webin, iev)
            return startResponse(webout, start_response)
    #if path == "/":
    #  path = rootPage
    """
  CLOAKING GONE
  cloakedPath = cloaked.get(path,None)
  clk = (not nocloak) and constants.nowCloaking and cloakedPath
  if clk:
    print "CLOAK",path
    webout = emitCloak(path,qs)
    print "ELAPSED TIME IS ",time.time() - startTime
    return startResponse(webout,start_response)
  host = environ['HTTP_HOST']
  """
    Logr.log("dispatch", "\n\n\n" + host)
    #Logr.log("dispatch",str(environ))
    #overCapacity = checkOverCapacity()
    ua = environ['HTTP_USER_AGENT']
    Logr.log("dispatch", ua)
    #iemt = re.search("MSIE (\d)",ua)
    #iev = None

    cookie = environ.get("HTTP_COOKIE", None)
    if cookie:
        Logr.log("dispatch", "cookie: [" + cookie + "]")
    isdev = host.find("dev.") == 0
    constants.devVersion = isdev
    theStore.cStore = None  # modules persist through invocations
    session = None
    if cookie:
        mt = re.search("sessionId\=(\w*)", cookie)
        if mt:
            sessionId = mt.group(1)
            Logr.log("api", "SESSIONID =[" + sessionId + "]")
            session = models.loadSessionD(sessionId)
            if session:
                Logr.log("api", "SESSION: " + str(session.__dict__))
            else:
                Logr.log("api", "SESSION " + sessionId + " not found")
    #Logr.log("test","TEST CONSTANT in LOGIN "+str(constants.__dict__.keys()))
    cln = environ.get("CONTENT_LENGTH", None)
    #cln = environ.get("HTTP_REFERER",None)
    Logr.log("dispatch", "contentt length:" + str(cln))
    cn = None
    istr = None
    if cln != None:
        Logr.log("dispatch", "content length:" + cln)
        istr = environ["wsgi.input"]
        cln = int(cln)
        #cn = istr.read(int(cln))
        #return startResponse(WebResponse("200 OK","text/plain","ookk"),start_response)
    #Logr.log("dispatch","content:"+cn)
    webin = WebInput(path, qs, istr, session, cln)
    Logr.log(
        "dispatch",
        "pathh = [{0}] qs = {1} session= {2} contentLength {3}".format(
            path, qs, session, cln)
    )  # watch out this requires stringifying webin, whether or not he dispatch tag is asserted
    if path == "/login":
        webout = emitLoginPage(webin)
        return startResponse(webout, start_response)
    if path == "/":
        webout = emitGalleryPage(webin)
        return startResponse(webout, start_response)
        """
    pp = apiutils.parsePath("/topic/album/cg/astoria_1923_1/1")
    if overCapacity:
      webout = emitOverCapacity(webin)
    else:
      webout = emitAlbumPage(webin,pp,True)
    return startResponse(webout,start_response)
    """
    print "WHY"
    pageEmitter = pageEmitters.get(path, None)
    if pageEmitter:
        webout = pageEmitter(webin)
        return startResponse(webout, start_response)
    if iev and path == "/unsupported_browser":
        webout = emitUnsupportedBrowserPage(iev)
        return startResponse(webout, start_response)
    isTopic = (path.find("/topic/") == 0) and (
        path.find("topic.json") < 0)  # topic.json's are handled by the api
    if isTopic:
        #if overCapacity:
        #  webout = emitOverCapacity(webin)
        #else:
        webout = topicHandler(webin)
        print "ELAPSED TIME IS ", time.time() - startTime

        return startResponse(webout, start_response)
    isApiCall = (path.find("/api/") == 0) or (path.find("topic.json") > 0)
    if isApiCall:
        hasMethod = path.find("()") > 0
        ps = path.split("/")
        Logr.log("api", "dispatch to api " + str(ps))
        lnps = len(ps)
        if lnps > 3:
            webout = emitJson(webin)
            return startResponse(webout, start_response)
        if len(ps) == 3:
            methodName = ps[2]
            Logr.log("api", "callingg method [" + methodName + "]")
            method = methods.get(methodName, None)
            if method == None:
                js = json.dumps({"status": "error", "msg": "no such method"})
                webout = WebResponse('200 OK', "application/json", js)
            else:
                webout = method(webin)
            Logr.log("api", "WEBOUT " + str(webout.__dict__))
            return startResponse(webout, start_response)
            #return startResponse(WebResponse("200 OK","text/plain","ok"),start_response)
    webout = emitNoSuchPage(webin)
    return startResponse(webout, start_response)
    """ the old mod_python code
コード例 #2
0
ファイル: model.py プロジェクト: chrisGoad/imagediver_sv
iii = snaps.xferSnaps("/album/cg/The_Ambassadors/1")
iii = snaps.xferSnaps("/album/cg/The_Ambassadors/2")



uu = models.UserD('/user/cg')
ss = uu.newSession()
dyn.createCountTable()
#dyn.deleteSessionTable()
#dyn.createSessionTable()
#st = dyn.sessionTable()
sid = '/session/9c60baf173ef3135aa5c2a10f52272f29aeafe0b12bfe19c8e9d6b2f'
sid = '/session/63a6be36afe13bd531777f885a6e88ad14465a1967e92baa7cb3515c'
ssid = '63a6be36afe13bd531777f885a6e88ad14465a1967e92baa7cb3515c'
ss = dyn.getSession(sid)
aa = models.loadSessionD(ssid)
ss = dyn.deactivateSession(sid)

ss = dyn.newSession('/user/cg')

st = dyn.snapTable()
st.update_throughput(40,10)
ss = dyn.snapTopicsInAlbum('/album/cg/The_Dutch_Proverbs/1')
sss = dyn.getTopics('Snap',ss)

sss = dyn.getSnaps(ss)




ff = []
コード例 #3
0
def application(environ, start_response):
  startTime = time.time()
  if constants.maintainenceMode:
    webout = WebResponse("200 OK","text/html",constants.maintainencePage)
    webout.startTime = startTime
    return startResponse(webout,start_response)
  host = environ['HTTP_HOST']
  setDomainVars(host)
  raddr = environ['REMOTE_ADDR']
  constants.remote_addr = raddr
  ua = environ["HTTP_USER_AGENT"]
  vprint("BROWSER****",ua)
  iev = ieVersion(ua)
  vprint("VERSION",iev)
  constants.ieVersion = iev
  ruri = environ["REQUEST_URI"]
  mprint("RURI ",ruri)
  prsu = urlparse.urlparse(ruri)
  qs = prsu.query
  cookie = environ.get("HTTP_COOKIE",None)
  sessionId = None
  if cookie:
    mt = re.search("sessionId\=(\w*)",cookie)
    if mt:
      sessionId = mt.group(1)
  vprint("PRSU",prsu)
  path = prsu.path
  if path == "/env":
    rs = ['{0}: {1}'.format(key,value) for key,value in sorted(environ.items())]
    frs = "\n".join(rs)
    webout = WebResponse("200 OK","text/plain",frs)
    webout.startTime = startTime
    return startResponse(webout,start_response) 
  rdir = redirectMap.get(path,None)
  if rdir:
    return redirectTo(rdir,start_response)
  """
  if 0 and (path == constants.homeJsonPath):
    fl = open(constants.pageRoot+"home.json")
    cn = fl.read()
    fl.close()
    webout =  WebResponse('200 OK',"application/json",cn)
    webout.startTime = startTime
    return startResponse(webout,start_response)
  """
  ua = environ['HTTP_USER_AGENT']
  session = None
  if sessionId:
    session = models.loadSessionD(sessionId)
  if path == "/":
    #if session:
    #  path  = "/mywork"
    #else:
    path = "/home"
  cln = environ.get("CONTENT_LENGTH",None)
  cn = None
  istr = None
  if cln!=None:
    istr = environ["wsgi.input"]
    cln = int(cln)
  webin = WebInput(path,qs,istr,session,cln)
  if iev:
    if iev < 7:
      webout = emitUnsupportedBrowserPage(webin,iev)
      return startResponse(webout,start_response)
  constants.webin = webin
  pathsplit = path.split("/")
  path1 = pathsplit[1]
  vprint("PATH ",path,path1)
  if path1 in thePages:
    if (path1 === "googlee28c8d08ee2e2f69.html")
      path1 = "googlee28c8d08ee2e2f69"
    pim = __import__("pages."+path1,None,None,"emitPage")
    webout = pim.emitPage(webin)
    webout.startTime = startTime
    return startResponse(webout,start_response)
  if iev and path=="/unsupported_browser":
    webout = emitUnsupportedBrowserPage(webin,iev)
    return startResponse(webout,start_response)
  isTopic = ((path.find("/topic/")==0) or (path.find("/topicd/")==0)) and (path.find("main.json")<0) # main.json's are handled by the api
  if isTopic:
    webout = topicHandler(webin)
    webout.startTime = startTime
    return startResponse(webout,start_response)
  isApiCall = (path.find("/api/")==0) or (path.find("main.json")>0)
  if isApiCall:
    hasMethod = path.find("()")>0
    ps = path.split("/")
    vprint("api","dispatch to api "+str(ps))
    lnps = len(ps)
    if lnps > 3:
      webout = emitJson(webin)
      webout.startTime = startTime
      return startResponse(webout,start_response)
    if len(ps)==3:
      methodName=ps[2]
      method = methods.get(methodName,None);
      if method == None:
        js = json.dumps({"status":"error","msg":"no such method"})
        webout = WebResponse('200 OK',"application/json",js)
      else:
        webout = method(webin)
      webout.startTime = startTime
      return startResponse(webout,start_response)
  webout = emitNotFound(webin);
  webout.startTime = startTime
  return startResponse(webout,start_response)