comparison mercurial/util.py @ 7388:5751631246de

dispatch: generalize signature checking for extension command wrapping
author Matt Mackall <mpm@selenic.com>
date Tue, 18 Nov 2008 16:02:14 -0600
parents 00d76fa3ffba
children 040484030491
comparison
equal deleted inserted replaced
7387:7e9a15fa6c8f 7388:5751631246de
11 This contains helper routines that are independent of the SCM core and hide 11 This contains helper routines that are independent of the SCM core and hide
12 platform-specific details from the core. 12 platform-specific details from the core.
13 """ 13 """
14 14
15 from i18n import _ 15 from i18n import _
16 import cStringIO, errno, getpass, re, shutil, sys, tempfile 16 import cStringIO, errno, getpass, re, shutil, sys, tempfile, traceback
17 import os, stat, threading, time, calendar, ConfigParser, locale, glob, osutil 17 import os, stat, threading, time, calendar, ConfigParser, locale, glob, osutil
18 import imp 18 import imp
19 19
20 # Python compatibility 20 # Python compatibility
21 21
669 else: 669 else:
670 os.environ[k] = v 670 os.environ[k] = v
671 if cwd is not None and oldcwd != cwd: 671 if cwd is not None and oldcwd != cwd:
672 os.chdir(oldcwd) 672 os.chdir(oldcwd)
673 673
674 class SignatureError:
675 pass
676
677 def checksignature(func):
678 '''wrap a function with code to check for calling errors'''
679 def check(*args, **kwargs):
680 try:
681 return func(*args, **kwargs)
682 except TypeError:
683 if len(traceback.extract_tb(sys.exc_info()[2])) == 1:
684 raise SignatureError
685 raise
686
687 return check
688
674 # os.path.lexists is not available on python2.3 689 # os.path.lexists is not available on python2.3
675 def lexists(filename): 690 def lexists(filename):
676 "test whether a file with this name exists. does not follow symlinks" 691 "test whether a file with this name exists. does not follow symlinks"
677 try: 692 try:
678 os.lstat(filename) 693 os.lstat(filename)