def GET(self, clazz, name): print ctx.get("query");#可以通过ctx获得各种头信息 params = input();#通过input可以获得一些参数 for key, value in params.items(): print key, value; return "Listing info about class: {0},user: {1}".format(clazz, name);
def GET(self, scope, name): """ List all replicas for data identifiers. HTTP Success: 200 OK HTTP Error: 401 Unauthorized 500 InternalError :returns: A dictionary containing all replicas information. :returns: A metalink description of replicas if metalink(4)+xml is specified in Accept: """ metalink = None if ctx.env.get('HTTP_ACCEPT') is not None: tmp = ctx.env.get('HTTP_ACCEPT').split(',') # first check if client accepts metalink if 'application/metalink+xml' in tmp: metalink = 3 # but prefer metalink4 if the client has support for it # (clients can put both in their ACCEPT header!) if 'application/metalink4+xml' in tmp: metalink = 4 dids, schemes, select, limit = [{'scope': scope, 'name': name}], None, None, None if ctx.query: try: params = loads(unquote(ctx.query[1:])) if 'schemes' in params: schemes = params['schemes'] except ValueError: params = parse_qs(ctx.query[1:]) if 'select' in params: select = params['select'][0] if 'limit' in params: limit = int(params['limit'][0]) try: # first, set the appropriate content type, and stream the header if metalink is None: header('Content-Type', 'application/x-json-stream') elif metalink == 3: header('Content-Type', 'application/metalink+xml') schemes = ['http', 'https'] yield '<?xml version="1.0" encoding="UTF-8"?>\n<metalink version="3.0" xmlns="http://www.metalinker.org/">\n<files>\n' elif metalink == 4: header('Content-Type', 'application/metalink4+xml') schemes = ['http', 'https'] yield '<?xml version="1.0" encoding="UTF-8"?>\n<metalink xmlns="urn:ietf:params:xml:ns:metalink">\n' # then, stream the replica information for rfile in list_replicas(dids=dids, schemes=schemes): client_ip = ctx.get('ip') replicas = [] dictreplica = {} for rse in rfile['rses']: for replica in rfile['rses'][rse]: replicas.append(replica) dictreplica[replica] = rse if select == 'geoip': try: replicas = geoIP_order(dictreplica, client_ip) except AddressNotFoundError: pass else: replicas = random_order(dictreplica, client_ip) if metalink is None: yield dumps(rfile) + '\n' elif metalink == 3: idx = 0 yield ' <file name="' + rfile['name'] + '">\n <resources>\n' for replica in replicas: yield ' <url type="http" preference="' + str(idx) + '">' + replica + '</url>\n' idx += 1 if limit and limit == idx: break yield ' </resources>\n </file>\n' elif metalink == 4: yield ' <file name="' + rfile['name'] + '">\n' yield ' <identity>' + rfile['scope'] + ':' + rfile['name'] + '</identity>\n' if rfile['adler32'] is not None: yield ' <hash type="adler32">' + rfile['adler32'] + '</hash>\n' if rfile['md5'] is not None: yield ' <hash type="md5">' + rfile['md5'] + '</hash>\n' yield ' <size>' + str(rfile['bytes']) + '</size>\n' idx = 0 for replica in replicas: yield ' <url location="' + str(dictreplica[replica]) + '" priority="' + str(idx + 1) + '">' + replica + '</url>\n' idx += 1 if limit and limit == idx: break yield ' </file>\n' # don't forget to send the metalink footer if metalink: if metalink == 3: yield '</files>\n</metalink>\n' elif metalink == 4: yield '</metalink>\n' except DataIdentifierNotFound, e: raise generate_http_error(404, 'DataIdentifierNotFound', e.args[0][0])
def GET(self, scope, name): """ Redirect download HTTP Success: 303 See Other HTTP Error: 401 Unauthorized 500 InternalError 404 Notfound :param scope: The scope name of the file. :param name: The name of the file. """ header("Access-Control-Allow-Origin", ctx.env.get("HTTP_ORIGIN")) header("Access-Control-Allow-Headers", ctx.env.get("HTTP_ACCESS_CONTROL_REQUEST_HEADERS")) header("Access-Control-Allow-Methods", "*") header("Access-Control-Allow-Credentials", "true") try: replicas = [ r for r in list_replicas(dids=[{"scope": scope, "name": name, "type": "FILE"}], schemes=["http", "https"]) ] select = "random" rse = None site = None if ctx.query: params = parse_qs(ctx.query[1:]) if "select" in params: select = params["select"][0] if "rse" in params: rse = params["rse"][0] if "site" in params: site = params["site"][0] for r in replicas: if r["rses"]: replicadict = {} if rse: if rse in r["rses"] and r["rses"][rse]: return found(r["rses"][rse][0]) return notfound("Sorry, the replica you were looking for was not found.") else: for rep in r["rses"]: for replica in r["rses"][rep]: replicadict[replica] = rep if not replicadict: return notfound("Sorry, the replica you were looking for was not found.") elif site: rep = site_selector(replicadict, site) if rep: return found(rep[0]) return notfound("Sorry, the replica you were looking for was not found.") else: client_ip = ctx.get("ip") if select == "geoip": rep = geoIP_order(replicadict, client_ip) else: rep = random_order(replicadict, client_ip) return found(rep[0]) return notfound("Sorry, the replica you were looking for was not found.") except RucioException, e: raise generate_http_error(500, e.__class__.__name__, e.args[0][0])