Skip to content

get_contents_entry() and get_contents_dir() returning 'str' instead of 'bytes' #3737

Open
@eugenhu

Description

@eugenhu

I'm not sure if this is accidental but get_contents_entry() and get_contents_dir() are returning strs (line 209, 219):

def get_contents_entry(node):
"""Fetch the contents of the entry. Returns the exact binary
contents of the file."""
try:
node = node.disambiguate(must_exist=1)
except SCons.Errors.UserError:
# There was nothing on disk with which to disambiguate
# this entry. Leave it as an Entry, but return a null
# string so calls to get_contents() in emitters and the
# like (e.g. in qt.py) don't have to disambiguate by hand
# or catch the exception.
return ''
else:
return _get_contents_map[node._func_get_contents](node)
def get_contents_dir(node):
"""Return content signatures and names of all our children
separated by new-lines. Ensure that the nodes are sorted."""
contents = []
for n in sorted(node.children(), key=lambda t: t.name):
contents.append('%s %s\n' % (n.get_csig(), n.name))
return ''.join(contents)

I ran into this when trying to debug this SConstruct,

v = Value('x')
e = Entry('something')
v.add_dependency([e])

v.get_contents()

which was producing the output,

AttributeError: 'str' object has no attribute 'decode':
  File ".../SConstruct", line 5:
    v.get_contents()
  File ".../SCons/Node/Python.py", line 155:
    text_contents = self.get_text_contents()
  File ".../SCons/Node/Python.py", line 147:
    contents = contents + kid.get_contents().decode()

I think this is because Value.get_text_contents() is expecting kid.get_contents() to be of type bytes.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions