Package flumotion :: Package common :: Module python
[hide private]

Source Code for Module flumotion.common.python

  1  # -*- Mode: Python; test-case-name: flumotion.test.test_config -*- 
  2  # vi:si:et:sw=4:sts=4:ts=4 
  3  # 
  4  # Flumotion - a streaming media server 
  5  # Copyright (C) 2004,2005,2006,2007 Fluendo, S.L. (www.fluendo.com). 
  6  # All rights reserved. 
  7   
  8  # This file may be distributed and/or modified under the terms of 
  9  # the GNU General Public License version 2 as published by 
 10  # the Free Software Foundation. 
 11  # This file is distributed without any warranty; without even the implied 
 12  # warranty of merchantability or fitness for a particular purpose. 
 13  # See "LICENSE.GPL" in the source distribution for more information. 
 14   
 15  # Licensees having purchased or holding a valid Flumotion Advanced 
 16  # Streaming Server license may use this file in accordance with the 
 17  # Flumotion Advanced Streaming Server Commercial License Agreement. 
 18  # See "LICENSE.Flumotion" in the source distribution for more information. 
 19   
 20  # Headers in this file shall remain intact. 
 21   
 22  """ 
 23  forward compatibility with future python versions 
 24  """ 
 25   
 26  import sys 
 27   
 28  __version__ = "$Rev: 7991 $" 
 29   
 30  # we're possibly redefining some builtins, so don't warn 
 31  __pychecker__ = 'no-shadowbuiltin' 
 32   
 33  # sorted() was introduced in 2.4 
 34  if sys.version_info[:2] < (2, 4): 
 35   
36 - def sorted(seq, reverse=False):
37 seq = seq[:] 38 seq.sort() 39 if reversed: 40 seq = seq[::-1] 41 return seq
42 else: 43 sorted = sorted 44 45 # any() was introduced in 2.5 46 if sys.version_info[:2] < (2, 5): 47
48 - def any(seq):
49 for item in seq: 50 if item: 51 return True 52 return False
53 else: 54 any = any 55 56 # all() was introduced in 2.5 57 if sys.version_info[:2] < (2, 5): 58
59 - def all(seq):
60 for item in seq: 61 if not item: 62 return False 63 return True
64 else: 65 all = all 66 67 68 # python2.4's os.makedirs() lacks EEXIST checks, so here's almost a 69 # literal copy from the python2.5's version of os module 70 if sys.version_info[:2] < (2, 5): 71 import os.path as path 72 from os import mkdir, curdir 73 from errno import EEXIST 74
75 - def makedirs(name, mode=0777):
76 head, tail = path.split(name) 77 if not tail: 78 head, tail = path.split(head) 79 if head and tail and not path.exists(head): 80 try: 81 makedirs(head, mode) 82 except OSError, e: 83 # be happy if someone already created the path 84 if e.errno != EEXIST: 85 raise 86 if tail == curdir: # xxx/newdir/. exists if xxx/newdir exists 87 return 88 mkdir(name, mode)
89 else: 90 from os import makedirs 91 92 # python 2.6 deprecates sha and md5 modules in favor of hashlib 93 try: 94 _hashlib = __import__("hashlib") 95 except ImportError: 96 from md5 import md5 97 from sha import sha as sha1 98 else: 99 from hashlib import md5 as md5 100 from hashlib import sha1 as sha1 101 102 # python 2.6 deprecated the sets module in favor of a builtin set class 103 try: 104 set = set 105 except NameError: 106 from sets import Set as set 107