1. Bożydar Sobczak
  2. PyTaus

Commits

bozy  committed 25ff7c7

formatting

  • Participants
  • Parent commits c990648
  • Branches default

Comments (0)

Files changed (1)

File src/pytaus.py

View file
  • Ignore whitespace
+# -*- coding: utf-8 -*-
 
 try:
     import json
         self.data = data
 
 class Taus:
-
     URL = "http://www.tausdata.org/api/"
     POST = 1
     GET = 2
 
     def __init__(self):
-
         self.conn = pycurl.Curl()
         self.json_decoder = json.JSONDecoder()
 
     def authenticate(self, login, password):
-
         self.auth_key = None
         self.conn.setopt(pycurl.USERPWD, "%s:%s" % (login, password))
         self._perform_action(Taus.POST, 'auth_key', {'action': 'login'}, self._on_receive_authentication)
         self._temp_data += data  
         
     def set_lang(self, source_lang, target_lang):
-
         self.source_lang = source_lang
         self.target_lang = target_lang
 
     def segment(self, q):
-
         action = {
             'q': q,
             'action': 'segment',
             'source_lang': self.source_lang,
             'target_lang': self.target_lang}
         self._perform_action(Taus.GET, 'segment', action, self._on_receive_segment)
-
         return self._parse_result(self._temp_data, allowed_codes = [200])
 
     def _on_receive_segment(self, data):
         self._temp_data += data        
 
     def _parse_result(self, data, allowed_codes = [200]):
-
         decoded = self.json_decoder.decode(data)
         if allowed_codes.count(decoded["status"]) == 0:
             raise TausException(decoded)
         return decoded
 
     def _perform_action(self, method, action, params, write_function):
-
         self._temp_data = ''
         action += '.json'
         if self.auth_key: