本文整理汇总了Python中Foundation.NSData.alloc方法的典型用法代码示例。如果您正苦于以下问题:Python NSData.alloc方法的具体用法?Python NSData.alloc怎么用?Python NSData.alloc使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Foundation.NSData
的用法示例。
在下文中一共展示了NSData.alloc方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from Foundation import NSData [as 别名]
# 或者: from Foundation.NSData import alloc [as 别名]
def main(argv):
p = optparse.OptionParser()
p.set_usage("""Usage: %prog [options] userdata.plist [password]""")
p.add_option("-v", "--verbose", action="store_true",
help="Verbose output.")
options, argv = p.parse_args(argv)
if len(argv) not in (2, 3):
print >>sys.stderr, p.get_usage()
return 1
# Read the userdata.plist.
plist = argv[1]
plist_data = NSData.dataWithContentsOfFile_(plist)
if not plist_data:
print >>sys.stderr, "Couldn't read %s" % plist
return 1
user_plist, plist_format, error = \
NSPropertyListSerialization.propertyListFromData_mutabilityOption_format_errorDescription_(
plist_data, NSPropertyListMutableContainers, None, None)
if error:
print >>sys.stderr, "Can't read %s: %s" % (plist, error)
return 1
# Use password on commandline, or ask if one isn't provided.
try:
password = argv[2]
except IndexError:
while True:
password = getpass.getpass()
verify_password = getpass.getpass("Password again: ")
if password == verify_password:
break
else:
print "Passwords don't match!"
# Hash password with all available methods.
hashed_passwords = dict()
for k, m in hash_methods.items():
hashed_pwd = m(password)
pwd_data = NSData.alloc().initWithBytes_length_(hashed_pwd, len(hashed_pwd))
hashed_passwords[k] = pwd_data
# Serialize hashed passwords to a binary plist.
serialized_passwords = serialize_hash_dict(hashed_passwords)
if not serialized_passwords:
return 2
# Write back userdata.plist with ShadowHashData.
user_plist["ShadowHashData"] = list()
user_plist["ShadowHashData"].append(serialized_passwords)
plist_data, error = \
NSPropertyListSerialization.dataFromPropertyList_format_errorDescription_(
user_plist, plist_format, None)
plist_data.writeToFile_atomically_(argv[1], True)
return 0
示例2: loadAndSetInterfaceData
# 需要导入模块: from Foundation import NSData [as 别名]
# 或者: from Foundation.NSData import alloc [as 别名]
def loadAndSetInterfaceData(self):
def setDefaults(interfaceData):
if not interfaceData:
# first start ever
self.view.SetClientSize(self.view.wx.Size(1200, 700))
self.view.Center(self.view.wx.BOTH)
self.setCurrentEditorStyle(self.defaultEditorStyle)
return
# fine grain tuning
try:
self.view.SetSize(interfaceData["Size"])
self.view.SetPosition(interfaceData["Position"])
self.view.splitter.SetSashPosition(interfaceData["SplitterSashPosition"])
except:
# set UI defaults
self.view.SetClientSize(self.view.wx.Size(1200, 700))
self.view.Center(self.view.wx.BOTH)
# at least try to set the editor style
try:
self.setCurrentEditorStyle(interfaceData["editorStyle"])
self.toggleMenuItemByStyleName(interfaceData["editorStyle"])
except:
# no editor style on file
self.setCurrentEditorStyle(self.defaultEditorStyle)
# Needs to be None
interfaceData = None
theFile = os.path.join(self.model.getApplicationSupportDir(), ".makerUISettings")
if os.path.isfile(theFile):
try:
interfaceData = readDataFromFile(theFile)
self.view.SetSize(interfaceData["Size"])
self.view.SetPosition(interfaceData["Position"])
self.view.splitter.SetSashPosition(interfaceData["SplitterSashPosition"])
try:
self.setCurrentEditorStyle(interfaceData["editorStyle"])
self.toggleMenuItemByStyleName(interfaceData["editorStyle"])
except:
# no editor style on file
self.setCurrentEditorStyle(self.defaultEditorStyle)
try:
# enable security-scoped-bookmarks for use in this session
for item in interfaceData["bookmarks"]:
nsdata = NSData.alloc().initWithBytes_length_(item, len(item))
url = NSURL.URLByResolvingBookmarkData_options_relativeToURL_bookmarkDataIsStale_error_(nsdata,
NSURLBookmarkResolutionWithSecurityScope,
None,
None,
None)
theURL = url[0]
# save again to bookmarks but only if this project
# is still linked
if theURL.path() in self.model.linkedProjectPaths:
self.model.bookmarks.append(item)
theURL.startAccessingSecurityScopedResource()
self.model.securityScopedResources.append(theURL)
except:
print "Unable to resolve security-scoped-bookmarks"
try:
# open all files that had been open in last session
for sessionFile in interfaceData["sessionFiles"]:
self.autoLoadProject(sessionFile[2])
#self.model.load(sessionFile[2])
item = (self.model.getActiveProject()).projectController.findTreeItem(sessionFile[0], sessionFile[1])
(self.model.getActiveProject()).projectController.selectTreeItemAndLoad(item)
# set scroll position
ed = ((self.model.getActiveProject()).getCurrentFile()).fileController.editor
ed.GotoPos(sessionFile[3])
# make last open file current file
for sessionFile in interfaceData["sessionFiles"]:
if sessionFile[-1] == "True":
self.autoLoadProject(sessionFile[2])
item = (self.model.getActiveProject()).projectController.findTreeItem(sessionFile[0], sessionFile[1])
(self.model.getActiveProject()).projectController.selectTreeItemAndLoad(item)
# set scroll position
ed = ((self.model.getActiveProject()).getCurrentFile()).fileController.editor
ed.GotoPos(sessionFile[3])
#.........这里部分代码省略.........