@classmethod<EOL><INDENT>def update(cls, content, dependency, version, spec="<STR_LIT>", hashes=()):<DEDENT>
new_line = "<STR_LIT>".format(name=dependency.full_name, spec=spec, version=version)<EOL>appendix = '<STR_LIT>'<EOL>if "<STR_LIT:;>" in dependency.line:<EOL><INDENT>new_line += "<STR_LIT:;>" + dependency.line.splitlines()[<NUM_LIT:0>].split("<STR_LIT:;>", <NUM_LIT:1>)[<NUM_LIT:1>].split("<STR_LIT:#>")[<NUM_LIT:0>].split("<STR_LIT>")[<NUM_LIT:0>].rstrip()<EOL><DEDENT>if "<STR_LIT:#>" in dependency.line:<EOL><INDENT>parts = dependency.line.split("<STR_LIT:#>")<EOL>requirement, comment = parts[<NUM_LIT:0>], "<STR_LIT:#>".join(parts[<NUM_LIT:1>:])<EOL>whitespaces = (hex(ord('<STR_LIT:\t>')), hex(ord('<STR_LIT:U+0020>')))<EOL>trailing_whitespace = '<STR_LIT>'<EOL>for c in requirement[::-<NUM_LIT:1>]:<EOL><INDENT>if hex(ord(c)) in whitespaces:<EOL><INDENT>trailing_whitespace += c<EOL><DEDENT>else:<EOL><INDENT>break<EOL><DEDENT><DEDENT>appendix += trailing_whitespace + "<STR_LIT:#>" + comment<EOL><DEDENT>if dependency.hashes and not new_line.endswith("<STR_LIT:\\>"):<EOL><INDENT>new_line += "<STR_LIT>"<EOL><DEDENT>if hashes:<EOL><INDENT>for n, new_hash in enumerate(hashes):<EOL><INDENT>new_line += "<STR_LIT>".format(<EOL>method=new_hash['<STR_LIT>'],<EOL>hash=new_hash['<STR_LIT>']<EOL>)<EOL>if len(hashes) > n + <NUM_LIT:1>:<EOL><INDENT>new_line += "<STR_LIT>"<EOL><DEDENT><DEDENT><DEDENT>new_line += appendix<EOL>regex = cls.SUB_REGEX.format(re.escape(dependency.line))<EOL>return re.sub(regex, new_line, content, flags=re.MULTILINE)<EOL>
Updates the requirement to the latest version for the given content and adds hashes
if neccessary.
:param content: str, content
:return: str, updated content