diff options
-rw-r--r-- | pym/portage/__init__.py | 5 | ||||
-rw-r--r-- | pym/portage/_selinux.py | 27 | ||||
-rw-r--r-- | pym/portage/cache/ebuild_xattr.py | 4 | ||||
-rw-r--r-- | pym/portage/checksum.py | 9 | ||||
-rw-r--r-- | pym/portage/env/loaders.py | 9 | ||||
-rw-r--r-- | pym/portage/mail.py | 25 | ||||
-rw-r--r-- | pym/portage/manifest.py | 20 | ||||
-rw-r--r-- | pym/portage/news.py | 14 | ||||
-rw-r--r-- | pym/portage/process.py | 6 | ||||
-rw-r--r-- | pym/portage/sets/files.py | 14 | ||||
-rw-r--r-- | pym/portage/tests/__init__.py | 8 | ||||
-rw-r--r-- | pym/portage/tests/ebuild/test_spawn.py | 7 | ||||
-rw-r--r-- | pym/portage/update.py | 20 | ||||
-rw-r--r-- | pym/portage/xpak.py | 43 |
14 files changed, 102 insertions, 109 deletions
diff --git a/pym/portage/__init__.py b/pym/portage/__init__.py index 5fefa505c..4c6efddb0 100644 --- a/pym/portage/__init__.py +++ b/pym/portage/__init__.py @@ -132,11 +132,6 @@ _encodings = { if _encodings['merge'] is None: _encodings['merge'] = 'ascii' -# Deprecated attributes. Instead use _encodings directly. -_content_encoding = _encodings['content'] -_fs_encoding = _encodings['fs'] -_merge_encoding = _encodings['merge'] - def _unicode_encode(s, encoding=_encodings['content'], errors='backslashreplace'): if isinstance(s, unicode): diff --git a/pym/portage/_selinux.py b/pym/portage/_selinux.py index 9c0f08299..ca6ec4dec 100644 --- a/pym/portage/_selinux.py +++ b/pym/portage/_selinux.py @@ -7,8 +7,7 @@ import os import shutil -from portage import _content_encoding -from portage import _fs_encoding +from portage import _encodings from portage import _unicode_encode from portage.localization import _ @@ -16,8 +15,8 @@ import selinux from selinux import is_selinux_enabled def copyfile(src, dest): - src = _unicode_encode(src, encoding=_fs_encoding, errors='strict') - dest = _unicode_encode(dest, encoding=_fs_encoding, errors='strict') + src = _unicode_encode(src, encoding=_encodings['fs'], errors='strict') + dest = _unicode_encode(dest, encoding=_encodings['fs'], errors='strict') (rc, ctx) = selinux.lgetfilecon(src) if rc < 0: raise OSError(_("copyfile: Failed getting context of \"%s\".") % src) @@ -36,8 +35,8 @@ def getcontext(): return ctx def mkdir(target, refdir): - target = _unicode_encode(target, encoding=_fs_encoding, errors='strict') - refdir = _unicode_encode(refdir, encoding=_fs_encoding, errors='strict') + target = _unicode_encode(target, encoding=_encodings['fs'], errors='strict') + refdir = _unicode_encode(refdir, encoding=_encodings['fs'], errors='strict') (rc, ctx) = selinux.getfilecon(refdir) if rc < 0: raise OSError( @@ -51,8 +50,8 @@ def mkdir(target, refdir): selinux.setfscreatecon() def rename(src, dest): - src = _unicode_encode(src, encoding=_fs_encoding, errors='strict') - dest = _unicode_encode(dest, encoding=_fs_encoding, errors='strict') + src = _unicode_encode(src, encoding=_encodings['fs'], errors='strict') + dest = _unicode_encode(dest, encoding=_encodings['fs'], errors='strict') (rc, ctx) = selinux.lgetfilecon(src) if rc < 0: raise OSError(_("rename: Failed getting context of \"%s\".") % src) @@ -69,13 +68,13 @@ def settype(newtype): return ":".join(ret) def setexec(ctx="\n"): - ctx = _unicode_encode(ctx, encoding=_content_encoding, errors='strict') + ctx = _unicode_encode(ctx, encoding=_encodings['content'], errors='strict') if selinux.setexeccon(ctx) < 0: raise OSError(_("setexec: Failed setting exec() context \"%s\".") % ctx) def setfscreate(ctx="\n"): ctx = _unicode_encode(ctx, - encoding=_content_encoding, errors='strict') + encoding=_encodings['content'], errors='strict') if selinux.setfscreatecon(ctx) < 0: raise OSError( _("setfscreate: Failed setting fs create context \"%s\".") % ctx) @@ -83,7 +82,7 @@ def setfscreate(ctx="\n"): def spawn_wrapper(spawn_func, selinux_type): selinux_type = _unicode_encode(selinux_type, - encoding=_content_encoding, errors='strict') + encoding=_encodings['content'], errors='strict') def wrapper_func(*args, **kwargs): con = settype(selinux_type) @@ -96,9 +95,9 @@ def spawn_wrapper(spawn_func, selinux_type): return wrapper_func def symlink(target, link, reflnk): - target = _unicode_encode(target, encoding=_fs_encoding, errors='strict') - link = _unicode_encode(link, encoding=_fs_encoding, errors='strict') - reflnk = _unicode_encode(reflnk, encoding=_fs_encoding, errors='strict') + target = _unicode_encode(target, encoding=_encodings['fs'], errors='strict') + link = _unicode_encode(link, encoding=_encodings['fs'], errors='strict') + reflnk = _unicode_encode(reflnk, encoding=_encodings['fs'], errors='strict') (rc, ctx) = selinux.lgetfilecon(reflnk) if rc < 0: raise OSError( diff --git a/pym/portage/cache/ebuild_xattr.py b/pym/portage/cache/ebuild_xattr.py index bcaf30640..4406b4e77 100644 --- a/pym/portage/cache/ebuild_xattr.py +++ b/pym/portage/cache/ebuild_xattr.py @@ -10,7 +10,7 @@ from portage.cache import fs_template from portage.versions import catsplit from portage import cpv_getkey from portage import os -from portage import _fs_encoding +from portage import _encoding from portage import _unicode_decode import xattr from errno import ENODATA,ENOSPC,E2BIG @@ -159,7 +159,7 @@ class database(fs_template.FsBased): for file in files: try: file = _unicode_decode(file, - encoding=_fs_encoding, errors='strict') + encoding=_encodings['fs'], errors='strict') except UnicodeDecodeError: continue if file[-7:] == '.ebuild': diff --git a/pym/portage/checksum.py b/pym/portage/checksum.py index f871c49ae..0a67d2dc0 100644 --- a/pym/portage/checksum.py +++ b/pym/portage/checksum.py @@ -7,8 +7,7 @@ import portage from portage.const import PRIVATE_PATH,PRELINK_BINARY,HASHING_BLOCKSIZE from portage.localization import _ from portage import os -from portage import _fs_encoding -from portage import _merge_encoding +from portage import _encodings from portage import _unicode_encode import errno import stat @@ -29,7 +28,7 @@ def _generate_hash_function(hashtype, hashobject, origin="unknown"): @return: The hash and size of the data """ f = open(_unicode_encode(filename, - encoding=_fs_encoding, errors='strict'), 'rb') + encoding=_encodings['fs'], errors='strict'), 'rb') blocksize = HASHING_BLOCKSIZE data = f.read(blocksize) size = 0L @@ -123,7 +122,7 @@ def perform_md5(x, calc_prelink=0): def _perform_md5_merge(x, **kwargs): return perform_md5(_unicode_encode(x, - encoding=_merge_encoding, errors='strict'), **kwargs) + encoding=_encodings['merge'], errors='strict'), **kwargs) def perform_all(x, calc_prelink=0): mydict = {} @@ -221,7 +220,7 @@ def perform_checksum(filename, hashname="MD5", calc_prelink=0): # Make sure filename is encoded with the correct encoding before # it is passed to spawn (for prelink) and/or the hash function. filename = _unicode_encode(filename, - encoding=_fs_encoding, errors='strict') + encoding=_encodings['fs'], errors='strict') myfilename = filename prelink_tmpfile = None try: diff --git a/pym/portage/env/loaders.py b/pym/portage/env/loaders.py index e878ba449..5ec3a066f 100644 --- a/pym/portage/env/loaders.py +++ b/pym/portage/env/loaders.py @@ -7,8 +7,7 @@ import codecs import errno import stat from portage import os -from portage import _content_encoding -from portage import _fs_encoding +from portage import _encodings from portage import _unicode_decode from portage import _unicode_encode from portage.localization import _ @@ -57,7 +56,7 @@ def RecursiveFileLoader(filename): for f in files: try: f = _unicode_decode(f, - encoding=_fs_encoding, errors='strict') + encoding=_encodings['fs'], errors='strict') except UnicodeDecodeError: continue if f[:1] == '.' or f[-1:] == '~': @@ -152,8 +151,8 @@ class FileLoader(DataLoader): for fn in RecursiveFileLoader(self.fname): try: f = codecs.open(_unicode_encode(fn, - encoding=_fs_encoding, errors='strict'), mode='r', - encoding=_content_encoding, errors='replace') + encoding=_encodings['fs'], errors='strict'), mode='r', + encoding=_encodings['content'], errors='replace') except EnvironmentError, e: if e.errno not in (errno.ENOENT, errno.ESTALE): raise diff --git a/pym/portage/mail.py b/pym/portage/mail.py index ce2f6760d..260455739 100644 --- a/pym/portage/mail.py +++ b/pym/portage/mail.py @@ -13,7 +13,7 @@ import sys import time from portage import os -from portage import _content_encoding +from portage import _encodings from portage import _unicode_encode from portage.localization import _ import portage @@ -22,13 +22,13 @@ def create_message(sender, recipient, subject, body, attachments=None): if sys.hexversion < 0x3000000: sender = _unicode_encode(sender, - encoding=_content_encoding, errors='strict') + encoding=_encodings['content'], errors='strict') recipient = _unicode_encode(recipient, - encoding=_content_encoding, errors='strict') + encoding=_encodings['content'], errors='strict') subject = _unicode_encode(subject, - encoding=_content_encoding, errors='replace') + encoding=_encodings['content'], errors='backslashreplace') body = _unicode_encode(body, - encoding=_content_encoding, errors='replace') + encoding=_encodings['content'], errors='backslashreplace') if attachments == None: mymessage = TextMessage(body) @@ -41,7 +41,8 @@ def create_message(sender, recipient, subject, body, attachments=None): elif isinstance(x, basestring): if sys.hexversion < 0x3000000: x = _unicode_encode(x, - encoding=_content_encoding, errors='replace') + encoding=_encodings['content'], + errors='backslashreplace') mymessage.attach(TextMessage(x)) else: raise portage.exception.PortageException(_("Can't handle type of attachment: %s") % type(x)) @@ -92,17 +93,17 @@ def send_mail(mysettings, message): if sys.hexversion < 0x3000000: myrecipient = _unicode_encode(myrecipient, - encoding=_content_encoding, errors='strict') + encoding=_encodings['content'], errors='strict') mymailhost = _unicode_encode(mymailhost, - encoding=_content_encoding, errors='strict') + encoding=_encodings['content'], errors='strict') mymailport = _unicode_encode(mymailport, - encoding=_content_encoding, errors='strict') + encoding=_encodings['content'], errors='strict') myfrom = _unicode_encode(myfrom, - encoding=_content_encoding, errors='strict') + encoding=_encodings['content'], errors='strict') mymailuser = _unicode_encode(mymailuser, - encoding=_content_encoding, errors='strict') + encoding=_encodings['content'], errors='strict') mymailpasswd = _unicode_encode(mymailpasswd, - encoding=_content_encoding, errors='strict') + encoding=_encodings['content'], errors='strict') # user wants to use a sendmail binary instead of smtp if mymailhost[0] == os.sep and os.path.exists(mymailhost): diff --git a/pym/portage/manifest.py b/pym/portage/manifest.py index 4c4cb60b3..25893d759 100644 --- a/pym/portage/manifest.py +++ b/pym/portage/manifest.py @@ -12,8 +12,7 @@ portage.proxy.lazyimport.lazyimport(globals(), ) from portage import os -from portage import _content_encoding -from portage import _fs_encoding +from portage import _encodings from portage import _unicode_decode from portage import _unicode_encode from portage.exception import DigestException, FileNotFound, \ @@ -145,8 +144,8 @@ class Manifest(object): Otherwise, a new dict will be created and returned.""" try: fd = codecs.open(_unicode_encode(file_path, - encoding=_fs_encoding, errors='strict'), mode='r', - encoding=_content_encoding, errors='replace') + encoding=_encodings['fs'], errors='strict'), mode='r', + encoding=_encodings['repo.content'], errors='replace') if myhashdict is None: myhashdict = {} self._parseDigests(fd, myhashdict=myhashdict, **kwargs) @@ -233,8 +232,9 @@ class Manifest(object): if not force: try: f = codecs.open(_unicode_encode(self.getFullname(), - encoding=_fs_encoding, errors='strict'), - mode='r', encoding=_content_encoding, errors='replace') + encoding=_encodings['fs'], errors='strict'), + mode='r', encoding=_encodings['repo.content'], + errors='replace') oldentries = list(self._parseManifestLines(f)) f.close() if len(oldentries) == len(myentries): @@ -327,7 +327,7 @@ class Manifest(object): for f in pkgdir_files: try: f = _unicode_decode(f, - encoding=_fs_encoding, errors='strict') + encoding=_encodings['fs'], errors='strict') except UnicodeDecodeError: continue if f[:1] == ".": @@ -362,7 +362,7 @@ class Manifest(object): for f in files: try: f = _unicode_decode(f, - encoding=_fs_encoding, errors='strict') + encoding=_encodings['fs'], errors='strict') except UnicodeDecodeError: continue full_path = os.path.join(parentdir, f) @@ -523,8 +523,8 @@ class Manifest(object): if not os.path.exists(mfname): return rVal myfile = codecs.open(_unicode_encode(mfname, - encoding=_fs_encoding, errors='strict'), - mode='r', encoding=_content_encoding, errors='replace') + encoding=_encodings['fs'], errors='strict'), + mode='r', encoding=_encodings['repo.content'], errors='replace') lines = myfile.readlines() myfile.close() for l in lines: diff --git a/pym/portage/news.py b/pym/portage/news.py index f3482150d..ca608d722 100644 --- a/pym/portage/news.py +++ b/pym/portage/news.py @@ -12,8 +12,7 @@ import logging import os as _os import re from portage import os -from portage import _content_encoding -from portage import _fs_encoding +from portage import _encodings from portage import _unicode_decode from portage import _unicode_encode from portage.util import apply_secpass_permissions, ensure_dirs, \ @@ -100,7 +99,7 @@ class NewsManager(object): news_dir = self._news_dir(repoid) try: news = _os.listdir(_unicode_encode(news_dir, - encoding=_fs_encoding, errors='strict')) + encoding=_encodings['fs'], errors='strict')) except OSError: return @@ -120,10 +119,10 @@ class NewsManager(object): for itemid in news: try: itemid = _unicode_decode(itemid, - encoding=_fs_encoding, errors='strict') + encoding=_encodings['fs'], errors='strict') except UnicodeDecodeError: itemid = _unicode_decode(itemid, - encoding=_fs_encoding, errors='replace') + encoding=_encodings['fs'], errors='replace') writemsg_level( "!!! Invalid encoding in news item name: '%s'\n" % \ itemid, level=logging.ERROR, noiselevel=-1) @@ -253,8 +252,9 @@ class NewsItem(object): def parse(self): lines = codecs.open(_unicode_encode(self.path, - encoding=_fs_encoding, errors='strict'), - mode='r', encoding=_content_encoding, errors='replace').readlines() + encoding=_encodings['fs'], errors='strict'), + mode='r', encoding=_encodings['content'], errors='replace' + ).readlines() self.restrictions = {} invalids = [] for i, line in enumerate(lines): diff --git a/pym/portage/process.py b/pym/portage/process.py index 1b5846883..1822a3082 100644 --- a/pym/portage/process.py +++ b/pym/portage/process.py @@ -10,7 +10,7 @@ import sys import traceback from portage import os -from portage import _content_encoding +from portage import _encodings from portage import _unicode_encode import portage portage.proxy.lazyimport.lazyimport(globals(), @@ -184,8 +184,8 @@ def spawn(mycommand, env={}, opt_name=None, fd_pipes=None, returnpid=False, # Avoid a potential UnicodeEncodeError from os.execve(). env_bytes = {} for k, v in env.iteritems(): - env_bytes[_unicode_encode(k, encoding=_content_encoding)] = \ - _unicode_encode(v, encoding=_content_encoding) + env_bytes[_unicode_encode(k, encoding=_encodings['content'])] = \ + _unicode_encode(v, encoding=_encodings['content']) env = env_bytes del env_bytes diff --git a/pym/portage/sets/files.py b/pym/portage/sets/files.py index 035c2dc99..64e36802e 100644 --- a/pym/portage/sets/files.py +++ b/pym/portage/sets/files.py @@ -7,7 +7,7 @@ import re from itertools import chain from portage import os -from portage import _fs_encoding +from portage import _encodings from portage import _unicode_decode from portage import _unicode_encode from portage.util import grabfile, write_atomic, ensure_dirs, normalize_path @@ -131,16 +131,16 @@ class StaticFileSet(EditablePackageSet): try: directory = _unicode_decode(directory, - encoding=_fs_encoding, errors='strict') + encoding=_encodings['fs'], errors='strict') # Now verify that we can also encode it. _unicode_encode(directory, - encoding=_fs_encoding, errors='strict') + encoding=_encodings['fs'], errors='strict') except UnicodeError: directory = _unicode_decode(directory, - encoding=_fs_encoding, errors='replace') + encoding=_encodings['fs'], errors='replace') raise SetConfigError( _("Directory path contains invalid character(s) for encoding '%s': '%s'") \ - % (_fs_encoding, directory)) + % (_encodings['fs'], directory)) if os.path.isdir(directory): directory = normalize_path(directory) @@ -148,7 +148,7 @@ class StaticFileSet(EditablePackageSet): for parent, dirs, files in os.walk(directory): try: parent = _unicode_decode(parent, - encoding=_fs_encoding, errors='strict') + encoding=_encodings['fs'], errors='strict') except UnicodeDecodeError: continue for d in dirs[:]: @@ -157,7 +157,7 @@ class StaticFileSet(EditablePackageSet): for filename in files: try: filename = _unicode_decode(filename, - encoding=_fs_encoding, errors='strict') + encoding=_encodings['fs'], errors='strict') except UnicodeDecodeError: continue if filename[:1] == '.': diff --git a/pym/portage/tests/__init__.py b/pym/portage/tests/__init__.py index 4a5ced8a3..6e7380409 100644 --- a/pym/portage/tests/__init__.py +++ b/pym/portage/tests/__init__.py @@ -8,16 +8,16 @@ import time import unittest from portage import os -from portage import _fs_encoding +from portage import _encodings from portage import _unicode_encode from portage import _unicode_decode def main(): TEST_FILE = _unicode_encode('__test__', - encoding=_fs_encoding, errors='strict') + encoding=_encodings['fs'], errors='strict') svn_dirname = _unicode_encode('.svn', - encoding=_fs_encoding, errors='strict') + encoding=_encodings['fs'], errors='strict') suite = unittest.TestSuite() basedir = os.path.dirname(os.path.realpath(__file__)) testDirs = [] @@ -30,7 +30,7 @@ def main(): dirs.remove(svn_dirname) try: root = _unicode_decode(root, - encoding=_fs_encoding, errors='strict') + encoding=_encodings['fs'], errors='strict') except UnicodeDecodeError: continue diff --git a/pym/portage/tests/ebuild/test_spawn.py b/pym/portage/tests/ebuild/test_spawn.py index 908fce606..97a5f42d0 100644 --- a/pym/portage/tests/ebuild/test_spawn.py +++ b/pym/portage/tests/ebuild/test_spawn.py @@ -6,8 +6,7 @@ import codecs import errno import sys from portage import os -from portage import _content_encoding -from portage import _fs_encoding +from portage import _encodings from portage import _unicode_encode from portage.tests import TestCase @@ -34,8 +33,8 @@ class SpawnTestCase(TestCase): free=1, fd_pipes={0:sys.stdin.fileno(), 1:null_fd, 2:null_fd}) os.close(null_fd) f = codecs.open(_unicode_encode(logfile, - encoding=_fs_encoding, errors='strict'), - mode='r', encoding=_content_encoding, errors='strict') + encoding=_encodings['fs'], errors='strict'), + mode='r', encoding=_encodings['content'], errors='strict') log_content = f.read() f.close() # When logging passes through a pty, this comparison will fail diff --git a/pym/portage/update.py b/pym/portage/update.py index d38ddf942..ca67370cd 100644 --- a/pym/portage/update.py +++ b/pym/portage/update.py @@ -8,8 +8,7 @@ import re import sys from portage import os -from portage import _content_encoding -from portage import _fs_encoding +from portage import _encodings from portage import _unicode_decode from portage import _unicode_encode import portage @@ -72,8 +71,8 @@ def fixdbentries(update_iter, dbdir): for myfile in [f for f in os.listdir(dbdir) if f not in ignored_dbentries]: file_path = os.path.join(dbdir, myfile) mydata[myfile] = codecs.open(_unicode_encode(file_path, - encoding=_fs_encoding, errors='strict'), - mode='r', encoding=_content_encoding, + encoding=_encodings['fs'], errors='strict'), + mode='r', encoding=_encodings['repo.content'], errors='replace').read() updated_items = update_dbentries(update_iter, mydata) for myfile, mycontent in updated_items.iteritems(): @@ -110,8 +109,9 @@ def grab_updates(updpath, prev_mtimes=None): if file_path not in prev_mtimes or \ long(prev_mtimes[file_path]) != long(mystat.st_mtime): content = codecs.open(_unicode_encode(file_path, - encoding=_fs_encoding, errors='strict'), - mode='r', encoding=_content_encoding, errors='replace').read() + encoding=_encodings['fs'], errors='strict'), + mode='r', encoding=_encodings['repo.content'], errors='replace' + ).read() update_data.append((file_path, mystat, content)) return update_data @@ -172,7 +172,7 @@ def update_config_files(config_root, protect, protect_mask, update_iter): for y in dirs: try: y = _unicode_decode(y, - encoding=_fs_encoding, errors='strict') + encoding=_encodings['fs'], errors='strict') except UnicodeDecodeError: dirs.remove(y) continue @@ -181,7 +181,7 @@ def update_config_files(config_root, protect, protect_mask, update_iter): for y in files: try: y = _unicode_decode(y, - encoding=_fs_encoding, errors='strict') + encoding=_encodings['fs'], errors='strict') except UnicodeDecodeError: continue if y.startswith("."): @@ -195,8 +195,8 @@ def update_config_files(config_root, protect, protect_mask, update_iter): try: file_contents[x] = codecs.open( _unicode_encode(os.path.join(abs_user_config, x), - encoding=_fs_encoding, errors='strict'), - mode='r', encoding=_content_encoding, + encoding=_encodings['fs'], errors='strict'), + mode='r', encoding=_encodings['content'], errors='replace').readlines() except IOError: if file_contents.has_key(x): diff --git a/pym/portage/xpak.py b/pym/portage/xpak.py index da68af59c..5b08c0a3f 100644 --- a/pym/portage/xpak.py +++ b/pym/portage/xpak.py @@ -22,7 +22,7 @@ import shutil from portage import os from portage import normalize_path -from portage import _fs_encoding +from portage import _encodings from portage import _unicode_decode from portage import _unicode_encode @@ -30,23 +30,24 @@ def addtolist(mylist, curdir): """(list, dir) --- Takes an array(list) and appends all files from dir down the directory tree. Returns nothing. list is modified.""" curdir = normalize_path(_unicode_decode(curdir, - encoding=_fs_encoding, errors='strict')) + encoding=_encodings['fs'], errors='strict')) for parent, dirs, files in os.walk(curdir): parent = _unicode_decode(parent, - encoding=_fs_encoding, errors='strict') + encoding=_encodings['fs'], errors='strict') if parent != curdir: mylist.append(parent[len(curdir) + 1:] + os.sep) for x in dirs: try: - _unicode_decode(x, encoding=_fs_encoding, errors='strict') + _unicode_decode(x, encoding=_encodings['fs'], errors='strict') except UnicodeDecodeError: dirs.remove(x) for x in files: try: - x = _unicode_decode(x, encoding=_fs_encoding, errors='strict') + x = _unicode_decode(x, + encoding=_encodings['fs'], errors='strict') except UnicodeDecodeError: continue mylist.append(os.path.join(parent, x)[len(curdir) + 1:]) @@ -82,13 +83,13 @@ def xpak(rootdir,outfile=None): mylist.sort() mydata = {} for x in mylist: - x = _unicode_encode(x, encoding=_fs_encoding, errors='strict') + x = _unicode_encode(x, encoding=_encodings['fs'], errors='strict') mydata[x] = open(os.path.join(rootdir, x), 'rb').read() xpak_segment = xpak_mem(mydata) if outfile: outf = open(_unicode_encode(outfile, - encoding=_fs_encoding, errors='strict'), 'wb') + encoding=_encodings['fs'], errors='strict'), 'wb') outf.write(xpak_segment) outf.close() else: @@ -118,9 +119,9 @@ def xsplit(infile): 'infile.index' contains the index segment. 'infile.dat' contails the data segment.""" infile = _unicode_decode(infile, - encoding=_fs_encoding, errors='strict') + encoding=_encodings['fs'], errors='strict') myfile = open(_unicode_encode(infile, - encoding=_fs_encoding, errors='strict'), 'rb') + encoding=_encodings['fs'], errors='strict'), 'rb') mydat=myfile.read() myfile.close() @@ -129,11 +130,11 @@ def xsplit(infile): return False myfile = open(_unicode_encode(infile + '.index', - encoding=_fs_encoding, errors='strict'), 'wb') + encoding=_encodings['fs'], errors='strict'), 'wb') myfile.write(splits[0]) myfile.close() myfile = open(_unicode_encode(infile + '.dat', - encoding=_fs_encoding, errors='strict'), 'wb') + encoding=_encodings['fs'], errors='strict'), 'wb') myfile.write(splits[1]) myfile.close() return True @@ -149,7 +150,7 @@ def xsplit_mem(mydat): def getindex(infile): """(infile) -- grabs the index segment from the infile and returns it.""" myfile = open(_unicode_encode(infile, - encoding=_fs_encoding, errors='strict'), 'rb') + encoding=_encodings['fs'], errors='strict'), 'rb') myheader=myfile.read(16) if myheader[0:8] != _unicode_encode('XPAKPACK'): myfile.close() @@ -163,7 +164,7 @@ def getboth(infile): """(infile) -- grabs the index and data segments from the infile. Returns an array [indexSegment,dataSegment]""" myfile = open(_unicode_encode(infile, - encoding=_fs_encoding, errors='strict'), 'rb') + encoding=_encodings['fs'], errors='strict'), 'rb') myheader=myfile.read(16) if myheader[0:8] != _unicode_encode('XPAKPACK'): myfile.close() @@ -238,7 +239,7 @@ def xpand(myid,mydest): if not os.path.exists(dirname): os.makedirs(dirname) mydat = open(_unicode_encode(myname, - encoding=_fs_encoding, errors='strict'), 'wb') + encoding=_encodings['fs'], errors='strict'), 'wb') mydat.write(mydata[datapos:datapos+datalen]) mydat.close() startpos=startpos+namelen+12 @@ -284,7 +285,7 @@ class tbz2(object): def recompose_mem(self, xpdata): self.scan() # Don't care about condition... We'll rewrite the data anyway. myfile = open(_unicode_encode(self.file, - encoding=_fs_encoding, errors='strict'), 'ab+') + encoding=_encodings['fs'], errors='strict'), 'ab+') if not myfile: raise IOError myfile.seek(-self.xpaksize,2) # 0,2 or -0,2 just mean EOF. @@ -322,7 +323,7 @@ class tbz2(object): return 1 self.filestat=mystat a = open(_unicode_encode(self.file, - encoding=_fs_encoding, errors='strict'), 'rb') + encoding=_encodings['fs'], errors='strict'), 'rb') a.seek(-16,2) trailer=a.read() self.infosize=0 @@ -366,7 +367,7 @@ class tbz2(object): if not myresult: return mydefault a = open(_unicode_encode(self.file, - encoding=_fs_encoding, errors='strict'), 'rb') + encoding=_encodings['fs'], errors='strict'), 'rb') a.seek(self.datapos+myresult[0],0) myreturn=a.read(myresult[1]) a.close() @@ -391,7 +392,7 @@ class tbz2(object): os.chdir("/") origdir="/" a = open(_unicode_encode(self.file, - encoding=_fs_encoding, errors='strict'), 'rb') + encoding=_encodings['fs'], errors='strict'), 'rb') if not os.path.exists(mydest): os.makedirs(mydest) os.chdir(mydest) @@ -406,7 +407,7 @@ class tbz2(object): if not os.path.exists(dirname): os.makedirs(dirname) mydat = open(_unicode_encode(myname, - encoding=_fs_encoding, errors='strict'), 'wb') + encoding=_encodings['fs'], errors='strict'), 'wb') a.seek(self.datapos+datapos) mydat.write(a.read(datalen)) mydat.close() @@ -420,7 +421,7 @@ class tbz2(object): if not self.scan(): return 0 a = open(_unicode_encode(self.file, - encoding=_fs_encoding, errors='strict'), 'rb') + encoding=_encodings['fs'], errors='strict'), 'rb') mydata = {} startpos=0 while ((startpos+8)<self.indexsize): @@ -440,7 +441,7 @@ class tbz2(object): return None a = open(_unicode_encode(self.file, - encoding=_fs_encoding, errors='strict'), 'rb') + encoding=_encodings['fs'], errors='strict'), 'rb') a.seek(self.datapos) mydata =a.read(self.datasize) a.close() |