[orca] Fix for bug #664384 - Need to move getLinkBasename() functionality out of Gecko script so all script
- From: Joanmarie Diggs <joanied src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [orca] Fix for bug #664384 - Need to move getLinkBasename() functionality out of Gecko script so all script
- Date: Sat, 19 Nov 2011 18:46:36 +0000 (UTC)
commit a30b2144bf6decc3b76a09be1dfbff41ef901fc8
Author: Joanmarie Diggs <jdiggs igalia com>
Date: Sat Nov 19 13:45:19 2011 -0500
Fix for bug #664384 - Need to move getLinkBasename() functionality out of Gecko script so all scripts can use it
src/orca/script_utilities.py | 57 ++++++++++++++++++++
.../scripts/toolkits/Gecko/braille_generator.py | 2 +-
src/orca/scripts/toolkits/Gecko/script.py | 56 -------------------
.../scripts/toolkits/Gecko/speech_generator.py | 2 +-
src/orca/speech_generator.py | 2 +-
5 files changed, 60 insertions(+), 59 deletions(-)
---
diff --git a/src/orca/script_utilities.py b/src/orca/script_utilities.py
index 3e29dce..6401aec 100644
--- a/src/orca/script_utilities.py
+++ b/src/orca/script_utilities.py
@@ -1028,6 +1028,63 @@ class Utilities:
return label
@staticmethod
+ def linkBasename(obj):
+ """Returns the relevant information from the URI. The idea is
+ to attempt to strip off all prefix and suffix, much like the
+ basename command in a shell."""
+
+ basename = None
+
+ try:
+ hyperlink = obj.queryHyperlink()
+ except:
+ pass
+ else:
+ uri = hyperlink.getURI(0)
+ if uri and len(uri):
+ # Sometimes the URI is an expression that includes a URL.
+ # Currently that can be found at the bottom of safeway.com.
+ # It can also be seen in the backwards.html test file.
+ #
+ expression = uri.split(',')
+ if len(expression) > 1:
+ for item in expression:
+ if item.find('://') >=0:
+ if not item[0].isalnum():
+ item = item[1:-1]
+ if not item[-1].isalnum():
+ item = item[0:-2]
+ uri = item
+ break
+
+ # We're assuming that there IS a base name to be had.
+ # What if there's not? See backwards.html.
+ #
+ uri = uri.split('://')[-1]
+
+ # Get the last thing after all the /'s, unless it ends
+ # in a /. If it ends in a /, we'll look to the stuff
+ # before the ending /.
+ #
+ if uri[-1] == "/":
+ basename = uri[0:-1]
+ basename = basename.split('/')[-1]
+ elif not uri.count("/"):
+ basename = uri
+ else:
+ basename = uri.split('/')[-1]
+ if basename.startswith("index"):
+ basename = uri.split('/')[-2]
+
+ # Now, try to strip off the suffixes.
+ #
+ basename = basename.split('.')[0]
+ basename = basename.split('?')[0]
+ basename = basename.split('#')[0]
+
+ return basename
+
+ @staticmethod
def linkIndex(obj, characterIndex):
"""A brute force method to see if an offset is a link. This
is provided because not all Accessible Hypertext implementations
diff --git a/src/orca/scripts/toolkits/Gecko/braille_generator.py b/src/orca/scripts/toolkits/Gecko/braille_generator.py
index 7a91e2c..52f6e27 100644
--- a/src/orca/scripts/toolkits/Gecko/braille_generator.py
+++ b/src/orca/scripts/toolkits/Gecko/braille_generator.py
@@ -124,7 +124,7 @@ class BrailleGenerator(braille_generator.BrailleGenerator):
# If there's no text for the link, expose part of the
# URI to the user.
#
- basename = self._script.getLinkBasename(link)
+ basename = self._script.utilities.linkBasename(link)
if basename:
result.append(basename)
diff --git a/src/orca/scripts/toolkits/Gecko/script.py b/src/orca/scripts/toolkits/Gecko/script.py
index a683f6a..df89e77 100644
--- a/src/orca/scripts/toolkits/Gecko/script.py
+++ b/src/orca/scripts/toolkits/Gecko/script.py
@@ -3144,62 +3144,6 @@ class Script(default.Script):
return True
- def getLinkBasename(self, obj):
- """Returns the relevant information from the URI. The idea is
- to attempt to strip off all prefix and suffix, much like the
- basename command in a shell."""
-
- basename = None
-
- try:
- hyperlink = obj.queryHyperlink()
- except:
- pass
- else:
- uri = hyperlink.getURI(0)
- if uri and len(uri):
- # Sometimes the URI is an expression that includes a URL.
- # Currently that can be found at the bottom of safeway.com.
- # It can also be seen in the backwards.html test file.
- #
- expression = uri.split(',')
- if len(expression) > 1:
- for item in expression:
- if item.find('://') >=0:
- if not item[0].isalnum():
- item = item[1:-1]
- if not item[-1].isalnum():
- item = item[0:-2]
- uri = item
- break
-
- # We're assuming that there IS a base name to be had.
- # What if there's not? See backwards.html.
- #
- uri = uri.split('://')[-1]
-
- # Get the last thing after all the /'s, unless it ends
- # in a /. If it ends in a /, we'll look to the stuff
- # before the ending /.
- #
- if uri[-1] == "/":
- basename = uri[0:-1]
- basename = basename.split('/')[-1]
- elif not uri.count("/"):
- basename = uri
- else:
- basename = uri.split('/')[-1]
- if basename.startswith("index"):
- basename = uri.split('/')[-2]
-
- # Now, try to strip off the suffixes.
- #
- basename = basename.split('.')[0]
- basename = basename.split('?')[0]
- basename = basename.split('#')[0]
-
- return basename
-
def isFormField(self, obj):
"""Returns True if the given object is a field inside of a form."""
diff --git a/src/orca/scripts/toolkits/Gecko/speech_generator.py b/src/orca/scripts/toolkits/Gecko/speech_generator.py
index b44f252..2f48c92 100644
--- a/src/orca/scripts/toolkits/Gecko/speech_generator.py
+++ b/src/orca/scripts/toolkits/Gecko/speech_generator.py
@@ -112,7 +112,7 @@ class SpeechGenerator(speech_generator.SpeechGenerator):
# If there's no text for the link, expose part of the
# URI to the user.
#
- basename = self._script.getLinkBasename(link)
+ basename = self._script.utilities.linkBasename(link)
if basename:
result.append(basename)
result.extend(acss)
diff --git a/src/orca/speech_generator.py b/src/orca/speech_generator.py
index d5a4ee2..1667215 100644
--- a/src/orca/speech_generator.py
+++ b/src/orca/speech_generator.py
@@ -452,7 +452,7 @@ class SpeechGenerator(generator.Generator):
# If there's no text for the link, expose part of the
# URI to the user.
#
- text = self._script.getLinkBasename(obj)
+ text = self._script.utilities.linkBasename(obj)
if text:
linkOutput += " " + text
result.append(linkOutput)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]