def __init__(self, url, progress_cb=None, auth=None, config=None, client_string_func=None, open_tmp_file_func=None): self.url = url (type, opaque) = urlparse.splittype(url) assert type in ("svn", "svn+ssh") (host, path) = urlparse.splithost(opaque) self._progress_cb = progress_cb self._auth = auth self._config = config self._client_string_func = client_string_func # open_tmp_file_func is ignored, as it is not needed for svn:// if type == "svn": (recv_func, send_func) = self._connect(host) else: (recv_func, send_func) = self._connect_ssh(host) super(SVNClient, self).__init__(recv_func, send_func) (min_version, max_version, _, self._server_capabilities) = self._recv_greeting() self.send_msg([max_version, [literal(x) for x in CAPABILITIES if x in self._server_capabilities], self.url]) (self._server_mechanisms, mech_arg) = self._unpack() if self._server_mechanisms != []: # FIXME: Support other mechanisms as well self.send_msg([literal("ANONYMOUS"), [base64.b64encode("anonymous@%s" % socket.gethostname())]]) self.recv_msg() msg = self._unpack() if len(msg) > 2: self._server_capabilities += msg[2] (self._uuid, self._root_url) = msg[0:2] self.busy = False
def __init__(self, url, progress_cb=None, auth=None, config=None, client_string_func=None, open_tmp_file_func=None): self.url = url (type, opaque) = urlparse.splittype(url) assert type in ("svn", "svn+ssh") (host, path) = urlparse.splithost(opaque) self._progress_cb = progress_cb self._auth = auth self._config = config self._client_string_func = client_string_func # open_tmp_file_func is ignored, as it is not needed for svn:// if type == "svn": (recv_func, send_func) = self._connect(host) else: (recv_func, send_func) = self._connect_ssh(host) super(SVNClient, self).__init__(recv_func, send_func) (min_version, max_version, _, self._server_capabilities) = ( self._recv_greeting()) self.send_msg( [max_version, [literal(x) for x in CAPABILITIES if x in self._server_capabilities], self.url]) (self._server_mechanisms, mech_arg) = self._unpack() if self._server_mechanisms != []: # FIXME: Support other mechanisms as well self.send_msg([literal("ANONYMOUS"), [base64.b64encode( "anonymous@%s" % socket.gethostname())]]) self.recv_msg() msg = self._unpack() if len(msg) > 2: self._server_capabilities += msg[2] (self._uuid, self._root_url) = msg[0:2] self.busy = False
def request(self, uri, method="GET", body='', headers=None, redirections=httplib2.DEFAULT_MAX_REDIRECTS, connection_type=None): DEFAULT_POST_CONTENT_TYPE = 'application/x-www-form-urlencoded' if not isinstance(headers, dict): headers = {} if method == "POST": headers['Content-Type'] = headers.get('Content-Type', DEFAULT_POST_CONTENT_TYPE) is_form_encoded = \ headers.get('Content-Type') == 'application/x-www-form-urlencoded' if is_form_encoded and body: parameters = parse_qs(body) else: parameters = None req = Request.from_consumer_and_token(self.consumer, token=self.token, http_method=method, http_url=uri, parameters=parameters, body=body, is_form_encoded=is_form_encoded) req.sign_request(self.method, self.consumer, self.token) try: schema, rest = urllib.splittype(uri) except AttributeError: schema, rest = urlparse.splittype(uri) if rest.startswith('//'): hierpart = '//' else: hierpart = '' try: host, rest = urllib.splithost(rest) except AttributeError: host, rest = urlparse.splithost(rest) realm = schema + ':' + hierpart + host if is_form_encoded: body = req.to_postdata() elif method == "GET": uri = req.to_url() else: headers.update(req.to_header(realm=realm)) return httplib2.Http.request(self, uri, method=method, body=body, headers=headers, redirections=redirections, connection_type=connection_type)
def get_full_url(self, source_url, half_url, is_image=False, special_urls=[], img_special_urls=[]): """ 获取完整url地址 :param base_url: String 源地址 :param half_url: String 提取后的非完整url地址 :param is_image: Bool 是否是图片地址 :param special_urls: List 特殊网页拼接地址 :param img_special_urls: List 特殊图片拼接地址 :return: String 完整的url地址 """ SPECIAL_URLS = special_urls IMG_SPECIAL_URLS = img_special_urls try: protocol, result = urllib.splittype(source_url) base_url, rest = urllib.splithost(result) except: protocol, result = urlparse.splittype(source_url) base_url, rest = urlparse.splithost(result) base_url = protocol + '://' + base_url if is_image: SPECIAL_URLS = IMG_SPECIAL_URLS url_flag = False for special_url in SPECIAL_URLS: if special_url in base_url: url_flag = True if half_url.startswith('../'): filter_url = re.sub('\.\./', '', half_url) url = urlparse.urljoin(base_url, filter_url) elif not url_flag and (not half_url.startswith('/') or half_url.startswith('./')): url = urlparse.urljoin(source_url, half_url) elif half_url.startswith('//'): url = 'http:' + half_url else: url = urlparse.urljoin(base_url, half_url.strip('..')) return url
def open_backend(self, url): (rooturl, location) = urlparse.splithost(url) self.repo_backend, self.relpath = self.backend.open_repository(location)
def open_backend(self, url): (rooturl, location) = urlparse.splithost(url) self.repo_backend, self.relpath = self.backend.open_repository( location)