本文整理匯總了Python中Foundation.NSDictionary.dictionaryWithContentsOfURL_方法的典型用法代碼示例。如果您正苦於以下問題:Python NSDictionary.dictionaryWithContentsOfURL_方法的具體用法?Python NSDictionary.dictionaryWithContentsOfURL_怎麽用?Python NSDictionary.dictionaryWithContentsOfURL_使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Foundation.NSDictionary
的用法示例。
在下文中一共展示了NSDictionary.dictionaryWithContentsOfURL_方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: init_with_sucatalog
# 需要導入模塊: from Foundation import NSDictionary [as 別名]
# 或者: from Foundation.NSDictionary import dictionaryWithContentsOfURL_ [as 別名]
def init_with_sucatalog(sucatalog, pkg_re = "^.*/XProtectPlistConfigData.*\.pkg$"):
meta = None
data = None
pkg_url = None
u = NSURL.URLWithString_(sucatalog)
d = NSDictionary.dictionaryWithContentsOfURL_(u)
if not d:
raise Exception("Invalid CatalogURL.", sucatalog)
for k, v in d["Products"].items():
for package in v["Packages"]:
r = re.compile(pkg_re)
if r.findall(package["URL"]) != []:
pkg_url = package["URL"]
if not pkg_url:
raise Exception("Package not found.", sucatalog, pkg_name)
tmp_t = "%f" % time.time()
tmp_pkg = "/tmp/xplist_%s.pkg" % tmp_t
tmp_dir = "/tmp/xplist_%s" % tmp_t
tmp_tar = "/tmp/xplist_%s/Payload" % tmp_t
cmds = [ "/usr/bin/curl -s -o '%s' '%s'" %(tmp_pkg, pkg_url),
"/usr/sbin/pkgutil --expand '%s' '%s'" %(tmp_pkg, tmp_dir),
"/usr/bin/tar xf '%s' -C '%s' -s '|.*/||' --include '*.plist'" %(tmp_tar, tmp_dir) ]
for cmd in cmds:
retcode = os.system(cmd)
if retcode != 0:
raise Exception("Error processing package.", pkg_url, retcode, cmd)
fmeta = "%s/XProtect.meta.plist" % tmp_dir
fdata = "%s/XProtect.plist" % tmp_dir
if os.path.exists(fmeta) and os.path.exists(fdata):
meta, data = init_with_files(fmeta, fdata)
return meta, data, pkg_url