This reminded me to look at the `fmt` variable code above this. It's possible for `fmt` to be most anything at this point. I believe the code there should be:

```python
    fmt = 'T' if data.get('format', '').lower() == 'text' else 'H'
```