<commit_before># Copyright (c) 2010 <NAME>
# Licensed under the MIT license

import os
import traceback
import urllib
import urllib2
import urlparse

from combine import Package, File, log

class URI:

    def __init__(self, uri, package=None, format=None, target=None):
        self.uri = uri
        self.parse = urlparse.urlparse(uri)
        self.package = package
        self.format = format
        self.target = target
        self.handle = None

    def __getitem__(self, key):
        return self.parse.__getattribute__(key)

    def fetch(self, target=None):
        parse = self.parse

        # local file
        if parse.scheme == "file":
            self.handle = File(parse.path, "r", format=self.format)

            if target:
                self.handle.decompress(target)
                self.handle.close()
                self.handle = File(target, "r")

        # package file
        elif parse.scheme == "package":
            if self.package is None:
                raise Exception("No package specified")

            filename = parse.path.lstrip("/")
            self.handle = self.package.open(filename, "r", format=self.format)

            if target:
                self.handle.decompress(target)
                self.handle.close()
                self.handle = File(target, "r")

        # remote http resource
        elif parse.scheme in ("http", "https"):
            failure = False
            tries = 0

            while failure:
                failure = False

                try:
                    if target:
                        log.info("Downloading {0} to file {1}".format(self.uri, target))
                        downloadpath, headers = urllib.urlretrieve(self.uri)
                        self.handle = File(downloadpath, "r", format=self.format)
                        self.handle.decompress(target)
                        self.handle.close()
                        self.handle = File(target, "r")
                    else:
                        self.handle = urllib2.urlopen(self.uri)

                except:
                    failure = True
                    if tries < 3:
                        log.info("Problem retrieving URI, retry in 3 seconds...")
                        log.debug(traceback.format_exception(sys.exc_type,
                                                             sys.exc_value,
                                                             sys.exc_traceback))
                        os.sleep(3)

                    else:
                        log.info("Failed retrieving URI")
                        raise

                finally:<commit_msg>Fix the URI retry guard condition<commit_after># Copyright (c) 2010 <NAME>
# Licensed under the MIT license

import os
import traceback
import urllib
import urllib2
import urlparse

from combine import Package, File, log

class URI:

    def __init__(self, uri, package=None, format=None, target=None):
        self.uri = uri
        self.parse = urlparse.urlparse(uri)
        self.package = package
        self.format = format
        self.target = target
        self.handle = None

    def __getitem__(self, key):
        return self.parse.__getattribute__(key)

    def fetch(self, target=None):
        parse = self.parse

        # local file
        if parse.scheme == "file":
            self.handle = File(parse.path, "r", format=self.format)

            if target:
                self.handle.decompress(target)
                self.handle.close()
                self.handle = File(target, "r")

        # package file
        elif parse.scheme == "package":
            if self.package is None:
                raise Exception("No package specified")

            filename = parse.path.lstrip("/")
            self.handle = self.package.open(filename, "r", format=self.format)

            if target:
                self.handle.decompress(target)
                self.handle.close()
                self.handle = File(target, "r")

        # remote http resource
        elif parse.scheme in ("http", "https"):
            failure = True
            tries = 0

            while failure:
                failure = False

                try:
                    if target:
                        log.info("Downloading {0} to file {1}".format(self.uri, target))
                        downloadpath, headers = urllib.urlretrieve(self.uri)
                        self.handle = File(downloadpath, "r", format=self.format)
                        self.handle.decompress(target)
                        self.handle.close()
                        self.handle = File(target, "r")
                    else:
                        self.handle = urllib2.urlopen(self.uri)

                except:
                    failure = True
                    if tries < 3:
                        log.info("Problem retrieving URI, retry in 3 seconds...")
                        log.debug(traceback.format_exception(sys.exc_type,
                                                             sys.exc_value,
                                                             sys.exc_traceback))
                        os.sleep(3)

                    else:
                        log.info("Failed retrieving URI")
                        raise

                finally:
{'fraction_non_alphanumeric': 0.08921513269339357, 'fraction_numerical': 0.004517221908526256, 'mean_word_length': 1.2421940928270043, 'pattern_counts': {'":': 4, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 14, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2523249', 'n_tokens_mistral': 1336, 'n_tokens_neox': 1237, 'n_words': 326}