Permalink
Browse files

Removed microsofttranslator as a shipped dependency, now that Python3…

… support has landed upstream
  • Loading branch information...
1 parent e963ca6 commit 6c638bcc3f16fc7540ca007fc3367b1f049ae1aa @mbi committed Jun 2, 2014
View
@@ -4,6 +4,7 @@ Version 0.7.5
* Fixed a test
* Added support for excluding certain locale paths from the list of PO catalogs (PR #102, thanks @elpaso)
* Added support for translator groups (PR #103, thanks @barklund)
+* Removed Microsoft Translator as a shipped lib, relying on an external version instead
Version 0.7.4
@@ -1,2 +1,2 @@
from .tests import *
-from ..utils.microsofttranslator.test import *
+from microsofttranslator.test import *
@@ -1,5 +0,0 @@
-language: python
-python:
- - "2.7"
-install: python setup.py install
-script: python setup.py test
@@ -1,12 +0,0 @@
-Changelog
-=========
-
-Version 0.4
------------
- * Updated to use the Oauth based token issued by Bing
- * This release is not backward compatibleas the class signature has changed
-
-Version 0.3
------------
- * Encode text as UTF-8 before sending to translator
- * Improved JSON Error handling
@@ -1,32 +0,0 @@
-Copyright (c) 2011 by Openlabs Technologies & Consulting (P) Limited.
-
-Some rights reserved.
-
-Redistribution and use in source and binary forms of the software as well
-as documentation, with or without modification, are permitted provided
-that the following conditions are met:
-
-* Redistributions of source code must retain the above copyright
- notice, this list of conditions and the following disclaimer.
-
-* Redistributions in binary form must reproduce the above
- copyright notice, this list of conditions and the following
- disclaimer in the documentation and/or other materials provided
- with the distribution.
-
-* The names of the contributors may not be used to endorse or
- promote products derived from this software without specific
- prior written permission.
-
-THIS SOFTWARE AND DOCUMENTATION IS PROVIDED BY THE COPYRIGHT HOLDERS AND
-CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
-NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
-OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
-EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
-PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
-LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
-NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-SOFTWARE AND DOCUMENTATION, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
-DAMAGE.
@@ -1,2 +0,0 @@
-include LICENSE
-include README.rst
@@ -1,45 +0,0 @@
-Microsoft Translator V2 -- Python API
-=====================================
-
-:Version: 0.4
-:Web: http://openlabs.co.in/
-:keywords: Micrsoft Translator
-:copyright: Openlabs Technologies & Consulting (P) LTD
-
-.. image:: https://secure.travis-ci.org/openlabs/Microsoft-Translator-Python-API.png?branch=master
- :target: http://travis-ci.org/#!/openlabs/Microsoft-Translator-Python-API
-
-
-This python API implements the Microsoft Translator services which can be used
-in web or client applications to perform language translation operations. The
-services support users who are not familiar with the default language of a page
-or application, or those desiring to communicate with people of a different
-language group.
-
-
-Example Usage:
-::
-
- >>> from microsofttranslator import Translator
- >>> translator = Translator('<Your Client ID>', '<Your Client Secret>')
- >>> print translator.translate("Hello", "pt")
- "Olá"
-
-Registering your application
-----------------------------
-
-To register your application with Azure DataMarket,
-visit https://datamarket.azure.com/developer/applications/ using the
-LiveID credentials from step 1, and click on “Register”. In the
-“Register your application” dialog box, you can define your own
-Client ID and Name. The redirect URI is not used for the Microsoft
-Translator API. However, the redirect URI field is a mandatory field,
-and you must provide a URI to obtain the access code. A description is
-optional.
-
-Take a note of the client ID and the client secret value.
-
-Bugs and Development on Github
-------------------------------
-
-https://github.com/openlabs/Microsoft-Translator-Python-API
@@ -1,203 +0,0 @@
-# -*- coding: utf-8 -*-
-"""
- __init__
-
- A translator using the micrsoft translation engine documented here:
-
- http://msdn.microsoft.com/en-us/library/ff512419.aspx
-
- :copyright: © 2011 by Openlabs Technologies & Consulting (P) Limited
- :license: BSD, see LICENSE for more details.
-"""
-
-__all__ = ['Translator', 'TranslateApiException']
-
-import requests
-import warnings
-import logging
-
-
-class ArgumentOutOfRangeException(Exception):
- def __init__(self, message):
- self.message = message.replace('ArgumentOutOfRangeException: ', '')
- super(ArgumentOutOfRangeException, self).__init__(self.message)
-
-
-class TranslateApiException(Exception):
- def __init__(self, message, *args):
- self.message = message.replace('TranslateApiException: ', '')
- super(TranslateApiException, self).__init__(self.message, *args)
-
-
-class Translator(object):
- """Implements AJAX API for the Microsoft Translator service
-
- :param app_id: A string containing the Bing AppID. (Deprecated)
- """
-
- def __init__(self, client_id, client_secret,
- scope="http://api.microsofttranslator.com",
- grant_type="client_credentials", app_id=None, debug=False):
- """
-
-
- :param client_id: The client ID that you specified when you registered
- your application with Azure DataMarket.
- :param client_secret: The client secret value that you obtained when
- you registered your application with Azure
- DataMarket.
- :param scope: Defaults to http://api.microsofttranslator.com
- ;param grant_type: Defaults to "client_credentials"
- :param app_id: Deprecated
- :param debug: If true, the logging level will be set to debug
-
- .. versionchanged: 0.4
- Bing AppID mechanism is deprecated and is no longer supported.
- See: http://msdn.microsoft.com/en-us/library/hh454950
- """
- if app_id is not None:
- warnings.warn("""app_id is deprected since v0.4.
- See: http://msdn.microsoft.com/en-us/library/hh454950
- """, DeprecationWarning, stacklevel=2)
-
- self.client_id = client_id
- self.client_secret = client_secret
- self.scope = scope
- self.grant_type = grant_type
- self.access_token = None
- self.debug = debug
- self.logger = logging.getLogger("microsofttranslator")
- if self.debug:
- self.logger.setLevel(level=logging.DEBUG)
-
- def get_access_token(self):
- """Bing AppID mechanism is deprecated and is no longer supported.
- As mentioned above, you must obtain an access token to use the
- Microsoft Translator API. The access token is more secure, OAuth
- standard compliant, and more flexible. Users who are using Bing AppID
- are strongly recommended to get an access token as soon as possible.
-
- .. note::
- The value of access token can be used for subsequent calls to the
- Microsoft Translator API. The access token expires after 10
- minutes. It is always better to check elapsed time between time at
- which token issued and current time. If elapsed time exceeds 10
- minute time period renew access token by following obtaining
- access token procedure.
-
- :return: The access token to be used with subsequent requests
- """
- args = {
- 'client_id': self.client_id,
- 'client_secret': self.client_secret,
- 'scope': self.scope,
- 'grant_type': self.grant_type
- }
- response = requests.post(
- 'https://datamarket.accesscontrol.windows.net/v2/OAuth2-13',
- data=args
- ).json()
-
- self.logger.debug(response)
-
- if "error" in response:
- raise TranslateApiException(
- response.get('error_description', 'No Error Description'),
- response.get('error', 'Unknown Error')
- )
- return response['access_token']
-
- def call(self, url, params):
- """Calls the given url with the params urlencoded
- """
- if not self.access_token:
- self.access_token = self.get_access_token()
-
- resp = requests.get(
- "%s" % url,
- params=params,
- headers={'Authorization': 'Bearer %s' % self.access_token}
- )
- resp.encoding = 'UTF-8-sig'
- rv = resp.json()
- #rv = json.loads(response.decode("UTF-8-sig"))
-
- if isinstance(rv, str) and \
- rv.startswith("ArgumentOutOfRangeException"):
- raise ArgumentOutOfRangeException(rv)
-
- if isinstance(rv, str) and \
- rv.startswith("TranslateApiException"):
- raise TranslateApiException(rv)
-
- return rv
-
- def translate(self, text, to_lang, from_lang=None,
- content_type='text/plain', category='general'):
- """Translates a text string from one language to another.
-
- :param text: A string representing the text to translate.
- :param to_lang: A string representing the language code to
- translate the text into.
- :param from_lang: A string representing the language code of the
- translation text. If left None the response will include the
- result of language auto-detection. (Default: None)
- :param content_type: The format of the text being translated.
- The supported formats are "text/plain" and "text/html". Any HTML
- needs to be well-formed.
- :param category: The category of the text to translate. The only
- supported category is "general".
- """
- params = {
- 'text': text.encode('utf8'),
- 'to': to_lang,
- 'contentType': content_type,
- 'category': category,
- }
- if from_lang is not None:
- params['from'] = from_lang
- return self.call(
- "http://api.microsofttranslator.com/V2/Ajax.svc/Translate",
- params)
-
- def translate_array(self, texts, to_lang, from_lang=None, **options):
- """Translates an array of text strings from one language to another.
-
- :param texts: A list containing texts for translation.
- :param to_lang: A string representing the language code to
- translate the text into.
- :param from_lang: A string representing the language code of the
- translation text. If left None the response will include the
- result of language auto-detection. (Default: None)
- :param options: A TranslateOptions element containing the values below.
- They are all optional and default to the most common settings.
-
- Category: A string containing the category (domain) of the
- translation. Defaults to "general".
- ContentType: The format of the text being translated. The
- supported formats are "text/plain" and "text/html". Any
- HTML needs to be well-formed.
- Uri: A string containing the content location of this
- translation.
- User: A string used to track the originator of the submission.
- State: User state to help correlate request and response. The
- same contents will be returned in the response.
- """
- options = {
- 'Category': "general",
- 'Contenttype': "text/plain",
- 'Uri': '',
- 'User': 'default',
- 'State': ''
- }.update(options)
- params = {
- 'texts': json.dumps(texts),
- 'to': to_lang,
- 'options': json.dumps(options),
- }
- if from_lang is not None:
- params['from'] = from_lang
-
- return self.call(
- "http://api.microsofttranslator.com/V2/Ajax.svc/TranslateArray",
- params)
@@ -1,65 +0,0 @@
-# -*- coding: utf-8 -*-
-"""
- Microsoft translator API
-
- The Microsoft Translator services can be used in web or client
- applications to perform language translation operations. The services
- support users who are not familiar with the default language of a page or
- application, or those desiring to communicate with people of a different
- language group.
-
- This module implements the AJAX API for the Microsoft Translator service.
-
- An example::
-
- >>> from microsofttranslator import Translator
- >>> translator = Translator('<Your API Key>')
- >>> print translator.translate("Hello", "pt")
- "Olá"
-
- The documentation for the service can be obtained here:
- http://msdn.microsoft.com/en-us/library/ff512423.aspx
-
- The project is hosted on GitHub where your could fork the project or report
- issues. Visit https://github.com/openlabs/Microsoft-Translator-Python-API
-
- :copyright: © 2011 by Openlabs Technologies & Consulting (P) Limited
- :license: BSD, see LICENSE for more details.
-"""
-import os
-from setuptools import setup
-
-def read(fname):
- return open(os.path.join(os.path.dirname(__file__), fname)).read()
-
-setup(
- name = "microsofttranslator",
- version = "0.4",
- packages = [
- 'microsofttranslator',
- ],
- package_dir = {
- 'microsofttranslator': '.'
- },
- author = "Openlabs Technologies & Consulting (P) Limited",
- author_email = "info@openlabs.co.in",
- description = "Microsoft Translator V2 - Python API",
- long_description = read('README.rst'),
- license = "BSD",
- keywords = "translation microsoft",
- url = "http://openlabs.co.in/",
- include_package_data = True,
- classifiers=[
- "Development Status :: 4 - Beta",
- "Intended Audience :: Developers",
- "License :: OSI Approved :: BSD License",
- "Natural Language :: English",
- "Operating System :: OS Independent",
- "Topic :: Software Development :: Internationalization",
- "Topic :: Utilities"
- ],
- test_suite = "microsofttranslator.test.test_all",
- install_requires=[
- 'requests >= 1.2.3',
- ]
-)
Oops, something went wrong. Retry.

0 comments on commit 6c638bc

Please sign in to comment.