Ejemplo n.º 1
0
def _write_resource_data_area_using_map(output, resource_map, resources_in_resource_data_area):
    for resource in resources_in_resource_data_area:
        resource_data = resource['data']
        resource_data_length = len(resource_data)
        
        write_unsigned(output, 4, resource_data_length)
        output.write(resource_data)
Ejemplo n.º 2
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.º 3
0
def _write_extras(output, ignored, value):
    extras = value
    
    this_module = globals()
    for extra in extras:
        extra_content_output = BytesIO()
        this_module['_write_' + extra.name + '_extra_content'](extra_content_output, extra.value)
        extra_content = extra_content_output.getvalue()
        extra_length = len(extra_content)
        
        write_unsigned(output, 2, extra.type)
        write_unsigned(output, 2, extra_length)
        output.write(extra_content)
        if extra_length & 0x1 == 1:
            output.write(NULL_BYTE)    # padding byte
Ejemplo n.º 4
0
def write_alias_record(output, alias_record):
    if 'record_size' in alias_record:
        _write_alias_record_structure(output, alias_record)
    else:
        alias_record['record_size'] = 0
        
        # Write record, except for the 'record_size' field
        start_offset = output.tell()
        _write_alias_record_structure(output, alias_record)
        end_offset = output.tell()
        
        # Write the 'record_size' field
        output.seek(start_offset + 4)
        record_size = end_offset - start_offset
        write_unsigned(output, 2, record_size)
        output.seek(end_offset)
Ejemplo n.º 5
0
def _write_extras(output, ignored, value):
    extras = value

    this_module = globals()
    for extra in extras:
        extra_content_output = BytesIO()
        this_module['_write_' + extra.name + '_extra_content'](
            extra_content_output, extra.value)
        extra_content = extra_content_output.getvalue()
        extra_length = len(extra_content)

        write_unsigned(output, 2, extra.type)
        write_unsigned(output, 2, extra_length)
        output.write(extra_content)
        if extra_length & 0x1 == 1:
            output.write(NULL_BYTE)  # padding byte
Ejemplo n.º 6
0
def write_alias_record(output, alias_record):
    if 'record_size' in alias_record:
        _write_alias_record_structure(output, alias_record)
    else:
        alias_record['record_size'] = 0

        # Write record, except for the 'record_size' field
        start_offset = output.tell()
        _write_alias_record_structure(output, alias_record)
        end_offset = output.tell()

        # Write the 'record_size' field
        output.seek(start_offset + 4)
        record_size = end_offset - start_offset
        write_unsigned(output, 2, record_size)
        output.seek(end_offset)
Ejemplo n.º 7
0
def _write_directory_ids_extra_content(output, extra_value):
    for path_id in extra_value:
        write_unsigned(output, 4, path_id)
Ejemplo n.º 8
0
def _write_directory_ids_extra_content(output, extra_value):
    for path_id in extra_value:
        write_unsigned(output, 4, path_id)