box/manifest"
           xmlns:mx="http://schemas.microsoft.com/appx/2013/xbox/manifest"
           xmlns:t="http://schemas.microsoft.com/appx/manifest/types"
           xmlns:m="http://schemas.microsoft.com/appx/2010/manifest"
           >

  <xs:import namespace="http://schemas.microsoft.com/appx/manifest/types"/>
  <xs:import namespace="http://schemas.microsoft.com/appx/2010/manifest"/>

  <!--ContentPackage-->
  <xs:element name="ContentPackage" type="xs:boolean"/>

  <xs:element name="Capability">
    <xs:complexType>
      <xs:attribute name="Name" type="ST_XboxPackageCapabilities" use="required"/>
    </xs:complexType>
  </xs:element>

  <xs:simpleType name="ST_XboxPackageCapabilities">
    <xs:restriction base="xs:string">
      <xs:enumeration value="contentRestrictions"/>
      <xs:enumeration value="kinectVision"/>
      <xs:enumeration value="kinectAudio"/>
      <xs:enumeration value="kinectFace"/>
      <xs:enumeration value="kinectExpressions"/>
      <xs:enumeration value="kinectGamechat"/>
      <xs:enumeration value="kinectRequired"/>
    </xs:restriction>
  </xs:simpleType>

  <!--PREREQUISITES-->
  <xs:element name="ApplicationEnvironment">
    <xs:simpleType>
      <xs:restriction base="xs:string">
        <xs:enumeration value="title"/>
        <xs:enumeration value="app"/>
      </xs:restriction>
    </xs:simpleType>
  </xs:element>

  <xs:element name="OSName">
    <xs:simpleType>
      <xs:restriction base="t:ST_NonEmptyString">
        <xs:maxLength value="128"/>
      </xs:restriction>
    </xs:simpleType>
  </xs:element>

  <!--VIEW STATES-->
  <xs:simpleType name="ST_SupportedViewStates">
    <xs:restriction base="xs:string">
      <xs:enumeration value="snapped"/>
      <xs:enumeration value="filled"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:element name="ViewStates">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="ViewState" minOccurs="1" maxOccurs="2">
          <xs:complexType>
            <xs:attribute name="Name" type="ST_SupportedViewStates" use="required"/>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>

  <!--XBOX LIVE EXTENSION SCHEMA-->
  <xs:simpleType name="ST_TitleId">
    <xs:restriction base="xs:string">
      <xs:minLength value="8"/>
      <xs:maxLength value="8"/>
      <xs:pattern value="[0-9a-fA-F]{8}"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:complexType name="CT_XboxLive">
    <xs:all minOccurs="0">
      <xs:element name="ConnectedStorage" minOccurs="0">
        <xs:complexType>
          <xs:sequence>
            <xs:element name="AllowReadFrom" minOccurs="0" maxOccurs="unbounded">
              <xs:complexType>
                <xs:attribute name="ServiceConfigId" type="t:ST_GUID" use="required"/>
              </xs:complexType>
            </xs:element>
          </xs:sequence>
          <xs:attribute name="MaxMegabytesPerUser" use="optional">
            <xs:simpleType>
              <xs:restriction base="xs:integer">
                <xs:minInclusive value="256"/>
                <xs:maxInclusive value="4096"/>
              </xs:restriction>
            </xs:simpleType>
          </xs:attribute>
        </xs:complexType>
      </xs:element>
    </xs:all>

    <xs:attribute name="TitleId" type="ST_TitleId" use="required"/>
    <xs:attribute name="PrimaryServiceConfigId" type="t:ST_GUID" use="required"/>
    <xs:attribute name="EnableProtocolHandler" type="xs:boolean" use="optional"/>
    <xs:attribute name="RequireXboxLive" type="xs:boolean" use="optional"/>
  </xs:complexType>
  
  <xs:complexType name="CT_Vui">
    <xs:attribute name="Alm" type="t:ST_NonEmptyString" use="required"/>
    <xs:attribute name="Pron" type="t:ST_NonEmptyString" use="optional"/>
  </xs:complexType>

  <!--XBOX MEDIA CAPTURE EXTENSION SCHEMA-->
  <xs:simpleType name="ST_BroadcastProviderId">
    <xs:restriction base="xs:string">
      <xs:minLength value="1"/>
      <xs:maxLength value="16"/>
      <xs:pattern value="[0-9a-zA-Z]+"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:complexType name="CT_XboxMediaCapture">
    <xs:attribute name="BroadcastProvider" type="xs:boolean" use="optional"/>
    <xs:attribute name="GameDVRSystemComponent" type="xs:boolean" use="optional"/>
    <xs:attribute name="BlockBroadcast" type="xs:boolean" use="optional"/>
    <xs:attribute name="BlockGameDVR" type="xs:boolean" use="optional"/>
    <xs:attribute name="BroadcastProviderId" type="ST_BroadcastProviderId" use="optional"/>
    <xs:attribute name="Version" use="optional">
        <xs:simpleType>
          <xs:restriction base="xs:integer">
            <xs:minInclusive value="0"/>
            <xs:maxInclusive value="99999"/>
          </xs:restriction>
        </xs:simpleType>
    </xs:attribute>
  </xs:complexType>

  <!--XBOX MULTIPLAYER EXTENSION SCHEMA-->
  <xs:complexType name="CT_XboxMultiplayer">
    <xs:attribute name="CanSuppressPartyChat" type="xs:boolean" use="optional"/>
  </xs:complexType>

  <!--XBOX SYSTEM RESOURCES SCHEMA-->
  <xs:simpleType name="ST_GpuAvailability">
    <xs:restriction base="xs:string">
      <xs:enumeration value="fixed"/>
      <xs:enumeration value="variable"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="ST_ResourceConfiguration">
    <xs:restriction base="xs:string">
      <xs:enumeration value="extended"/>
      <xs:enumeration value="extendedVideoPlayback"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="ST_TitleMemoryMaxGB">
    <xs:restriction base="xs:integer">
      <xs:maxInclusive value="9"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="ST_TitleMemoryMaxMB">
    <xs:restriction base="xs:integer">
      <xs:maxInclusive value="9216"/>
    </xs:restriction>
  </xs:simpleType>
  
  <xs:simpleType name="ST_ConsoleType">
    <xs:restriction base="xs:string">
      <xs:enumeration value="Xbox_One"/>
      <xs:enumeration value="Xbox_One_X"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:complexType name="CT_TitleMemory">
    <xs:attribute name="ConsoleType" type="ST_ConsoleType" use="required" />
    <xs:attribute name="Size" type="ST_TitleMemoryMaxGB" use="optional" />
    <xs:attribute name="SizeInMegabytes" type="ST_TitleMemoryMaxMB" use="optional" />
  </xs:complexType>
  
  <xs:complexType name="CT_XboxSystemResources">
    <xs:all minOccurs="0">
      <xs:element name="GpuAvailability" type="ST_GpuAvailability" minOccurs="0"/>
      <xs:element name="TitleMemory" type="CT_TitleMemory" minOccurs="0" maxOccurs="1"/>
      <!-- We support Scorpio and Durango as ConsoleTypes now.  When this 
           changes, the max occurences here needs to increase as well. -->
      <xs:element name="TitleMemoryList" minOccurs ="0" maxOccurs="1">
        <xs:complexType>
          <xs:sequence>
            <xs:element name="TitleMemory" type="CT_TitleMemory" minOccurs="1" maxOccurs="2"/>
          </xs:sequence>
        </xs:complexType>
      </xs:element>
    </xs:all>
    <xs:attribute name="resourceConfiguration" type="ST_ResourceConfiguration" use="optional"/>
  </xs:complexType>

  <!--XBOX REMOTE LAUNCH SCHEMA-->
  <xs:complexType name="CT_XboxRemoteLaunchDial">
    <xs:attribute name="Name" type="xs:string" use="required"/>
  </xs:complexType>

  <xs:complexType name="CT_XboxRemoteLaunch">
    <xs:sequence>
      <xs:element name="DIAL" type="CT_XboxRemoteLaunchDial" minOccurs="0" maxOccurs="1"/>
    </xs:sequence>
  </xs:complexType>

  <!--KINECT SCHEMA-->
  <xs:complexType name="CT_Kinect">
    <xs:sequence>
      <xs:element name="AudioPipeline">
        <xs:complexType>
          <xs:attribute name="Version" type="t:ST_VersionDuoOrTrio" use="required" />
        </xs:complexType>
      </xs:element>
      <xs:element name="SpeechPipeline">
        <xs:complexType>
          <xs:attribute name="Version" type="t:ST_VersionDuoOrTrio" use="required" />
        </xs:complexType>
      </xs:element>
      <xs:element name="VisionPipeline">
        <xs:complexType>
          <xs:attribute name="Version" type="t:ST_VersionDuoOrTrio" use="required" />
        </xs:complexType>
      </xs:element>
    </xs:sequence>
    <xs:attribute name="IsVersionLocked" type="xs:boolean" use="optional" />
  </xs:complexType>

  <!--XBOX FISSION SCHEMA-->
  <xs:complexType name="CT_XboxFission">
    <xs:attribute name="IsFissionApp" type="xs:boolean" use="optional"/>
  </xs:complexType>

  <!--XBOX NETWORKING MANIFEST EXTENSION SCHEMA-->
  <xs:complexType name="CT_XboxNetworkingManifest">
    <xs:sequence>
      <xs:any namespace="##targetNamespace" minOccurs="0" maxOccurs="unbounded" processContents="lax" />
    </xs:sequence>
    <xs:anyAttribute namespace="##any" processContents="lax" />
  </xs:complexType>

  <!--DLC SCHEMA-->
  <xs:complexType name="CT_ContentPackage">
    <xs:sequence>
      <xs:element name="AllowedProduct" minOccurs="1" maxOccurs="1">
        <xs:complexType>
          <xs:attribute name="Id" type="t:ST_GUID" use="required" />
        </xs:complexType>
      </xs:element>
      <xs:element name="ContentPackageVisualElements" minOccurs="1" maxOccurs="1">
        <xs:complexType>
          <xs:attribute name="DisplayName" type="t:ST_DisplayName" use="required"/>
          <xs:attribute name="Description" type="t:ST_Description" use="required"/>
          <xs:attribute name="ForegroundText" type="t:ST_ForegroundText" use="required"/>
          <xs:attribute name="BackgroundColor" type="t:ST_Color" use="required"/>
          <xs:attribute name="Logo" type="t:ST_ImageFile" use="required"/>
          <xs:attribute name="SmallLogo" type="t:ST_ImageFile" use="required"/>
          <xs:attribute name="WideLogo" type="t:ST_ImageFile" use="required"/>
        </xs:complexType>
      </xs:element>
    </xs:sequence>      
  </xs:complexType>

  <!--XBOX STORE SCHEMA-->
  <xs:complexType name="CT_XboxStore">
    <xs:all>
      <xs:element name="RelatedProducts" type="CT_RelatedProduct" minOccurs="0" maxOccurs="1" />
      <xs:element name="TrialLicense" type="CT_TrialLicense" minOccurs="0" maxOccurs="1" />        
    </xs:all>
  </xs:complexType>
    
  <xs:complexType name="CT_RelatedProduct">
    <xs:sequence>
      <xs:element name="RelatedProduct" minOccurs="1" maxOccurs="unbounded">
        <xs:complexType>
            <xs:attribute name="Id" type="t:ST_GUID" use="required" />
        </xs:complexType>
      </xs:element>
    </xs:sequence>
  </xs:complexType>

  <xs:complexType name="CT_TrialLicense">
    <xs:attribute name="SuspendOptOut" type="xs:boolean" use="optional" />
  </xs:complexType>
  
  <!-- STORAGE SCHEMA -->
 <xs:complexType name="CT_Storage">
    <xs:all minOccurs="0">
      <xs:element name="PersistentLocalStorage" minOccurs="0" maxOccurs="1">
        <xs:complexType>
          <xs:attribute name="SizeInMegabytes" use="required">
            <xs:simpleType>
              <xs:restriction base="xs:integer"/>
            </xs:simpleType>
          </xs:attribute>
        </xs:complexType>
      </xs:element>
      <xs:element name="SharedStorage" minOccurs="0" maxOccurs="1">
        <xs:complexType>
          <xs:attribute name="SharedId" type="t:ST_GUID" use="required"/>
        </xs:complexType>
      </xs:element>
    </xs:all>
  </xs:complexType>

  <!--PER-PACKAGE EXTENSIONS-->
  <xs:simpleType name="ST_XboxPackageExtensionCategory">
    <xs:restriction base="xs:string">
      <xs:enumeration value="windows.kinect"/>
      <xs:enumeration value="xbox.contentpackage"/>
      <xs:enumeration value="xbox.store"/>
      <xs:enumeration value="xbox.storage"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:complexType name="CT_XboxPackageExtension">
    <xs:choice>
      <xs:element name="Kinect" type="CT_Kinect"/>
      <xs:element name="ContentPackage" type="CT_ContentPackage"/>
      <xs:element name="XboxStore" type="CT_XboxStore" />
      <xs:element name="Storage" type="CT_Storage" />
    </xs:choice>
    <xs:attribute name="Category" type="ST_XboxPackageExtensionCategory" use="required"/>
  </xs:complexType>

  <xs:element name="PackageExtension" type="CT_XboxPackageExtension"/>

  <!--APPLICATION EXTENSIONS-->
  <xs:simpleType name="ST_XboxApplicationExtensionCategory">
    <xs:restriction base="xs:string">
      <xs:enumeration value="xbox.live"/>
      <xs:enumeration value="xbox.media.capture"/>
      <xs:enumeration value="xbox.multiplayer"/>
      <xs:enumeration value="xbox.fission"/>    
      <xs:enumeration value="windows.xbox.networking"/>
      <xs:enumeration value="xbox.system.resources"/>
      <xs:enumeration value="xbox.remoteLaunch" />
      <xs:enumeration value="xbox.vui" />
    </xs:restriction>
  </xs:simpleType>

  <xs:element name="Extension">
    <xs:complexType>
      <xs:choice>
        <!--Xbox Live Title ID DEH-->
        <xs:element name="XboxLive" type="CT_XboxLive"/>
        <!--Xbox Media Capture DEH-->
        <xs:element name="XboxMediaCapture" type="CT_XboxMediaCapture"/>
        <!--Xbox System Resources DEH-->
        <xs:element name="XboxSystemResources" type="CT_XboxSystemResources"/>
        <!--Xbox Fission DEH-->
        <xs:element name="XboxFission" type="CT_XboxFission"/>    
        <!--Xbox Multiplayer DEH-->
        <xs:element name="XboxMultiplayer" type="CT_XboxMultiplayer"/>
        <!--Xbox Networking DEH-->
        <xs:element name="XboxNetworkingManifest" type="CT_XboxNetworkingManifest"/>
        <!-- Xbox Remote Launch DEH -->
        <xs:element name="XboxRemoteLaunch" type="CT_XboxRemoteLaunch"/>
        <!-- Xbox VUI DEH -->
        <xs:element name="XboxVui" type="CT_Vui"/>
      </xs:choice>
      <xs:attribute name="Category" type="ST_XboxApplicationExtensionCategory" use="required"/>
      <xs:attributeGroup ref="m:ExtensionBaseAttributes"/>
    </xs:complexType>
  </xs:element>

  <!--PER-APPLICATION RATINGS-->
  <xs:element name="Ratings">
    <xs:complexType>
      <xs:sequence>
        <xs:elemfrom __future__ import absolute_import

