Skip to content

_read_planar_code() incorrectly treats Plantri format as text rather than binary #40062

@maxale

Description

@maxale

Steps To Reproduce

Download the file https://users.cecs.anu.edu.au/~bdm/data/5reg_20-32.pc and run the code:

file = open("5reg_20-32.pc")
list( graphs._read_planar_code(file) )

Expected Behavior

It is expected that we obtain a list of 6 graphs contained in 5reg_20-32.pc in Plantri format.

Actual Behavior

We get an error:

ValueError: 10 and 6 are not neighbors but 10 is in the list associated with 6

Deep down, the reason is that, since we opened the file in text mode, _read_planar_code starts screwing things up as soon as it encounters code 0x0A (encoding vertex number 10 in Plantri). However, apparent attempt to change the mode via open("5reg_20-32.pc", "rb") raises another error in line 1493:

AssertionError: Not a valid planar code header

Additional Information

Line 1493 should perform comparison to a binary string, that is, header == b'>>planar_code<<'. It will also ensure that the file is opened in binary mode, so an error message could be made a bit more general - like:

assert header == b'>>planar_code<<', 'Not a valid planar code header or file is not opened in binary mode'

Environment

  • OS: Ubuntu 24.04.2 LTS
  • Sage Version: 10.7.beta1

Checklist

  • I have searched the existing issues for a bug report that matches the one I want to file, without success.
  • I have read the documentation and troubleshoot guide

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions