
  <xs:simpleType name="ST_ExecutableNoPath">
    <xs:restriction base="ST_FileName">
      <xs:pattern value="[^\\]+\.([Ee][Xx][Ee])"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="ST_ExecutableAnyCase">
    <xs:restriction base="ST_FileName">
      <xs:pattern value=".+\.([Ee][Xx][Ee])"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="ST_DllFile">
    <xs:restriction base="ST_FileName">
      <xs:pattern value=".+\.([Dd][Ll][Ll])"/>
    </xs:restriction>
  </xs:simpleType>
  
  <xs:simpleType name="ST_ImageFile">
    <xs:restriction base="ST_FileName">
      <xs:pattern value=".+\.((jpg)|(png)|(jpeg))"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="ST_AsciiIdentifier">
    <xs:restriction base="ST_NonEmptyString">
      <xs:pattern value="[-.A-Za-z0-9]+"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="ST_AlphaNumericString">
    <xs:restriction base="ST_NonEmptyString">
      <xs:pattern value="[A-Za-z0-9]+"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="ST_PackageName">
    <xs:restriction base="ST_AsciiIdentifier">
      <xs:minLength value="3"/>
      <xs:maxLength value="50"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="ST_ResourceId">
    <xs:restriction base="ST_AsciiIdentifier">
      <xs:maxLength value="30"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="ST_AsciiWindowsId">
    <xs:restriction base="ST_NonEmptyString">
      <xs:pattern value="([A-Za-z][A-Za-z0-9]*)(\.[A-Za-z][A-Za-z0-9]*)*"/>
      <xs:maxLength value="255"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="ST_ApplicationId">
    <xs:restriction base="ST_AsciiWindowsId">
      <xs:maxLength value="64"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="ST_ActivatableClassId">
    <xs:restriction base="ST_FileNameCharSet">
      <xs:pattern value="([^.]+)(\.[^.]+)*"/>
      <xs:maxLength value="255"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="ST_EntryPoint">
    <xs:restriction base="ST_NonEmptyString">
      <xs:maxLength value="256"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="ST_ServiceId">
    <xs:restriction base="ST_NonEmptyString">
      <xs:pattern value="[-.a-z0-9]+"/>
      <xs:maxLength value="256"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="ST_ProgId">
    <xs:restriction base="ST_NonEmptyString">
      <xs:pattern value="[A-Za-z][A-Za-z0-9\.]*"/>
      <xs:maxLength value="255"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="ST_FileTypeAssociationSupportedVerbId">
    <xs:restriction base="ST_NonEmptyString">
      <xs:minLength value="3"/>
      <xs:maxLength value="64"/>
      <xs:pattern value="([A-Za-z0-9]*)"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="ST_ApplicationStartPageUri">
    <xs:restriction base="ST_URI">
      <xs:pattern value="[Hh][Tt][Tt][Pp]://.+" />
      <xs:pattern value="[Hh][Tt][Tt][Pp][Ss]://.+" />
      <xs:pattern value="[Mm][Ss]-[Aa][Pp][Pp][Xx]-[Ww][Ee][Bb]://.+" />
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="ST_ApplicationStartPage">
    <xs:union memberTypes="ST_FileName ST_ApplicationStartPageUri"/>
  </xs:simpleType>

  <xs:simpleType name="ST_DomainName">
    <xs:restriction base="ST_NonEmptyString">
      <xs:pattern value="([0-9a-zA-Z]+(-[0-9a-zA-Z]+)*\.)+[a-zA-Z]{1,63}"/>
      <xs:maxLength value="255"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="ST_DomainNameWithStarSubDomain">
    <xs:restriction base="ST_NonEmptyString">
      <xs:pattern value="((\*\.)?[0-9a-zA-Z]+(-[0-9a-zA-Z]+)*\.)+[a-zA-Z]{1,63}"/>
      <xs:maxLength value="255"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="ST_GUID">
    <xs:restriction base="ST_NonEmptyString">
      <xs:pattern value="[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="ST_MediaCodecSubType">
    <xs:restriction base="ST_NonEmptyString">
      <!-- ST_GUID or 4 character code -->
      <xs:pattern value="([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})|([^\s]{1,4})"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="ST_Publisher_2010">
    <xs:restriction base="ST_NonEmptyString">
      <xs:pattern value="(CN|L|O|OU|E|C|S|STREET|T|G|I|SN|DC|SERIALNUMBER|(OID\.(0|[1-9][0-9]*)(\.(0|[1-9][0-9]*))+))=(([^,+=&quot;&lt;&gt;#;])+|&quot;.*&quot;)(, ((CN|L|O|OU|E|C|S|STREET|T|G|I|SN|DC|SERIALNUMBER|(OID\.(0|[1-9][0-9]*)(\.(0|[1-9][0-9]*))+))=(([^,+=&quot;&lt;&gt;#;])+|&quot;.*&quot;)))*"/>
      <xs:maxLength value="8192"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="ST_Publisher_2010_v2">
    <xs:restriction base="ST_NonEmptyString">
      <xs:pattern value="(CN|L|O|OU|E|C|S|STREET|T|G|I|SN|DC|SERIALNUMBER|Description|PostalCode|POBox|Phone|X21Address|dnQualifier|(OID\.(0|[1-9][0-9]*)(\.(0|[1-9][0-9]*))+))=(([^,+=&quot;&lt;&gt;#;])+|&quot;.*&quot;)(, ((CN|L|O|OU|E|C|S|STREET|T|G|I|SN|DC|SERIALNUMBER|Description|PostalCode|POBox|Phone|X21Address|dnQualifier|(OID\.(0|[1-9][0-9]*)(\.(0|[1-9][0-9]*))+))=(([^,+=&quot;&lt;&gt;#;])+|&quot;.*&quot;)))*"/>
      <xs:maxLength value="8192"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="ST_VersionDuoOrTrio">
    <xs:restriction base="ST_NonEmptyString">
      <xs:pattern value="(0|[1-9][0-9]{0,3}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5])(\.(0|[1-9][0-9]{0,3}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5])){1,2}"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="ST_VersionQuad">
    <xs:restriction base="ST_NonEmptyString">
      <xs:pattern value="(0|[1-9][0-9]{0,3}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5])(\.(0|[1-9][0-9]{0,3}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5])){3}"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="ST_VersionQuadNoneZero">
    <xs:restriction base="ST_NonEmptyString">
      <xs:pattern value="([1-9][0-9]{0,3}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5])(\.(0|[1-9][0-9]{0,3}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5])){3}"/>
      <xs:pattern value="(0|[1-9][0-9]{0,3}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5])(\.([1-9][0-9]{0,3}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5]))(\.(0|[1-9][0-9]{0,3}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5])){2}"/>
      <xs:pattern value="(0|[1-9][0-9]{0,3}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5])(\.(0|[1-9][0-9]{0,3}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5]))(\.([1-9][0-9]{0,3}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5]))(\.(0|[1-9][0-9]{0,3}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5]))"/>
      <xs:pattern value="(0|[1-9][0-9]{0,3}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5])(\.(0|[1-9][0-9]{0,3}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5])){2}(\.([1-9][0-9]{0,3}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5]))"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="ST_Date">
    <xs:restriction base="xs:date">
      <xs:pattern value=".{10}"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="ST_URI">
    <xs:restriction base="ST_NonEmptyString">
      <xs:maxLength value="2084"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="ST_Architecture">
    <xs:restriction base="xs:string">
      <xs:enumeration value="x86"/>
      <xs:enumeration value="x64"/>
      <xs:enumeration value="arm"/>
      <xs:enumeration value="arm64"/>
      <xs:enumeration value="neutral"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="ST_Architecture_v2">
    <xs:restriction base="xs:string">
      <xs:enumeration value="x86"/>
      <xs:enumeration value="x64"/>
      <xs:enumeration value="arm"/>
      <xs:enumeration value="arm64"/>
      <xs:enumeration value="x86a64"/>
      <xs:enumeration value="neutral"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="ST_ArchitectureNonNeutral">
    <xs:restriction base="xs:string">
      <xs:enumeration value="x86"/>
      <xs:enumeration value="x64"/>
      <xs:enumeration value="arm"/>
      <xs:enumeration value="arm64"/>
      <xs:enumeration value="x86a64"/>
    </xs:restriction>
  </xs:simpleType>
  
  <xs:simpleType name="ST_ArchitectureUnrestricted">
    <xs:restriction base="ST_AsciiIdentifier">
      <xs:maxLength value="7"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="ST_Capability_2010">
    <xs:restriction base="xs:string">
      <xs:enumeration value="internetClient"/>
      <xs:enumeration value="internetClientServer"/>
      <xs:enumeration value="privateNetworkClientServer"/>
      <xs:enumeration value="documentsLibrary"/>
      <xs:enumeration value="picturesLibrary"/>
      <xs:enumeration value="videosLibrary"/>
      <xs:enumeration value="musicLibrary"/>
      <xs:enumeration value="enterpriseAuthentication"/>
      <xs:enumeration value="sharedUserCertificates"/>
      <xs:enumeration value="removableStorage"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="ST_Capability_2014">
    <xs:restriction base="xs:string">
      <xs:enumeration value="appointments"/>
      <xs:enumeration value="contacts"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="ST_Capability_Foundation">
    <xs:restriction base="xs:string">
      <xs:enumeration value="internetClient"/>
      <xs:enumeration value="internetClientServer"/>
      <xs:enumeration value="privateNetworkClientServer"/>
      <xs:enumeration value="allJoyn"/>
      <xs:enumeration value="codeGeneration"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="ST_Capability_Uap">
    <xs:restriction base="xs:string">
      <xs:enumeration value="documentsLibrary"/>
      <xs:enumeration value="picturesLibrary"/>
      <xs:enumeration value="videosLibrary"/>
      <xs:enumeration value="musicLibrary"/>
      <xs:enumeration value="enterpriseAuthentication"/>
      <xs:enumeration value="sharedUserCertificates"/>
      <xs:enumeration value="userAccountInformation"/>
      <xs:enumeration value="removableStorage"/>
      <xs:enumeration value="appointments"/>
      <xs:enumeration value="contacts"/>
      <xs:enumeration value="phoneCall"/>
      <xs:enumeration value="blockedChatMessages"/>
      <xs:enumeration value="objects3D"/>
      <xs:enumeration value="voipCall"/>
      <xs:enumeration value="chat"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="ST_Capability_Uap_2">
    <xs:restriction base="xs:string">
      <xs:enumeration value="phoneCallHistoryPublic"/>
      <xs:enumeration value="spatialPerception"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="ST_Capability_Uap_3">
    <xs:restriction base="xs:string">
      <xs:enumeration value="backgroundMediaPlayback"/>
      <xs:enumeration value="userNotificationListener"/>
      <xs:enumeration value="remoteSystem"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="ST_Capability_Uap_4">
    <xs:restriction base="xs:string">
      <xs:enumeration value="offlineMapsManagement"/>
      <xs:enumeration value="userDataTasks"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="ST_Capability_Uap_6">
    <xs:restriction base="xs:string">
      <xs:enumeration value="graphicsCapture"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="ST_Capability_Uap_7">
    <xs:restriction base="xs:string">
      <xs:enumeration value="globalMediaControl"/>
      <xs:enumeration value="gazeInput"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="ST_Capability_Mobile">
    <xs:restriction base="xs:string">
      <xs:enumeration value="recordedCallsFolder"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="ST_Capability_Iot">
    <xs:restriction base="xs:string">
      <xs:enumeration value="systemManagement"/>
      <xs:enumeration value="lowLevelDevices"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="ST_Capability_Windows_Restricted_Party">
    <xs:annotation>
      <xs:documentation>Windows and Restricted capabilities should be camel cased strings upto 128 characters in length. Legacy capabilities will continue to begin with ID_CAP_*</xs:documentation>
    </xs:annotation>
    <xs:restriction base="xs:string">
      <xs:pattern value="[a-z][-_.A-Za-z0-9]+"/>
      <xs:minLength value="3"/>
      <xs:maxLength value="128"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="ST_DeviceCapability">
    <xs:restriction base="ST_NonEmptyString">
      <xs:pattern value="[-.A-Za-z0-9]+"/>
      <xs:pattern value="[0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12}"/>
      <xs:maxLength value="50"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="ST_DeviceFunction">
    <xs:restriction base="ST_NonEmptyString">
      <xs:maxLength value="100"/>
      <xs:pattern value="name:\S+"/>
      <xs:pattern value="classId:[0-9a-fA-F]{2} (([0-9a-fA-F]{2} ([0-9a-fA-F]{2}|\*))|\* \*)"/>
      <xs:pattern value="winUsbId:[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}"/>
      <xs:pattern value="serviceId:[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}"/>
      <xs:pattern value="serviceId:[0-9a-fA-F]{1,8}"/>
      <xs:pattern value="usage:[0-9a-fA-F]{4} ([0-9a-fA-F]{4}|\*)"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="ST_DeviceFunction_Foundation">
    <xs:restriction base="ST_NonEmptyString">
      <xs:maxLength value="100"/>
      <xs:pattern value="name:\S+"/>
      <xs:pattern value="classId:[0-9a-fA-F]{2} (([0-9a-fA-F]{2} ([0-9a-fA-F]{2}|\*))|\* \*)"/>
      <xs:pattern value="winUsbId:[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}"/>
      <xs:pattern value="serviceId:[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}"/>
      <xs:pattern value="serviceId:[0-9a-fA-F]{1,8}"/>
      <xs:pattern value="usage:[0-9a-fA-F]{4} ([0-9a-fA-F]{4}|\*)"/>
      <xs:pattern value="interfaceId:[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="ST_DeviceId">
    <xs:restriction base="ST_NonEmptyString">
      <xs:pattern value="any"/>
      <xs:pattern value="vidpid:[0-9a-fA-F]{4} [0-9a-fA-F]{4}( (usb|bluetooth))?"/>
      <xs:pattern value="model:[^;]{1,512};.{1,512}"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="ST_Scale_2013">
    <xs:restriction base ="xs:string">
      <xs:enumeration value="100"/>
      <xs:enumeration value="120"/>
      <xs:enumeration value="140"/>
      <xs:enumeration value="150"/>
      <xs:enumeration value="160"/>
      <xs:enumeration value="180"/>
      <xs:enumeration value="225"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="ST_Scale_2013_v2">
    <xs:restriction base ="xs:string">
      <xs:enumeration value="100"/>
      <xs:enumeration value="120"/>
      <xs:enumeration value="140"/>
      <xs:enumeration value="160"/>
      <xs:enumeration value="180"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="ST_Scale_2014">
    <xs:restriction base ="xs:string">
      <xs:enumeration value="200"/>
      <xs:enumeration value="220"/>
      <xs:enumeration value="240"/>
      <xs:enumeration value="300"/>
      <xs:enumeration value="400"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="ST_Scale_Uap">
    <xs:restriction base ="xs:string">
      <xs:enumeration value="100"/>
      <xs:enumeration value="125"/>
      <xs:enumeration value="150"/>
      <xs:enumeration value="200"/>
      <xs:enumeration value="250"/>
      <xs:enumeration value="300"/>
      <xs:enumeration value="400"/>
      <xs:enumeration value="500"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="ST_Scale_All">
    <xs:union memberTypes="ST_Scale_2013 ST_Scale_2013_v2 ST_Scale_2014 ST_Scale_Uap"/>
  </xs:simpleType>

  <xs:simpleType name="ST_DXFeatureLevel">
    <xs:restriction base="xs:string">
      <xs:enumeration value="dx9"/>
      <xs:enumeration value="dx10"/>
      <xs:enumeration value="dx11"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="ST_MinDeviceMemory">
    <xs:restriction base="xs:string">
      <xs:enumeration value="512MB"/>
      <xs:enumeration value="1GB"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="ST_AppListEntry">
    <xs:restriction base="xs:string">
      <xs:enumeration value="default"/>
      <xs:enumeration value="none"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="ST_PackageExtensionCategory_2010">
    <xs:restriction base="xs:string">
      <xs:enumeration value="windows.activatableClass.inProcessServer"/>
      <xs:enumeration value="windows.activatableClass.outOfProcessServer"/>
      <xs:enumeration value="windows.activatableClass.proxyStub"/>
      <xs:enumeration value="windows.gameExplorer"/>
      <xs:enumeration value="windows.certificates"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="ST_PackageExtensionCategory_2010_v2">
    <xs:restriction base="xs:string">
      <xs:enumeration value="windows.activatableClass.inProcessServer"/>
      <xs:enumeration value="windows.activatableClass.outOfProcessServer"/>
      <xs:enumeration value="windows.activatableClass.proxyStub"/>
      <xs:enumeration value="windows.certificates"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="ST_PackageExtensionCategory_Com">
    <xs:restriction base="xs:string">
      <xs:enumeration value="windows.comInterface"/>
    </xs:restriction>
  </xs:simpleType>
  
  <xs:simpleType name="ST_PackageExtensionCategory_Foundation">
    <xs:restriction base="xs:string">
      <xs:enumeration value="windows.activatableClass.inProcessServer"/>
      <xs:enumeration value="windows.activatableClass.outOfProcessServer"/>
      <xs:enumeration value="windows.activatableClass.proxyStub"/>
      <xs:enumeration value="windows.certificates"/>
      <xs:enumeration value="windows.publisherCacheFolders"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="ST_ApplicationExtensionCategory_2010">
    <xs:restriction base="xs:string">
      <xs:enumeration value="windows.fileTypeAssociation"/>
      <xs:enumeration value="windows.protocol"/>
      <xs:enumeration value="windows.autoPlayContent"/>
      <xs:enumeration value="windows.autoPlayDevice"/>
      <xs:enumeration value="windows.shareTarget"/>
      <xs:enumeration value="windows.search"/>
      <xs:enumeration value="windows.fileOpenPicker"/>
      <xs:enumeration value="windows.fileSavePicker"/>
      <xs:enumeration value="windows.cachedFileUpdater"/>
      <xs:enumeration value="windows.contactPicker"/>
      <xs:enumeration value="windows.backgroundTasks"/>
      <xs:enumeration value="windows.cameraSettings"/>
      <xs:enumeration value="windows.accountPictureProvider"/>
      <xs:enumeration value="windows.printTaskSettings"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="ST_ApplicationExtensionCategory_2013">
    <xs:restriction base="xs:string">
      <xs:enumeration value="windows.lockScreenCall"/>
      <xs:enumeration value="windows.contact"/>
      <xs:enumeration value="windows.appointmentsProvider"/>
      <xs:enumeration value="windows.alarm"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="ST_ApplicationExtensionCategory_2014">
    <xs:restriction base="xs:string">
      <xs:enumeration value="windows.preInstalledConfigTask"/>
      <xs:enumeration value="windows.updateTask"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="ST_ApplicationExtensionCategory_Foundation">
    <xs:restriction base="xs:string">
      <xs:enumeration value="windows.backgroundTasks"/>
      <xs:enumeration value="windows.preInstalledConfigTask"/>
      <xs:enumeration value="windows.updateTask"/>
      <xs:enumeration value="windows.restrictedLaunch"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="ST_ApplicationContentUriRunTimeAccess_Uap">
    <xs:restriction base="xs:string">
      <xs:enumeration value="allowForWebOnly"/>
      <xs:enumeration value="all"/>
      <xs:enumeration value="none"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="ST_ApplicationExtensionCategory_Uap">
    <xs:restriction base="xs:string">
      <xs:enumeration value="windows.fileTypeAssociation"/>
      <xs:enumeration value="windows.protocol"/>
      <xs:enumeration value="windows.autoPlayContent"/>
      <xs:enumeration value="windows.autoPlayDevice"/>
      <xs:enumeration value="windows.shareTarget"/>
      <xs:enumeration value="windows.search"/>
      <xs:enumeration value="windows.fileOpenPicker"/>
      <xs:enumeration value="windows.fileSavePicker"/>
      <xs:enumeration value="windows.cachedFileUpdater"/>
      <xs:enumeration value="windows.cameraSettings"/>
      <xs:enumeration value="windows.accountPictureProvider"/>
      <xs:enumeration value="windows.printTaskSettings"/>
      <xs:enumeration value="windows.lockScreenCall"/>
      <xs:enumeration value="windows.appointmentsProvider"/>
      <xs:enumeration value="windows.alarm"/>
      <xs:enumeration value="windows.webAccountProvider"/>
      <xs:enumeration value="windows.dialProtocol"/>
      <xs:enumeration value="windows.appService"/>
      <xs:enumeration value="windows.mediaPlayback"/>
      <xs:enumeration value="windows.print3DWorkflow"/>
      <xs:enumeration value="windows.lockScreen"/>
      <xs:enumeration value="windows.aboveLockScreen"/>
      <xs:enumeration value="windows.personalAssistantLaunch"/>
      <xs:enumeration value="windows.voipCall"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="ST_ApplicationExtensionCategory_Uap2">
    <xs:restriction base="xs:string">
      <xs:enumeration value="windows.webAccountProvider"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="ST_ApplicationExtensionCategory_Uap3">
    <xs:restriction base="xs:string">
      <xs:enumeration value="windows.appExtensionHost"/>
      <xs:enumeration value="windows.appExtension"/>
      <xs:enumeration value="windows.appUriHandler"/>
      <xs:enumeration value="windows.appointmentDataProvider"/>
      <xs:enumeration value="windows.emailDataProvider"/>
      <xs:enumeration value="windows.contactDataProvider"/>
      <xs:enumeration value="windows.appExecutionAlias"/>
      <xs:enumeration value="windows.appService"/>
      <xs:enumeration value="windows.protocol"/>
      <xs:enumeration value="windows.fileTypeAssociation"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="ST_ApplicationExtensionCategory_Uap4">
    <xs:restriction base="xs:string">
      <xs:enumeration value="windows.sharedFonts"/>
      <xs:enumeration value="windows.userDataTaskDataProvider"/>
      <xs:enumeration value="windows.mediaCodec"/>
      <xs:enumeration value="windows.contactPanel"/>
      <xs:enumeration value="windows.loopbackAccessRules"/>
      <xs:enumeration value="windows.devicePortalProvider"/>
      <xs:enumeration value="windows.printWorkflowBackgroundTask"/>
      <xs:enumeration value="windows.printWorkflowForegroundTask"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="ST_ApplicationExtensionCategory_Uap5">
    <xs:restriction base="xs:string">
      <xs:enumeration value="windows.userActivity"/>
      <xs:enumeration value="windows.mediaSource"/>
      <xs:enumeration value="windows.videoRendererEffect"/>
      <xs:enumeration value="windows.activatableClass.outOfProcessServer"/>
      <xs:enumeration value="windows.startupTask"/>
      <xs:enumeration value="windows.appExecutionAlias"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="ST_ExtensionCategory_Uap6">
    <xs:restriction base="xs:string">
      <!-- Application Extensions -->
      <xs:enumeration value="windows.barcodeScannerProvider"/>
      <xs:enumeration value="windows.localExperiencePack"/>
      <xs:enumeration value="windows.barcodeScannerPreviewProvider"/>
      <!-- Package Extensions -->
      <xs:enumeration value="windows.loaderSearchPathOverride"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="ST_ExtensionCategory_Uap7">
    <xs:restriction base="xs:string">
      <!-- Package Extensions -->
      <xs:enumeration value="windows.sharedFonts"/>
      <xs:enumeration value="windows.enterpriseDataProtection"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="ST_ExtensionCategory_Uap8">
    <xs:restriction base="xs:string">
      <!-- Application Extensions -->
      <xs:enumeration value="windows.posPaymentConnector"/>
      <!-- Package Extensions -->
      <xs:enumeration value="windows.dataProtection"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="ST_ExtensionCategory_Uap10">
    <xs:restriction base="xs:string">
      <!-- Application Extensions -->
      <xs:enumeration value="windows.protocol"/>
      <!-- Package Extensions -->
      <xs:enumeration value="windows.hostRuntime"/>
      <xs:enumeration value="windows.installedLocationVirtualization"/>
      <xs:enumeration value="windows.mediaContentDecryptionModule"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="ST_ExtensionCategory_Com">
    <xs:restriction base="xs:string">
      <xs:enumeration value="windows.comServer"/>
      <xs:enumeration value="windows.comInterface"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="ST_ExtensionCategory_Preview_Com">
    <xs:restriction base="xs:string">
      <xs:enumeration value="windows.comServer"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="ST_ApplicationExtensionCategory_Mobile">
    <xs:restriction base="xs:string">
      <xs:enumeration value="windows.aowApp"/>
      <xs:enumeration value="windows.mobileMultiScreenProperties"/>
      <xs:enumeration value="windows.communicationBlockingProvider"/>
      <xs:enumeration value="windows.phoneCallOriginProvider"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="ST_ApplicationExtensionCategory_Desktop">
    <xs:restriction base="xs:string">
      <xs:enumeration value="windows.fullTrustProcess"/>
      <xs:enumeration value="windows.startupTask"/>
      <xs:enumeration value="windows.toastNotificationActivation"/>
      <xs:enumeration value="windows.searchProtocolHandler"/>
    </xs:restricfrom __future__ import absolute_import

