harbor run -t openthoughts/tasktrove-exp-rpt-issue-issue-2237harbor download openthoughts/tasktrove-exp-rpt-issue-issue-2237Task: Extend FITS header and card parsing to accept Python 3 bytes in addition to str
File: app/astropy/io/fits/card.py
class Card:
@classmethod
def fromstring(cls, image):
"""Create a Card from string representation of a FITS card."""
card = cls()
card._image = _pad(image)
card._verified = False
return card
File: app/astropy/io/fits/header.py
__doctest_skip__ = ['Header', 'Header.*']
class Header:
@classmethod
def fromstring(cls, data, sep=''):
"""
Parameters
----------
data : str
String containing the entire header.
sep : str, optional
The string separating cards from each other, such as a newline.
"""
require_full_cardlength = set(sep).issubset(VALID_HEADER_CHARS)
# Split the header into individual cards
idx = 0
image = []
cards = []
while idx < len(data):
end_idx = data.find(sep, idx)
if end_idx == -1:
end_idx = len(data)
next_image = data[idx:end_idx]
image.append(next_image)
if image:
cards.append(Card.fromstring(''.join(image)))
image = []
idx = end_idx + len(sep)
if require_full_cardlength:
if next_image == END_CARD:
break
else:
if next_image.split(sep)[0].rstrip() == 'END':
break
if image:
cards.append(Card.fromstring(''.join(image)))
return cls._fromcards(cards)