#!/usr/bin/env python# -*- coding: utf-8 -*-## This file is part of the `pypath` python module## Copyright 2014-2023# EMBL, EMBL-EBI, Uniklinik RWTH Aachen, Heidelberg University## Authors: see the file `README.rst`# Contact: Dénes Türei (turei.denes@gmail.com)## Distributed under the GPLv3 License.# See accompanying file LICENSE.txt or copy at# https://www.gnu.org/licenses/gpl-3.0.html## Website: https://pypath.omnipathdb.org/#importpypath.resources.urlsasurlsimportpypath.share.curlascurlimportpypath.inputs.mitabasmitabimportpypath.share.cacheas_cache
[docs]defdip_login(user,passwd):""" This does not work for unknown reasons. In addition, the binary_data parameter of Curl().__init__() has been changed, below updates are necessary. """bdr='---------------------------8945224391427558067125853467'useragent='Mozilla/5.0 (X11; U; Linux i686; en-US; rv:43.0) '\
'Gecko/20110304 Firefox/43.0'loginfname=os.path.join(_cache.get_cachedir(),'dip.logindata.tmp')url=urls.urls['dip']['login']req_hdrs=['User-Agent: %s'%useragent]c=curl.Curl(url,cache=False,write_cache=False,req_headers=req_hdrs,return_headers=True,debug=True)res=c.resulthdr=c.resp_headerscookie=hdr['set-cookie'].split(';')[0]cookie2='%s%u'%(cookie[:-1],int(cookie[-1])+1)othercookie='DIPID=11133%3A'req_hdrs=['Content-type: multipart/form-data; ''boundary = %s'%bdr,'Cookie: %s'%cookie2,'Referer: %s'%url,'User-Agent: %s'%useragent,'Connection: keep-alive',]post={'lgn':'1','login':user,'pass':passwd,'Login':'Login'}login='--%s\r\n\r\nContent-Disposition: form-data; name = "lgn"\r\n\r\n1'\
'\r\n--%s\r\n\r\nContent-Disposition: form-data; name = "login"\r\n\r\n'\
'%s\r\n--%s\r\n\r\nContent-Disposition: form-data; name = "pass"\r\n\r'\
'\n%s\r\n--%s\r\n\r\nContent-Disposition: form-data; name = "Login"\r\n'\
'\r\nLogin\r\n%s--\r\n'%(bdr,bdr,user,bdr,passwd,bdr,bdr)# login = login.replace('\r', '')withcodecs.open(loginfname,encoding='ISO-8859-1',mode='w')asf:f.write(login)c=curl.Curl(url,cache=False,write_cache=False,follow=True,req_headers=req_hdrs,timeout=10,binary_data=loginfname,return_headers=True,debug=True)res=c.resulthdr=c.resp_headersreturnres,hdr