Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 430488
Collapse All | Expand All

(-)a/pym/portage/__init__.py (+4 lines)
Lines 181-186 if sys.hexversion >= 0x3000000: Link Here
181
		if isinstance(s, bytes):
181
		if isinstance(s, bytes):
182
			s = str(s, encoding=encoding, errors=errors)
182
			s = str(s, encoding=encoding, errors=errors)
183
		return s
183
		return s
184
185
	_native_string = _unicode_decode
184
else:
186
else:
185
	def _unicode_encode(s, encoding=_encodings['content'], errors='backslashreplace'):
187
	def _unicode_encode(s, encoding=_encodings['content'], errors='backslashreplace'):
186
		if isinstance(s, unicode):
188
		if isinstance(s, unicode):
Lines 192-197 else: Link Here
192
			s = unicode(s, encoding=encoding, errors=errors)
194
			s = unicode(s, encoding=encoding, errors=errors)
193
		return s
195
		return s
194
196
197
	_native_string = _unicode_encode
198
195
class _unicode_func_wrapper(object):
199
class _unicode_func_wrapper(object):
196
	"""
200
	"""
197
	Wraps a function, converts arguments from unicode to bytes,
201
	Wraps a function, converts arguments from unicode to bytes,
(-)a/pym/portage/_selinux.py (-27 / +26 lines)
Lines 1-4 Link Here
1
# Copyright 1999-2011 Gentoo Foundation
1
# Copyright 1999-2013 Gentoo Foundation
2
# Distributed under the terms of the GNU General Public License v2
2
# Distributed under the terms of the GNU General Public License v2
3
3
4
# Don't use the unicode-wrapped os and shutil modules here since
4
# Don't use the unicode-wrapped os and shutil modules here since
Lines 8-25 import shutil Link Here
8
8
9
import portage
9
import portage
10
from portage import _encodings
10
from portage import _encodings
11
from portage import _unicode_decode
11
from portage import _native_string, _unicode_decode
12
from portage import _unicode_encode
13
from portage.localization import _
12
from portage.localization import _
14
portage.proxy.lazyimport.lazyimport(globals(),
13
portage.proxy.lazyimport.lazyimport(globals(),
15
	'selinux')
14
	'selinux')
16
15
17
def copyfile(src, dest):
16
def copyfile(src, dest):
18
	src = _unicode_encode(src, encoding=_encodings['fs'], errors='strict')
17
	src = _native_string(src, encoding=_encodings['fs'], errors='strict')
19
	dest = _unicode_encode(dest, encoding=_encodings['fs'], errors='strict')
18
	dest = _native_string(dest, encoding=_encodings['fs'], errors='strict')
20
	(rc, ctx) = selinux.lgetfilecon(src)
19
	(rc, ctx) = selinux.lgetfilecon(src)
21
	if rc < 0:
20
	if rc < 0:
22
		src = _unicode_decode(src, encoding=_encodings['fs'], errors='replace')
21
		if sys.hexversion < 0x3000000:
22
			src = _unicode_decode(src, encoding=_encodings['fs'], errors='replace')
23
		raise OSError(_("copyfile: Failed getting context of \"%s\".") % src)
23
		raise OSError(_("copyfile: Failed getting context of \"%s\".") % src)
24
24
25
	setfscreate(ctx)
25
	setfscreate(ctx)
Lines 39-50 def is_selinux_enabled(): Link Here
39
	return selinux.is_selinux_enabled()
39
	return selinux.is_selinux_enabled()
40
40
41
def mkdir(target, refdir):
41
def mkdir(target, refdir):
42
	target = _unicode_encode(target, encoding=_encodings['fs'], errors='strict')
42
	target = _native_string(target, encoding=_encodings['fs'], errors='strict')
43
	refdir = _unicode_encode(refdir, encoding=_encodings['fs'], errors='strict')
43
	refdir = _native_string(refdir, encoding=_encodings['fs'], errors='strict')
44
	(rc, ctx) = selinux.getfilecon(refdir)
44
	(rc, ctx) = selinux.getfilecon(refdir)
45
	if rc < 0:
45
	if rc < 0:
46
		refdir = _unicode_decode(refdir, encoding=_encodings['fs'],
46
		if sys.hexversion < 0x3000000:
47
			errors='replace')
47
			refdir = _unicode_decode(refdir, encoding=_encodings['fs'], errors='replace')
48
		raise OSError(
48
		raise OSError(
49
			_("mkdir: Failed getting context of reference directory \"%s\".") \
49
			_("mkdir: Failed getting context of reference directory \"%s\".") \
50
			% refdir)
50
			% refdir)
Lines 56-66 def mkdir(target, refdir): Link Here
56
		setfscreate()
56
		setfscreate()
57
57
58
def rename(src, dest):
58
def rename(src, dest):
59
	src = _unicode_encode(src, encoding=_encodings['fs'], errors='strict')
59
	src = _native_string(src, encoding=_encodings['fs'], errors='strict')
60
	dest = _unicode_encode(dest, encoding=_encodings['fs'], errors='strict')
