예제 #1
0
 def open(self, url, conn_timeout=None):
   if conn_timeout == 0:
     raise urllib_error.URLError('Could not reach %s within deadline.' % url)
   if url.startswith('http'):
     self.opened.set()
   if self.error:
     raise urllib_error.HTTPError(url, self.error, None, None, Compatibility.BytesIO(b'glhglhg'))
   return urllib_request.addinfourl(Compatibility.BytesIO(self.rv), url, None, self.code)
예제 #2
0
 def _get_code(self, fullmodname):
   submodname, is_package, relpath = self._get_info(fullmodname)
   relsplit, _ = os.path.split(relpath)
   fullpath = '%s%s%s' % (self.archive, os.sep, relpath)
   pyc = os.path.splitext(fullpath)[0] + '.pyc'
   try:
     with timed('Unmarshaling %s' % pyc, at_level=2):
       pyc_object = CodeMarshaller.from_pyc(Compatibility.BytesIO(Nested.read(pyc)))
   except (Nested.FileNotFound, ValueError, CodeMarshaller.InvalidCode) as e:
     with timed('Compiling %s because of %s' % (fullpath, e.__class__.__name__), at_level=2):
       py = Nested.read(fullpath)
       assert py is not None
       if Compatibility.PY3:
         py = py.decode('utf8')
       pyc_object = CodeMarshaller.from_py(py, fullpath)
   return submodname, is_package, fullpath, pyc_object.code
예제 #3
0
 def to_pyc(self):
     sio = Compatibility.BytesIO()
     sio.write(struct.pack('I', CodeMarshaller.MAGIC))
     sio.write(struct.pack('I', self._stamp))
     sio.write(marshal.dumps(self._code))
     return sio.getvalue()