Public Member Functions | Static Public Attributes | Private Member Functions | Private Attributes | List of all members
ECLAPI.ECLConnection Class Reference

Public Member Functions

def __init__ (self, url, username=None, password=None, xml_user=True)
 
def post (self, entry)
 
def close (self)
 
def list (self, category=None, form=None, tag=None, limit=None, after=None, substring=None, text=None)
 
def get (self, eid)
 

Static Public Attributes

string SignatureMethod = "md5"
 

Private Member Functions

def _make_salt (self)
 
def _signature (self, method, args, body)
 
def _add_signature (self, req, args, body)
 

Private Attributes

 _url
 
 _username
 
 _password
 

Detailed Description

Definition at line 47 of file ECLAPI.py.

Constructor & Destructor Documentation

def ECLAPI.ECLConnection.__init__ (   self,
  url,
  username = None,
  password = None,
  xml_user = True 
)
 

Definition at line 51 of file ECLAPI.py.

51  def __init__(self, url, username=None, password=None, xml_user=True):
52  '''
53  '''
54  self._url = url
55  self._username = username
56  self._password = password
57 
58 
def __init__(self, url, username=None, password=None, xml_user=True)
Definition: ECLAPI.py:51

Member Function Documentation

def ECLAPI.ECLConnection._add_signature (   self,
  req,
  args,
  body 
)
private

Definition at line 80 of file ECLAPI.py.

80  def _add_signature(self, req, args, body):
81  if self._username:
82  req.add_header("X-Signature-Method", self.SignatureMethod)
83  req.add_header("X-User", self._username)
84  req.add_header("X-Signature",
85  self._signature(self.SignatureMethod, args, body))
86 
def _add_signature(self, req, args, body)
Definition: ECLAPI.py:80
def _signature(self, method, args, body)
Definition: ECLAPI.py:65
string SignatureMethod
Definition: ECLAPI.py:49
def ECLAPI.ECLConnection._make_salt (   self)
private

Definition at line 59 of file ECLAPI.py.

59  def _make_salt(self):
60  m = hashlib.new('md5')
61  m.update("%s" % (random.randint(1,1234567890),))
62  return m.hexdigest()
63 
64 
def _make_salt(self)
Definition: ECLAPI.py:59
def ECLAPI.ECLConnection._signature (   self,
  method,
  args,
  body 
)
private

Definition at line 65 of file ECLAPI.py.

65  def _signature(self, method, args, body):
66  text = '%s:%s:%s' % (args, self._password, body)
67  h = None
68  if method == 'sha1':
69  h = hashlib.sha1()
70  elif method == 'md5':
71  h = hashlib.md5()
72  elif method == 'sha512':
73  h = hashlib.sha512()
74  if h == None:
75  return None
76  h.update(text)
77  return h.hexdigest()
78 
79 
def _signature(self, method, args, body)
Definition: ECLAPI.py:65
def ECLAPI.ECLConnection.close (   self)

Definition at line 112 of file ECLAPI.py.

112  def close(self):
113  pass
114 
def close(self)
Definition: ECLAPI.py:112
def ECLAPI.ECLConnection.get (   self,
  eid 
)

Definition at line 153 of file ECLAPI.py.

153  def get(self, eid):
154  args = ['e=%s' % (eid,), 'salt=%s' % (self._make_salt(),)]
155  url = self._url + '/E/xml_get'
156  args = '&'.join(args)
157  if args:
158  url += '?' + args
159  req = urllib2.Request(url=url)
160  self._add_signature(req, args, '')
161  response = urllib2.urlopen(req)
162  return response.read()
163 
164 
165 
def get(self, eid)
Definition: ECLAPI.py:153
def _add_signature(self, req, args, body)
Definition: ECLAPI.py:80
def _make_salt(self)
Definition: ECLAPI.py:59
def ECLAPI.ECLConnection.list (   self,
  category = None,
  form = None,
  tag = None,
  limit = None,
  after = None,
  substring = None,
  text = None 
)

Definition at line 116 of file ECLAPI.py.

116  limit=None, after=None, substring=None, text=None):
117  args = ['o=ids', 'salt=%s' % (self._make_salt(),)]
118  if category:
119  args.append('c=%s' % (urllib.quote_plus(category,)))
120  if form:
121  args.append('f=%s' % (urllib.quote_plus(form,)))
122  if after:
123  if type(after) != type(''):
124  after = after.strptime('%Y-%m-%d %H:%M:%S')
125  args.append('a=%s' % (urllib.quote_plus(after),))
126  if tag:
127  args.append('t=%s' % (tag,))
128  if limit:
129  args.append('l=%s' % (limit,))
130  if substring:
131  args.append('st=%s' % (urllib.quote_plus(substring),))
132  if text:
133  args.append('si=%s' % (urllib.quote_plus(text),))
134 
135  url = self._url + '/E/xml_search'
136  args = '&'.join(args)
137 
138  if args:
139  url += '?' + args
140  req = urllib2.Request(url=url)
141  self._add_signature(req, args, '')
142  #print 'Signature: '+ self.calculate_signature(self._password + ":" + params,
143  # self.SignatureMethod)
144 
145  try:
146  response = urllib2.urlopen(req)
147  except HTTPError, error:
148  raise ECLHTTPError(error.code, error.msg, error.fp.read())
149  tree = etree.parse(response)
150  entries = tree.findall('entry')
151  return [int(e.attrib.get('id')) for e in entries]
152 
def _add_signature(self, req, args, body)
Definition: ECLAPI.py:80
def _make_salt(self)
Definition: ECLAPI.py:59
def ECLAPI.ECLConnection.post (   self,
  entry 
)
 

Definition at line 87 of file ECLAPI.py.

87  def post(self, entry):
88  '''
89  '''
90  if self._username:
91  entry.setAuthor(self._username)
92  params = entry.xshow().strip()
93  args = "salt=%s" % (self._make_salt(),)
94  req = urllib2.Request(url=self._url + '/E/xml_post' +
95  '?' + args, data=params)
96  #print 'Signature: '+ self.calculate_signature(self._password + ":" + params,
97  # self.SignatureMethod)
98  req.add_header("Content-type", "text/xml")
99  if self._url.startswith("https:"):
100  req.add_header("X-Password", self._password)
101  self._add_signature(req, args, params)
102  try:
103  response = urllib2.urlopen(req)
104  except HTTPError, err:
105  return err.code, err.msg, err.fp.read()
106 
107  data = response.read()
108 
109  #print data # DEBUG
110  return response.code, response.msg, data
111 
def post(self, entry)
Definition: ECLAPI.py:87
def _add_signature(self, req, args, body)
Definition: ECLAPI.py:80
def _make_salt(self)
Definition: ECLAPI.py:59

Member Data Documentation

ECLAPI.ECLConnection._password
private

Definition at line 56 of file ECLAPI.py.

ECLAPI.ECLConnection._url
private

Definition at line 54 of file ECLAPI.py.

ECLAPI.ECLConnection._username
private

Definition at line 55 of file ECLAPI.py.

string ECLAPI.ECLConnection.SignatureMethod = "md5"
static

Definition at line 49 of file ECLAPI.py.


The documentation for this class was generated from the following file: