
import urllib

__version__ = '0.0~20090901.1'
__user_agent__ = 'EpiDBClient v%s/python' % __version__

class EpiDBClientOpener(urllib.FancyURLopener):
	version = __user_agent__

class EpiDBClient:

	version = __version__
	user_agent = __user_agent__

	server = 'https://egg.science.uva.nl:7443'
	path_survey = '/survey/'

	def __init__(self, api_key=None):
		self.api_key = api_key

	def __epidb_call(self, url, param):
		data = urllib.urlencode(param)
		opener = EpiDBClientOpener()
		sock = opener.open(url, data)
		res = sock.read()
		sock.close()

		return res
	
	def survey_submit(self, data):
		param = {
			'data': data
		}

		url = self.server + self.path_survey
		res = self.__epidb_call(url, param)

		return res



import urllib
import urllib2

__version__ = '0.0~20090901.1'
__user_agent__ = 'EpiDBClient v%s/python' % __version__

class EpiDBClient:

	version = __version__
	user_agent = __user_agent__

	server = 'https://egg.science.uva.nl:7443'
	path_survey = '/survey/'

	def __init__(self, api_key=None):
		self.api_key = api_key

	def __epidb_call(self, url, param):
		data = urllib.urlencode(param)

		req = urllib2.Request(url)
		req.add_header('User-Agent', self.user_agent)
		if self.api_key:
			req.add_header('Cookie', 'epidb-apikey=%s' % self.api_key)
		sock = urllib2.urlopen(req, data)
		res = sock.read()
		sock.close()

		return res
	
	def survey_submit(self, data):
		param = {
			'data': data
		}

		url = self.server + self.path_survey
		res = self.__epidb_call(url, param)

		return res


Send api-key through HTTP cookie.
[python] Send api-key through HTTP cookie.

  
  import urllib
+ import urllib2
  
  __version__ = '0.0~20090901.1'
  __user_agent__ = 'EpiDBClient v%s/python' % __version__
- 
- class EpiDBClientOpener(urllib.FancyURLopener):
- 	version = __user_agent__
  
  class EpiDBClient:
  
  	version = __version__
  	user_agent = __user_agent__
  
  	server = 'https://egg.science.uva.nl:7443'
  	path_survey = '/survey/'
  
  	def __init__(self, api_key=None):
  		self.api_key = api_key
  
  	def __epidb_call(self, url, param):
  		data = urllib.urlencode(param)
- 		opener = EpiDBClientOpener()
- 		sock = opener.open(url, data)
+ 
+ 		req = urllib2.Request(url)
+ 		req.add_header('User-Agent', self.user_agent)
+ 		if self.api_key:
+ 			req.add_header('Cookie', 'epidb-apikey=%s' % self.api_key)
+ 		sock = urllib2.urlopen(req, data)
  		res = sock.read()
  		sock.close()
  
  		return res
  	
  	def survey_submit(self, data):
  		param = {
  			'data': data
  		}
  
  		url = self.server + self.path_survey
  		res = self.__epidb_call(url, param)
  
  		return res
  
  
Send api-key through HTTP cookie.
## Code Before:

import urllib

__version__ = '0.0~20090901.1'
__user_agent__ = 'EpiDBClient v%s/python' % __version__

class EpiDBClientOpener(urllib.FancyURLopener):
	version = __user_agent__

class EpiDBClient:

	version = __version__
	user_agent = __user_agent__

	server = 'https://egg.science.uva.nl:7443'
	path_survey = '/survey/'

	def __init__(self, api_key=None):
		self.api_key = api_key

	def __epidb_call(self, url, param):
		data = urllib.urlencode(param)
		opener = EpiDBClientOpener()
		sock = opener.open(url, data)
		res = sock.read()
		sock.close()

		return res
	
	def survey_submit(self, data):
		param = {
			'data': data
		}

		url = self.server + self.path_survey
		res = self.__epidb_call(url, param)

		return res


## Instruction:
Send api-key through HTTP cookie.
## Code After:

import urllib
import urllib2

__version__ = '0.0~20090901.1'
__user_agent__ = 'EpiDBClient v%s/python' % __version__

class EpiDBClient:

	version = __version__
	user_agent = __user_agent__

	server = 'https://egg.science.uva.nl:7443'
	path_survey = '/survey/'

	def __init__(self, api_key=None):
		self.api_key = api_key

	def __epidb_call(self, url, param):
		data = urllib.urlencode(param)

		req = urllib2.Request(url)
		req.add_header('User-Agent', self.user_agent)
		if self.api_key:
			req.add_header('Cookie', 'epidb-apikey=%s' % self.api_key)
		sock = urllib2.urlopen(req, data)
		res = sock.read()
		sock.close()

		return res
	
	def survey_submit(self, data):
		param = {
			'data': data
		}

		url = self.server + self.path_survey
		res = self.__epidb_call(url, param)

		return res

