当前位置: 首页>>代码示例>>Python>>正文


Python NSData.dataWithContentsOfFile_方法代码示例

本文整理汇总了Python中Foundation.NSData.dataWithContentsOfFile_方法的典型用法代码示例。如果您正苦于以下问题:Python NSData.dataWithContentsOfFile_方法的具体用法?Python NSData.dataWithContentsOfFile_怎么用?Python NSData.dataWithContentsOfFile_使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Foundation.NSData的用法示例。


在下文中一共展示了NSData.dataWithContentsOfFile_方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: from Foundation import NSData [as 别名]
# 或者: from Foundation.NSData import dataWithContentsOfFile_ [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
开发者ID:Jaharmi,项目名称:instadmg,代码行数:62,代码来源:hash_lion_password.py

示例2: _readPlist

# 需要导入模块: from Foundation import NSData [as 别名]
# 或者: from Foundation.NSData import dataWithContentsOfFile_ [as 别名]
def _readPlist(filepath):
    """
    Read a .plist file from filepath.  Return the unpacked root object
    (which is usually a dictionary).

    If the file doesn't exist, this returns None
    """
    if not os.path.isfile(filepath):
        log.debug('Tried to read non-existent property list at path: {0}'.format(filepath))
        return None

    plistData = NSData.dataWithContentsOfFile_(filepath)

    dataObject, plistFormat, error = \
        NSPropertyListSerialization.propertyListFromData_mutabilityOption_format_errorDescription_(
            plistData, NSPropertyListMutableContainers, None, None)
    if error:
        error = error.encode('ascii', 'ignore')
        errmsg = "%s in file %s" % (error, filepath)

        import traceback

        log.debug(errmsg)
        log.debug(traceback.format_exc())
        raise NSPropertyListSerializationException(errmsg)
    else:
        return dataObject
开发者ID:mafrosis,项目名称:salt-osx,代码行数:29,代码来源:plist_serialization.py

示例3: readPlist

# 需要导入模块: from Foundation import NSData [as 别名]
# 或者: from Foundation.NSData import dataWithContentsOfFile_ [as 别名]
def readPlist(filepath):
    """Read a .plist file from filepath.  Return the unpacked root object
    (which is usually a dictionary)."""
    try:
        data = NSData.dataWithContentsOfFile_(filepath)
    except NSPropertyListSerializationException, error:
        # insert filepath info into error message
        errmsg = u"%s in %s" % (error, filepath)
        raise NSPropertyListSerializationException(errmsg)
开发者ID:RhondaMichelleR,项目名称:autopkg,代码行数:11,代码来源:FoundationPlist.py

示例4: readPlist

# 需要导入模块: from Foundation import NSData [as 别名]
# 或者: from Foundation.NSData import dataWithContentsOfFile_ [as 别名]
def readPlist(path):
    plistData = NSData.dataWithContentsOfFile_(path)
    dataObject, plistFormat, error = \
        NSPropertyListSerialization.propertyListFromData_mutabilityOption_format_errorDescription_(
        plistData, NSPropertyListMutableContainers, None, None)
    if error:
        errmsg = "%s in file %s" % (repr(error), repr(path))
        raise NSPropertyListSerializationException(errmsg)
    else:
        return dataObject
开发者ID:MagerValp,项目名称:extractinstalls,代码行数:12,代码来源:extractinstalls.py

示例5: _init_from_file

# 需要导入模块: from Foundation import NSData [as 别名]
# 或者: from Foundation.NSData import dataWithContentsOfFile_ [as 别名]
 def _init_from_file(self, file):
     #ns_image = NSImage.alloc().initWithContentsOfFile_(file)
     #if not ns_image:
     ns_data = NSData.dataWithContentsOfFile_(file)
     if not ns_data:
         raise EnvironmentError("Unable to read image file: %s" % file)
     ns_rep = NSBitmapImageRep.imageRepWithData_(ns_data)
     if not ns_rep:
         raise ValueError("Unrecognised image file type: %s" % file)
     ns_rep.setSize_((ns_rep.pixelsWide(), ns_rep.pixelsHigh()))
     self._init_from_ns_rep(ns_rep)
开发者ID:karlmatthew,项目名称:pygtk-craigslist,代码行数:13,代码来源:Image.py

示例6: readPlist

