Mercurial > kallithea
annotate kallithea/lib/compat.py @ 7789:75b128508fa8
compat: use collections.OrderedDict - we only support Python 2.7 and no longer need our own implementation
author | Mads Kiilerich <mads@kiilerich.com> |
---|---|
date | Sun, 21 Jul 2019 19:12:20 +0200 |
parents | 7691290837d2 |
children | a7d7157eca8e |
rev | line source |
---|---|
1514
87ec80c280bb
fixed issues with python2.5
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1 # -*- coding: utf-8 -*- |
87ec80c280bb
fixed issues with python2.5
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2 # This program is free software: you can redistribute it and/or modify |
87ec80c280bb
fixed issues with python2.5
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
3 # it under the terms of the GNU General Public License as published by |
87ec80c280bb
fixed issues with python2.5
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
4 # the Free Software Foundation, either version 3 of the License, or |
87ec80c280bb
fixed issues with python2.5
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
5 # (at your option) any later version. |
87ec80c280bb
fixed issues with python2.5
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
6 # |
87ec80c280bb
fixed issues with python2.5
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
7 # This program is distributed in the hope that it will be useful, |
87ec80c280bb
fixed issues with python2.5
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
8 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
87ec80c280bb
fixed issues with python2.5
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
9 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
87ec80c280bb
fixed issues with python2.5
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
10 # GNU General Public License for more details. |
87ec80c280bb
fixed issues with python2.5
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
11 # |
87ec80c280bb
fixed issues with python2.5
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
12 # You should have received a copy of the GNU General Public License |
87ec80c280bb
fixed issues with python2.5
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
13 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3872
diff
changeset
|
14 """ |
4186
7e5f8c12a3fc
First step in two-part process to rename directories to kallithea.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4116
diff
changeset
|
15 kallithea.lib.compat |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3872
diff
changeset
|
16 ~~~~~~~~~~~~~~~~~~~~ |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3872
diff
changeset
|
17 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3872
diff
changeset
|
18 Python backward compatibility functions and common libs |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3872
diff
changeset
|
19 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3872
diff
changeset
|
20 |
4211
1948ede028ef
RhodeCode GmbH is not the sole author of this work
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4208
diff
changeset
|
21 This file was forked by the Kallithea project in July 2014. |
1948ede028ef
RhodeCode GmbH is not the sole author of this work
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4208
diff
changeset
|
22 Original author and date, and relevant copyright and licensing information is below: |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3872
diff
changeset
|
23 :created_on: Oct 7, 2011 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3872
diff
changeset
|
24 :author: marcink |
4211
1948ede028ef
RhodeCode GmbH is not the sole author of this work
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4208
diff
changeset
|
25 :copyright: (c) 2013 RhodeCode GmbH, and others. |
4208
ad38f9f93b3b
Correct licensing information in individual files.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4187
diff
changeset
|
26 :license: GPLv3, see LICENSE.md for more details. |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3872
diff
changeset
|
27 """ |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3872
diff
changeset
|
28 |
1514
87ec80c280bb
fixed issues with python2.5
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
29 |
6208
f4d128af1a01
compat: drop unnecessary wrappers for old Python versions
Mads Kiilerich <madski@unity3d.com>
parents:
5555
diff
changeset
|
30 import sys |
1549
d6cb805c92fd
moved kill function to compat
Marcin Kuzminski <marcin@python-works.com>
parents:
1514
diff
changeset
|
31 import os |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3872
diff
changeset
|
32 import functools |
1549
d6cb805c92fd
moved kill function to compat
Marcin Kuzminski <marcin@python-works.com>
parents:
1514
diff
changeset
|
33 |
1514
87ec80c280bb
fixed issues with python2.5
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
34 #============================================================================== |
87ec80c280bb
fixed issues with python2.5
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
35 # json |
87ec80c280bb
fixed issues with python2.5
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
36 #============================================================================== |
4186
7e5f8c12a3fc
First step in two-part process to rename directories to kallithea.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4116
diff
changeset
|
37 from kallithea.lib.ext_json import json |
2151
12ceeda33339
#404 API extensions for showing permission for users
Marcin Kuzminski <marcin@python-works.com>
parents:
2068
diff
changeset
|
38 |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3872
diff
changeset
|
39 # alias for formatted json |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3872
diff
changeset
|
40 formatted_json = functools.partial(json.dumps, indent=4, sort_keys=True) |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3872
diff
changeset
|
41 |
6208
f4d128af1a01
compat: drop unnecessary wrappers for old Python versions
Mads Kiilerich <madski@unity3d.com>
parents:
5555
diff
changeset
|
42 |
f4d128af1a01
compat: drop unnecessary wrappers for old Python versions
Mads Kiilerich <madski@unity3d.com>
parents:
5555
diff
changeset
|
43 #============================================================================== |
f4d128af1a01
compat: drop unnecessary wrappers for old Python versions
Mads Kiilerich <madski@unity3d.com>
parents:
5555
diff
changeset
|
44 # unittest |
f4d128af1a01
compat: drop unnecessary wrappers for old Python versions
Mads Kiilerich <madski@unity3d.com>
parents:
5555
diff
changeset
|
45 #============================================================================== |
f4d128af1a01
compat: drop unnecessary wrappers for old Python versions
Mads Kiilerich <madski@unity3d.com>
parents:
5555
diff
changeset
|
46 if sys.version_info >= (2, 7): |
3872
2b9da8749065
Use unittest2 for testing
Marcin Kuzminski <marcin@python-works.com>
parents:
3797
diff
changeset
|
47 import unittest |
2b9da8749065
Use unittest2 for testing
Marcin Kuzminski <marcin@python-works.com>
parents:
3797
diff
changeset
|
48 else: |
2b9da8749065
Use unittest2 for testing
Marcin Kuzminski <marcin@python-works.com>
parents:
3797
diff
changeset
|
49 import unittest2 as unittest |
1514
87ec80c280bb
fixed issues with python2.5
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
50 |
87ec80c280bb
fixed issues with python2.5
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
51 |
87ec80c280bb
fixed issues with python2.5
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
52 #============================================================================== |
87ec80c280bb
fixed issues with python2.5
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
53 # OrderedSet |
87ec80c280bb
fixed issues with python2.5
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
54 #============================================================================== |
87ec80c280bb
fixed issues with python2.5
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
55 from sqlalchemy.util import OrderedSet |
1549
d6cb805c92fd
moved kill function to compat
Marcin Kuzminski <marcin@python-works.com>
parents:
1514
diff
changeset
|
56 |
d6cb805c92fd
moved kill function to compat
Marcin Kuzminski <marcin@python-works.com>
parents:
1514
diff
changeset
|
57 |
d6cb805c92fd
moved kill function to compat
Marcin Kuzminski <marcin@python-works.com>
parents:
1514
diff
changeset
|
58 #============================================================================== |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3872
diff
changeset
|
59 # Hybrid property/method |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3872
diff
changeset
|
60 #============================================================================== |
6208
f4d128af1a01
compat: drop unnecessary wrappers for old Python versions
Mads Kiilerich <madski@unity3d.com>
parents:
5555
diff
changeset
|
61 from sqlalchemy.ext.hybrid import hybrid_property |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3872
diff
changeset
|
62 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3872
diff
changeset
|
63 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3872
diff
changeset
|
64 #============================================================================== |
6208
f4d128af1a01
compat: drop unnecessary wrappers for old Python versions
Mads Kiilerich <madski@unity3d.com>
parents:
5555
diff
changeset
|
65 # kill |
1549
d6cb805c92fd
moved kill function to compat
Marcin Kuzminski <marcin@python-works.com>
parents:
1514
diff
changeset
|
66 #============================================================================== |
6208
f4d128af1a01
compat: drop unnecessary wrappers for old Python versions
Mads Kiilerich <madski@unity3d.com>
parents:
5555
diff
changeset
|
67 if os.name == 'nt': # Windows |
1549
d6cb805c92fd
moved kill function to compat
Marcin Kuzminski <marcin@python-works.com>
parents:
1514
diff
changeset
|
68 import ctypes |
d6cb805c92fd
moved kill function to compat
Marcin Kuzminski <marcin@python-works.com>
parents:
1514
diff
changeset
|
69 |
d6cb805c92fd
moved kill function to compat
Marcin Kuzminski <marcin@python-works.com>
parents:
1514
diff
changeset
|
70 def kill(pid, sig): |
d6cb805c92fd
moved kill function to compat
Marcin Kuzminski <marcin@python-works.com>
parents:
1514
diff
changeset
|
71 """kill function for Win32""" |
d6cb805c92fd
moved kill function to compat
Marcin Kuzminski <marcin@python-works.com>
parents:
1514
diff
changeset
|
72 kernel32 = ctypes.windll.kernel32 |
d6cb805c92fd
moved kill function to compat
Marcin Kuzminski <marcin@python-works.com>
parents:
1514
diff
changeset
|
73 handle = kernel32.OpenProcess(1, 0, pid) |
d6cb805c92fd
moved kill function to compat
Marcin Kuzminski <marcin@python-works.com>
parents:
1514
diff
changeset
|
74 return (0 != kernel32.TerminateProcess(handle, 0)) |
d6cb805c92fd
moved kill function to compat
Marcin Kuzminski <marcin@python-works.com>
parents:
1514
diff
changeset
|
75 |
d6cb805c92fd
moved kill function to compat
Marcin Kuzminski <marcin@python-works.com>
parents:
1514
diff
changeset
|
76 else: |
d6cb805c92fd
moved kill function to compat
Marcin Kuzminski <marcin@python-works.com>
parents:
1514
diff
changeset
|
77 kill = os.kill |