'''
Created on Jan 16, 2014

@author: sean
'''
from __future__ import print_function

import os
from conda_build import environ
import json
_setuptools_data = None

def load_setuptools():
    global _setuptools_data

    if _setuptools_data is None:
        _setuptools_data = {}
        def setup(**kw):
            _setuptools_data.update(kw)

        import setuptools
        #Patch setuptools
        setuptools_setup = setuptools.setup
        setuptools.setup = setup
        exec(open('setup.py').read())
        setuptools.setup = setuptools_setup

    return _setuptools_data

def load_npm():
    with open('package.json') as pkg:
        return json.load(pkg)

def context_processor():
    ctx = environ.get_dict()
    ctx.update(load_setuptools=load_setuptools,
               load_npm=load_npm,
               environ=os.environ)
    return ctx

@@ -67,33 +67,148 @@
 ort 
-print_function%0A%0Aimport os
+(absolute_import, division, print_function,%0A                        unicode_literals)%0A%0Aimport json%0Aimport os%0Aimport sys%0Afrom io import open%0A
 %0Afro
@@ -236,27 +236,16 @@
 environ%0A
-import json
 %0A_setupt
@@ -600,16 +600,34 @@
 etup.py'
+, encoding='utf-8'
 ).read()
@@ -726,31 +726,219 @@
     
-with open('package.json
+# json module expects bytes in Python 2 and str in Python 3.%0A    if sys.version_info %3E= (3, 0):%0A        file_mode = 'w'%0A    else:%0A        file_mode = 'wb'%0A    with open('package.json', file_mode, encoding='utf-8
 ') a

Switch to io.open and make encoding handling explicit in jinja_context.py