File: _compat.py

package info (click to toggle)
python-persistent 4.2.2-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 664 kB
  • sloc: python: 4,899; ansic: 2,787; makefile: 125
file content (57 lines) | stat: -rw-r--r-- 1,524 bytes parent folder | download | duplicates (2)
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
55
56
57
##############################################################################
#
# 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
    from sys import intern

    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

    intern = intern