import logging
import os
import subprocess

from pip._vendor.six.moves import shlex_quote

from pip._internal.cli.spinners import SpinnerInterface, open_spinner
from pip._internal.exceptions import InstallationError
from pip._internal.utils.compat import console_to_str, str_to_display
from pip._internal.utils.logging import subprocess_logger
from pip._internal.utils.misc import HiddenText, path_to_display
from pip._internal.utils.typing import MYPY_CHECK_RUNNING

if MYPY_CHECK_RUNNING:
    from typing import (
        Any, Callable, Iterable, List, Mapping, Optional, Text, Union,
    )

    CommandArgs = List[Union[str, HiddenText]]


LOG_DIVIDER = '----------------------------------------'


def make_command(*args):
    # type: (Union[str, HiddenText, CommandArgs]) -> CommandArgs
    """
    Create a CommandArgs object.
    """
    command_args = []  # type: CommandArgs
    for arg in args:
        # Check for list instead of CommandArgs since CommandArgs is
        # only known during type-checking.
        if isinstance(arg, list):
            command_args.extend(arg)
        else:
            # Otherwise, arg is str or HiddenText.
            command_args.append(arg)

    return command_args


def format_command_args(args):
    # type: (Union[List[str], CommandArgs]) -> str
    """
    Format command arguments for display.
    """
    # For HiddenText arguments, display the redacted form by calling str().
    # Also, we don't apply str() to arguments that aren't HiddenText since
    # this can trigger a UnicodeDecodeError in Python 2 if the argument
    # has type unicode and includes a non-ascii character.  (The type
    # checker doesn't ensure the annotations are correct in all cases.)
    return ' '.join(
        shlex_quote(str(arg)) if isinstance(arg, HiddenText)
        else shlex_quote(arg) for arg in args
    )


