mirror of
https://github.com/gryf/weechat-replacer.git
synced 2025-12-19 04:20:19 +01:00
Change a way for detecting python3 vs python2.
This commit is contained in:
14
replacer.py
14
replacer.py
@@ -21,7 +21,6 @@ Examples:
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
import json
|
import json
|
||||||
import sys
|
|
||||||
|
|
||||||
import weechat
|
import weechat
|
||||||
|
|
||||||
@@ -40,15 +39,20 @@ COLOR_RESET = weechat.color('reset')
|
|||||||
|
|
||||||
|
|
||||||
def _decode(string):
|
def _decode(string):
|
||||||
if sys.version_info.major == 2:
|
try:
|
||||||
return string.decode('utf-8')
|
return string.decode('utf-8')
|
||||||
return string
|
except AttributeError:
|
||||||
|
return string
|
||||||
|
|
||||||
|
|
||||||
def _encode(string):
|
def _encode(string):
|
||||||
if sys.version_info.major == 2:
|
try:
|
||||||
|
# Encode only, if we have decode attribute, which is available for
|
||||||
|
# string only on python2
|
||||||
|
string.decode
|
||||||
return string.encode('utf-8')
|
return string.encode('utf-8')
|
||||||
return string
|
except AttributeError:
|
||||||
|
return string
|
||||||
|
|
||||||
|
|
||||||
class Replacer(object):
|
class Replacer(object):
|
||||||
|
|||||||
Reference in New Issue
Block a user