Permalink
Browse files

Convert u".." literals to u("..")

  • Loading branch information...
1 parent e334775 commit 1897a0a30c3f10803d76b4fa6aff7c4272948c72 @daviddrysdale committed Nov 26, 2011
@@ -26,6 +26,7 @@
# limitations under the License.
import re
+from .util import u
from .unicode_util import digit as unicode_digit
from .re_util import fullmatch
from .phonemetadata import PhoneMetadata
@@ -34,26 +35,26 @@
from .phonenumberutil import _extract_country_code, region_code_for_country_code
from .phonenumberutil import country_code_for_region
-_EMPTY_METADATA = PhoneMetadata(id=u"", international_prefix=u"NA", register=False)
+_EMPTY_METADATA = PhoneMetadata(id=u(""), international_prefix=u("NA"), register=False)
# A pattern that is used to match character classes in regular expressions. An
# example of a character class is [1-4].
-_CHARACTER_CLASS_PATTERN = re.compile(u"\\[([^\\[\\]])*\\]")
+_CHARACTER_CLASS_PATTERN = re.compile(u("\\[([^\\[\\]])*\\]"))
# Any digit in a regular expression that actually denotes a digit. For
# example, in the regular expression 80[0-2]\d{6,10}, the first 2 digits (8
# and 0) are standalone digits, but the rest are not.
# Two look-aheads are needed because the number following \\d could be a
# two-digit number, since the phone number can be as long as 15 digits.
-_STANDALONE_DIGIT_PATTERN = re.compile(u"\\d(?=[^,}][^,}])")
+_STANDALONE_DIGIT_PATTERN = re.compile(u("\\d(?=[^,}][^,}])"))
# A pattern that is used to determine if a number_format under
# available_formats is eligible to be used by the AYTF. It is eligible when
# the format element under number_format contains groups of the dollar sign
# followed by a single digit, separated by valid phone number
# punctuation. This prevents invalid punctuation (such as the star sign in
# Israeli star numbers) getting into the output of the AYTF.
-_ELIGIBLE_FORMAT_PATTERN = re.compile(u"[" + _VALID_PUNCTUATION + u"]*" +
- u"(\\\\\\d" + u"[" + _VALID_PUNCTUATION + u"]*)+")
+_ELIGIBLE_FORMAT_PATTERN = re.compile(u("[") + _VALID_PUNCTUATION + u("]*") +
+ u("(\\\\\\d") + u("[") + _VALID_PUNCTUATION + u("]*)+"))
# This is the minimum length of national number accrued that is required to
# trigger the formatter. The first element of the leading_digits_pattern of each
@@ -62,7 +63,7 @@
_MIN_LEADING_DIGITS_LENGTH = 3
# The digits that have not been entered yet will be represented by a \u2008,
# the punctuation space.
-_DIGIT_PLACEHOLDER = u"\u2008"
+_DIGIT_PLACEHOLDER = u("\u2008")
_DIGIT_PATTERN = re.compile(_DIGIT_PLACEHOLDER)
@@ -184,7 +185,7 @@ def _get_formatting_template(self, number_pattern, number_format):
# entered so far is longer than the maximum the current formatting
# rule can accommodate.
if len(a_phone_number) < len(self._national_number):
- return u""
+ return u("")
# Formats the number according to number_format
template = re.sub(number_pattern, number_format, a_phone_number)
# Replaces each digit with character _DIGIT_PLACEHOLDER
@@ -43,6 +43,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
+from .util import u
from .phonenumberutil import format_number, PhoneNumberFormat, is_valid_number
from .phonenumberutil import region_code_for_number
from .geodata import GEOCODE_DATA, GEOCODE_LONGEST_PREFIX
@@ -103,8 +104,8 @@ def area_description_for_number(numobj, lang, script=None, region=None):
if name is not None:
return name
else:
- return u""
- return u""
+ return u("")
+ return u("")
def country_name_for_number(numobj, lang, script=None, region=None):
@@ -137,7 +138,7 @@ def region_display_name(region_code, lang, script=None, region=None):
other_lang = name[1:]
name = LOCALE_DATA[region_code].get(other_lang, "")
return name
- return u""
+ return u("")
def description_for_valid_number(numobj, lang, script=None, region=None):
@@ -16,7 +16,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
-from .util import UnicodeMixin
+from .util import UnicodeMixin, u
class NumberFormat(UnicodeMixin):
@@ -124,17 +124,17 @@ def __repr__(self):
def __unicode__(self):
# Generate a string that is valid Python input for the constructor.
# Note that we use %r, which generates its own quotes.
- result = u"NumberFormat(pattern=%r, format=%r" % (self.pattern, self.format)
+ result = u("NumberFormat(pattern=%r, format=%r") % (self.pattern, self.format)
if len(self.leading_digits_pattern) > 0:
- result += (u", leading_digits_pattern=[%s]" %
+ result += (u(", leading_digits_pattern=[%s]") %
", ".join(["%r" % ld for ld in self.leading_digits_pattern]))
if self.national_prefix_formatting_rule is not None:
- result += u", national_prefix_formatting_rule=%r" % self.national_prefix_formatting_rule
+ result += u(", national_prefix_formatting_rule=%r") % self.national_prefix_formatting_rule
if self.national_prefix_optional_when_formatting:
- result += u", national_prefix_optional_when_formatting=%r" % self.national_prefix_optional_when_formatting
+ result += u(", national_prefix_optional_when_formatting=%r") % self.national_prefix_optional_when_formatting
if self.domestic_carrier_code_formatting_rule is not None:
- result += u", domestic_carrier_code_formatting_rule=%r" % self.domestic_carrier_code_formatting_rule
- result += u")"
+ result += u(", domestic_carrier_code_formatting_rule=%r") % self.domestic_carrier_code_formatting_rule
+ result += u(")")
return result
@@ -185,18 +185,18 @@ def __repr__(self):
def __unicode__(self):
# Generate a string that is valid Python input for constructor
- result = u"PhoneNumberDesc("
- sep = u""
+ result = u("PhoneNumberDesc(")
+ sep = u("")
if self.national_number_pattern is not None:
- result += u"%snational_number_pattern=%r" % (sep, self.national_number_pattern)
- sep = u", "
+ result += u("%snational_number_pattern=%r") % (sep, self.national_number_pattern)
+ sep = u(", ")
if self.possible_number_pattern is not None:
- result += u"%spossible_number_pattern=%r" % (sep, self.possible_number_pattern)
- sep = u", "
+ result += u("%spossible_number_pattern=%r") % (sep, self.possible_number_pattern)
+ sep = u(", ")
if self.example_number is not None:
- result += u"%sexample_number=%r" % (sep, self.example_number)
- sep = u", "
- result += u")"
+ result += u("%sexample_number=%r") % (sep, self.example_number)
+ sep = u(", ")
+ result += u(")")
return result
@@ -414,7 +414,7 @@ def __unicode__(self):
country_code = self.country_code
if country_code is None:
country_code = -1
- result = (u"PhoneMetadata(id='%s', country_code=%d, international_prefix=%r" %
+ result = (u("PhoneMetadata(id='%s', country_code=%d, international_prefix=%r") %
(self.id, country_code, self.international_prefix))
result += ",\n general_desc=%s" % self.general_desc
result += ",\n fixed_line=%s" % self.fixed_line
@@ -450,5 +450,5 @@ def __unicode__(self):
result += ",\n leading_digits='%s'" % self.leading_digits
if self.leading_zero_possible:
result += ",\n leading_zero_possible=True"
- result += u")"
+ result += u(")")
return result
@@ -21,7 +21,7 @@
# Extra regexp function; see README
from .re_util import fullmatch
-from .util import UnicodeMixin
+from .util import UnicodeMixin, u
from .unicode_util import Category, Block, is_letter
from .phonenumberutil import _MAX_LENGTH_FOR_NSN, _MAX_LENGTH_COUNTRY_CODE
from .phonenumberutil import _VALID_PUNCTUATION, _PLUS_CHARS, _NON_DIGITS_PATTERN
@@ -41,14 +41,14 @@ def _limit(lower, upper):
"""Returns a regular expression quantifier with an upper and lower limit."""
if ((lower < 0) or (upper <= 0) or (upper < lower)):
raise Exception("Illegal argument to _limit")
- return u"{%d,%d}" % (lower, upper)
+ return u("{%d,%d}") % (lower, upper)
# Build the MATCHING_BRACKETS and PATTERN regular expression patterns. The
# building blocks below exist to make the patterns more easily understood.
-_OPENING_PARENS = u"(\\[\uFF08\uFF3B"
-_CLOSING_PARENS = u")\\]\uFF09\uFF3D"
-_NON_PARENS = u"[^" + _OPENING_PARENS + _CLOSING_PARENS + u"]"
+_OPENING_PARENS = u("(\\[\uFF08\uFF3B")
+_CLOSING_PARENS = u(")\\]\uFF09\uFF3D")
+_NON_PARENS = u("[^") + _OPENING_PARENS + _CLOSING_PARENS + u("]")
# Limit on the number of pairs of brackets in a phone number.
_BRACKET_PAIR_LIMIT = _limit(0, 3)
@@ -60,12 +60,12 @@ def _limit(lower, upper):
# should be. It's also possible that the leading bracket was dropped, so we
# shouldn't be surprised if we see a closing bracket first. We limit the sets
# of brackets in a phone number to four.
-_MATCHING_BRACKETS = re.compile(u"(?:[" + _OPENING_PARENS + u"])?" + u"(?:" + _NON_PARENS + u"+" +
- u"[" + _CLOSING_PARENS + u"])?" +
- _NON_PARENS + u"+" +
- u"(?:[" + _OPENING_PARENS + u"]" + _NON_PARENS +
- u"+[" + _CLOSING_PARENS + u"])" + _BRACKET_PAIR_LIMIT +
- _NON_PARENS + u"*")
+_MATCHING_BRACKETS = re.compile(u("(?:[") + _OPENING_PARENS + u("])?") + u("(?:") + _NON_PARENS + u("+") +
+ u("[") + _CLOSING_PARENS + u("])?") +
+ _NON_PARENS + u("+") +
+ u("(?:[") + _OPENING_PARENS + u("]") + _NON_PARENS +
+ u("+[") + _CLOSING_PARENS + u("])") + _BRACKET_PAIR_LIMIT +
+ _NON_PARENS + u("*"))
# Limit on the number of leading (plus) characters.
_LEAD_LIMIT = _limit(0, 2)
@@ -80,12 +80,12 @@ def _limit(lower, upper):
_BLOCK_LIMIT = _limit(0, _DIGIT_BLOCK_LIMIT)
# A punctuation sequence allowing white space.
-_PUNCTUATION = u"[" + _VALID_PUNCTUATION + u"]" + _PUNCTUATION_LIMIT
+_PUNCTUATION = u("[") + _VALID_PUNCTUATION + u("]") + _PUNCTUATION_LIMIT
# A digits block without punctuation.
-_DIGIT_SEQUENCE = u"(?u)\\d" + _limit(1, _DIGIT_BLOCK_LIMIT)
+_DIGIT_SEQUENCE = u("(?u)\\d") + _limit(1, _DIGIT_BLOCK_LIMIT)
# Punctuation that may be at the start of a phone number - brackets and plus signs.
_LEAD_CLASS_CHARS = _OPENING_PARENS + _PLUS_CHARS
-_LEAD_CLASS = u"[" + _LEAD_CLASS_CHARS + u"]"
+_LEAD_CLASS = u("[") + _LEAD_CLASS_CHARS + u("]")
_LEAD_PATTERN = re.compile(_LEAD_CLASS)
# Phone number pattern allowing optional punctuation.
@@ -99,30 +99,30 @@ def _limit(lower, upper):
# - No whitespace is allowed at the start or end.
# - No alpha digits (vanity numbers such as 1-800-SIX-FLAGS) are currently
# supported.
-_PATTERN = re.compile(u"(?:" + _LEAD_CLASS + _PUNCTUATION + u")" + _LEAD_LIMIT +
- _DIGIT_SEQUENCE + u"(?:" + _PUNCTUATION + _DIGIT_SEQUENCE + u")" + _BLOCK_LIMIT +
- u"(?:" + _EXTN_PATTERNS_FOR_MATCHING + u")?",
+_PATTERN = re.compile(u("(?:") + _LEAD_CLASS + _PUNCTUATION + u(")") + _LEAD_LIMIT +
+ _DIGIT_SEQUENCE + u("(?:") + _PUNCTUATION + _DIGIT_SEQUENCE + u(")") + _BLOCK_LIMIT +
+ u("(?:") + _EXTN_PATTERNS_FOR_MATCHING + u(")?"),
_REGEX_FLAGS)
# Matches strings that look like publication pages. Example: "Computing
# Complete Answers to Queries in the Presence of Limited Access Patterns.
# Chen Li. VLDB J. 12(3): 211-227 (2003)."
#
# The string "211-227 (2003)" is not a telephone number.
-_PUB_PAGES = re.compile(u"\\d{1,5}-+\\d{1,5}\\s{0,4}\\(\\d{1,4}")
+_PUB_PAGES = re.compile(u("\\d{1,5}-+\\d{1,5}\\s{0,4}\\(\\d{1,4}"))
# Matches strings that look like dates using "/" as a separator. Examples:
# 3/10/2011, 31/10/96 or 08/31/95.
-_SLASH_SEPARATED_DATES = re.compile(u"(?:(?:[0-3]?\\d/[01]?\\d)|(?:[01]?\\d/[0-3]?\\d))/(?:[12]\\d)?\\d{2}")
+_SLASH_SEPARATED_DATES = re.compile(u("(?:(?:[0-3]?\\d/[01]?\\d)|(?:[01]?\\d/[0-3]?\\d))/(?:[12]\\d)?\\d{2}"))
# Matches white-space, which may indicate the end of a phone number and the
# start of something else (such as a neighbouring zip-code). If white-space is
# found, continues to match all characters that are not typically used to
# start a phone number.
-_GROUP_SEPARATOR = re.compile(u"(?u)\\s" + # Unicode Separator, \p{Z}
- u"[^" + _LEAD_CLASS_CHARS +
- u"\\d]*") # Unicode Decimal Digit Number, \p{Nd}
+_GROUP_SEPARATOR = re.compile(u("(?u)\\s") + # Unicode Separator, \p{Z}
+ u("[^") + _LEAD_CLASS_CHARS +
+ u("\\d]*")) # Unicode Decimal Digit Number, \p{Nd}
class Leniency(object):
@@ -376,7 +376,7 @@ def __init__(self, text, region,
# The text searched for phone numbers.
self.text = text
if self.text is None:
- self.text = u""
+ self.text = u("")
# The region (country) to assume for phone numbers without an
# international prefix, possibly None.
self.preferred_region = region
@@ -668,4 +668,4 @@ def __repr__(self):
self.number))
def __unicode__(self):
- return u"PhoneNumberMatch [%s,%s) %s" % (self.start, self.end, self.raw_string)
+ return u("PhoneNumberMatch [%s,%s) %s") % (self.start, self.end, self.raw_string)
Oops, something went wrong.

0 comments on commit 1897a0a

Please sign in to comment.