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


Python plistlib.InvalidFileException方法代码示例

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


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

示例1: main

# 需要导入模块: import plistlib [as 别名]
# 或者: from plistlib import InvalidFileException [as 别名]
def main():
    try:
        try:
            plist_file = determine_plist_path(sys.argv[1])
            with open(plist_file, 'rb') as f:
                plist_data = plistlib.load(f)
        except IndexError:
            plist_file = '<stdin>'
            plist_data = plistlib.loads(sys.stdin.buffer.read())

        print(yaml.dump(plist_data, default_flow_style=False), end='')
    except IOError:
        print(f'{RED}Error: The requested plist file {plist_file} was not found{ENDC}')
        exit(1)
    except plistlib.InvalidFileException:
        print(f'{RED}Error: Unable to parse the requested plist file {plist_file}{ENDC}')
        exit(1)
    except KeyboardInterrupt:
        pass 
开发者ID:fgimian,项目名称:macbuild-ansible,代码行数:21,代码来源:plistinfo.py

示例2: parse

# 需要导入模块: import plistlib [as 别名]
# 或者: from plistlib import InvalidFileException [as 别名]
def parse(self, fp):
        try:
            # The basic file format:
            # HEADER
            # object...
            # refid->offset...
            # TRAILER
            self._fp = fp
            self._fp.seek(-32, os.SEEK_END)
            trailer = self._fp.read(32)
            if len(trailer) != 32:
                raise InvalidFileException()
            (
                offset_size, self._ref_size, num_objects, top_object,
                offset_table_offset
            ) = struct.unpack('>6xBBQQQ', trailer)
            self._fp.seek(offset_table_offset)
            self._object_offsets = self._read_ints(num_objects, offset_size)
            self._objects = [_undefined] * num_objects
            return self._read_object(top_object)

        except (OSError, IndexError, struct.error, OverflowError,
                UnicodeDecodeError):
            raise InvalidFileException() 
开发者ID:corpnewt,项目名称:USBMap,代码行数:26,代码来源:plist.py

示例3: get_sus_install_report

# 需要导入模块: import plistlib [as 别名]
# 或者: from plistlib import InvalidFileException [as 别名]
def get_sus_install_report():
    """Return installed apple updates from softwareupdate"""
    try:
        history = plistlib.loads(
            pathlib.Path('/Library/Receipts/InstallHistory.plist').read_bytes())
    except (IOError, plistlib.InvalidFileException):
        history = []
    return {
        i['displayName']: {
            'date_managed': i['date'],
            'status': 'PRESENT',
            'data': {
                'type': 'Apple SUS Install',
                'version': i['displayVersion'].strip()
            }
        } for i in history if i['processName'] == 'softwareupdated'} 
开发者ID:salopensource,项目名称:sal-scripts,代码行数:18,代码来源:apple_sus_checkin.py

示例4: get_managed_install_report

# 需要导入模块: import plistlib [as 别名]
# 或者: from plistlib import InvalidFileException [as 别名]
def get_managed_install_report():
    """Return Munki ManagedInstallsReport.plist as a plist dict.

    Returns:
        ManagedInstalls report for last Munki run as a plist
        dict, or an empty dict.
    """
    # Checks munki preferences to see where the install directory is set to.
    managed_install_dir = munkicommon.pref('ManagedInstallDir')

    # set the paths based on munki's configuration.
    managed_install_report = pathlib.Path(managed_install_dir) / 'ManagedInstallReport.plist'

    try:
        munki_report = plistlib.loads(managed_install_report.read_bytes())
    except (IOError, plistlib.InvalidFileException):
        munki_report = {}

    if 'MachineInfo' not in munki_report:
        munki_report['MachineInfo'] = {}

    return sal.unobjctify(munki_report) 
开发者ID:salopensource,项目名称:sal-scripts,代码行数:24,代码来源:munki_checkin.py

示例5: get_optional_manifest

# 需要导入模块: import plistlib [as 别名]
# 或者: from plistlib import InvalidFileException [as 别名]
def get_optional_manifest():
    """Return Munki SelfServeManifest as a plist dict.

    Returns:
        SelfServeManifest for last Munki run as a plist
        dict, or an empty dict.
    """
    # Checks munki preferences to see where the install directory is set to.
    managed_install_dir = munkicommon.pref('ManagedInstallDir')

    # set the paths based on munki's configuration.
    optional_manifest_path = pathlib.Path(managed_install_dir) / 'manifests/SelfServeManifest'

    try:
        optional_manifest = plistlib.loads(optional_manifest_path.read_bytes())
    except (IOError, plistlib.InvalidFileException):
        optional_manifest = {}

    return optional_manifest 
开发者ID:salopensource,项目名称:sal-scripts,代码行数:21,代码来源:munki_checkin.py

