| |
- builtins.object
-
- Leniency
- PhoneNumberMatcher
- phonenumbers.util.UnicodeMixin(builtins.object)
-
- PhoneNumberMatch
class Leniency(builtins.object) |
|
Leniency when finding potential phone numbers in text segments.
The levels here are ordered in increasing strictness. |
|
Data descriptors defined here:
- __dict__
- dictionary for instance variables (if defined)
- __weakref__
- list of weak references to the object (if defined)
Data and other attributes defined here:
- EXACT_GROUPING = 3
- POSSIBLE = 0
- STRICT_GROUPING = 2
- VALID = 1
|
class PhoneNumberMatch(phonenumbers.util.UnicodeMixin) |
|
PhoneNumberMatch(start, raw_string, numobj)
The immutable match of a phone number within a piece of text.
Matches may be found using the find() method of PhoneNumberMatcher.
A match consists of the phone number (in .number) as well as the .start
and .end offsets of the corresponding subsequence of the searched
text. Use .raw_string to obtain a copy of the matched subsequence.
The following annotated example clarifies the relationship between the
searched text, the match offsets, and the parsed number:
>>> text = "Call me at +1 425 882-8080 for details."
>>> country = "US"
>>> import phonenumbers
>>> matcher = phonenumbers.PhoneNumberMatcher(text, country)
>>> matcher.has_next()
True
>>> m = matcher.next() # Find the first phone number match
>>> m.raw_string # contains the phone number as it appears in the text.
"+1 425 882-8080"
>>> (m.start, m.end) # define the range of the matched subsequence.
(11, 26)
>>> text[m.start, m.end]
"+1 425 882-8080"
>>> phonenumberutil.parse("+1 425 882-8080", "US") == m.number
True |
|
- Method resolution order:
- PhoneNumberMatch
- phonenumbers.util.UnicodeMixin
- builtins.object
Methods defined here:
- __eq__(self, other)
- Return self==value.
- __init__(self, start, raw_string, numobj)
- Initialize self. See help(type(self)) for accurate signature.
- __ne__(self, other)
- Return self!=value.
- __repr__(self)
- Return repr(self).
- __unicode__(self)
Data and other attributes defined here:
- __hash__ = None
Methods inherited from phonenumbers.util.UnicodeMixin:
- __str__(self)
- Return str(self).
Data descriptors inherited from phonenumbers.util.UnicodeMixin:
- __dict__
- dictionary for instance variables (if defined)
- __weakref__
- list of weak references to the object (if defined)
|
class PhoneNumberMatcher(builtins.object) |
|
PhoneNumberMatcher(text, region, leniency=1, max_tries=65535)
A stateful class that finds and extracts telephone numbers from text.
Vanity numbers (phone numbers using alphabetic digits such as '1-800-SIX-FLAGS' are
not found.
This class is not thread-safe. |
|
Methods defined here:
- __init__(self, text, region, leniency=1, max_tries=65535)
- Creates a new instance.
Arguments:
text -- The character sequence that we will search, None for no text.
country -- The country to assume for phone numbers not written in
international format (with a leading plus, or with the
international dialing prefix of the specified region). May be
None or "ZZ" if only numbers with a leading plus should be
considered.
leniency -- The leniency to use when evaluating candidate phone
numbers.
max_tries -- The maximum number of invalid numbers to try before
giving up on the text. This is to cover degenerate cases where
the text has a lot of false positives in it. Must be >= 0.
- __iter__(self)
- has_next(self)
- Indicates whether there is another match available
- next(self)
- Return the next match; raises Exception if no next match available
Data descriptors defined here:
- __dict__
- dictionary for instance variables (if defined)
- __weakref__
- list of weak references to the object (if defined)
| |