def merge_cookies(cookiejar, cookies):
if not isinstance(cookiejar, cookielib.CookieJar):<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>if isinstance(cookies, dict):<EOL><INDENT>cookiejar = cookiejar_from_dict(<EOL>cookies, cookiejar=cookiejar, overwrite=False)<EOL><DEDENT>elif isinstance(cookies, cookielib.CookieJar):<EOL><INDENT>try:<EOL><INDENT>cookiejar.update(cookies)<EOL><DEDENT>except AttributeError:<EOL><INDENT>for cookie_in_jar in cookies:<EOL><INDENT>cookiejar.set_cookie(cookie_in_jar)<EOL><DEDENT><DEDENT><DEDENT>return cookiejar<EOL>
Add cookies to cookiejar and returns a merged CookieJar.

    :param cookiejar: CookieJar object to add the cookies to.
    :param cookies: Dictionary or CookieJar object to be added.