当前位置: 首页>>代码示例>>Python>>正文


Python HTTP.get_file方法代码示例

本文整理汇总了Python中http.HTTP.get_file方法的典型用法代码示例。如果您正苦于以下问题:Python HTTP.get_file方法的具体用法?Python HTTP.get_file怎么用?Python HTTP.get_file使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在http.HTTP的用法示例。


在下文中一共展示了HTTP.get_file方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: RipperSVN

# 需要导入模块: from http import HTTP [as 别名]
# 或者: from http.HTTP import get_file [as 别名]
class RipperSVN(object):
    def __init__(self, vulnerability, threads=0):
        self.vulnerability = vulnerability
        self.host = vulnerability['host']
        self.session = HTTP()
        self.output_folder = "output/{}/".format(self.host.host)
        self.threads = threads


    def parse_wc(self):
        self.session.get_file("", self.output_folder + "wc.db", with_data=self.vulnerability['data'])
        print "Wrote wc.db to disk"

        conn = sqlite3.connect(self.output_folder + 'wc.db')
        c = conn.cursor()
        files = []

        for row in c.execute('select local_relpath, checksum from NODES'):
            try:
                path = ".svn/pristine/" + row[1][6:8] + "/" + row[1][6:] + ".svn-base"
                url = self.host.replace(path=path)
                filename = row[0]

                if not os.path.exists(self.output_folder + filename):
                    files.append((url, self.output_folder + filename))

            except:
                pass


        if self.threads:
            with concurrent.futures.ThreadPoolExecutor(max_workers=self.threads) as executor:
                for file in files:
                    executor.submit(self.session.get_file, file[0], file[1])
        else:
            self.session.get_file(file[0], file[1])
开发者ID:simontoft,项目名称:VCSRip,代码行数:38,代码来源:RipperSVN.py

示例2: RipperGIT

# 需要导入模块: from http import HTTP [as 别名]
# 或者: from http.HTTP import get_file [as 别名]
class RipperGIT(object):

    META_FILES = ['HEAD', 'FETCH_HEAD', 'COMMIT_EDITMSG', 'ORIG_HEAD', 'config', 'packed-refs', 'objects/info/packs']

    def __init__(self, vulnerability, threads=0):
        self.vulnerability = vulnerability
        self.host = vulnerability['host']
        self.session = HTTP()
        self.output_folder = "output/{}/".format(self.host.host)
        self.output_git = self.output_folder + ".git/"
        self.threads = threads

    def get_meta_files(self):
        for meta_file in self.META_FILES:
            url = self.vulnerability['host'].replace(path = ".git/" + meta_file)
            destination = self.output_git + meta_file

            if self.session.get_file(url, destination):
                logging.debug("Fetched {}".format(url))

        self.session.get_file("", self.output_git + "index", with_data = self.vulnerability['data'])
        self.index_files = parse_index(self.output_git + "index")

        logging.debug("Writing index")

    def get_objects(self):
        objects = []

        for file in self.index_files:
            git_file_path = ".git/objects/" + file['sha1'][0:2] + "/" + file['sha1'][2:]
            path =  self.output_folder + git_file_path
            url = self.vulnerability['host'].replace(path = git_file_path)

            objects.append((url, path))

        if self.threads:
            with concurrent.futures.ThreadPoolExecutor(max_workers=self.threads) as executor:
                for object in objects:
                    executor.submit(self.session.get_file, object[0], object[1])
        else:
            for object in objects:
                self.session.get_file(object[0], object[1])


    def get_pack_files(self):
        if os.path.exists(self.output_git + "objects/info/packs"):
            f = open(self.output_git + "objects/info/packs").read()

            for pack in f.split("\n"):
                if not len(pack):
                    continue

                pack_url = self.vulnerability['host'].replace(path = ".git/objects/pack/" + pack[2:])
                pack_dest = self.output_git + "objects/pack/" + pack[2:]

                idx_url = str(pack_url).replace(".pack", ".idx")
                idx_dest = pack_dest.replace(".pack", ".idx")

                if self.session.get_file(pack_url, pack_dest):
                    logging.debug("Failed {}".format(pack_url))
                if self.session.get_file(idx_url, idx_dest):
                    logging.debug("Failed {}".format(idx_url))

    def unpack_objects(self):
        for file in self.index_files:
            object_path = self.output_git + "objects/" + file['sha1'][0:2] + "/" + file['sha1'][2:]
            file_path = self.output_folder + file['name']

            with open(object_path) as f:
                object_data = f.read()

            if not os.path.exists(os.path.dirname(file_path)):
                os.makedirs(os.path.dirname(file_path))

            unpacked_object = zlib.decompress(object_data)

            with open(file_path, "wb") as f:
                f.write(unpacked_object.split('\x00', 1)[1])

    def extract_pack_file(self):
        raise NotImplementedError("TODO")
开发者ID:simontoft,项目名称:VCSRip,代码行数:83,代码来源:RipperGIT.py


注:本文中的http.HTTP.get_file方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。