本文整理汇总了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