def get_url_and_search()

in Xcode/AppleURLSearcher.py [0:0]


    def get_url_and_search(self, url, re_pattern, headers=None, flags=None, opts=None):
        """Get data from url and search for re_pattern"""
        flag_accumulator = 0
        if flags:
            for flag in flags:
                if flag in re.__dict__:
                    flag_accumulator += re.__dict__[flag]

        re_pattern = re.compile(re_pattern, flags=flag_accumulator)

        try:
            cmd = [self.env["CURL_PATH"], "--location", "--compressed"]
            if headers:
                for header, value in headers.items():
                    cmd.extend(["--header", "%s: %s" % (header, value)])
            if opts:
                for item in opts:
                    cmd.extend([item])
            cmd.append(url)
            proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
            (content, stderr) = proc.communicate()
            if proc.returncode:
                raise ProcessorError("Could not retrieve URL %s: %s" % (url, stderr))
        except OSError:
            raise ProcessorError("Could not retrieve URL: %s" % url)

        # Output this to disk so I can search it later
        with open(
            os.path.join(self.env["RECIPE_CACHE_DIR"], "downloads", "url_text.txt"),
            "wb",
        ) as f:
            f.write(content)
        match = re_pattern.search(content.decode('utf-8'))

        if not match:
            raise ProcessorError("No match found on URL: %s" % url)

        # return the last matched group with the dict of named groups
        return (match.group(match.lastindex or 0), match.groupdict())