From 10eda9a824369b8f7bc397a467f6f5120bc8710b Mon Sep 17 00:00:00 2001 From: bernat Date: Fri, 15 Jul 2005 17:38:42 +0200 Subject: [PATCH] Acceleration de QuadToDec aussi... darcs-hash:20050715153842-d1718-990cd3f4e7b3e6233afc166d962d71ab179b9b1a.gz --- gestion/iptools.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/gestion/iptools.py b/gestion/iptools.py index a130e6a0..a4f500e4 100755 --- a/gestion/iptools.py +++ b/gestion/iptools.py @@ -28,18 +28,25 @@ def QuadToDec(ip) : __QuadToDecDone[ip] = ip_dec return ip_dec + +# Pour accélérer DecToQuad +__DecToQuadDone = {} def DecToQuad(ip_dec) : """ Retourne la représentation habituelle d'une ip (xxx.xxx.xxx.xxx) ip_dec est l'IP en base 10 """ + if ip_dec in __DecToQuadDone: + return __DecToQuadDone[ip_dec] try : - return "%d.%d.%d.%d" % ( \ + result = "%d.%d.%d.%d" % ( \ ip_dec/(256**3) , (ip_dec%(256**3)) / (256**2) , ( (ip_dec%(256**3)) % (256**2) ) / 256 , ( (ip_dec%(256**3)) % (256**2) ) % 256 ) + __DecToQuadDone[ip_dec] = result + return result except : raise ValueError('IP Invalide')