import zipfile
import json


def _GetExtensionInfoFromCRX(crx_path):
  """Parse an extension archive and return information.

  Note:
    The extension name returned by this function may not be valid
  (e.g. in the case of a localized extension name).  It's use is just
  meant to be informational.

  Args:
    crx_path: path to crx archive to look at.

  Returns:
    Tuple consisting of:
    (crx_version, extension_name)"""
  crx_zip = zipfile.ZipFile(crx_path)
  manifest_contents = crx_zip.read('manifest.json')
  decoded_manifest = json.loads(manifest_contents)
  crx_version = decoded_manifest['version']
  extension_name = decoded_manifest['name']

  return (crx_version, extension_name)