aboutsummaryrefslogtreecommitdiff
blob: 9ba5ad1f079456542171fcb26604d6bd3bb44a01 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# -*- coding: utf-8 -*-

"""
    g_octave.compat
    ~~~~~~~~~~~~~~~
    
    This module implements some helper function to compatibility with
    Python 3k.
    
    :copyright: (c) 2010 by Rafael Goncalves Martins
    :license: GPL-2, see LICENSE for more details.
"""

__all__ = [
    'py3k',
    'open',
]

import codecs
import sys


py3k = sys.version_info >= (3, 0)

def open(filename, mode='r', encoding='utf-8'):
    '''custom implementation of the 'open' builtin, using the codecs module'''
    try:
        return codecs.open(filename, mode=mode, encoding=encoding)
    except:
        return codecs.open(filename, mode=mode, encoding='iso-8859-15')