# 需要导入模块: from Foundation import NSData [as 别名]
# 或者: from Foundation.NSData import dataWithContentsOfFile_ [as 别名]
def readPlist(filepath):
    '''Read a .plist file from filepath.  Return the unpacked root object
    (which is usually a dictionary).'''
    plistData = NSData.dataWithContentsOfFile_(filepath)
    (dataObject, plistFormat, error) = (
        NSPropertyListSerialization.propertyListWithData_options_format_error_(
            plistData, NSPropertyListMutableContainersAndLeaves, None, None))
    if error:
        errmsg = u"%s in file %s" % (error, filepath)
        raise NSPropertyListSerializationException(errmsg)
    else:
        return dataObject
开发者ID:jbaker10,项目名称:PSU-2016,代码行数:14,代码来源:FoundationPlist.py

示例7: readPlist

# 需要导入模块: from Foundation import NSData [as 别名]
# 或者: from Foundation.NSData import dataWithContentsOfFile_ [as 别名]
 def readPlist(self, filepath):
     """
     Read a .plist file from filepath.  Return the unpacked root object
     (which is usually a dictionary).
     """
     plistData = NSData.dataWithContentsOfFile_(filepath)
     dataObject, plistFormat, error = \
         NSPropertyListSerialization.propertyListFromData_mutabilityOption_format_errorDescription_(
                      plistData, NSPropertyListMutableContainers, None, None)
     if error:
         errmsg = "%s in file %s" % (error, filepath)
         raise ProcessorError(errmsg)
     else:
         return dataObject
开发者ID:elflames,项目名称:macautopkg,代码行数:16,代码来源:Versioner.py

示例8: read_bundle_info

# 需要导入模块: from Foundation import NSData [as 别名]
# 或者: from Foundation.NSData import dataWithContentsOfFile_ [as 别名]
 def read_bundle_info(self, path):
     """Read Contents/Info.plist inside a bundle."""
     
     plistpath = os.path.join(path, "Contents", "Info.plist")
     info, format, error = \
         NSPropertyListSerialization.propertyListFromData_mutabilityOption_format_errorDescription_(
             NSData.dataWithContentsOfFile_(plistpath),
             NSPropertyListMutableContainers,
             None,
             None
         )
     if error:
         raise ProcessorError("Can't read %s: %s" % (plistpath, error))
     
     return info
开发者ID:Chalcahuite,项目名称:autopkg,代码行数:17,代码来源:AppDmgVersioner.py

示例9: read_recipe

# 需要导入模块: from Foundation import NSData [as 别名]
# 或者: from Foundation.NSData import dataWithContentsOfFile_ [as 别名]
    def read_recipe(self, path):
        """Read a recipe into a dict."""
        path = os.path.expanduser(path)
        if not (os.path.isfile(path)):
            raise Exception("File does not exist: %s" % path)
        info, pformat, error = \
            NSPropertyListSerialization.propertyListWithData_options_format_error_(
                NSData.dataWithContentsOfFile_(path),
                NSPropertyListMutableContainers,
                None,
                None
            )
        if error:
            raise Exception("Can't read %s: %s" % (path, error))

        self._xml = info
开发者ID:mattlavine,项目名称:Recategorizer,代码行数:18,代码来源:Recategorizer.py

示例10: addToWf

# 需要导入模块: from Foundation import NSData [as 别名]
# 或者: from Foundation.NSData import dataWithContentsOfFile_ [as 别名]
def addToWf(wf, buffer, icon):
    for filename in buffer:
        filename = filename.strip(u"\r\n")
        plist_data = NSData.dataWithContentsOfFile_(filename)
        (dataObject, plistFormat, error) = (
            NSPropertyListSerialization.
            propertyListWithData_options_format_error_(
                plist_data,
                NSPropertyListMutableContainersAndLeaves,
                None,
                None))
        wf.add_item(title=dataObject["Name"],
                    subtitle=dataObject["URL"],
                    arg=dataObject["URL"],
                    valid=True,
                    icon=icon)
开发者ID:gybcb,项目名称:alfred-workflow,代码行数:18,代码来源:safarisearch.py

示例11: readPlist

# 需要导入模块: from Foundation import NSData [as 别名]
# 或者: from Foundation.NSData import dataWithContentsOfFile_ [as 别名]
def readPlist(filepath):
    """
    Read a .plist file from filepath.  Return the unpacked root object
    (which is usually a dictionary).
    """
    plistData = NSData.dataWithContentsOfFile_(filepath)
    dataObject, dummy_plistFormat, error = (
        NSPropertyListSerialization.
        propertyListFromData_mutabilityOption_format_errorDescription_(
            plistData, NSPropertyListMutableContainers, None, None))
    if error:
        error = error.encode('ascii', 'ignore')
        errmsg = "%s in file %s" % (error, filepath)
        raise NSPropertyListSerializationException(errmsg)
    else:
        return dataObject
