# Copyright (c) 2010 ActiveState Software Inc. All rights reserved.
"""
    pypm.common.backport
    ~~~~~~~~~~~~~~~~~~~~~
    
    Provide what is *not* in 'six' already
    You should just do "import ...backport" and then use the new imports as
    six.moves.<name>
"""

__all__ = ['utf8_cat']

from six import PY3
from six import MovedModule
from six import MovedAttribute
from six import add_move


attributes = [
    MovedModule('xmlrpc_client', 'xmlrpclib', 'xmlrpc.client'),
    MovedAttribute('HTTPError', 'urllib2', 'urllib.error'),
    MovedAttribute('URLError', 'urllib2', 'urllib.error'),
    MovedAttribute('Request', 'urllib2', 'urllib.request'),
    MovedAttribute('urlopen', 'urllib2', 'urllib.request'),
    MovedAttribute('urllib_version', 'urllib2', 'urllib.request', '__version__'),
    MovedAttribute('urlparse', 'urlparse', 'urllib.parse'),
]
for attr in attributes:
    add_move(attr)
del attr
del attributes

if PY3:
    def utf8_cat(f):
        """Read the given file in utf8 encoding"""
        return open(f, encoding='utf8').read()
else:
    def utf8_cat(f):
        """Read the given file in utf8 encoding"""
        return open(f).read().decode('utf8')