import hashlib

from pip._vendor.six import iteritems, iterkeys, itervalues

from pip._internal.exceptions import (
    HashMismatch,
    HashMissing,
    InstallationError,
)
from pip._internal.utils.misc import read_chunks
from pip._internal.utils.typing import MYPY_CHECK_RUNNING

if MYPY_CHECK_RUNNING:
    from typing import (
        Dict, List, BinaryIO, NoReturn, Iterator
    )
    from pip._vendor.six import PY3
    if PY3:
        from hashlib import _Hash
    else:
        from hashlib import _hash as _Hash


# The recommended hash algo of the moment. Change this whenever the state of
# the art changes; it won't hurt backward compatibility.
FAVORITE_HASH = 'sha256'


# Names of hashlib algorithms allowed by the --hash option and ``pip hash``
# Currently, those are the ones at least as collision-resistant as sha256.
STRONG_HASHES = ['sha256', 'sha384', 'sha512']


class Hashes(object):
    """A wrapper that builds multiple hashes at once and checks them against
    known-good values

    """
    def __init__(self, hashes=None):
        # type: (Dict[str, List[str]]) -> None
        """
        :param hashes: A dict of algorithm names pointing to lists of allowed
            hex digests
        """
        self._allowed = {} if hashes is None else hashes

    def __and__(self, other):
        # type: (Hashes) -> Hashes
        if not isinstance(other, Hashes):
            return NotImplemented

        # If either of the Hashes object is entirely empty (i.e. no hash
        # specified at all), all hashes from the other object are allowed.
        if not other:
            return self
        if not self:
            return other

        # Otherwise only hashes that present in both objects are allowed.
        new = {}
        for alg, values in iteritems(other._allowed):
            if alg not in self._allowed:
                continue
            new[alg] = [v for v in values if v in self._allowed[alg]]
        return Hashes(new)

    @property
    def digest_count(self):
        # type: () -> int
        return sum(len(digests) for digests in self._allowed.values())

    def is_hash_allowed(
        self,
        hash_name,   # type: str
        hex_digest,  # type: str
    ):
        # type: (...) -> bool
        """Return whether the given hex digest is allowed."""
        return hex_digest in self._allowed.get(hash_name, [])

    def check_against_chunks(self, chunks):
        # type: (Iterator[bytes]) -> None
        """Check good hashes against ones built from iterable of chunks of
        data.

        Raise HashMismatch if none match.

        """
        gots = {}
        for hash_name in iterkeys(self._allowed):
            try:
                gots[hash_name] = hashlib.new(hash_name)
            except (ValueError, TypeError):
                raise InstallationError(
                    'Unknown hash name: {}'.format(hash_name)
                )

        for chunk in chunks:
            for hash in itervalues(gots):
                hash.update(chunk)

        for hash_name, got in iteritems(gots):
            if got.hexdigest() in self._allowed[hash_name]:
                return
        self._raise(gots)

    def _raise(self, gots):
        # type: (Dict[str, _Hash]) -> NoReturn
        raise HashMismatch(self._allowed, gots)

    def check_against_file(self, file):
        # type: (BinaryIO) -> None
        """Check good hashes against a file-like object

        Raise HashMismatch if none match.

        """
        return self.check_against_chunks(read_chunks(file))

    def check_against_path(self, path):
        # type: (str) -> None
        with open(path, 'rb') as file:
            return self.check_against_file(file)

    def __nonzero__(self):
        # type: () -> bool
        """Return whether I know any known-good hashes."""
        return bool(self._allowed)

    def __bool__(self):
        # type: () -> bool
        return self.__nonzero__()


class MissingHashes(Hashes):
    """A workalike for Hashes used when we're missing a hash for a requirement

    It computes the actual hash of the requirement and raises a HashMissing
    exception showing it to the user.

    """
    def __init__(self):
        # type: () -> None
        """Don't offer the ``hashes`` kwarg."""
        # Pass our favorite hash in to generate a "gotten hash". With the
        # empty list, it will never match, so an error will always raise.
        super(MissingHashes, self).__init__(hashes={FAVORITE_HASH: []})

    def _raise(self, gots):
        # type: (Dict[str, _Hash]) -> NoReturn
        raise HashMissing(gots[FAVORITE_HASH].hexdigest())
