Package proton :: Module _compat
[frames] | no frames]

Source Code for Module proton._compat

 1  # 
 2  # Licensed to the Apache Software Foundation (ASF) under one 
 3  # or more contributor license agreements.  See the NOTICE file 
 4  # distributed with this work for additional information 
 5  # regarding copyright ownership.  The ASF licenses this file 
 6  # to you under the Apache License, Version 2.0 (the 
 7  # "License"); you may not use this file except in compliance 
 8  # with the License.  You may obtain a copy of the License at 
 9  # 
10  #   http://www.apache.org/licenses/LICENSE-2.0 
11  # 
12  # Unless required by applicable law or agreed to in writing, 
13  # software distributed under the License is distributed on an 
14  # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 
15  # KIND, either express or implied.  See the License for the 
16  # specific language governing permissions and limitations 
17  # under the License. 
18  # 
19   
20  """ 
21  Utilities to help Proton support both python2 and python3. 
22  """ 
23   
24  import sys 
25   
26  # bridge between py2 Queue renamed as py3 queue 
27  try: 
28      import Queue as queue 
29  except ImportError: 
30      import queue # type: ignore 
31   
32  try: 
33      from urlparse import urlparse, urlunparse 
34      from urllib import quote, unquote # type: ignore 
35  except ImportError: 
36      from urllib.parse import urlparse, urlunparse, quote, unquote 
37   
38  PY3 = sys.version_info[0] == 3 
39   
40  if PY3: 
41 - def raise_(t, v=None, tb=None):
42 """Mimic the old 2.x raise behavior: 43 Raise an exception of type t with value v using optional traceback tb 44 """ 45 if v is None: 46 v = t() 47 if tb is None: 48 raise v 49 else: 50 raise v.with_traceback(tb)
51
52 - def iteritems(d, **kw):
53 return iter(d.items(**kw))
54
55 - def socket_errno(e):
56 return e.errno
57 58 unichr = chr 59 else: 60 # the raise syntax will cause a parse error in Py3, so 'sneak' in a 61 # definition that won't cause the parser to barf 62 exec ("""def raise_(t, v=None, tb=None): 63 raise t, v, tb 64 """) 65
66 - def iteritems(d, **kw):
67 return d.iteritems(**kw)
68
69 - def socket_errno(e):
70 return e[0]
71 72 unichr = unichr 73