import re


class FindSpam:
  rules = [
   {'regex': "(?i)\\b(baba(ji)?|nike|vashikaran|here is|porn)\\b", 'all': True,
    'sites': [], 'reason': "Bad keyword detected"},
   {'regex': "\\+\\d{10}|\\+?\\d{2}[\\s\\-]?\\d{8,11}", 'all': True, 
    'sites': ["patents.stackexchange.com"], 'reason': "Phone number detected"},
   {'regex': "(?i)\\b([Nn]igga|[Nn]igger|niga|[Aa]sshole|crap|fag|[Ff]uck|idiot|[Ss]hit|[Ww]hore)s?\\b", 'all': True,
    'sites': [], 'reason': "Offensive title detected",'insensitive':True},
   {'regex': "^[A-Z0-9\\(\\)\\.\\-\\?\\s'\"]*$", 'all': True, 'sites': [], 'reason': "All-caps title"}
  ]

  @staticmethod
  def testpost(title, site):
    result = [];
    for rule in FindSpam.rules:
      if rule['all'] != (site in rule['sites']):
        if re.compile(rule['regex']).search(title):
          result.append(rule['reason'])
    return result

  @staticmethod
  def testtitle(title):
    regexes=["\\b(baba(ji)?|vashikaran|fashion|here is|porn)\\b","\\+\\d{10}","\\+?\\d{2}\\s?\\d{8}","\\b(asshole|crap|fag|fuck|idiot|shit|whore)s?\\b"]
    result = []
    p = [not not re.compile(s).search(title) for s in regexes]
    if 'vashikaran' in title or 'baba' in title or True in p:
      result.append('Possible spam')
      # magic if matches word
    return result

@@ -3,16 +3,36 @@
 port re%0A
+import phonenumbers%0A
 %0A%0Aclass 
@@ -324,32 +324,69 @@
 number detected%22
+, 'validation_method': 'phonenumbers'
 %7D,%0A   %7B'regex': 
@@ -864,24 +864,237 @@
 rch(title):%0A
+          try:%0A            if getattr(TestClass, %22%25s%22 %25 rule%5B'validation_method'%5D)(title):%0A              result.append(rule%5B'reason'%5D)%0A          except KeyError:        # There is no special logic for this rule%0A  
           re
@@ -1117,24 +1117,24 @@
 %5B'reason'%5D)%0A
-
     return r
@@ -1541,16 +1541,16 @@
 es word%0A
-
     retu
@@ -1543,24 +1543,422 @@
  word%0A    return result%0A
+%0A  @staticmethod%0A  def phonenumbers(msg):%0A    try:%0A      z = phonenumbers.parse(msg, %22IN%22)%0A      if phonenumbers.is_possible_number(z) and phonenumbers.is_valid_number(z):%0A        print %22Possible %25s, Valid %25s, Expain: %25s%22 %25 (phonenumbers.is_possible_number(z), phonenumbers.is_valid_number(z), z)%0A        return True%0A    except phonenumbers.phonenumberutil.NumberParseException:%0A      return False%0A

Add better error checking against phone numbers