Commits

Branko Vukelic  committed 51d57ed

Working raw argument

  • Participants
  • Parent commits 3028939
  • Branches lang_attr

Comments (0)

Files changed (5)

File mstranslator/client.py

         if data:
             request.add_data(data)
 
+        response = urlopen(request)
+
+        if endpoint.raw:
+            return response
+
         return endpoint.process_response(urlopen(request))
 
     # api calls

File mstranslator/endpoints/base.py

     api_type = 'HTTP.svc'
     params = {}
     data = None
+    raw = False
 
     def convert_args(self, args):
         pass
 
     def convert_kwargs(self, kwargs):
+        if 'raw' in kwargs:
+            self.raw = kwargs['raw']
+            del kwargs['raw']
+
         if 'self' in kwargs:
             del kwargs['self']
+
         if 'tfrom' in kwargs:
             kwargs['from'] = kwargs['tfrom']
             del kwargs['tfrom']

File mstranslator/endpoints/translate.py

 from base import GetEndpoint, CONTENT, LANGUAGE_CODES
+from mstranslator.tstring import TString
 
 class TranslateEndpoint(GetEndpoint):
     endpoint = 'Translate'
 
-    def __init__(self, text, to, tfrom=''):
+    lang = None
 
+    def __init__(self, text, to, tfrom='', raw=False):
         if tfrom and tfrom not in LANGUAGE_CODES or to not in LANGUAGE_CODES:
             raise ValueError('Invalid language codes')
 
+        self.lang = to
+
         self.convert_kwargs(locals())
 
     def process_response(self, resp):
         root = self.parse_xml(resp)
-        return root.text
+        s = TString(root.text)
+        return s

File mstranslator/tstring.py

+from endpoints.base import LANGUAGE_CODES
+
+class TString(unicode):
+    """Unicode string with lang attribute"""
+    lang = None
+
+    def __setattr__(self, name, v):
+        if name != 'lang' and v not in LANGUAGE_CODES:
+            raise ValueError('%s is not a valid language' % v)
+
+        super(TString, self).__setattr__(name, v)
     name='pymstranslator',
     description='Python module for interfacing with Microsoft(r) Translator',
     long_description=open('README.rst').read(),
-    version='0.0.3',
+    version='0.0.4',
     packages=['mstranslator', 'mstranslator/endpoints'],
     author='Monwara LLC',
     author_email='branko@monwara.com',