source: OpenRLabs-Git/deploy/rlabs-docker/web2py-rlabs/gluon/contrib/fpdf/py3k.py

main
Last change on this file was 42bd667, checked in by David Fuertes <dfuertes@…>, 4 years ago

Historial Limpio

  • Property mode set to 100755
File size: 1.7 KB
Line 
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3
4"Special module to handle differences between Python 2 and 3 versions"
5
6import sys
7
8PY3K = sys.version_info >= (3, 0)
9
10try:
11    import cPickle as pickle
12except ImportError:
13    import pickle
14
15try:
16        from urllib import urlopen
17except ImportError:
18        from urllib.request import urlopen
19
20try:
21    from io import BytesIO
22except ImportError:
23    try:
24        from cStringIO import StringIO as BytesIO
25    except ImportError:
26        from StringIO import StringIO as BytesIO
27
28try:
29    from hashlib import md5
30except ImportError:
31    try:
32        from md5 import md5
33    except ImportError:
34        md5 = None
35def hashpath(fn):
36    h = md5()
37    if PY3K:
38        h.update(fn.encode("UTF-8"))
39    else:
40        h.update(fn)
41    return h.hexdigest()
42
43# Check if PIL is available (tries importing both pypi version and corrected or manually installed versions).
44# Necessary for JPEG and GIF support.
45# TODO: Pillow support
46try:
47    from PIL import Image
48except ImportError:
49    try:
50        import Image
51    except ImportError:
52        Image = None
53
54try:
55        from HTMLParser import HTMLParser
56except ImportError:
57        from html.parser import HTMLParser
58
59if PY3K:
60    basestring = str
61    unicode = str
62    ord = lambda x: x
63else:
64    basestring = basestring
65    unicode = unicode
66    ord = ord
67
68# shortcut to bytes conversion (b prefix)
69def b(s):
70    if isinstance(s, basestring):
71        return s.encode("latin1")
72    elif isinstance(s, int):
73        if PY3K:
74            return bytes([s])       # http://bugs.python.org/issue4588
75        else:
76            return chr(s)
77
78def exception():
79    "Return the current the exception instance currently being handled"
80    # this is needed to support Python 2.5 that lacks "as" syntax
81    return sys.exc_info()[1]
82
83
Note: See TracBrowser for help on using the repository browser.