def reveal_command_args(args):
    # type: (Union[List[str], CommandArgs]) -> List[str]
    """
    Return the arguments in their raw, unredacted form.
    """
    return [
        arg.secret if isinstance(arg, HiddenText) else arg for arg in args
    ]


def make_subprocess_output_error(
    cmd_args,     # type: Union[List[str], CommandArgs]
    cwd,          # type: Optional[str]
    lines,        # type: List[Text]
    exit_status,  # type: int
):
    # type: (...) -> Text
    """
    Create and return the error message to use to log a subprocess error
    with command output.

    :param lines: A list of lines, each ending with a newline.
    """
    command = format_command_args(cmd_args)
    # Convert `command` and `cwd` to text (unicode in Python 2) so we can use
    # them as arguments in the unicode format string below. This avoids
    # "UnicodeDecodeError: 'ascii' codec can't decode byte ..." in Python 2
    # if either contains a non-ascii character.
    command_display = str_to_display(command, desc='command bytes')
    cwd_display = path_to_display(cwd)

    # We know the joined output value ends in a newline.
    output = ''.join(lines)
    msg = (
        # Use a unicode string to avoid "UnicodeEncodeError: 'ascii'
        # codec can't encode character ..." in Python 2 when a format
        # argument (e.g. `output`) has a non-ascii character.
        u'Command errored out with exit status {exit_status}:\n'
        ' command: {command_display}\n'
        '     cwd: {cwd_display}\n'
        'Complete output ({line_count} lines):\n{output}{divider}'
    ).format(
        exit_status=exit_status,
        command_display=command_display,
        cwd_display=cwd_display,
        line_count=len(lines),
        output=output,
        divider=LOG_DIVIDER,
    )
    return msg