示例6: get_profiles

# 需要导入模块: import plistlib [as 别名]
# 或者: from plistlib import InvalidFileException [as 别名]
def get_profiles():
    try:
        temp_dir = pathlib.Path(tempfile.mkdtemp())
        profile_out = temp_dir / 'profiles.plist'

        cmd = ['/usr/bin/profiles', '-C', '-o', profile_out]
        # dev_null = open(os.devnull, 'w')
        try:
            subprocess.call(cmd, stdout=subprocess.PIPE)
        except OSError:
            return {}

        try:
            profiles = plistlib.loads(profile_out.read_bytes())
        except plistlib.InvalidFileException:
            return {}
    finally:
        profile_out.unlink(missing_ok=True)
        temp_dir.rmdir()

    return profiles 
开发者ID:salopensource,项目名称:sal-scripts,代码行数:23,代码来源:profile_checkin.py

示例7: do_plist

# 需要导入模块: import plistlib [as 别名]
# 或者: from plistlib import InvalidFileException [as 别名]
def do_plist(module, filename, values, backup=False):
    working_values = values
    changed = False

    try:
        f = open(filename, 'rb')
        plist = plistlib.load(f)
    except IOError:
        plist = {}
    except plistlib.InvalidFileException:
        module.fail_json(msg="an invalid plist already exists")

    changed = not equal(plist, working_values)

    if changed and not module.check_mode:
        if backup:
            module.backup_local(filename)

        try:
            update(plist, working_values)
            plist_dir = os.path.dirname(filename)
            if not os.path.exists(plist_dir):
                os.makedirs(plist_dir)
            f = open(filename, 'wb')
            plistlib.dump(plist, f)
        except Exception as e:
            module.fail_json(msg="Can't change %s" % filename, error=str(e))

    return changed 
开发者ID:fgimian,项目名称:macbuild-ansible,代码行数:31,代码来源:plist.py

示例8: _read_ints

# 需要导入模块: import plistlib [as 别名]
# 或者: from plistlib import InvalidFileException [as 别名]
def _read_ints(self, n, size):
        data = self._fp.read(size * n)
        if size in _BINARY_FORMAT:
            return struct.unpack('>' + _BINARY_FORMAT[size] * n, data)
        else:
            if not size or len(data) != size * n:
                raise InvalidFileException()
            return tuple(int.from_bytes(data[i: i + size], 'big')
                         for i in range(0, size * n, size)) 
开发者ID:corpnewt,项目名称:USBMap,代码行数:11,代码来源:plist.py

示例9: __init__

# 需要导入模块: import plistlib [as 别名]
# 或者: from plistlib import InvalidFileException [as 别名]
def __init__(self, f):
        try:
            self._pl = plistlib.load(f)
        except plistlib.InvalidFileException:
            # maybe a signed plist
            infile, _ = self.save_tempory_file(f)
            outfile_fd, outfile = tempfile.mkstemp()
            outfile_f = os.fdopen(outfile_fd, "rb")
            try:
                # TODO: noverify -> verify signature ???
                subprocess.check_call(["/usr/bin/openssl", "smime", "-verify",
                                       "-in", infile, "-inform", "DER",
                                       "-noverify", "-out", outfile])
            except subprocess.CalledProcessError:
                # not a valid
                raise AttachmentError("Unable to read plist")
            else:
                try:
                    self._pl = plistlib.load(outfile_f)
                except plistlib.InvalidFileException:
                    raise AttachmentError("Signed data not a plist")
            finally:
                os.remove(infile)
                outfile_f.close()
                os.unlink(outfile)

        # extract attributes
        for attr, pl_attr in (("name", "PayloadDisplayName"),
                              ("identifier", "PayloadIdentifier")):
            try:
                setattr(self, attr, self._pl[pl_attr])
            except KeyError:
                raise AttachmentError("Plist without {}".format(pl_attr)) 
开发者ID:zentralopensource,项目名称:zentral,代码行数:35,代码来源:attachments.py

示例10: submission_plist_loads

# 需要导入模块: import plistlib [as 别名]
# 或者: from plistlib import InvalidFileException [as 别名]
def submission_plist_loads(data: Text, compression: str = '') -> Plist:
    if compression:
        data = decode_submission_data(data, compression)
    if isinstance(data, str):
        data = data.encode()
    try:
        plist = plistlib.loads(data)
    except (plistlib.InvalidFileException, ExpatError):
        logger.warning("Submission data failed plist deserialization: '%s'", data)
        plist = {}
    return plist 
开发者ID:salopensource,项目名称:sal,代码行数:13,代码来源:text_utils.py

示例11: is_valid_plist

