當前位置: 首頁>>代碼示例>>Python>>正文


Python win32com.__gen_path__方法代碼示例

本文整理匯總了Python中win32com.__gen_path__方法的典型用法代碼示例。如果您正苦於以下問題:Python win32com.__gen_path__方法的具體用法?Python win32com.__gen_path__怎麽用?Python win32com.__gen_path__使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在win32com的用法示例。


在下文中一共展示了win32com.__gen_path__方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_win32com

# 需要導入模塊: import win32com [as 別名]
# 或者: from win32com import __gen_path__ [as 別名]
def test_win32com(self):
            """
            win32com should not be prevented from caching COM interfaces
            in gen_py.
            """
            import win32com
            gen_py = win32com.__gen_path__
            target = os.path.join(gen_py, 'test_write')
            sandbox = DirectorySandbox(self.dir)
            try:
                try:
                    sandbox.run(self._file_writer(target))
                except SandboxViolation:
                    self.fail("Could not create gen_py file due to SandboxViolation")
            finally:
                if os.path.exists(target): os.remove(target) 
開發者ID:MayOneUS,項目名稱:pledgeservice,代碼行數:18,代碼來源:test_sandbox.py

示例2: GetGeneratePath

# 需要導入模塊: import win32com [as 別名]
# 或者: from win32com import __gen_path__ [as 別名]
def GetGeneratePath():
	"""Returns the name of the path to generate to.
	Checks the directory is OK.
	"""
	assert not is_readonly, "Why do you want the genpath for a readonly store?"
	try:
		os.makedirs(win32com.__gen_path__)
		#os.mkdir(win32com.__gen_path__)
	except os.error:
		pass
	try:
		fname = os.path.join(win32com.__gen_path__, "__init__.py")
		os.stat(fname)
	except os.error:
		f = open(fname,"w")
		f.write('# Generated file - this directory may be deleted to reset the COM cache...\n')
		f.write('import win32com\n')
		f.write('if __path__[:-1] != win32com.__gen_path__: __path__.append(win32com.__gen_path__)\n')
		f.close()
	
	return win32com.__gen_path__

#
# The helpers for win32com.client.Dispatch and OCX clients.
# 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:27,代碼來源:gencache.py

示例3: _SaveDicts

# 需要導入模塊: import win32com [as 別名]
# 或者: from win32com import __gen_path__ [as 別名]
def _SaveDicts():
	if is_readonly:
		raise RuntimeError("Trying to write to a readonly gencache ('%s')!" \
		                    % win32com.__gen_path__)
	f = open(os.path.join(GetGeneratePath(), "dicts.dat"), "wb")
	try:
		p = pickle.Pickler(f)
		p.dump(pickleVersion)
		p.dump(clsidToTypelib)
	finally:
		f.close() 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:13,代碼來源:gencache.py

示例4: _Dump

# 需要導入模塊: import win32com [as 別名]
# 或者: from win32com import __gen_path__ [as 別名]
def _Dump():
	print "Cache is in directory", win32com.__gen_path__
	# Build a unique dir
	d = {}
	for clsid, (typelibCLSID, lcid, major, minor) in clsidToTypelib.iteritems():
		d[typelibCLSID, lcid, major, minor] = None
	for typelibCLSID, lcid, major, minor in d.iterkeys():
		mod = GetModuleForTypelib(typelibCLSID, lcid, major, minor)
		print "%s - %s" % (mod.__doc__, typelibCLSID)

# Boot up 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:13,代碼來源:gencache.py

示例5: __init__

# 需要導入模塊: import win32com [as 別名]
# 或者: from win32com import __gen_path__ [as 別名]
def __init__(self, *args, **kwargs):
        """
        Attempts to retrieve list of voices from the SAPI.SpVoice API.

        However, if not running on Windows, no environment inspection is
        attempted and an exception is immediately raised.
        """

        if not self.IS_WINDOWS:
            raise EnvironmentError("SAPI 5 is only available on Windows")

        super(SAPI5COM, self).__init__(*args, **kwargs)

        # win32com and pythoncom are Windows only, pylint:disable=import-error

        try:
            import win32com.client
        except IOError:  # some Anki packages have an unwritable cache path
            self._logger.warn("win32com.client import failed; trying again "
                              "with alternate __gen_path__ set")
            import win32com
            import os.path
            import tempfile
            win32com.__gen_path__ = os.path.join(tempfile.gettempdir(),
                                                 'gen_py')
            import win32com.client
        self._client = win32com.client

        import pythoncom
        self._pythoncom = pythoncom

        # pylint:enable=import-error

        voices = self._client.Dispatch('SAPI.SpVoice').getVoices()
        self._voice_map = {
            voice.getAttribute('name'): voice
            for voice in [voices.item(i) for i in range(voices.count)]
        }

        if not self._voice_map:
            raise EnvironmentError("No voices returned by SAPI 5") 
