当前位置: 首页>>代码示例>>Python>>正文


Python urllib.splitquery方法代码示例

本文整理汇总了Python中urllib.splitquery方法的典型用法代码示例。如果您正苦于以下问题:Python urllib.splitquery方法的具体用法?Python urllib.splitquery怎么用?Python urllib.splitquery使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在urllib的用法示例。


在下文中一共展示了urllib.splitquery方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: do_GET

# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import splitquery [as 别名]
def do_GET(self):
        query = urllib.splitquery(self.path)
        path = urllib.unquote_plus(query[0]).decode("utf-8", "ignore")
        queryParams = {}

        if "?" in self.path:
            if query[1]:
                queryParams = transDicts(query[1])

        fn = "%s%s" % (g_filepath, path)
        fn = urllib.unquote_plus(fn).decode("utf-8", "ignore")
        fn = fn.replace("/",os.sep)

        content = ""
        self.send_response(200)
        self.send_header("content-type","application/json")
        if os.path.isfile(fn):
            f = open(fn, "rb")
            content = f.read()
            f.close()
            contenttype,_ = mimetypes.guess_type(fn)
            if contenttype:
                self.send_header("content-type",contenttype)
        elif os.path.isdir(fn):
            filelist = []
            for filename in os.listdir(fn):
                if filename[0] != ".":
                    filepath = "%s%s%s" % (fn, os.sep, filename)
                    if os.path.isdir(filepath):
                        filename += os.sep
                    mtime = os.path.getmtime(filepath)
                    filelist.append({"filename":filename,"mtime":mtime})
            content = json.dumps(filelist)
        else:
            print(g_filepath, path, fn)
            content = "<h1>404<h1>"
            self.send_header("content-type","text/html")

        self.end_headers()
        self.wfile.write(content) 
开发者ID:hanxi,项目名称:http-file-server,代码行数:42,代码来源:file-server.py

示例2: test_splitquery

# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import splitquery [as 别名]
def test_splitquery(self):
        # Normal cases are exercised by other tests; ensure that we also
        # catch cases with no port specified (testcase ensuring coverage)
        splitquery = urllib.splitquery
        self.assertEqual(splitquery('http://python.org/fake?foo=bar'),
                         ('http://python.org/fake', 'foo=bar'))
        self.assertEqual(splitquery('http://python.org/fake?foo=bar?'),
                         ('http://python.org/fake?foo=bar', ''))
        self.assertEqual(splitquery('http://python.org/fake'),
                         ('http://python.org/fake', None))
        self.assertEqual(splitquery('?foo=bar'), ('', 'foo=bar')) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:13,代码来源:test_urllib.py

示例3: do_POST

# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import splitquery [as 别名]
def do_POST(self):
        query = urllib.splitquery(self.path)
        path = query[0]
        queryParams = {}

        if "?" in self.path:
            if query[1]:
                queryParams = transDicts(query[1])

        resultdict = {"result":0, "msg":"OK"}
        if path=="/upload":
            if queryParams.has_key("name"):
                filesize = int(self.headers["content-length"])
                filecontent = self.rfile.read(filesize)
                fn = queryParams["name"]
                resultdict["filename"] = fn
                fn = "%s%s" % (g_filepath, fn)
                dirname = os.path.dirname(fn)
                if not os.path.exists(dirname):
                    os.makedirs(dirname)
                if os.path.isdir(fn):
                    resultdict.result = 1
                    resultdict.msg = "File name is directory."
                else:
                    f = open(fn,"wb")
                    f.write(filecontent)
                    f.close()
            else:
                resultdict.result = 2
                resultdict.msg = "Need file name."
        else:
            resultdict.result = 3
            resultdict.msg = "No this API."

        content = json.dumps(resultdict)
        self.send_response(200)
        self.send_header("content-type","application/json")
        self.end_headers()
        self.wfile.write(content) 
开发者ID:hanxi,项目名称:http-file-server,代码行数:41,代码来源:file-server.py

示例4: makeReqHeaders

# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import splitquery [as 别名]
def makeReqHeaders(self):

        range_format = self.url.range_format
        Range = (self.progress.begin + self.progress.go_inc, self.progress.end)

        req_path = self.target.path

        req_headers = dict(self.url.headers.items())

        if range_format[0] == '&':
            path, query = splitquery(self.target.path)
            query_dict = extract_query(query)
            range_format = range_format % Range
            for i in range_format[1:].split('&'):
                param_key, param_value = splitvalue(i)
                query_dict[param_key] = param_value

            new_query = urlencode(query_dict)
            req_path = '%s?%s' % (path, new_query)

        else:

            range_field = range_format % Range
            key_value = [i.strip() for i in range_field.split(':')]

            key = key_value[0]
            value = key_value[1]

            add_headers = {
                key: value,
                'Accept-Ranges': 'bytes'
            }

            req_headers.update(add_headers)

        return req_path, req_headers 
开发者ID:ZSAIm,项目名称:iqiyi-parser,代码行数:38,代码来源:DLProcessor.py

示例5: process

# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import splitquery [as 别名]
def process(self, type):
		#是否注册了处理程序
		query = urllib.parse.splitquery(self.path)
		path = query[0]
		if not path in self.respondFunc:
			return self.send_error(404, 'File Not Found: %s' % path)
		#获取get和post数据
		get, post = self.get_post_data(query)
		content = self.respondFunc[path](get, post)
		try:
			self.send_response(200)
			self.send_header('Content-type','text/html')
			self.end_headers()
			if content:
				self.wfile.write(content.encode())
			else:
				self.wfile.write(b'')
			#f.close()
		except IOError:
			self.send_error(500, 'System error : %s' % path)


		'''
		#print(str(self))
		#return
		content = ""
		if type==1:#post方法,接收post参数
			datas = self.rfile.read(int(self.headers['content-length']))
			datas = urllib.unquote(datas).decode("utf-8", 'ignore')#指定编码方式
			datas = transDicts(datas)#将参数转换为字典
			if datas.has_key('data'):
				content = "data:"+datas['data']+"\r\n"
		if '?' in self.path:
			query = urllib.splitquery(self.path)
			action = query[0]
			if query[1]:#接收get参数
				queryParams = {}
				for qp in query[1].split('&'):
					kv = qp.split('=')
					queryParams[kv[0]] = urllib.unquote(kv[1]).decode("utf-8", 'ignore')
					content+= kv[0]+':'+queryParams[kv[0]]+"\r\n"
		#指定返回编码
		enc="UTF-8"
		content = content.encode(enc)
		f = io.BytesIO()
		f.write(content)
		f.seek(0)
		self.send_response(200)
		self.send_header("Content-type", "text/html; charset=%s" % enc)
		self.send_header("Content-Length", str(len(content)))
		self.end_headers()
		shutil.copyfileobj(f,self.wfile)
		'''


##注册处理程序 
开发者ID:jojoin,项目名称:cutout,代码行数:58,代码来源:http.py


注:本文中的urllib.splitquery方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。