예제 #1
0
    def cat_file(self, path, rev="tip"):
        if rev == HEAD or rev == UNKNOWN:
            rev = "tip"
        elif rev == PRE_CREATION:
            rev = ""

        for rawpath in ["raw-file", "raw", "hg-history"]:
            try:
                base_url = self.path.rstrip('/')

                if rawpath == 'hg-history':
                    base_url = self.path[:self.path.rfind('/')]

                url = self.FULL_FILE_URL % {
                    'url': base_url,
                    'rawpath': rawpath,
                    'revision': rev,
                    'quoted_path': urllib_quote(path.lstrip('/')),
                }

                return self.get_file_http(url, path, rev)
            except Exception:
                # It failed. Error was logged and we may try again.
                pass

        raise FileNotFoundError(path, rev)
예제 #2
0
파일: hg.py 프로젝트: harrifeng/reviewboard
    def cat_file(self, path, rev="tip"):
        if rev == HEAD or rev == UNKNOWN:
            rev = "tip"
        elif rev == PRE_CREATION:
            rev = ""

        for rawpath in ["raw-file", "raw", "hg-history"]:
            try:
                base_url = self.path.rstrip('/')

                if rawpath == 'hg-history':
                    base_url = self.path[:self.path.rfind('/')]

                url = self.FULL_FILE_URL % {
                    'url': base_url,
                    'rawpath': rawpath,
                    'revision': rev,
                    'quoted_path': urllib_quote(path.lstrip('/')),
                }

                return self.get_file_http(url, path, rev)
            except Exception:
                # It failed. Error was logged and we may try again.
                pass

        raise FileNotFoundError(path, rev)
예제 #3
0
파일: hg.py 프로젝트: nzhuk/reviewboard
    def cat_file(self, path, rev="tip"):
        if rev == HEAD or rev == UNKNOWN:
            rev = "tip"
        elif rev == PRE_CREATION:
            rev = ""

        found = False
		
        try:
            full_url = self.FULL_FILE_URL % {
                   'username': self.username,
                   'repository': self.name,
                   'revision': rev,
                   'quoted_path': urllib_quote(path.lstrip('/')),
            }
            request = urllib2.Request(full_url)
            authHeader = base64.encodestring('%s:%s' % (self.username, self.password)).replace('\n', '')
            request.add_header("Authorization", "Basic %s" % authHeader)   
            result = urllib2.urlopen(request)
            return result.read();
            
        except urllib2.HTTPError, e:

        	if e.code != 404:
        	    logging.error("%s: HTTP error code %d when fetching "
        	    "file from %s: %s", self.__class__.__name__,
                e.code, full_url, e)
예제 #4
0
    def cat_file(self, path, rev="tip"):
        if rev == HEAD or rev == UNKNOWN:
            rev = "tip"
        elif rev == PRE_CREATION:
            rev = ""

        found = False

        for rawpath in ["raw-file", "raw"]:
            url = ''

            try:
                url = self.FULL_FILE_URL % {
                    'url': self.url.rstrip('/'),
                    'rawpath': rawpath,
                    'revision': rev,
                    'quoted_path': urllib_quote(path.lstrip('/')),
                }
                logging.info('Fetching file from %s' % url)
                auth = requests.auth.HTTPBasicAuth(self.username, self.password)
                response = requests.get(url, auth=auth)
                if response.status_code == requests.codes.ok:
                    return response.text
                elif response.status_code != 404:
                    response.raise_for_status()

            except Exception, e:
                logging.error('%s: Error fetching file from %s: %s' %
                              (self.__class__.__name__, url, e))
                raise SCMError('Error fetching file from %s: %s' % (url, e))
예제 #5
0
    def cat_file(self, path, rev="tip"):
        if rev == HEAD or rev == UNKNOWN:
            rev = "tip"
        elif rev == PRE_CREATION:
            rev = ""

        found = False

        try:
            full_url = self.FULL_FILE_URL % {
                'username': self.username,
                'repository': self.name,
                'revision': rev,
                'quoted_path': urllib_quote(path.lstrip('/')),
            }
            request = urllib2.Request(full_url)
            authHeader = base64.encodestring(
                '%s:%s' % (self.username, self.password)).replace('\n', '')
            request.add_header("Authorization", "Basic %s" % authHeader)
            result = urllib2.urlopen(request)
            return result.read()

        except urllib2.HTTPError, e:

            if e.code != 404:
                logging.error(
                    "%s: HTTP error code %d when fetching "
                    "file from %s: %s", self.__class__.__name__, e.code,
                    full_url, e)
