# Path: pyxc/util.py
# class TempDir:
#     
#     def __init__(self):
#         self.path = tempfile.mkdtemp()
#     
#     def __enter__(self):
#         return self
#     
#     def __exit__(self, *args):
#         subprocess.check_call(['rm', '-rf', self.path])
# 
# def parentOf(path):
#     return '/'.join(path.rstrip('/').split('/')[:-1])
# 
# def simplePost(url, POST={}):
#     try:
#         import urllib.parse, urllib.request
#         data = urllib.parse.urlencode(POST)
#         return urllib.request.urlopen(url, data).read()
#     except ImportError:
#         import urllib, urllib2
#         data = urllib.urlencode(POST)
#         return urllib2.urlopen(urllib2.Request(url, data)).read()


import sys, os, json, subprocess, re, hashlib, time
import urllib.request
import urllib.parse
import pj.api_internal
from pyxc.util import TempDir, parentOf, simplePost
                            prependJs=prependJs)
    js = info['js']
    sourceMap = info['sourceMap']
    sourceDict = info['sourceDict']
    
    with TempDir() as td:
        
        jsPath = '%s/%s.js' % (td.path, filename)
        with open(jsPath, 'wb') as f:
            f.write(js.encode('utf-8'))
        
        exception_server_proc = None
        if runExceptionServer:
            exception_server_proc = startExceptionServer(
                                        exceptionServerPort, js, sourceMap, sourceDict, jsPath)
        try:
            subprocess.check_call(['node', jsPath])
            if exception_server_proc is not None:
                exception_server_proc.kill()
        except Exception:
            sys.stderr.write('[PYXC] Leaving exception server running until you Control-C...\n')
            try:
                while True:
                    time.sleep(1)
            finally:
                if exception_server_proc is not None:
                    exception_server_proc.kill()


def startExceptionServer(exceptionServerPort, js, sourceMap, sourceDict, jsPath):

# Path: pyxc/util.py
# class TempDir:
#     
#     def __init__(self):
#         self.path = tempfile.mkdtemp()
#     
#     def __enter__(self):
#         return self
#     
#     def __exit__(self, *args):
#         subprocess.check_call(['rm', '-rf', self.path])
# 
# def parentOf(path):
#     return '/'.join(path.rstrip('/').split('/')[:-1])
# 
# def simplePost(url, POST={}):
#     try:
#         import urllib.parse, urllib.request
#         data = urllib.parse.urlencode(POST)
#         return urllib.request.urlopen(url, data).read()
#     except ImportError:
#         import urllib, urllib2
#         data = urllib.urlencode(POST)
#         return urllib2.urlopen(urllib2.Request(url, data)).read()


# Path: pj/nodejs.py
import sys, os, json, subprocess, re, hashlib, time
import urllib.request
import urllib.parse
import pj.api_internal
from pyxc.util import TempDir, parentOf, simplePost

                            prependJs=prependJs)
    js = info['js']
    sourceMap = info['sourceMap']
    sourceDict = info['sourceDict']
    
    with TempDir() as td:
        
        jsPath = '%s/%s.js' % (td.path, filename)
        with open(jsPath, 'wb') as f:
            f.write(js.encode('utf-8'))
        
        exception_server_proc = None
        if runExceptionServer:
            exception_server_proc = startExceptionServer(
                                        exceptionServerPort, js, sourceMap, sourceDict, jsPath)
        try:
            subprocess.check_call(['node', jsPath])
            if exception_server_proc is not None:
                exception_server_proc.kill()
        except Exception:
            sys.stderr.write('[PYXC] Leaving exception server running until you Control-C...\n')
            try:
                while True:
                    time.sleep(1)
            finally:
                if exception_server_proc is not None:
                    exception_server_proc.kill()


def startExceptionServer(exceptionServerPort, js, sourceMap, sourceDict, jsPath):

    path = '%s/nodejs_exception_server.js' % parentOf(__file__)