Skip to content

Commit

Permalink
Updated some import locations for Python 3 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
claudep committed Aug 18, 2015
1 parent a5eebce commit 47b93ab
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 20 deletions.
4 changes: 2 additions & 2 deletions translate/convert/oo2po.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"""

import logging
from urllib import urlencode
from six.moves.urllib import parse

from translate.storage import oo, po

Expand Down Expand Up @@ -95,7 +95,7 @@ def convertstore(self, theoofile, duplicatestyle="msgctxt"):
thetargetfile = po.pofile()
# create a header for the file
bug_url = 'http://qa.openoffice.org/issues/enter_bug.cgi?%s' % \
urlencode({
parse.urlencode({
"subcomponent": "ui",
"comment": "",
"short_desc": "Localization issue in file: %s" %
Expand Down
5 changes: 3 additions & 2 deletions translate/convert/oo2xliff.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
"""

import logging
from urllib import urlencode
from six.moves.urllib import parse


from translate.storage import oo, xliff

Expand Down Expand Up @@ -100,7 +101,7 @@ def convertstore(self, theoofile, duplicatestyle="msgctxt"):
thetargetfile.settargetlanguage(self.targetlanguage)
# create a header for the file
bug_url = 'http://qa.openoffice.org/issues/enter_bug.cgi?%s' % \
urlencode({
parse.urlencode({
"subcomponent": "ui",
"comment": "",
"short_desc": "Localization issue in file: %s" %
Expand Down
17 changes: 9 additions & 8 deletions translate/convert/test_oo2po.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
# -*- coding: utf-8 -*-

import os
import urlparse
from urlparse import parse_qs
from six.moves.urllib import parse

from translate.convert import oo2po, po2oo, test_convert
from translate.misc import wStringIO
Expand Down Expand Up @@ -118,14 +117,16 @@ def test_msgid_bug_error_address(self):
pofile = self.convert(oosource)
assert pofile.units[0].isheader()
assert pofile.parseheader()["Report-Msgid-Bugs-To"]
bug_url = urlparse.urlparse(pofile.parseheader()["Report-Msgid-Bugs-To"])
bug_url = parse.urlparse(pofile.parseheader()["Report-Msgid-Bugs-To"])
print(bug_url)
assert bug_url[:3] == ("http", "qa.openoffice.org", "/issues/enter_bug.cgi")
assert parse_qs(bug_url[4], True) == {u'comment': [u''],
u'component': [u'l10n'],
u'form_name': [u'enter_issue'],
u'short_desc': [u'Localization issue in file: '],
u'subcomponent': [u'ui'],}
assert parse.parse_qs(bug_url[4], True) == {
'comment': [''],
'component': ['l10n'],
'form_name': ['enter_issue'],
'short_desc': ['Localization issue in file: '],
'subcomponent': ['ui'],
}

def test_x_comment_inclusion(self):
"""test that we can merge x-comment language entries into comment sections of the PO file"""
Expand Down
4 changes: 2 additions & 2 deletions translate/search/match.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
translation units."""

import heapq
import itertools
import re
from six.moves import filter as ifilter

from translate.misc.multistring import multistring
from translate.search import lshtein, terminology
Expand Down Expand Up @@ -103,7 +103,7 @@ def extendtm(self, units, store=None, sort=True):
"""
if isinstance(units, base.TranslationUnit):
units = [units]
for candidate in itertools.ifilter(self.usable, units):
for candidate in ifilter(self.usable, units):
simpleunit = base.TranslationUnit("")
# We need to ensure that we don't pass multistrings futher, since
# some modules (like the native Levenshtein) can't use it.
Expand Down
6 changes: 3 additions & 3 deletions translate/storage/pocommon.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
# along with this program; if not, see <http://www.gnu.org/licenses/>.

import re
import urllib
from six.moves.urllib import parse

from translate.storage import base, poheader
from translate.storage.workflow import StateEnum as state
Expand All @@ -41,15 +41,15 @@ def extract_msgid_comment(text):

def quote_plus(text):
"""Quote the query fragment of a URL; replacing ' ' with '+'"""
return urllib.quote_plus(text.encode("utf-8"))
return parse.quote_plus(text.encode("utf-8"))


def unquote_plus(text):
"""unquote('%7e/abc+def') -> '~/abc def'"""
try:
if isinstance(text, unicode):
text = text.encode('utf-8')
return urllib.unquote_plus(text).decode('utf-8')
return parse.unquote_plus(text).decode('utf-8')
except UnicodeEncodeError as e:
# for some reason there is a non-ascii character here. Let's assume it
# is already unicode (because of originally decoding the file)
Expand Down
5 changes: 2 additions & 3 deletions translate/storage/statsdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@
import re
import stat
import sys
import thread
from six.moves import _thread, UserDict
from sqlite3 import dbapi2
from UserDict import UserDict

from translate import __version__ as toolkitversion
from translate.lang.common import Common
Expand Down Expand Up @@ -291,7 +290,7 @@ class StatsCache(object):
"""The current cursor"""

def __new__(cls, statsfile=None):
current_thread = thread.get_ident()
current_thread = _thread.get_ident()

def make_database(statsfile):

Expand Down

0 comments on commit 47b93ab

Please sign in to comment.