X Tutup
Skip to content

Printing an update isn't too pretty #12

@FichteFoll

Description

@FichteFoll

Due to the top-down .to_json() approach, all the double quotes get applied and escaped recursively. Example result of calling str(update), where update is for example bot.getUpdates()[0].

{"message": "{\"from\": \"{\\\"id\\\": 1234567890, \\\"first_name\\\": \\\"Somebody\\\", \\\"username\\\": \\\"somebody\\\"}\", \"chat\": \"{\\\"id\\\": 45858904, \\\"first_name\\\": \\\"Somebody\\\", \\\"username\\\": \\\"somebody\\\"}\", \"message_id\": 7, \"text\": \"s\", \"date\": 1437171749}", "update_id": 532670696}

Proposed solution: Add datafy, to_data or to_dict method to each data container class that is called top-down instead and define to_json as:

def to_json(self):
    return json.dumps(self.to_data())

Edit: I would probably add this method in a new base class named telegram.DataContainer and make to_data abstract.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    X Tutup