I like the approach of @gwk in https://github.com/gwk/gloss/blob/master/python/gloss/io/sgr.py, I think we should copy that for the most part.