From edd47ff474c5a1fce57ea0b274014476d129f075 Mon Sep 17 00:00:00 2001 From: Brian Harring Date: Wed, 8 Feb 2006 17:51:52 +0000 Subject: [PATCH] cPickle import protection; fall back to pickle if cPickle is unavailable. svn path=/main/trunk/; revision=2679 --- pym/getbinpkg.py | 7 ++++++- pym/portage.py | 6 +++++- pym/portage_util.py | 9 +++++++-- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/pym/getbinpkg.py b/pym/getbinpkg.py index ccffc1dd2..d9c9810f5 100644 --- a/pym/getbinpkg.py +++ b/pym/getbinpkg.py @@ -5,7 +5,12 @@ from output import * -import htmllib,HTMLParser,string,formatter,sys,os,xpak,time,tempfile,cPickle,base64 +import htmllib,HTMLParser,string,formatter,sys,os,xpak,time,tempfile,base64 + +try: + import cPickle +except ImportError: + import pickle as cPickle try: import ftplib diff --git a/pym/portage.py b/pym/portage.py index 0849841ae..0018ab914 100644 --- a/pym/portage.py +++ b/pym/portage.py @@ -20,9 +20,13 @@ except: try: import os,string,types,signal,fcntl - import time,cPickle,traceback,copy + import time,traceback,copy import re,pwd,grp,commands import shlex,shutil + try: + import cPickle + except ImportError: + import pickle as cPickle import stat import commands diff --git a/pym/portage_util.py b/pym/portage_util.py index ef155b5db..ddb1426ad 100644 --- a/pym/portage_util.py +++ b/pym/portage_util.py @@ -4,6 +4,11 @@ import sys,string,shlex,os.path +try: + import cPickle +except ImportError: + import pickle as cPickle + if not hasattr(__builtins__, "set"): from sets import Set as set @@ -365,7 +370,7 @@ def varexpand(mystring,mydict={}): return newstring[1:] def pickle_write(data,filename,debug=0): - import cPickle,os + import os try: myf=open(filename,"w") cPickle.dump(data,myf,-1) @@ -381,7 +386,7 @@ def pickle_write(data,filename,debug=0): return 1 def pickle_read(filename,default=None,debug=0): - import cPickle,os + import os if not os.access(filename, os.R_OK): writemsg("pickle_read(): File not readable. '"+filename+"'\n",1) return default -- 2.26.2