# Path: Cython/Utils.py
# def open_new_file(path):
#     if os.path.exists(path):
#         # Make sure to create a new file here so we can
#         # safely hard link the output files.
#         os.unlink(path)
# 
#     # we use the ISO-8859-1 encoding here because we only write pure
#     # ASCII strings or (e.g. for file names) byte encoded strings as
#     # Unicode, so we need a direct mapping from the first 256 Unicode
#     # characters to a byte sequence, which ISO-8859-1 provides
#     return codecs.open(path, "w", encoding="ISO-8859-1")
# 
# def replace_suffix(path, newsuf):
#     base, _ = os.path.splitext(path)
#     return base + newsuf


import cython
import os, time
import Future
import Annotate
import Code
import Naming
import Nodes
import Options
import TypeSlots
import Version
import PyrexTypes
from PyrexTypes import CPtrType
from Errors import error, warning
from PyrexTypes import py_object_type
from Cython.Utils import open_new_file, replace_suffix
from Code import UtilityCode
from StringEncoding import EncodedString
            for entry in module.cfunc_entries:
                if entry.defined_in_pxd:
                    return 1
        return 0

    def generate_dep_file(self, env, result):
        modules = self.referenced_modules
        if len(modules) > 1 or env.included_files:
            dep_file = replace_suffix(result.c_file, ".dep")
            f = open(dep_file, "w")
            try:
                for module in modules:
                    if module is not env:
                        f.write("cimport %s\n" % module.qualified_name)
                    for path in module.included_files:
                        f.write("include %s\n" % path)
            finally:
                f.close()

    def generate_h_code(self, env, options, result):
        def h_entries(entries, api=0, pxd=0):
            return [entry for entry in entries
                    if ((entry.visibility == 'public') or
                        (api and entry.api) or
                        (pxd and entry.defined_in_pxd))]
        h_types = h_entries(env.type_entries, api=1)
        h_vars = h_entries(env.var_entries)
        h_funcs = h_entries(env.cfunc_entries)
        h_extension_types = h_entries(env.c_class_entries)
        if (h_types or  h_vars or h_funcs or h_extension_types):

# Path: Cython/Utils.py
# def open_new_file(path):
#     if os.path.exists(path):
#         # Make sure to create a new file here so we can
#         # safely hard link the output files.
#         os.unlink(path)
# 
#     # we use the ISO-8859-1 encoding here because we only write pure
#     # ASCII strings or (e.g. for file names) byte encoded strings as
#     # Unicode, so we need a direct mapping from the first 256 Unicode
#     # characters to a byte sequence, which ISO-8859-1 provides
#     return codecs.open(path, "w", encoding="ISO-8859-1")
# 
# def replace_suffix(path, newsuf):
#     base, _ = os.path.splitext(path)
#     return base + newsuf


# Path: Cython/Compiler/ModuleNode.py
import cython
import os, time
import Future
import Annotate
import Code
import Naming
import Nodes
import Options
import TypeSlots
import Version
import PyrexTypes
from PyrexTypes import CPtrType
from Errors import error, warning
from PyrexTypes import py_object_type
from Cython.Utils import open_new_file, replace_suffix
from Code import UtilityCode
from StringEncoding import EncodedString

            for entry in module.cfunc_entries:
                if entry.defined_in_pxd:
                    return 1
        return 0

    def generate_dep_file(self, env, result):
        modules = self.referenced_modules
        if len(modules) > 1 or env.included_files:
            dep_file = replace_suffix(result.c_file, ".dep")
            f = open(dep_file, "w")
            try:
                for module in modules:
                    if module is not env:
                        f.write("cimport %s\n" % module.qualified_name)
                    for path in module.included_files:
                        f.write("include %s\n" % path)
            finally:
                f.close()

    def generate_h_code(self, env, options, result):
        def h_entries(entries, api=0, pxd=0):
            return [entry for entry in entries
                    if ((entry.visibility == 'public') or
                        (api and entry.api) or
                        (pxd and entry.defined_in_pxd))]
        h_types = h_entries(env.type_entries, api=1)
        h_vars = h_entries(env.var_entries)
        h_funcs = h_entries(env.cfunc_entries)
        h_extension_types = h_entries(env.c_class_entries)
        if (h_types or  h_vars or h_funcs or h_extension_types):

            result.h_file = replace_suffix(result.c_file, ".h")