irods  4.2.8
About: iRODS (the integrated Rule Oriented Data System) is a distributed data-management system for creating data grids, digital libraries, persistent archives, and real-time data systems.
  Fossies Dox: irods-4.2.8.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

six.py
Go to the documentation of this file.
1 """Utilities for writing code that runs on Python 2 and 3"""
2 
3 # Copyright (c) 2010-2015 Benjamin Peterson
4 #
5 # Permission is hereby granted, free of charge, to any person obtaining a copy
6 # of this software and associated documentation files (the "Software"), to deal
7 # in the Software without restriction, including without limitation the rights
8 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 # copies of the Software, and to permit persons to whom the Software is
10 # furnished to do so, subject to the following conditions:
11 #
12 # The above copyright notice and this permission notice shall be included in all
13 # copies or substantial portions of the Software.
14 #
15 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 # SOFTWARE.
22 
23 from __future__ import absolute_import
24 
25 import functools
26 import itertools
27 import operator
28 import sys
29 import types
30 
31 __author__ = "Benjamin Peterson <benjamin@python.org>"
32 __version__ = "1.9.0"
33 
34 
35 # Useful for very coarse version differentiation.
36 PY2 = sys.version_info[0] == 2
37 PY3 = sys.version_info[0] == 3
38 
39 if PY3:
40  string_types = str,
41  integer_types = int,
42  class_types = type,
43  text_type = str
44  binary_type = bytes
45 
46  MAXSIZE = sys.maxsize
47 else:
48  string_types = basestring,
49  integer_types = (int, long)
50  class_types = (type, types.ClassType)
51  text_type = unicode
52  binary_type = str
53 
54  if sys.platform.startswith("java"):
55  # Jython always uses 32 bits.
56  MAXSIZE = int((1 << 31) - 1)
57  else:
58  # It's possible to have sizeof(long) != sizeof(Py_ssize_t).
59  class X(object):
60 
61  def __len__(self):
62  return 1 << 31
63  try:
64  len(X())
65  except OverflowError:
66  # 32-bit
67  MAXSIZE = int((1 << 31) - 1)
68  else:
69  # 64-bit
70  MAXSIZE = int((1 << 63) - 1)
71  del X
72 
73 
74 def _add_doc(func, doc):
75  """Add documentation to a function."""
76  func.__doc__ = doc
77 
78 
79 def _import_module(name):
80  """Import module, returning the module after the last dot."""
81  __import__(name)
82  return sys.modules[name]
83 
84 
85 class _LazyDescr(object):
86 
87  def __init__(self, name):
88  self.name = name
89 
90  def __get__(self, obj, tp):
91  result = self._resolve()
92  setattr(obj, self.name, result) # Invokes __set__.
93  try:
94  # This is a bit ugly, but it avoids running this again by
95  # removing this descriptor.
96  delattr(obj.__class__, self.name)
97  except AttributeError:
98  pass
99  return result
100 
101 
103 
104  def __init__(self, name, old, new=None):
105  super(MovedModule, self).__init__(name)
106  if PY3:
107  if new is None:
108  new = name
109  self.mod = new
110  else:
111  self.mod = old
112 
113  def _resolve(self):
114  return _import_module(self.mod)
115 
116  def __getattr__(self, attr):
117  _module = self._resolve()
118  value = getattr(_module, attr)
119  setattr(self, attr, value)
120  return value
121 
122 
123 class _LazyModule(types.ModuleType):
124 
125  def __init__(self, name):
126  super(_LazyModule, self).__init__(name)
127  self.__doc__ = self.__class__.__doc__
128 
129  def __dir__(self):
130  attrs = ["__doc__", "__name__"]
131  attrs += [attr.name for attr in self._moved_attributes]
132  return attrs
133 
134  # Subclasses should override this
135  _moved_attributes = []
136 
137 
139 
140  def __init__(self, name, old_mod, new_mod, old_attr=None, new_attr=None):
141  super(MovedAttribute, self).__init__(name)
142  if PY3:
143  if new_mod is None:
144  new_mod = name
145  self.mod = new_mod
146  if new_attr is None:
147  if old_attr is None:
148  new_attr = name
149  else:
150  new_attr = old_attr
151  self.attr = new_attr
152  else:
153  self.mod = old_mod
154  if old_attr is None:
155  old_attr = name
156  self.attr = old_attr
157 
158  def _resolve(self):
159  module = _import_module(self.mod)
160  return getattr(module, self.attr)
161 
162 
163 class _SixMetaPathImporter(object):
164 
165  """
166  A meta path importer to import six.moves and its submodules.
167 
168  This class implements a PEP302 finder and loader. It should be compatible
169  with Python 2.5 and all existing versions of Python3
170  """
171 
172  def __init__(self, six_module_name):
173  self.name = six_module_name
174  self.known_modules = {}
175 
176  def _add_module(self, mod, *fullnames):
177  for fullname in fullnames:
178  self.known_modules[self.name + "." + fullname] = mod
179 
180  def _get_module(self, fullname):
181  return self.known_modules[self.name + "." + fullname]
182 
183  def find_module(self, fullname, path=None):
184  if fullname in self.known_modules:
185  return self
186  return None
187 
188  def __get_module(self, fullname):
189  try:
190  return self.known_modules[fullname]
191  except KeyError:
192  raise ImportError("This loader does not know module " + fullname)
193 
194  def load_module(self, fullname):
195  try:
196  # in case of a reload
197  return sys.modules[fullname]
198  except KeyError:
199  pass
200  mod = self.__get_module(fullname)
201  if isinstance(mod, MovedModule):
202  mod = mod._resolve()
203  else:
204  mod.__loader__ = self
205  sys.modules[fullname] = mod
206  return mod
207 
208  def is_package(self, fullname):
209  """
210  Return true, if the named module is a package.
211 
212  We need this method to get correct spec objects with
213  Python 3.4 (see PEP451)
214  """
215  return hasattr(self.__get_module(fullname), "__path__")
216 
217  def get_code(self, fullname):
218  """Return None
219 
220  Required, if is_package is implemented"""
221  self.__get_module(fullname) # eventually raises ImportError
222  return None
223  get_source = get_code # same as get_code
224 
225 _importer = _SixMetaPathImporter(__name__)
226 
227 
229 
230  """Lazy loading of moved objects"""
231  __path__ = [] # mark as package
232 
233 
234 _moved_attributes = [
235  MovedAttribute("cStringIO", "cStringIO", "io", "StringIO"),
236  MovedAttribute("filter", "itertools", "builtins", "ifilter", "filter"),
237  MovedAttribute("filterfalse", "itertools", "itertools", "ifilterfalse", "filterfalse"),
238  MovedAttribute("input", "__builtin__", "builtins", "raw_input", "input"),
239  MovedAttribute("intern", "__builtin__", "sys"),
240  MovedAttribute("map", "itertools", "builtins", "imap", "map"),
241  MovedAttribute("range", "__builtin__", "builtins", "xrange", "range"),
242  MovedAttribute("reload_module", "__builtin__", "imp", "reload"),
243  MovedAttribute("reduce", "__builtin__", "functools"),
244  MovedAttribute("shlex_quote", "pipes", "shlex", "quote"),
245  MovedAttribute("StringIO", "StringIO", "io"),
246  MovedAttribute("UserDict", "UserDict", "collections"),
247  MovedAttribute("UserList", "UserList", "collections"),
248  MovedAttribute("UserString", "UserString", "collections"),
249  MovedAttribute("xrange", "__builtin__", "builtins", "xrange", "range"),
250  MovedAttribute("zip", "itertools", "builtins", "izip", "zip"),
251  MovedAttribute("zip_longest", "itertools", "itertools", "izip_longest", "zip_longest"),
252 
253  MovedModule("builtins", "__builtin__"),
254  MovedModule("configparser", "ConfigParser"),
255  MovedModule("copyreg", "copy_reg"),
256  MovedModule("dbm_gnu", "gdbm", "dbm.gnu"),
257  MovedModule("_dummy_thread", "dummy_thread", "_dummy_thread"),
258  MovedModule("http_cookiejar", "cookielib", "http.cookiejar"),
259  MovedModule("http_cookies", "Cookie", "http.cookies"),
260  MovedModule("html_entities", "htmlentitydefs", "html.entities"),
261  MovedModule("html_parser", "HTMLParser", "html.parser"),
262  MovedModule("http_client", "httplib", "http.client"),
263  MovedModule("email_mime_multipart", "email.MIMEMultipart", "email.mime.multipart"),
264  MovedModule("email_mime_nonmultipart", "email.MIMENonMultipart", "email.mime.nonmultipart"),
265  MovedModule("email_mime_text", "email.MIMEText", "email.mime.text"),
266  MovedModule("email_mime_base", "email.MIMEBase", "email.mime.base"),
267  MovedModule("BaseHTTPServer", "BaseHTTPServer", "http.server"),
268  MovedModule("CGIHTTPServer", "CGIHTTPServer", "http.server"),
269  MovedModule("SimpleHTTPServer", "SimpleHTTPServer", "http.server"),
270  MovedModule("cPickle", "cPickle", "pickle"),
271  MovedModule("queue", "Queue"),
272  MovedModule("reprlib", "repr"),
273  MovedModule("socketserver", "SocketServer"),
274  MovedModule("_thread", "thread", "_thread"),
275  MovedModule("tkinter", "Tkinter"),
276  MovedModule("tkinter_dialog", "Dialog", "tkinter.dialog"),
277  MovedModule("tkinter_filedialog", "FileDialog", "tkinter.filedialog"),
278  MovedModule("tkinter_scrolledtext", "ScrolledText", "tkinter.scrolledtext"),
279  MovedModule("tkinter_simpledialog", "SimpleDialog", "tkinter.simpledialog"),
280  MovedModule("tkinter_tix", "Tix", "tkinter.tix"),
281  MovedModule("tkinter_ttk", "ttk", "tkinter.ttk"),
282  MovedModule("tkinter_constants", "Tkconstants", "tkinter.constants"),
283  MovedModule("tkinter_dnd", "Tkdnd", "tkinter.dnd"),
284  MovedModule("tkinter_colorchooser", "tkColorChooser",
285  "tkinter.colorchooser"),
286  MovedModule("tkinter_commondialog", "tkCommonDialog",
287  "tkinter.commondialog"),
288  MovedModule("tkinter_tkfiledialog", "tkFileDialog", "tkinter.filedialog"),
289  MovedModule("tkinter_font", "tkFont", "tkinter.font"),
290  MovedModule("tkinter_messagebox", "tkMessageBox", "tkinter.messagebox"),
291  MovedModule("tkinter_tksimpledialog", "tkSimpleDialog",
292  "tkinter.simpledialog"),
293  MovedModule("urllib_parse", __name__ + ".moves.urllib_parse", "urllib.parse"),
294  MovedModule("urllib_error", __name__ + ".moves.urllib_error", "urllib.error"),
295  MovedModule("urllib", __name__ + ".moves.urllib", __name__ + ".moves.urllib"),
296  MovedModule("urllib_robotparser", "robotparser", "urllib.robotparser"),
297  MovedModule("xmlrpc_client", "xmlrpclib", "xmlrpc.client"),
298  MovedModule("xmlrpc_server", "SimpleXMLRPCServer", "xmlrpc.server"),
299  MovedModule("winreg", "_winreg"),
300 ]
301 for attr in _moved_attributes:
302  setattr(_MovedItems, attr.name, attr)
303  if isinstance(attr, MovedModule):
304  _importer._add_module(attr, "moves." + attr.name)
305 del attr
306 
307 _MovedItems._moved_attributes = _moved_attributes
308 
309 moves = _MovedItems(__name__ + ".moves")
310 _importer._add_module(moves, "moves")
311 
312 
314 
315  """Lazy loading of moved objects in six.moves.urllib_parse"""
316 
317 
318 _urllib_parse_moved_attributes = [
319  MovedAttribute("ParseResult", "urlparse", "urllib.parse"),
320  MovedAttribute("SplitResult", "urlparse", "urllib.parse"),
321  MovedAttribute("parse_qs", "urlparse", "urllib.parse"),
322  MovedAttribute("parse_qsl", "urlparse", "urllib.parse"),
323  MovedAttribute("urldefrag", "urlparse", "urllib.parse"),
324  MovedAttribute("urljoin", "urlparse", "urllib.parse"),
325  MovedAttribute("urlparse", "urlparse", "urllib.parse"),
326  MovedAttribute("urlsplit", "urlparse", "urllib.parse"),
327  MovedAttribute("urlunparse", "urlparse", "urllib.parse"),
328  MovedAttribute("urlunsplit", "urlparse", "urllib.parse"),
329  MovedAttribute("quote", "urllib", "urllib.parse"),
330  MovedAttribute("quote_plus", "urllib", "urllib.parse"),
331  MovedAttribute("unquote", "urllib", "urllib.parse"),
332  MovedAttribute("unquote_plus", "urllib", "urllib.parse"),
333  MovedAttribute("urlencode", "urllib", "urllib.parse"),
334  MovedAttribute("splitquery", "urllib", "urllib.parse"),
335  MovedAttribute("splittag", "urllib", "urllib.parse"),
336  MovedAttribute("splituser", "urllib", "urllib.parse"),
337  MovedAttribute("uses_fragment", "urlparse", "urllib.parse"),
338  MovedAttribute("uses_netloc", "urlparse", "urllib.parse"),
339  MovedAttribute("uses_params", "urlparse", "urllib.parse"),
340  MovedAttribute("uses_query", "urlparse", "urllib.parse"),
341  MovedAttribute("uses_relative", "urlparse", "urllib.parse"),
342 ]
343 for attr in _urllib_parse_moved_attributes:
344  setattr(Module_six_moves_urllib_parse, attr.name, attr)
345 del attr
346 
347 Module_six_moves_urllib_parse._moved_attributes = _urllib_parse_moved_attributes
348 
349 _importer._add_module(Module_six_moves_urllib_parse(__name__ + ".moves.urllib_parse"),
350  "moves.urllib_parse", "moves.urllib.parse")
351 
352 
354 
355  """Lazy loading of moved objects in six.moves.urllib_error"""
356 
357 
358 _urllib_error_moved_attributes = [
359  MovedAttribute("URLError", "urllib2", "urllib.error"),
360  MovedAttribute("HTTPError", "urllib2", "urllib.error"),
361  MovedAttribute("ContentTooShortError", "urllib", "urllib.error"),
362 ]
363 for attr in _urllib_error_moved_attributes:
364  setattr(Module_six_moves_urllib_error, attr.name, attr)
365 del attr
366 
367 Module_six_moves_urllib_error._moved_attributes = _urllib_error_moved_attributes
368 
369 _importer._add_module(Module_six_moves_urllib_error(__name__ + ".moves.urllib.error"),
370  "moves.urllib_error", "moves.urllib.error")
371 
372 
374 
375  """Lazy loading of moved objects in six.moves.urllib_request"""
376 
377 
378 _urllib_request_moved_attributes = [
379  MovedAttribute("urlopen", "urllib2", "urllib.request"),
380  MovedAttribute("install_opener", "urllib2", "urllib.request"),
381  MovedAttribute("build_opener", "urllib2", "urllib.request"),
382  MovedAttribute("pathname2url", "urllib", "urllib.request"),
383  MovedAttribute("url2pathname", "urllib", "urllib.request"),
384  MovedAttribute("getproxies", "urllib", "urllib.request"),
385  MovedAttribute("Request", "urllib2", "urllib.request"),
386  MovedAttribute("OpenerDirector", "urllib2", "urllib.request"),
387  MovedAttribute("HTTPDefaultErrorHandler", "urllib2", "urllib.request"),
388  MovedAttribute("HTTPRedirectHandler", "urllib2", "urllib.request"),
389  MovedAttribute("HTTPCookieProcessor", "urllib2", "urllib.request"),
390  MovedAttribute("ProxyHandler", "urllib2", "urllib.request"),
391  MovedAttribute("BaseHandler", "urllib2", "urllib.request"),
392  MovedAttribute("HTTPPasswordMgr", "urllib2", "urllib.request"),
393  MovedAttribute("HTTPPasswordMgrWithDefaultRealm", "urllib2", "urllib.request"),
394  MovedAttribute("AbstractBasicAuthHandler", "urllib2", "urllib.request"),
395  MovedAttribute("HTTPBasicAuthHandler", "urllib2", "urllib.request"),
396  MovedAttribute("ProxyBasicAuthHandler", "urllib2", "urllib.request"),
397  MovedAttribute("AbstractDigestAuthHandler", "urllib2", "urllib.request"),
398  MovedAttribute("HTTPDigestAuthHandler", "urllib2", "urllib.request"),
399  MovedAttribute("ProxyDigestAuthHandler", "urllib2", "urllib.request"),
400  MovedAttribute("HTTPHandler", "urllib2", "urllib.request"),
401  MovedAttribute("HTTPSHandler", "urllib2", "urllib.request"),
402  MovedAttribute("FileHandler", "urllib2", "urllib.request"),
403  MovedAttribute("FTPHandler", "urllib2", "urllib.request"),
404  MovedAttribute("CacheFTPHandler", "urllib2", "urllib.request"),
405  MovedAttribute("UnknownHandler", "urllib2", "urllib.request"),
406  MovedAttribute("HTTPErrorProcessor", "urllib2", "urllib.request"),
407  MovedAttribute("urlretrieve", "urllib", "urllib.request"),
408  MovedAttribute("urlcleanup", "urllib", "urllib.request"),
409  MovedAttribute("URLopener", "urllib", "urllib.request"),
410  MovedAttribute("FancyURLopener", "urllib", "urllib.request"),
411  MovedAttribute("proxy_bypass", "urllib", "urllib.request"),
412 ]
413 for attr in _urllib_request_moved_attributes:
414  setattr(Module_six_moves_urllib_request, attr.name, attr)
415 del attr
416 
417 Module_six_moves_urllib_request._moved_attributes = _urllib_request_moved_attributes
418 
419 _importer._add_module(Module_six_moves_urllib_request(__name__ + ".moves.urllib.request"),
420  "moves.urllib_request", "moves.urllib.request")
421 
422 
424 
425  """Lazy loading of moved objects in six.moves.urllib_response"""
426 
427 
428 _urllib_response_moved_attributes = [
429  MovedAttribute("addbase", "urllib", "urllib.response"),
430  MovedAttribute("addclosehook", "urllib", "urllib.response"),
431  MovedAttribute("addinfo", "urllib", "urllib.response"),
432  MovedAttribute("addinfourl", "urllib", "urllib.response"),
433 ]
434 for attr in _urllib_response_moved_attributes:
435  setattr(Module_six_moves_urllib_response, attr.name, attr)
436 del attr
437 
438 Module_six_moves_urllib_response._moved_attributes = _urllib_response_moved_attributes
439 
440 _importer._add_module(Module_six_moves_urllib_response(__name__ + ".moves.urllib.response"),
441  "moves.urllib_response", "moves.urllib.response")
442 
443 
445 
446  """Lazy loading of moved objects in six.moves.urllib_robotparser"""
447 
448 
449 _urllib_robotparser_moved_attributes = [
450  MovedAttribute("RobotFileParser", "robotparser", "urllib.robotparser"),
451 ]
452 for attr in _urllib_robotparser_moved_attributes:
453  setattr(Module_six_moves_urllib_robotparser, attr.name, attr)
454 del attr
455 
456 Module_six_moves_urllib_robotparser._moved_attributes = _urllib_robotparser_moved_attributes
457 
458 _importer._add_module(Module_six_moves_urllib_robotparser(__name__ + ".moves.urllib.robotparser"),
459  "moves.urllib_robotparser", "moves.urllib.robotparser")
460 
461 
462 class Module_six_moves_urllib(types.ModuleType):
463 
464  """Create a six.moves.urllib namespace that resembles the Python 3 namespace"""
465  __path__ = [] # mark as package
466  parse = _importer._get_module("moves.urllib_parse")
467  error = _importer._get_module("moves.urllib_error")
468  request = _importer._get_module("moves.urllib_request")
469  response = _importer._get_module("moves.urllib_response")
470  robotparser = _importer._get_module("moves.urllib_robotparser")
471 
472  def __dir__(self):
473  return ['parse', 'error', 'request', 'response', 'robotparser']
474 
475 _importer._add_module(Module_six_moves_urllib(__name__ + ".moves.urllib"),
476  "moves.urllib")
477 
478 
479 def add_move(move):
480  """Add an item to six.moves."""
481  setattr(_MovedItems, move.name, move)
482 
483 
484 def remove_move(name):
485  """Remove item from six.moves."""
486  try:
487  delattr(_MovedItems, name)
488  except AttributeError:
489  try:
490  del moves.__dict__[name]
491  except KeyError:
492  raise AttributeError("no such move, %r" % (name,))
493 
494 
495 if PY3:
496  _meth_func = "__func__"
497  _meth_self = "__self__"
498 
499  _func_closure = "__closure__"
500  _func_code = "__code__"
501  _func_defaults = "__defaults__"
502  _func_globals = "__globals__"
503 else:
504  _meth_func = "im_func"
505  _meth_self = "im_self"
506 
507  _func_closure = "func_closure"
508  _func_code = "func_code"
509  _func_defaults = "func_defaults"
510  _func_globals = "func_globals"
511 
512 
513 try:
514  advance_iterator = next
515 except NameError:
517  return it.next()
518 next = advance_iterator
519 
520 
521 try:
522  callable = callable
523 except NameError:
524  def callable(obj):
525  return any("__call__" in klass.__dict__ for klass in type(obj).__mro__)
526 
527 
528 if PY3:
529  def get_unbound_function(unbound):
530  return unbound
531 
532  create_bound_method = types.MethodType
533 
534  Iterator = object
535 else:
536  def get_unbound_function(unbound):
537  return unbound.im_func
538 
539  def create_bound_method(func, obj):
540  return types.MethodType(func, obj, obj.__class__)
541 
542  class Iterator(object):
543 
544  def next(self):
545  return type(self).__next__(self)
546 
547  callable = callable
548 _add_doc(get_unbound_function,
549  """Get the function out of a possibly unbound function""")
550 
551 
552 get_method_function = operator.attrgetter(_meth_func)
553 get_method_self = operator.attrgetter(_meth_self)
554 get_function_closure = operator.attrgetter(_func_closure)
555 get_function_code = operator.attrgetter(_func_code)
556 get_function_defaults = operator.attrgetter(_func_defaults)
557 get_function_globals = operator.attrgetter(_func_globals)
558 
559 
560 if PY3:
561  def iterkeys(d, **kw):
562  return iter(d.keys(**kw))
563 
564  def itervalues(d, **kw):
565  return iter(d.values(**kw))
566 
567  def iteritems(d, **kw):
568  return iter(d.items(**kw))
569 
570  def iterlists(d, **kw):
571  return iter(d.lists(**kw))
572 
573  viewkeys = operator.methodcaller("keys")
574 
575  viewvalues = operator.methodcaller("values")
576 
577  viewitems = operator.methodcaller("items")
578 else:
579  def iterkeys(d, **kw):
580  return iter(d.iterkeys(**kw))
581 
582  def itervalues(d, **kw):
583  return iter(d.itervalues(**kw))
584 
585  def iteritems(d, **kw):
586  return iter(d.iteritems(**kw))
587 
588  def iterlists(d, **kw):
589  return iter(d.iterlists(**kw))
590 
591  viewkeys = operator.methodcaller("viewkeys")
592 
593  viewvalues = operator.methodcaller("viewvalues")
594 
595  viewitems = operator.methodcaller("viewitems")
596 
597 _add_doc(iterkeys, "Return an iterator over the keys of a dictionary.")
598 _add_doc(itervalues, "Return an iterator over the values of a dictionary.")
599 _add_doc(iteritems,
600  "Return an iterator over the (key, value) pairs of a dictionary.")
601 _add_doc(iterlists,
602  "Return an iterator over the (key, [values]) pairs of a dictionary.")
603 
604 
605 if PY3:
606  def b(s):
607  return s.encode("latin-1")
608 
609  def u(s):
610  return s
611  unichr = chr
612  if sys.version_info[1] <= 1:
613  def int2byte(i):
614  return bytes((i,))
615  else:
616  # This is about 2x faster than the implementation above on 3.2+
617  int2byte = operator.methodcaller("to_bytes", 1, "big")
618  byte2int = operator.itemgetter(0)
619  indexbytes = operator.getitem
620  iterbytes = iter
621  import io
622  StringIO = io.StringIO
623  BytesIO = io.BytesIO
624  _assertCountEqual = "assertCountEqual"
625  _assertRaisesRegex = "assertRaisesRegex"
626  _assertRegex = "assertRegex"
627 else:
628  def b(s):
629  return s
630  # Workaround for standalone backslash
631 
632  def u(s):
633  return unicode(s.replace(r'\\', r'\\\\'), "unicode_escape")
634  unichr = unichr
635  int2byte = chr
636 
637  def byte2int(bs):
638  return ord(bs[0])
639 
640  def indexbytes(buf, i):
641  return ord(buf[i])
642  iterbytes = functools.partial(itertools.imap, ord)
643  import StringIO
644  StringIO = BytesIO = StringIO.StringIO
645  _assertCountEqual = "assertItemsEqual"
646  _assertRaisesRegex = "assertRaisesRegexp"
647  _assertRegex = "assertRegexpMatches"
648 _add_doc(b, """Byte literal""")
649 _add_doc(u, """Text literal""")
650 
651 
652 def assertCountEqual(self, *args, **kwargs):
653  return getattr(self, _assertCountEqual)(*args, **kwargs)
654 
655 
656 def assertRaisesRegex(self, *args, **kwargs):
657  return getattr(self, _assertRaisesRegex)(*args, **kwargs)
658 
659 
660 def assertRegex(self, *args, **kwargs):
661  return getattr(self, _assertRegex)(*args, **kwargs)
662 
663 
664 if PY3:
665  exec_ = getattr(moves.builtins, "exec")
666 
667  def reraise(tp, value, tb=None):
668  if value is None:
669  value = tp()
670  if value.__traceback__ is not tb:
671  raise value.with_traceback(tb)
672  raise value
673 
674 else:
675  def exec_(_code_, _globs_=None, _locs_=None):
676  """Execute code in a namespace."""
677  if _globs_ is None:
678  frame = sys._getframe(1)
679  _globs_ = frame.f_globals
680  if _locs_ is None:
681  _locs_ = frame.f_locals
682  del frame
683  elif _locs_ is None:
684  _locs_ = _globs_
685  exec("""exec _code_ in _globs_, _locs_""")
686 
687  exec_("""def reraise(tp, value, tb=None):
688  raise tp, value, tb
689 """)
690 
691 
692 if sys.version_info[:2] == (3, 2):
693  exec_("""def raise_from(value, from_value):
694  if from_value is None:
695  raise value
696  raise value from from_value
697 """)
698 elif sys.version_info[:2] > (3, 2):
699  exec_("""def raise_from(value, from_value):
700  raise value from from_value
701 """)
702 else:
703  def raise_from(value, from_value):
704  raise value
705 
706 
707 print_ = getattr(moves.builtins, "print", None)
708 if print_ is None:
709  def print_(*args, **kwargs):
710  """The new-style print function for Python 2.4 and 2.5."""
711  fp = kwargs.pop("file", sys.stdout)
712  if fp is None:
713  return
714 
715  def write(data):
716  if not isinstance(data, basestring):
717  data = str(data)
718  # If the file has an encoding, encode unicode with it.
719  if (isinstance(fp, file) and
720  isinstance(data, unicode) and
721  fp.encoding is not None):
722  errors = getattr(fp, "errors", None)
723  if errors is None:
724  errors = "strict"
725  data = data.encode(fp.encoding, errors)
726  fp.write(data)
727  want_unicode = False
728  sep = kwargs.pop("sep", None)
729  if sep is not None:
730  if isinstance(sep, unicode):
731  want_unicode = True
732  elif not isinstance(sep, str):
733  raise TypeError("sep must be None or a string")
734  end = kwargs.pop("end", None)
735  if end is not None:
736  if isinstance(end, unicode):
737  want_unicode = True
738  elif not isinstance(end, str):
739  raise TypeError("end must be None or a string")
740  if kwargs:
741  raise TypeError("invalid keyword arguments to print()")
742  if not want_unicode:
743  for arg in args:
744  if isinstance(arg, unicode):
745  want_unicode = True
746  break
747  if want_unicode:
748  newline = unicode("\n")
749  space = unicode(" ")
750  else:
751  newline = "\n"
752  space = " "
753  if sep is None:
754  sep = space
755  if end is None:
756  end = newline
757  for i, arg in enumerate(args):
758  if i:
759  write(sep)
760  write(arg)
761  write(end)
762 if sys.version_info[:2] < (3, 3):
763  _print = print_
764 
765  def print_(*args, **kwargs):
766  fp = kwargs.get("file", sys.stdout)
767  flush = kwargs.pop("flush", False)
768  _print(*args, **kwargs)
769  if flush and fp is not None:
770  fp.flush()
771 
772 _add_doc(reraise, """Reraise an exception.""")
773 
774 if sys.version_info[0:2] < (3, 4):
775  def wraps(wrapped, assigned=functools.WRAPPER_ASSIGNMENTS,
776  updated=functools.WRAPPER_UPDATES):
777  def wrapper(f):
778  f = functools.wraps(wrapped, assigned, updated)(f)
779  f.__wrapped__ = wrapped
780  return f
781  return wrapper
782 else:
783  wraps = functools.wraps
784 
785 
786 def with_metaclass(meta, *bases):
787  """Create a base class with a metaclass."""
788  # This requires a bit of explanation: the basic idea is to make a dummy
789  # metaclass for one level of class instantiation that replaces itself with
790  # the actual metaclass.
791  class metaclass(meta):
792 
793  def __new__(cls, name, this_bases, d):
794  return meta(name, bases, d)
795  return type.__new__(metaclass, 'temporary_class', (), {})
796 
797 
798 def add_metaclass(metaclass):
799  """Class decorator for creating a class with a metaclass."""
800  def wrapper(cls):
801  orig_vars = cls.__dict__.copy()
802  slots = orig_vars.get('__slots__')
803  if slots is not None:
804  if isinstance(slots, str):
805  slots = [slots]
806  for slots_var in slots:
807  orig_vars.pop(slots_var)
808  orig_vars.pop('__dict__', None)
809  orig_vars.pop('__weakref__', None)
810  return metaclass(cls.__name__, cls.__bases__, orig_vars)
811  return wrapper
812 
813 
815  """
816  A decorator that defines __unicode__ and __str__ methods under Python 2.
817  Under Python 3 it does nothing.
818 
819  To support Python 2 and 3 with a single code base, define a __str__ method
820  returning text and apply this decorator to the class.
821  """
822  if PY2:
823  if '__str__' not in klass.__dict__:
824  raise ValueError("@python_2_unicode_compatible cannot be applied "
825  "to %s because it doesn't define __str__()." %
826  klass.__name__)
827  klass.__unicode__ = klass.__str__
828  klass.__str__ = lambda self: self.__unicode__().encode('utf-8')
829  return klass
830 
831 
832 # Complete the moves implementation.
833 # This code is at the end of this module to speed up module loading.
834 # Turn this module into a package.
835 __path__ = [] # required for PEP 302 and PEP 451
836 __package__ = __name__ # see PEP 366 @ReservedAssignment
837 if globals().get("__spec__") is not None:
838  __spec__.submodule_search_locations = [] # PEP 451 @UndefinedVariable
839 # Remove other six meta path importers, since they cause problems. This can
840 # happen if six is removed from sys.modules and then reloaded. (Setuptools does
841 # this for some reason.)
842 if sys.meta_path:
843  for i, importer in enumerate(sys.meta_path):
844  # Here's some real nastiness: Another "instance" of the six module might
845  # be floating around. Therefore, we can't use isinstance() to check for
846  # the six meta path importer, since the other six instance will have
847  # inserted an importer with different class.
848  if (type(importer).__name__ == "_SixMetaPathImporter" and
849  importer.name == __name__):
850  del sys.meta_path[i]
851  break
852  del i, importer
853 # Finally, add the importer to the meta path import hook.
854 sys.meta_path.append(_importer)
irods.six.MovedAttribute.attr
attr
Definition: six.py:151
irods.six._LazyDescr.__get__
def __get__(self, obj, tp)
Definition: six.py:90
irods.six.MovedAttribute.mod
mod
Definition: six.py:145
irods.six._LazyDescr.__init__
def __init__(self, name)
Definition: six.py:87
irods.six.iterkeys
def iterkeys(d, **kw)
Definition: six.py:561
irods.six._MovedItems
Definition: six.py:228
irods.six._SixMetaPathImporter.__get_module
def __get_module(self, fullname)
Definition: six.py:188
irods.six.add_metaclass
def add_metaclass(metaclass)
Definition: six.py:798
irods.six.Iterator
Definition: six.py:542
irods.six._LazyModule
Definition: six.py:123
irods.six.raise_from
def raise_from(value, from_value)
Definition: six.py:703
irods.six.X
Definition: six.py:59
irods.six.Module_six_moves_urllib_response
Definition: six.py:423
irods.six.iteritems
def iteritems(d, **kw)
Definition: six.py:567
irods.six._SixMetaPathImporter
Definition: six.py:163
irods.six.get_unbound_function
def get_unbound_function(unbound)
Definition: six.py:529
irods.six.with_metaclass
def with_metaclass(meta, *bases)
Definition: six.py:786
irods.six.create_bound_method
create_bound_method
Definition: six.py:532
irods.six.MovedModule.mod
mod
Definition: six.py:109
irods.six.exec_
exec_
Definition: six.py:665
irods.six.Iterator.next
def next(self)
Definition: six.py:544
irods.pypyodbc.unicode
unicode
Definition: pypyodbc.py:44
irods.six._SixMetaPathImporter.get_code
def get_code(self, fullname)
Definition: six.py:217
irods.six.byte2int
byte2int
Definition: six.py:618
irods.six._import_module
def _import_module(name)
Definition: six.py:79
irods.six._LazyModule._moved_attributes
list _moved_attributes
Definition: six.py:135
irods.six._SixMetaPathImporter.__init__
def __init__(self, six_module_name)
Definition: six.py:172
irods.six.add_move
def add_move(move)
Definition: six.py:479
irods.six.Module_six_moves_urllib.__dir__
def __dir__(self)
Definition: six.py:472
irods.six.MovedModule.__init__
def __init__(self, name, old, new=None)
Definition: six.py:104
irods.six.MovedModule._resolve
def _resolve(self)
Definition: six.py:113
irods.six.python_2_unicode_compatible
def python_2_unicode_compatible(klass)
Definition: six.py:814
irods.six._add_doc
def _add_doc(func, doc)
Definition: six.py:74
irods.six._SixMetaPathImporter.find_module
def find_module(self, fullname, path=None)
Definition: six.py:183
irods.six.int2byte
int2byte
Definition: six.py:617
irods.six.MovedAttribute._resolve
def _resolve(self)
Definition: six.py:158
irods.six.indexbytes
indexbytes
Definition: six.py:619
irods.six._SixMetaPathImporter._get_module
def _get_module(self, fullname)
Definition: six.py:180
irods.six.advance_iterator
advance_iterator
Definition: six.py:514
irods.six.remove_move
def remove_move(name)
Definition: six.py:484
irods.six.u
def u(s)
Definition: six.py:609
irods::experimental::filesystem::client::copy
auto copy(rcComm_t &_comm, const path &_from, const path &_to, copy_options _options=copy_options::none) -> void
Definition: filesystem.cpp:370
irods.six.wraps
def wraps
Definition: six.py:783
irods.six.assertRegex
def assertRegex(self, *args, **kwargs)
Definition: six.py:660
irods.six.MovedAttribute
Definition: six.py:138
irods.six.print_
print_
Definition: six.py:707
irods.six.reraise
def reraise(tp, value, tb=None)
Definition: six.py:667
irods.six.iterlists
def iterlists(d, **kw)
Definition: six.py:570
irods.six.Module_six_moves_urllib_parse
Definition: six.py:313
irods.six._SixMetaPathImporter.load_module
def load_module(self, fullname)
Definition: six.py:194
irods.six.Module_six_moves_urllib
Definition: six.py:462
irods.six.callable
callable
Definition: six.py:522
int
typedef int((*funcPtr)())
irods.six.assertRaisesRegex
def assertRaisesRegex(self, *args, **kwargs)
Definition: six.py:656
irods.six.itervalues
def itervalues(d, **kw)
Definition: six.py:564
irods.six.MovedModule
Definition: six.py:102
irods.six.Module_six_moves_urllib_request
Definition: six.py:373
irods.six._LazyDescr
Definition: six.py:85
irods.six._LazyModule.__doc__
__doc__
Definition: six.py:127
irods.six._print
_print
Definition: six.py:763
irods.six._SixMetaPathImporter.name
name
Definition: six.py:173
irods.six._LazyModule.__dir__
def __dir__(self)
Definition: six.py:129
irods.six._SixMetaPathImporter.is_package
def is_package(self, fullname)
Definition: six.py:208
irods.six.b
def b(s)
Definition: six.py:606
irods.six._LazyDescr.name
name
Definition: six.py:88
irods.six.MovedModule.__getattr__
def __getattr__(self, attr)
Definition: six.py:116
irods.six.Module_six_moves_urllib_robotparser
Definition: six.py:444
irods.six._SixMetaPathImporter.known_modules
known_modules
Definition: six.py:174
irods.six.X.__len__
def __len__(self)
Definition: six.py:61
irods.six._SixMetaPathImporter._add_module
def _add_module(self, mod, *fullnames)
Definition: six.py:176
irods.six._LazyModule.__init__
def __init__(self, name)
Definition: six.py:125
irods.six.assertCountEqual
def assertCountEqual(self, *args, **kwargs)
Definition: six.py:652
irods.six.Module_six_moves_urllib_error
Definition: six.py:353
irods.six.MovedAttribute.__init__
def __init__(self, name, old_mod, new_mod, old_attr=None, new_attr=None)
Definition: six.py:140
type
int type
Definition: filesystem.cpp:103
irods.password_obfuscation.encode
def encode(s, uid=None, mtime=None)
Definition: password_obfuscation.py:88