You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by jo...@apache.org on 2013/08/17 00:04:20 UTC
[3/3] git commit: [#6464] Fixed handling of attachment links in GC
Tracker importer
[#6464] Fixed handling of attachment links in GC Tracker importer
Signed-off-by: Cory Johns <cj...@slashdotmedia.com>
Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/7474e6e5
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/7474e6e5
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/7474e6e5
Branch: refs/heads/cj/6464
Commit: 7474e6e55c333ab64082433e00356f7ea0f0e30f
Parents: 283554b
Author: Cory Johns <cj...@slashdotmedia.com>
Authored: Fri Aug 16 22:04:00 2013 +0000
Committer: Cory Johns <cj...@slashdotmedia.com>
Committed: Fri Aug 16 22:04:00 2013 +0000
----------------------------------------------------------------------
ForgeImporters/forgeimporters/google/__init__.py | 16 ++++++++--------
.../forgeimporters/tests/google/test_extractor.py | 6 +++---
2 files changed, 11 insertions(+), 11 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/7474e6e5/ForgeImporters/forgeimporters/google/__init__.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/google/__init__.py b/ForgeImporters/forgeimporters/google/__init__.py
index 22be7c2..fbf3eb0 100644
--- a/ForgeImporters/forgeimporters/google/__init__.py
+++ b/ForgeImporters/forgeimporters/google/__init__.py
@@ -17,7 +17,7 @@
import re
import urllib
-from urlparse import urlparse, urljoin
+from urlparse import urlparse, urljoin, parse_qs
from collections import defaultdict
from contextlib import closing
try:
@@ -123,7 +123,7 @@ class GoogleCodeProjectExtractor(ProjectExtractor):
def get_icon(self, project):
page = self.get_page('project_info')
- icon_url = urljoin(self.url, page.find(itemprop='image').attrMap['src'])
+ icon_url = urljoin(self.url, page.find(itemprop='image').get('src'))
if icon_url == self.DEFAULT_ICON:
return
icon_name = urllib.unquote(urlparse(icon_url).path).split('/')[-1]
@@ -222,7 +222,7 @@ class GoogleCodeProjectExtractor(ProjectExtractor):
def get_issue_attachments(self):
attachments = self.page.find(id='hc0').find('div', 'attachments')
if attachments:
- return map(Attachment, attachments.findAll('tr'))
+ return [Attachment(a.parent) for a in attachments.findAll('a', text='Download')]
else:
return []
@@ -233,8 +233,8 @@ class GoogleCodeProjectExtractor(ProjectExtractor):
class UserLink(object):
def __init__(self, tag):
self.name = tag.string.strip()
- if 'href' in tag.attrMap:
- self.url = urljoin(GoogleCodeProjectExtractor.BASE_URL, tag.attrMap['href'])
+ if tag.get('href'):
+ self.url = urljoin(GoogleCodeProjectExtractor.BASE_URL, tag.get('href'))
else:
self.url = None
@@ -264,7 +264,7 @@ class Comment(object):
def _get_attachments(self, tag):
attachments = tag.find('div', 'attachments')
if attachments:
- self.attachments = map(Attachment, attachments.findAll('tr'))
+ self.attachments = [Attachment(a.parent) for a in attachments.findAll('a', text='Download')]
else:
self.attachments = []
@@ -288,8 +288,8 @@ class Comment(object):
class Attachment(object):
def __init__(self, tag):
- self.filename = _as_text(tag).strip().split()[0]
- self.url = urljoin(GoogleCodeProjectExtractor.BASE_URL, tag.a.get('href'))
+ self.url = urljoin(GoogleCodeProjectExtractor.BASE_URL, tag.get('href'))
+ self.filename = parse_qs(urlparse(self.url).query)['name'][0]
self.type = None
@property
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/7474e6e5/ForgeImporters/forgeimporters/tests/google/test_extractor.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/tests/google/test_extractor.py b/ForgeImporters/forgeimporters/tests/google/test_extractor.py
index 4157c98..e208e8d 100644
--- a/ForgeImporters/forgeimporters/tests/google/test_extractor.py
+++ b/ForgeImporters/forgeimporters/tests/google/test_extractor.py
@@ -76,7 +76,7 @@ class TestGoogleCodeProjectExtractor(TestCase):
def test_get_icon(self, M, StringIO):
self.urlopen.return_value.info.return_value = {'content-type': 'image/png'}
extractor = google.GoogleCodeProjectExtractor('my-project', 'project_info')
- extractor.page.find.return_value.attrMap = {'src': 'http://example.com/foo/bar/my-logo.png'}
+ extractor.page.find.return_value.get.return_value = 'http://example.com/foo/bar/my-logo.png'
self.urlopen.reset_mock()
extractor.get_icon(self.project)
@@ -260,13 +260,13 @@ class TestUserLink(TestCase):
def test_plain(self):
tag = mock.Mock()
tag.string.strip.return_value = 'name'
- tag.attrMap = {}
+ tag.get.return_value = None
link = google.UserLink(tag)
self.assertEqual(str(link), 'name')
def test_linked(self):
tag = mock.Mock()
tag.string.strip.return_value = 'name'
- tag.attrMap = {'href': '/p/project'}
+ tag.get.return_value = '/p/project'
link = google.UserLink(tag)
self.assertEqual(str(link), '[name](http://code.google.com/p/project)')