開發者ID:AwesomeTTS,項目名稱:awesometts-anki-addon,代碼行數:43,代碼來源:sapi5com.py

示例6: _LoadDicts

# 需要導入模塊: import win32com [as 別名]
# 或者: from win32com import __gen_path__ [as 別名]
def _LoadDicts():
	# Load the dictionary from a .zip file if that is where we live.
	if hasattr(win32com, "__loader__"):
		import cStringIO as io
		loader = win32com.__loader__
		arc_path = loader.archive
		dicts_path = os.path.join(win32com.__gen_path__, "dicts.dat")
		if dicts_path.startswith(arc_path):
			dicts_path = dicts_path[len(arc_path)+1:]
		else:
			# Hm. See below.
			return
		try:
			data = loader.get_data(dicts_path)
		except AttributeError:
			# The __loader__ has no get_data method.  See below.
			return
		except IOError:
			# Our gencache is in a .zip file (and almost certainly readonly)
			# but no dicts file.  That actually needn't be fatal for a frozen
			# application.  Assuming they call "EnsureModule" with the same
			# typelib IDs they have been frozen with, that EnsureModule will
			# correctly re-build the dicts on the fly.  However, objects that
			# rely on the gencache but have not done an EnsureModule will
			# fail (but their apps are likely to fail running from source
			# with a clean gencache anyway, as then they would be getting
			# Dynamic objects until the cache is built - so the best answer
			# for these apps is to call EnsureModule, rather than freezing
			# the dict)
			return
		f = io.StringIO(data)
	else:
		# NOTE: IOError on file open must be caught by caller.
		f = open(os.path.join(win32com.__gen_path__, "dicts.dat"), "rb")
	try:
		p = pickle.Unpickler(f)
		version = p.load()
		global clsidToTypelib
		clsidToTypelib = p.load()
		versionRedirectMap.clear()
	finally:
		f.close() 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:44,代碼來源:gencache.py

示例7: GetGeneratedInfos

# 需要導入模塊: import win32com [as 別名]
# 或者: from win32com import __gen_path__ [as 別名]
def GetGeneratedInfos():
	zip_pos = win32com.__gen_path__.find(".zip\\")
	if zip_pos >= 0:
		import zipfile
		zip_file = win32com.__gen_path__[:zip_pos+4]
		zip_path = win32com.__gen_path__[zip_pos+5:].replace("\\", "/")
		zf = zipfile.ZipFile(zip_file)
		infos = {}
		for n in zf.namelist():
			if not n.startswith(zip_path):
				continue
			base = n[len(zip_path)+1:].split("/")[0]
			try:
				iid, lcid, major, minor = base.split("x")
				lcid = int(lcid)
				major = int(major)
				minor = int(minor)
				iid = pywintypes.IID("{" + iid + "}")
			except ValueError:
				continue
			except pywintypes.com_error:
				# invalid IID
				continue
			infos[(iid, lcid, major, minor)] = 1
		zf.close()
		return list(infos.keys())
	else:
		# on the file system
		files = glob.glob(win32com.__gen_path__+ "\\*")
		ret = []
		for file in files:
			if not os.path.isdir(file) and not os.path.splitext(file)[1]==".py":
				continue
			name = os.path.splitext(os.path.split(file)[1])[0]
			try:
				iid, lcid, major, minor = name.split("x")
				iid = pywintypes.IID("{" + iid + "}")
				lcid = int(lcid)
				major = int(major)
				minor = int(minor)
			except ValueError:
				continue
			except pywintypes.com_error:
				# invalid IID
				continue
			ret.append((iid, lcid, major, minor))
		return ret 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:49,代碼來源:gencache.py


注:本文中的win32com.__gen_path__方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。