# 需要导入模块: import plistlib [as 别名]
# 或者: from plistlib import InvalidFileException [as 别名]
def is_valid_plist(data: Text) -> bool:
    if isinstance(data, str):
        data = data.encode()
    try:
        plistlib.loads(data)
        return True
    except (plistlib.InvalidFileException, ExpatError):
        return False 
开发者ID:salopensource,项目名称:sal,代码行数:10,代码来源:text_utils.py

示例12: get_ios_manifest

# 需要导入模块: import plistlib [as 别名]
# 或者: from plistlib import InvalidFileException [as 别名]
def get_ios_manifest(zip_file):
        """
        Check if this is an iOS application by looking for the application and its plist

        :param zip_file: zipfile.ZipFile to scan
        :return: path to the iOS plist file
        """
        # IPA files have a /Payload/[something].app directory with the plist file in it, try to find it via regex
        paths = TruegazeUtils.get_matching_paths_from_zip(zip_file, IOS_PATTERN, True)

        # Check if the path was found and try to parse
        if len(paths) > 0:
            plist_path = paths[0]
            plist_contents = zip_file.read(plist_path)
            try:
                plist_dic = plistlib.loads(plist_contents)
            except plistlib.InvalidFileException:
                return None

            # Test to make sure some required keys are present
            if ('CFBundleIdentifier' in plist_dic) and \
                    ('CFBundleShortVersionString' in plist_dic):
                return plist_path

        # Otherwise, return None if not detected
        return None 
开发者ID:nightwatchcybersecurity,项目名称:truegaze,代码行数:28,代码来源:utils.py

示例13: load

# 需要导入模块: import plistlib [as 别名]
# 或者: from plistlib import InvalidFileException [as 别名]
def load(fp, fmt=None, use_builtin_types=None, dict_type=dict):
    if _check_py3():
        use_builtin_types = True if use_builtin_types == None else use_builtin_types
        # We need to monkey patch this to allow for hex integers - code taken/modified from 
        # https://github.com/python/cpython/blob/3.8/Lib/plistlib.py
        if fmt is None:
            header = fp.read(32)
            fp.seek(0)
            for info in plistlib._FORMATS.values():
                if info['detect'](header):
                    P = info['parser']
                    break
            else:
                raise plistlib.InvalidFileException()
        else:
            P = plistlib._FORMATS[fmt]['parser']
        p = P(use_builtin_types=use_builtin_types, dict_type=dict_type)
        if isinstance(p,plistlib._PlistParser):
            # Monkey patch!
            def end_integer():
                d = p.get_data()
                p.add_object(int(d,16) if d.lower().startswith("0x") else int(d))
            p.end_integer = end_integer
        return p.parse(fp)
    elif not _is_binary(fp):
        # Is not binary - assume a string - and try to load
        # We avoid using readPlistFromString() as that uses
        # cStringIO and fails when Unicode strings are detected
        # Don't subclass - keep the parser local
        from xml.parsers.expat import ParserCreate
        # Create a new PlistParser object - then we need to set up
        # the values and parse.
        p = plistlib.PlistParser()
        # We also need to monkey patch this to allow for other dict_types
        def begin_dict(attrs):
            d = dict_type()
            p.addObject(d)
            p.stack.append(d)
        def end_integer():
            d = p.getData()
            p.addObject(int(d,16) if d.lower().startswith("0x") else int(d))
        p.begin_dict = begin_dict
        p.end_integer = end_integer
        parser = ParserCreate()
        parser.StartElementHandler = p.handleBeginElement
        parser.EndElementHandler = p.handleEndElement
        parser.CharacterDataHandler = p.handleData
        if isinstance(fp, unicode):
            # Encode unicode -> string; use utf-8 for safety
            fp = fp.encode("utf-8")
        if isinstance(fp, basestring):
            # It's a string - let's wrap it up
            fp = StringIO(fp)
        # Parse it
        parser.ParseFile(fp)
        return p.root
    else:
        use_builtin_types = False if use_builtin_types == None else use_builtin_types
        p = _BinaryPlistParser(use_builtin_types=use_builtin_types, dict_type=dict_type)
        return p.parse(fp) 
开发者ID:corpnewt,项目名称:USBMap,代码行数:62,代码来源:plist.py

示例14: upload_profile

