diff 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
line wrap: on
line diff
--- a/mercurial/util.py	Tue Nov 18 15:35:34 2008 -0600
+++ b/mercurial/util.py	Tue Nov 18 16:02:14 2008 -0600
@@ -13,7 +13,7 @@
 """
 
 from i18n import _
-import cStringIO, errno, getpass, re, shutil, sys, tempfile
+import cStringIO, errno, getpass, re, shutil, sys, tempfile, traceback
 import os, stat, threading, time, calendar, ConfigParser, locale, glob, osutil
 import imp
 
@@ -671,6 +671,21 @@
         if cwd is not None and oldcwd != cwd:
             os.chdir(oldcwd)
 
+class SignatureError:
+    pass
+
+def checksignature(func):
+    '''wrap a function with code to check for calling errors'''
+    def check(*args, **kwargs):
+        try:
+            return func(*args, **kwargs)
+        except TypeError:
+            if len(traceback.extract_tb(sys.exc_info()[2])) == 1:
+                raise SignatureError
+            raise
+
+    return check
+
 # os.path.lexists is not available on python2.3
 def lexists(filename):
     "test whether a file with this name exists. does not follow symlinks"