Mercurial > repos > shellac > guppy_basecaller
comparison env/lib/python3.7/site-packages/rdflib/compat.py @ 0:26e78fe6e8c4 draft
"planemo upload commit c699937486c35866861690329de38ec1a5d9f783"
| author | shellac |
|---|---|
| date | Sat, 02 May 2020 07:14:21 -0400 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:26e78fe6e8c4 |
|---|---|
| 1 # | |
| 2 # code to simplify supporting older python versions | |
| 3 # | |
| 4 | |
| 5 | |
| 6 import sys | |
| 7 | |
| 8 from decimal import Decimal | |
| 9 | |
| 10 if sys.version_info[:2] < (2, 7): | |
| 11 | |
| 12 # Pre-2.7 decimal and float did not compare correctly | |
| 13 | |
| 14 def numeric_greater(a, b): | |
| 15 if isinstance(a, Decimal) and isinstance(b, float): | |
| 16 return float(a) > b | |
| 17 elif isinstance(a, float) and isinstance(b, Decimal): | |
| 18 return a > float(b) | |
| 19 else: | |
| 20 return a > b | |
| 21 | |
| 22 else: | |
| 23 | |
| 24 def numeric_greater(a, b): | |
| 25 return a > b | |
| 26 | |
| 27 | |
| 28 try: | |
| 29 from lxml import etree | |
| 30 except ImportError: | |
| 31 try: | |
| 32 # Python 2.5 | |
| 33 import xml.etree.cElementTree as etree | |
| 34 except ImportError: | |
| 35 try: | |
| 36 # Python 2.5 | |
| 37 import xml.etree.ElementTree as etree | |
| 38 except ImportError: | |
| 39 try: | |
| 40 # normal cElementTree install | |
| 41 import cElementTree as etree | |
| 42 except ImportError: | |
| 43 try: | |
| 44 # normal ElementTree install | |
| 45 import elementtree.ElementTree as etree | |
| 46 except ImportError: | |
| 47 raise Exception("Failed to import ElementTree from any known place") | |
| 48 | |
| 49 try: | |
| 50 etree_register_namespace = etree.register_namespace | |
| 51 except AttributeError: | |
| 52 | |
| 53 import xml.etree.ElementTree as etreenative | |
| 54 | |
| 55 def etree_register_namespace(prefix, uri): | |
| 56 etreenative._namespace_map[uri] = prefix | |
| 57 | |
| 58 try: | |
| 59 from functools import cmp_to_key | |
| 60 except ImportError: | |
| 61 # Backport from Py2.7 for Py2.6: | |
| 62 def cmp_to_key(mycmp): | |
| 63 """Convert a cmp= function into a key= function""" | |
| 64 class K(object): | |
| 65 __slots__ = ['obj'] | |
| 66 def __init__(self, obj, *args): | |
| 67 self.obj = obj | |
| 68 def __lt__(self, other): | |
| 69 return mycmp(self.obj, other.obj) < 0 | |
| 70 def __gt__(self, other): | |
| 71 return mycmp(self.obj, other.obj) > 0 | |
| 72 def __eq__(self, other): | |
| 73 return mycmp(self.obj, other.obj) == 0 | |
| 74 def __le__(self, other): | |
| 75 return mycmp(self.obj, other.obj) <= 0 | |
| 76 def __ge__(self, other): | |
| 77 return mycmp(self.obj, other.obj) >= 0 | |
| 78 def __ne__(self, other): | |
| 79 return mycmp(self.obj, other.obj) != 0 | |
| 80 def __hash__(self): | |
| 81 raise TypeError('hash not implemented') | |
| 82 return K |
