本文整理汇总了Python中exe.engine.path.Path.write_bytes方法的典型用法代码示例。如果您正苦于以下问题:Python Path.write_bytes方法的具体用法?Python Path.write_bytes怎么用?Python Path.write_bytes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类exe.engine.path.Path
的用法示例。
在下文中一共展示了Path.write_bytes方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testReferenceCounting
# 需要导入模块: from exe.engine.path import Path [as 别名]
# 或者: from exe.engine.path.Path import write_bytes [as 别名]
def testReferenceCounting(self):
"""
Make 3 resources with different names but same md5, ensure they are reference counted properly
"""
res1 = Path('my.resource1.bin')
res2 = Path('my.resource2.bin')
res3 = Path('my.resource3.bin')
for res in (res1, res2, res3):
res.write_bytes('SOME NICE DATA')
res1md5 = res1.md5
res4 = Path('tmp/my.resource1.bin')
if not res4.dirname().exists():
res4.dirname().makedirs()
res4.write_bytes('SOME *DIFFERENT* DATA')
res4md5 = res4.md5
res1, res2, res3, res4 = map(lambda f: Resource(self.package, f), (res1, res2, res3, res4))
assert res1.storageName == 'my.resource1.bin', res1.storageName
assert res2.storageName == 'my.resource1.bin', res2.storageName
assert res3.storageName == 'my.resource1.bin', res3.storageName
assert res4.storageName == 'my.resource1.1.bin', res4.storageName
assert res4.userName == 'my.resource1.bin', res4.userName
assert len(self.package.resources) == 2
assert len(self.package.resources[res1.path.md5]) == 3
assert len(self.package.resources[res4.path.md5]) == 1
assert self.package.resources[res4md5][0] is res4
# Now start deleting things
res4path = Path(res4.path)
assert res4path.exists()
res4.delete()
assert not res4path.exists()
assert res4md5 not in self.package.resources
assert not res4path.exists()
res1path = Path(res1.path)
assert res1path.exists()
res2.delete()
assert res1path.exists()
assert res2 not in self.package.resources[res1md5]
res1.delete()
assert res1path.exists()
assert res1 not in self.package.resources[res1md5]
res3.delete()
assert res1md5 not in self.package.resources
assert not res1path.exists()
示例2: Path
# 需要导入模块: from exe.engine.path import Path [as 别名]
# 或者: from exe.engine.path.Path import write_bytes [as 别名]
sys.path.insert(0, ".")
from twisted.web.microdom import parseString
from twisted.web.domhelpers import findNodesNamed
from exe.engine.path import Path
import json
import re
if __name__ == "__main__":
files = {
"lomVocab": Path("exe") / "webui" / "schemas" / "scorm2004" / "common" / "vocabValues.xsd",
"lomesVocab": Path("exe") / "webui" / "schemas" / "scorm2004" / "vocab" / "lomesvocab.xsd",
}
response = ""
vocab = {}
for varname, f in files.items():
document = parseString(f.bytes(), escapeAttributes=0)
nodes = findNodesNamed(document, "xs:simpletype")
for node in nodes:
name = node.getAttribute("name", str())
enumerations = findNodesNamed(node, "xs:enumeration")
vocab[name] = []
for enumeration in enumerations:
vocab[name].append([enumeration.getAttribute("value"), "_(%s)" % enumeration.getAttribute("value")])
response += "%s = %s;\n\n" % (varname, json.dumps(vocab, indent=4).encode("utf-8"))
outfile = Path("exe") / "jsui" / "scripts" / "lomvocab.js"
response = re.sub('"_\(', '_("', response)
response = re.sub('\)"', '")', response)
outfile.write_bytes(response)