def call_subprocess(
    cmd,  # type: Union[List[str], CommandArgs]
    show_stdout=False,  # type: bool
    cwd=None,  # type: Optional[str]
    on_returncode='raise',  # type: str
    extra_ok_returncodes=None,  # type: Optional[Iterable[int]]
    command_desc=None,  # type: Optional[str]
    extra_environ=None,  # type: Optional[Mapping[str, Any]]
    unset_environ=None,  # type: Optional[Iterable[str]]
    spinner=None,  # type: Optional[SpinnerInterface]
    log_failed_cmd=True  # type: Optional[bool]
):
    # type: (...) -> Text
    """
    Args:
      show_stdout: if true, use INFO to log the subprocess's stderr and
        stdout streams.  Otherwise, use DEBUG.  Defaults to False.
      extra_ok_returncodes: an iterable of integer return codes that are
        acceptable, in addition to 0. Defaults to None, which means [].
      unset_environ: an iterable of environment variable names to unset
        prior to calling subprocess.Popen().
      log_failed_cmd: if false, failed commands are not logged, only raised.
    """
    if extra_ok_returncodes is None:
        extra_ok_returncodes = []
    if unset_environ is None:
        unset_environ = []
    # Most places in pip use show_stdout=False. What this means is--
    #
    # - We connect the child's output (combined stderr and stdout) to a
    #   single pipe, which we read.
    # - We log this output to stderr at DEBUG level as it is received.
    # - If DEBUG logging isn't enabled (e.g. if --verbose logging wasn't
    #   requested), then we show a spinner so the user can still see the
    #   subprocess is in progress.
    # - If the subprocess exits with an error, we log the output to stderr
    #   at ERROR level if it hasn't already been displayed to the console
    #   (e.g. if --verbose logging wasn't enabled).  This way we don't log
    #   the output to the console twice.
    #
    # If show_stdout=True, then the above is still done, but with DEBUG
    # replaced by INFO.
    if show_stdout:
        # Then log the subprocess output at INFO level.
        log_subprocess = subprocess_logger.info
        used_level = logging.INFO
    else:
        # Then log the subprocess output using DEBUG.  This also ensures
        # it will be logged to the log file (aka user_log), if enabled.
        log_subprocess = subprocess_logger.debug
        used_level = logging.DEBUG

    # Whether the subprocess will be visible in the console.
    showing_subprocess = subprocess_logger.getEffectiveLevel() <= used_level

    # Only use the spinner if we're not showing the subprocess output
    # and we have a spinner.
    use_spinner = not showing_subprocess and spinner is not None

    if command_desc is None:
        command_desc = format_command_args(cmd)

    log_subprocess("Running command %s", command_desc)
    env = os.environ.copy()
    if extra_environ:
        env.update(extra_environ)
    for name in unset_environ:
        env.pop(name, None)
    try:
        proc = subprocess.Popen(
            # Convert HiddenText objects to the underlying str.
            reveal_command_args(cmd),
            stderr=subprocess.STDOUT, stdin=subprocess.PIPE,
            stdout=subprocess.PIPE, cwd=cwd, env=env,
        )
        assert proc.stdin
        assert proc.stdout
        proc.stdin.close()
    except Exception as exc:
        if log_failed_cmd:
            subprocess_logger.critical(
                "Error %s while executing command %s", exc, command_desc,
            )
        raise
    all_output = []
    while True:
        # The "line" value is a unicode string in Python 2.
        line = console_to_str(proc.stdout.readline())
        if not line:
            break
        line = line.rstrip()
        all_output.append(line + '\n')

        # Show the line immediately.
        log_subprocess(line)
        # Update the spinner.
        if use_spinner:
            assert spinner
            spinner.spin()
    try:
        proc.wait()
    finally:
        if proc.stdout:
            proc.stdout.close()
    proc_had_error = (
        proc.returncode and proc.returncode not in extra_ok_returncodes
    )
    if use_spinner:
        assert spinner
        if proc_had_error:
            spinner.finish("error")
        else:
            spinner.finish("done")
    if proc_had_error:
        if on_returncode == 'raise':
            if not showing_subprocess and log_failed_cmd:
                # Then the subprocess streams haven't been logged to the
                # console yet.
                msg = make_subprocess_output_error(
                    cmd_args=cmd,
                    cwd=cwd,
                    lines=all_output,
                    exit_status=proc.returncode,
                )
                subprocess_logger.error(msg)
            exc_msg = (
                'Command errored out with exit status {}: {} '
                'Check the logs for full command output.'
            ).format(proc.returncode, command_desc)
            raise InstallationError(exc_msg)
        elif on_returncode == 'warn':
            subprocess_logger.warning(
                'Command "%s" had error code %s in %s',
                command_desc,
                proc.returncode,
                cwd,
            )
        elif on_returncode == 'ignore':
            pass
        else:
            raise ValueError('Invalid value: on_returncode={!r}'.format(
                             on_returncode))
    return ''.join(all_output)


def runner_with_spinner_message(message):
    # type: (str) -> Callable[..., None]
    """Provide a subprocess_runner that shows a spinner message.

    Intended for use with for pep517's Pep517HookCaller. Thus, the runner has
    an API that matches what's expected by Pep517HookCaller.subprocess_runner.
    """

    def runner(
        cmd,  # type: List[str]
        cwd=None,  # type: Optional[str]
        extra_environ=None  # type: Optional[Mapping[str, Any]]
    ):
        # type: (...) -> None
        with open_spinner(message) as spinner:
            call_subprocess(
                cmd,
                cwd=cwd,
                extra_environ=extra_environ,
                spinner=spinner,
            )

    return runner