开发者ID:CLCMacTeam,项目名称:bigfiximport,代码行数:18,代码来源:FoundationPlist.py

示例12: read_bundle_info

# 需要导入模块: from Foundation import NSData [as 别名]
# 或者: from Foundation.NSData import dataWithContentsOfFile_ [as 别名]
    def read_bundle_info(self, path):
        """Read Contents/Info.plist inside a bundle."""
        # pylint: disable=no-self-use

        plistpath = os.path.join(path, "Contents", "Info.plist")
        # pylint: disable=line-too-long
        info, _, error = NSPropertyListSerialization.propertyListFromData_mutabilityOption_format_errorDescription_(
            NSData.dataWithContentsOfFile_(plistpath),
            NSPropertyListMutableContainers,
            None,
            None,
        )
        # pylint: enable=line-too-long

        if error:
            raise ProcessorError("Can't read %s: %s" % (plistpath, error))

        return info
开发者ID:autopkg,项目名称:autopkg,代码行数:20,代码来源:AppDmgVersioner.py

示例13: pdf2tiff

# 需要导入模块: from Foundation import NSData [as 别名]
# 或者: from Foundation.NSData import dataWithContentsOfFile_ [as 别名]
def pdf2tiff(pdfPath, pageNum=0, resolution=72.0):
    "Convert one page of a PDF to TIFF at a specific res. in DPI."

    tiffPath = "%s-%d.tiff" % (splitext(pdfPath)[0], pageNum)
    pdfData = NSData.dataWithContentsOfFile_(pdfPath)
    pdfRep = NSPDFImageRep.imageRepWithData_(pdfData)
    pageCount = pdfRep.pageCount()
    if pageNum > pageCount-1: return
    pdfRep.setCurrentPage_(pageNum)
    pdfImage = NSImage.alloc().init()
    pdfImage.addRepresentation_(pdfRep)
    originalSize = pdfImage.size()
    width, height = originalSize
    pdfImage.setScalesWhenResized_(YES)
    rf = resolution / 72.0
    pdfImage.setSize_((width*rf, height*rf))
    tiffData = pdfImage.TIFFRepresentation()
    tiffData.writeToFile_atomically_(tiffPath, YES)
开发者ID:bhramoss,项目名称:code,代码行数:20,代码来源:recipe-223320.py

示例14: convertIconToPNG

# 需要导入模块: from Foundation import NSData [as 别名]
# 或者: from Foundation.NSData import dataWithContentsOfFile_ [as 别名]
def convertIconToPNG(icon_path, destination_path, desired_pixel_height=350):
    '''Converts an icns file to a png file, choosing the representation
    closest to (but >= if possible) the desired_pixel_height.
    Returns True if successful, False otherwise'''
    if os.path.exists(icon_path):
        image_data = NSData.dataWithContentsOfFile_(icon_path)
        bitmap_reps = NSBitmapImageRep.imageRepsWithData_(image_data)
        chosen_rep = None
        for bitmap_rep in bitmap_reps:
            if not chosen_rep:
                chosen_rep = bitmap_rep
            elif (bitmap_rep.pixelsHigh() >= desired_pixel_height
                  and bitmap_rep.pixelsHigh() < chosen_rep.pixelsHigh()):
                chosen_rep = bitmap_rep
        if chosen_rep:
            png_data = chosen_rep.representationUsingType_properties_(
                NSPNGFileType, None)
            png_data.writeToFile_atomically_(destination_path, False)
            return True
    return False
开发者ID:CLCMacTeam,项目名称:bigfiximport,代码行数:22,代码来源:iconutils.py

示例15: read_file

# 需要导入模块: from Foundation import NSData [as 别名]
# 或者: from Foundation.NSData import dataWithContentsOfFile_ [as 别名]
    def read_file(self, path):
        """Replace internal XML dict with data from plist at path.
        Args:
            path: String path to a plist file.

        Raises:
            PlistParseError: Error in reading plist file.
        """
        # pylint: disable=unused-variable
        info, pformat, error = (
            NSPropertyListSerialization.propertyListWithData_options_format_error_(
                NSData.dataWithContentsOfFile_(os.path.expanduser(path)),
                NSPropertyListMutableContainersAndLeaves,
                None,
                None
            ))
        # pylint: enable=unused-variable
        if info is None:
            if error is None:
                error = "Invalid plist file."
            raise PlistParseError("Can't read %s: %s" % (path, error))

        return info
开发者ID:futureimperfect,项目名称:jss-recipes,代码行数:25,代码来源:validate_recipes.py


注:本文中的Foundation.NSData.dataWithContentsOfFile_方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。