예제 #6
0
    def cat_file(self, path, rev="tip"):
        if rev == HEAD:
            rev = "tip"
        elif rev == PRE_CREATION:
            rev = ""

        found = False

        for rawpath in ["raw-file", "raw"]:
            try:
                passman = urllib2.HTTPPasswordMgrWithDefaultRealm()
                passman.add_password(None, self.url, self.username,
                                     self.password)
                authhandler = urllib2.HTTPBasicAuthHandler(passman)
                opener = urllib2.build_opener(authhandler)
                f = opener.open('%s/%s/%s/%s' %
                                (self.url, rawpath, rev, urllib_quote(path)))
                return f.read()
            except Exception, e:
                pass
예제 #7
0
파일: hg.py 프로젝트: aineko/reviewboard
    def cat_file(self, path, rev="tip"):
        if rev == HEAD or rev == UNKNOWN:
            rev = "tip"
        elif rev == PRE_CREATION:
            rev = ""

        for rawpath in ["raw-file", "raw"]:
            try:
                url = self.FULL_FILE_URL % {
                    'url': self.path.rstrip('/'),
                    'rawpath': rawpath,
                    'revision': rev,
                    'quoted_path': urllib_quote(path.lstrip('/')),
                }

                url = url.replace('https', 'http')
                return self.get_file_http(url, path, rev)
            except Exception:
                # It failed. Error was logged and we may try again.
                pass

        raise FileNotFoundError(path, rev)
예제 #8
0
파일: hg.py 프로젝트: smacleod/reviewboard
    def cat_file(self, path, rev="tip"):
        if rev == HEAD or rev == UNKNOWN:
            rev = "tip"
        elif rev == PRE_CREATION:
            rev = ""

        found = False

        for rawpath in ["raw-file", "raw"]:
            full_url = ""

            try:
                passman = urllib2.HTTPPasswordMgrWithDefaultRealm()
                passman.add_password(None, self.url, self.username, self.password)
                authhandler = urllib2.HTTPBasicAuthHandler(passman)
                opener = urllib2.build_opener(authhandler)
                full_url = self.FULL_FILE_URL % {
                    "url": self.url.rstrip("/"),
                    "rawpath": rawpath,
                    "revision": rev,
                    "quoted_path": urllib_quote(path.lstrip("/")),
                }
                f = opener.open(full_url)
                return f.read()

            except urllib2.HTTPError, e:

                if e.code != 404:
                    logging.error(
                        "%s: HTTP error code %d when fetching " "file from %s: %s",
                        self.__class__.__name__,
                        e.code,
                        full_url,
                        e,
                    )

            except Exception:
                logging.exception("%s: Non-HTTP error when fetching %r: ", self.__class__.__name__, full_url)
예제 #9
0
파일: hg.py 프로젝트: isakb/reviewboard
    def cat_file(self, path, rev="tip"):
        if rev == HEAD or rev == UNKNOWN:
            rev = "tip"
        elif rev == PRE_CREATION:
            rev = ""

        found = False

        for rawpath in ["raw-file", "raw"]:
            full_url = ''

            try:
                passman = urllib2.HTTPPasswordMgrWithDefaultRealm()
                passman.add_password(None, self.url, self.username,
                                     self.password)
                authhandler = urllib2.HTTPBasicAuthHandler(passman)
                opener = urllib2.build_opener(authhandler)
                full_url = self.FULL_FILE_URL % {
                    'url': self.url.rstrip('/'),
                    'rawpath': rawpath,
                    'revision': rev,
                    'quoted_path': urllib_quote(path.lstrip('/')),
                }
                f = opener.open(full_url)
                return f.read()

            except urllib2.HTTPError, e:

                if e.code != 404:
                    logging.error(
                        "%s: HTTP error code %d when fetching "
                        "file from %s: %s", self.__class__.__name__, e.code,
                        full_url, e)

            except Exception:
                logging.exception('%s: Non-HTTP error when fetching %r: ',
                                  self.__class__.__name__, full_url)
예제 #10
0
 def _build_raw_url(self, path, revision):
     url = self.raw_file_url
     url = url.replace("<revision>", revision)
     url = url.replace("<filename>", urllib_quote(path))
     return url
예제 #11
0
def quoteUrl(sText):
    """
    See urllib.quote().
    """
    return urllib_quote(sText)
예제 #12
0
def quoteUrl(sText):
    """
    See urllib.quote().
    """
    return urllib_quote(sText);