# 需要导入模块: import plistlib [as 别名]
# 或者: from plistlib import InvalidFileException [as 别名]
def upload_profile():
    """Upload a custom profile using multipart/form-data I.E from an upload input.

    Encrypted profiles are not supported.

    The profiles contents will be stored using the following process:
    - For the top level profile (and each payload) there is a marshmallow schema which maps the payload keys into
        the SQLAlchemy model keys. It is also the responsibility of the marshmallow schema to be the validator for 
        uploaded profiles.
    - The profile itself is inserted as a Profile model.
    - Each payload is unmarshalled using marshmallow to a specific Payload model. Each specific model contains a join
        table inheritance to the base ``payloads`` table.

    The returned body contains a jsonapi object with details of the newly created profile and associated payload ID's.

    Note: Does not support ``application/x-www-form-urlencoded``

    TODO:
        - Support signed profiles

    :reqheader Accept: application/vnd.api+json
    :reqheader Content-Type: multipart/form-data
    :resheader Content-Type: application/vnd.api+json
    :statuscode 201: profile created
    :statuscode 400: If the request contained malformed or missing payload data.
    :statuscode 500: If something else went wrong with parsing or persisting the payload(s)
    """
    if 'file' not in request.files:
        abort(400, 'no file uploaded in request data')

    f = request.files['file']

    if not f.content_type == 'application/x-apple-aspen-config':
        abort(400, 'incorrect MIME type in request')

    try:
        data = f.read()
        plist = plistlib.loads(data)

        profile = ProfilePlistSchema().load(plist).data
    except plistlib.InvalidFileException as e:
        current_app.logger.error(e)
        abort(400, 'invalid plist format supplied')

    except BaseException as e:  # TODO: separate errors for exceptions caught here
        current_app.logger.error(e)
        abort(400, 'cannot parse the supplied profile')

    profile.data = data
    db.session.add(profile)
    db.session.commit()

    profile_schema = ProfileSchema()
    model_data = profile_schema.dump(profile).data
    resp = make_response(jsonify(model_data), 201, {'Content-Type': 'application/vnd.api+json'})
    return resp 
开发者ID:cmdmnt,项目名称:commandment,代码行数:58,代码来源:app_json.py

示例15: test_invalid_binary

# 需要导入模块: import plistlib [as 别名]
# 或者: from plistlib import InvalidFileException [as 别名]
def test_invalid_binary(self):
        for data in [
                # too short data
                b'',
                # too large offset_table_offset and nonstandard offset_size
                b'\x00\x08'
                b'\x00\x00\x00\x00\x00\x00\x03\x01'
                b'\x00\x00\x00\x00\x00\x00\x00\x01'
                b'\x00\x00\x00\x00\x00\x00\x00\x00'
                b'\x00\x00\x00\x00\x00\x00\x00\x2a',
                # integer overflow in offset_table_offset
                b'\x00\x08'
                b'\x00\x00\x00\x00\x00\x00\x01\x01'
                b'\x00\x00\x00\x00\x00\x00\x00\x01'
                b'\x00\x00\x00\x00\x00\x00\x00\x00'
                b'\xff\xff\xff\xff\xff\xff\xff\xff',
                # offset_size = 0
                b'\x00\x08'
                b'\x00\x00\x00\x00\x00\x00\x00\x01'
                b'\x00\x00\x00\x00\x00\x00\x00\x01'
                b'\x00\x00\x00\x00\x00\x00\x00\x00'
                b'\x00\x00\x00\x00\x00\x00\x00\x09',
                # ref_size = 0
                b'\xa1\x01\x00\x08\x0a'
                b'\x00\x00\x00\x00\x00\x00\x01\x00'
                b'\x00\x00\x00\x00\x00\x00\x00\x02'
                b'\x00\x00\x00\x00\x00\x00\x00\x00'
                b'\x00\x00\x00\x00\x00\x00\x00\x0b',
                # integer overflow in offset
                b'\x00\xff\xff\xff\xff\xff\xff\xff\xff'
                b'\x00\x00\x00\x00\x00\x00\x08\x01'
                b'\x00\x00\x00\x00\x00\x00\x00\x01'
                b'\x00\x00\x00\x00\x00\x00\x00\x00'
                b'\x00\x00\x00\x00\x00\x00\x00\x09',
                # invalid ASCII
                b'\x51\xff\x08'
                b'\x00\x00\x00\x00\x00\x00\x01\x01'
                b'\x00\x00\x00\x00\x00\x00\x00\x01'
                b'\x00\x00\x00\x00\x00\x00\x00\x00'
                b'\x00\x00\x00\x00\x00\x00\x00\x0a',
                # invalid UTF-16
                b'\x61\xd8\x00\x08'
                b'\x00\x00\x00\x00\x00\x00\x01\x01'
                b'\x00\x00\x00\x00\x00\x00\x00\x01'
                b'\x00\x00\x00\x00\x00\x00\x00\x00'
                b'\x00\x00\x00\x00\x00\x00\x00\x0b',
                ]:
            with self.assertRaises(plistlib.InvalidFileException):
                plistlib.loads(b'bplist00' + data, fmt=plistlib.FMT_BINARY) 
开发者ID:bkerler,项目名称:android_universal,代码行数:51,代码来源:test_plistlib.py


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