[WIP] Extract common functionality to xblock-utils

I missed this on the other PR, but since this is python code I would prefer to not have the "from_python" part. Ie either keep the old `publish_event` / `_publish_event` names, or have `publish_event_json` / `publish_event` (ie renaming the json_handler instead) if you don't like the `_publish_event` name for this function