Example #1
0
 def load(self, s, python_version=None):
   if python_version is None:
     ret1 = loadmarshal.loads(s, (2, 7))
     ret2 = loadmarshal.loads(s, (3, 6))
     self.assertStrictEqual(ret1, ret2)
     return ret1
   else:
     return loadmarshal.loads(s, python_version)
Example #2
0
def parse_pyc_stream(fi):
  """Parse pyc data from a file.

  Args:
    fi: A file-like object.

  Returns:
    An instance of loadmarshal.CodeType.

  Raises:
    IOError: If we can't read the file or the file is malformed.
  """
  magic_word = fi.read(2)
  python_version = magic.magic_word_to_version(magic_word)
  crlf = fi.read(2)  # cr, lf
  if crlf != "\r\n":
    raise IOError("Malformed pyc file")
  fi.read(4)  # timestamp
  if python_version >= (3, 3):
    # This field was introduced in Python 3.3
    fi.read(4)  # raw size
  return loadmarshal.loads(fi.read(), python_version)
Example #3
0
File: pyc.py Project: syyunn/pytype
def parse_pyc_stream(fi):
    """Parse pyc data from a file.

  Args:
    fi: A file-like object.

  Returns:
    An instance of loadmarshal.CodeType.

  Raises:
    IOError: If we can't read the file or the file is malformed.
  """
    magic_word = fi.read(2)
    python_version = magic.magic_word_to_version(magic_word)
    crlf = fi.read(2)  # cr, lf
    if crlf != b"\r\n":
        raise IOError("Malformed pyc file")
    fi.read(4)  # timestamp
    if python_version >= (3, 3):
        # This field was introduced in Python 3.3
        fi.read(4)  # raw size
    return loadmarshal.loads(fi.read(), python_version)
Example #4
0
 def load(self, s, python_version=(2, 7)):
   return loadmarshal.loads(s, python_version)
Example #5
0
 def load(self, s, python_version=(2, 7)):
     return loadmarshal.loads(s, python_version)
Example #6
0
 def load(self, s, python_version=None):
     python_version = python_version or (3, 9)
     return loadmarshal.loads(s, python_version)