File: _compat.py

package info (click to toggle)
python-persistent 4.0.8-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 680 kB
  • ctags: 1,140
  • sloc: python: 4,156; ansic: 2,727; xml: 845; makefile: 112
file content (54 lines) | stat: -rw-r--r-- 1,476 bytes parent folder | download
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
##############################################################################
#
# Copyright (c) 2012 Zope Foundation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################

import sys

if sys.version_info[0] > 2: #pragma NO COVER
    import copyreg as copy_reg
    from collections import UserDict as IterableUserDict
    from collections import UserList

    def _u(s):
        return s

    def _b(s):
        if isinstance(s, str):
            return s.encode('unicode_escape')
        return s

    def _native(s):
        if isinstance(s, bytes):
            return s.decode('unicode_escape')
        return s

    PYTHON3 = True
    PYTHON2 = False

else: #pragma NO COVER
    import copy_reg
    from UserDict import IterableUserDict
    from UserList import UserList

    def _u(s):
        return unicode(s, 'unicode_escape')

    def _native(s):
        if isinstance(s, unicode):
            return s.encode('unicode_escape')
        return s

    _b = _native

    PYTHON3 = False
    PYTHON2 = True