我们从Python开源项目中,提取了以下5个代码示例,用于说明如何使用urllib.splitquery()。
def do_GET(self): if "?payload" in self.path: query= urllib.splitquery(self.path) action = query[1].split('=')[1] print action action = urllib.unquote(action) print action try: x = cPickle.loads(action) #string argv content = "command executed" except Exception,e: print e content = e else: content = "hello World" self.send_response(200) self.send_header("Content-type","text/html") self.end_headers() self.wfile.write("<html>") self.wfile.write(" %s " % content) self.wfile.write("</html>")
def run(self, url): xbmc = self.theGlobals['xbmc'] urlScheme = urlparse.urlparse(url) if urlScheme.scheme != 'plugin': return # Plugin diferente pluginId, urlArgs = urllib.splitquery(url) self.theGlobals['sys'].argv = [pluginId, self.theGlobals['sys'].argv[1] + 1, '?' + (urlArgs or '')] self.addonID = actualID = urlScheme.netloc addonDir = xbmc.translatePath('special://home/addons/' + actualID) if addonDir.startswith('vrt:%s' % os.path.sep): self.vrtDisk.installPathHook() sys.path.insert(0, addonDir) sourceCode = self.getVrtDiskAddonSource() else: sourceCode = self.getCompiledAddonSource(actualID) self.importer.setAddonDir(addonDir) try: exec(sourceCode, self.theGlobals) except Exception as e: xbmc.log(str(e), xbmc.LOGERROR) msg = traceback.format_exc() xbmc.log(msg, xbmc.LOGERROR) self.answ = None return self.answ
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'))
def request_url(self, request_url): """?????URL ???????URL???????, ?: ??: /wp-admin/admin-ajax.php?postviews_id=1348 ???: /wp-admin/admin-ajax.php """ proto, rest = urllib.splittype(request_url) url_path, url_param = urllib.splitquery(rest) if url_path.startswith('/tag/'): url_path = '/tag/' self._request_url = url_path