Exemple #1
0
 def fetch(self, parser=None):
     p = core.url2path(self.orig_uri.url, fragments=True)
     if len(p) != 2:
         raise ValueError("Wrong formed URL '%s'"%self.orig_uri.url)
     zipfname, fname = p
     if parser:
         zipfname = parser.ensureinput(zipfname)
     # Open and read. Obtain options first
     if parser and parser.engine:
         urlopts = parser.engine.urlcfgfile.urlopts(self.orig_uri.url) or {}
     else:
         urlopts = {}
     # password is string, convert to bytes, but if is empty, set to None (not used)
     password = urlopts.get('password', '').encode('utf8')
     if not password: password = None
     # opening zip file and read what is need
     with zipfile.ZipFile(zipfname, 'r') as zip:
         fileinfo = zip.getinfo(fname)
         buffer = zip.read(fname, password)
     # prepare file metainfo
     name = os.path.basename(fname)
     ext = os.path.splitext(name)[1]
     atime = core.VfileInfo.mkst_time(fileinfo.date_time)
     mtime = core.VfileInfo.mkst_time(fileinfo.date_time)
     mode = (fileinfo.external_attr >> 16) & 0x1FF # & 0777
     fileinfo = core.VfileInfo(fmt=ext, name=name, mode=mode, atime=atime, mtime=mtime)
     return (fileinfo, buffer)
Exemple #2
0
 def fetch(self, parser=None):
     p = core.url2path(self.orig_uri.url, fragments=True)
     if len(p) != 2:
         raise ValueError("Wrong formed URL '%s'" % self.orig_uri.url)
     zipfname, fname = p
     if parser:
         zipfname = parser.ensureinput(zipfname)
     # Open and read. Obtain options first
     if parser and parser.engine:
         urlopts = parser.engine.urlcfgfile.urlopts(self.orig_uri.url) or {}
     else:
         urlopts = {}
     # password is string, convert to bytes, but if is empty, set to None (not used)
     password = urlopts.get('password', '').encode('utf8')
     if not password: password = None
     # opening zip file and read what is need
     with zipfile.ZipFile(zipfname, 'r') as zip:
         fileinfo = zip.getinfo(fname)
         buffer = zip.read(fname, password)
     # prepare file metainfo
     name = os.path.basename(fname)
     ext = os.path.splitext(name)[1]
     atime = core.VfileInfo.mkst_time(fileinfo.date_time)
     mtime = core.VfileInfo.mkst_time(fileinfo.date_time)
     mode = (fileinfo.external_attr >> 16) & 0x1FF  # & 0777
     fileinfo = core.VfileInfo(fmt=ext,
                               name=name,
                               mode=mode,
                               atime=atime,
                               mtime=mtime)
     return (fileinfo, buffer)
Exemple #3
0
 def fetch(self, parser=None):
     p = core.url2path(self.orig_uri.url, fragments=True)
     exename = p[0]
     cmdline = p[1] if len(p) > 1 else ''
     # normalization of exename path
     normpath = lambda p: os.path.normpath(os.path.normcase(p)) # used below
     exename = normpath(exename)
     # Check that exec is located in right place
     secure = False
     if normpath(sys.executable) == exename:
         # it's python exe file
         secure = True
     else:
         # something else
         exename = core.extrapath(exename)
         if os.path.exists(exename):
             # it's existent in extradir. 
             secure = True
     # so, if insecure
     if not secure:
         raise RuntimeError("Insecure URL '%s'"%self.orig_uri.url)
     # Run and read
     args = [exename] + cmdline.split()
     proc = subprocess.Popen(args, stdout=subprocess.PIPE)
     exitcode = proc.wait()
     stdoutbuf = proc.stdout.read()
     return (None, stdoutbuf)
Exemple #4
0
 def fetch(self, parser=None):
     p = core.url2path(self.orig_uri.url, fragments=True)
     exename = p[0]
     cmdline = p[1] if len(p) > 1 else ''
     # normalization of exename path
     normpath = lambda p: os.path.normpath(os.path.normcase(p)
                                           )  # used below
     exename = normpath(exename)
     # Check that exec is located in right place
     secure = False
     if normpath(sys.executable) == exename:
         # it's python exe file
         secure = True
     else:
         # something else
         exename = core.extrapath(exename)
         if os.path.exists(exename):
             # it's existent in extradir.
             secure = True
     # so, if insecure
     if not secure:
         raise RuntimeError("Insecure URL '%s'" % self.orig_uri.url)
     # Run and read
     args = [exename] + cmdline.split()
     proc = subprocess.Popen(args, stdout=subprocess.PIPE)
     exitcode = proc.wait()
     stdoutbuf = proc.stdout.read()
     return (None, stdoutbuf)