def chown(self, tarinfo, targetpath):
if pwd and hasattr(os, "<STR_LIT>") and os.geteuid() == <NUM_LIT:0>:<EOL><INDENT>try:<EOL><INDENT>g = grp.getgrnam(tarinfo.gname)[<NUM_LIT:2>]<EOL><DEDENT>except KeyError:<EOL><INDENT>g = tarinfo.gid<EOL><DEDENT>try:<EOL><INDENT>u = pwd.getpwnam(tarinfo.uname)[<NUM_LIT:2>]<EOL><DEDENT>except KeyError:<EOL><INDENT>u = tarinfo.uid<EOL><DEDENT>try:<EOL><INDENT>if tarinfo.issym() and hasattr(os, "<STR_LIT>"):<EOL><INDENT>os.lchown(targetpath, u, g)<EOL><DEDENT>else:<EOL><INDENT>if sys.platform != "<STR_LIT>":<EOL><INDENT>os.chown(targetpath, u, g)<EOL><DEDENT><DEDENT><DEDENT>except EnvironmentError as e:<EOL><INDENT>raise ExtractError("<STR_LIT>")<EOL><DEDENT><DEDENT>
Set owner of targetpath according to tarinfo.