60
	dest = _native_string(dest, encoding=_encodings['fs'], errors='strict')
61
	(rc, ctx) = selinux.lgetfilecon(src)
61
	(rc, ctx) = selinux.lgetfilecon(src)
62
	if rc < 0:
62
	if rc < 0:
63
		src = _unicode_decode(src, encoding=_encodings['fs'], errors='replace')
63
		if sys.hexversion < 0x3000000:
64
			src = _unicode_decode(src, encoding=_encodings['fs'], errors='replace')
64
		raise OSError(_("rename: Failed getting context of \"%s\".") % src)
65
		raise OSError(_("rename: Failed getting context of \"%s\".") % src)
65
66
66
	setfscreate(ctx)
67
	setfscreate(ctx)
Lines 75-84 def settype(newtype): Link Here
75
	return ":".join(ret)
76
	return ":".join(ret)
76
77
77
def setexec(ctx="\n"):
78
def setexec(ctx="\n"):
78
	ctx = _unicode_encode(ctx, encoding=_encodings['content'], errors='strict')
79
	ctx = _native_string(ctx, encoding=_encodings['content'], errors='strict')
79
	if selinux.setexeccon(ctx) < 0:
80
	if selinux.setexeccon(ctx) < 0:
80
		ctx = _unicode_decode(ctx, encoding=_encodings['content'],
81
		if sys.hexversion < 0x3000000:
81
			errors='replace')
82
			ctx = _unicode_decode(ctx, encoding=_encodings['content'], errors='replace')
82
		if selinux.security_getenforce() == 1:
83
		if selinux.security_getenforce() == 1:
83
			raise OSError(_("Failed setting exec() context \"%s\".") % ctx)
84
			raise OSError(_("Failed setting exec() context \"%s\".") % ctx)
84
		else:
85
		else:
Lines 87-97 def setexec(ctx="\n"): Link Here
87
				noiselevel=-1)
88
				noiselevel=-1)
88
89
89
def setfscreate(ctx="\n"):
90
def setfscreate(ctx="\n"):
90
	ctx = _unicode_encode(ctx,
91
	ctx = _native_string(ctx, encoding=_encodings['content'], errors='strict')
91
		encoding=_encodings['content'], errors='strict')
92
	if selinux.setfscreatecon(ctx) < 0:
92
	if selinux.setfscreatecon(ctx) < 0:
93
		ctx = _unicode_decode(ctx,
93
		if sys.hexversion < 0x3000000:
94
			encoding=_encodings['content'], errors='replace')
94
			ctx = _unicode_decode(ctx, encoding=_encodings['content'], errors='replace')
95
		raise OSError(
95
		raise OSError(
96
			_("setfscreate: Failed setting fs create context \"%s\".") % ctx)
96
			_("setfscreate: Failed setting fs create context \"%s\".") % ctx)
97
97
Lines 106-113 class spawn_wrapper(object): Link Here
106
106
107
	def __init__(self, spawn_func, selinux_type):
107
	def __init__(self, spawn_func, selinux_type):
108
		self._spawn_func = spawn_func
108
		self._spawn_func = spawn_func
109
		selinux_type = _unicode_encode(selinux_type,
109
		selinux_type = _native_string(selinux_type, encoding=_encodings['content'], errors='strict')
110
			encoding=_encodings['content'], errors='strict')
111
		self._con = settype(selinux_type)
110
		self._con = settype(selinux_type)
112
111
113
	def __call__(self, *args, **kwargs):
112
	def __call__(self, *args, **kwargs):
Lines 123-135 class spawn_wrapper(object): Link Here
123
		return self._spawn_func(*args, **kwargs)
122
		return self._spawn_func(*args, **kwargs)
124
123
125
def symlink(target, link, reflnk):
124
def symlink(target, link, reflnk):
126
	target = _unicode_encode(target, encoding=_encodings['fs'], errors='strict')
125
	target = _native_string(target, encoding=_encodings['fs'], errors='strict')
127
	link = _unicode_encode(link, encoding=_encodings['fs'], errors='strict')
126
	link = _native_string(link, encoding=_encodings['fs'], errors='strict')
128
	reflnk = _unicode_encode(reflnk, encoding=_encodings['fs'], errors='strict')
127
	reflnk = _native_string(reflnk, encoding=_encodings['fs'], errors='strict')
129
	(rc, ctx) = selinux.lgetfilecon(reflnk)
128
	(rc, ctx) = selinux.lgetfilecon(reflnk)
130
	if rc < 0:
129
	if rc < 0:
131
		reflnk = _unicode_decode(reflnk, encoding=_encodings['fs'],
130
		if sys.hexversion < 0x3000000:
132
			errors='replace')
131
			reflnk = _unicode_decode(reflnk, encoding=_encodings['fs'], errors='replace')
133
		raise OSError(
132
		raise OSError(
134
			_("symlink: Failed getting context of reference symlink \"%s\".") \
133
			_("symlink: Failed getting context of reference symlink \"%s\".") \
135
			% reflnk)
134
			% reflnk)

Return to bug 430488