Ejemplo n.º 1
0
def _write_macbinary_header(output, macbinary_header):
    # Try to convert unicode filenames to MacRoman automatically
    if macbinary_header.get('filename_script', SM_ROMAN) != SM_ROMAN:
        raise NotImplementedError(
            "Filename script other than MacRoman specified. " +
            "Don't know how to encode scripts other than MacRoman.")
    macbinary_header['filename'] = macbinary_header['filename'].encode('macroman')
    
    # If datetime fields not specified, use the current datetime
    if 'created' not in macbinary_header or 'modified' not in macbinary_header:
        now_mac_timestamp = convert_local_to_mac_timestamp(time.time())
        if 'created' not in macbinary_header:
            macbinary_header['created'] = now_mac_timestamp
        if 'modified' not in macbinary_header:
            macbinary_header['modified'] = now_mac_timestamp
    
    # Write the header
    macbinary_header['header_crc'] = 0
    write_structure(output, _MACBINARY_HEADER_MEMBERS, macbinary_header)
    
    # Amend the header with the actual CRC
    with save_stream_position(output):
        offset_to_crc_member = offset_to_structure_member(
            _MACBINARY_HEADER_MEMBERS, 'header_crc')
        
        # Compute CRC of header
        output.seek(0)
        header_section_to_crc = output.read(offset_to_crc_member)
        header_crc = _compute_macbinary_crc(header_section_to_crc)
        
        # Write CRC to header
        write_unsigned(output, 2, header_crc)
        
        # Save CRC to MacBinary object in case the caller is interested
        macbinary_header['header_crc'] = header_crc
Ejemplo n.º 2
0
def _write_alias_record_structure(output, alias_record):
    write_structure(output, _ALIAS_RECORD_MEMBERS, alias_record, external_writers={
        'write_extras': _write_extras
    })
Ejemplo n.º 3
0
def _write_alias_record_structure(output, alias_record):
    write_structure(output,
                    _ALIAS_RECORD_MEMBERS,
                    alias_record,
                    external_writers={'write_extras': _write_extras})
Ejemplo n.º 4
0
def _write_resource_reference(output, resource_reference):
    write_structure(output, _RESOURCE_REFERENCE_MEMBERS, resource_reference)
Ejemplo n.º 5
0
def _write_resource_type(output, resource_type):
    write_structure(output, _RESOURCE_TYPE_MEMBERS, resource_type)
Ejemplo n.º 6
0
def _write_resource_map_header(output, resource_map_header):
    write_structure(output, _RESOURCE_MAP_HEADER_MEMBERS, resource_map_header)
Ejemplo n.º 7
0
def _write_resource_fork_header(output, resource_fork_header):
    write_structure(output, _RESOURCE_FORK_HEADER_MEMBERS, resource_fork_header)