I'm not sure the best way to conditionalize on version.  I've used "if PY2: xxx; else: yyy" and "if PY3: xxx; else: yyy".  Here you have "if PY2: xxx; elif PY3: yyy" which seems a little redundant, but I guess is nicely explicit.  Further down you have "if PY2: xxx; if PY3: yyy", which seems too decoupled.