tools/android/checkxmlstyle/checkxmlstyle.py
def _checkStringResourcePunctuations(regex, warning, input_api, output_api):
  """Check whether inappropriate punctuations are used"""
  warnings = []
  result = []
  # Removing placeholders for parsing purpose:
  # placeholders will be parsed as children of the parent node.
  ph = re.compile(r'<ph>.*</ph>')
  for f in IncludedFiles(input_api, helpers.INCLUDED_GRD_PATHS):
    contents = input_api.ReadFile(f)

    contents = re.sub(ph, '', contents)
    tree = ET.fromstring(contents)

    # some grds don't contain release and messages tags
    if tree.find('release') is None:
      continue
    if tree.find('release').find('messages') is None:
      continue

    messages = tree.find('release').find('messages')

    quotes = set()
    for child in messages:
      if child.tag == 'message':
        lines = child.text.split('\n')
        quotes.update(l for l in lines if regex.search(l))

    # Only report the lines in the changed contents of the current workspace
    for line_number, line in f.ChangedContents():
      lineWithoutPh = re.sub(ph, '', line)
      if lineWithoutPh in quotes:
        warnings.append('  %s:%d\n    \t%s' %
                        (f.LocalPath(), line_number, line))

  if warnings:
    result += [output_api.PresubmitPromptWarning(warning, warnings)]
  return result
Check whether inappropriate punctuations are used
Check whether inappropriate punctuations are used
Check whether inappropriate punctuations are used
def _checkStringResourcePunctuations(regex, warning, input_api, output_api):
  warnings = []
  result = []
  ph = re.compile(r'<ph>.*</ph>')
  for f in IncludedFiles(input_api, helpers.INCLUDED_GRD_PATHS):
    contents = input_api.ReadFile(f)
    contents = re.sub(ph, '', contents)
    tree = ET.fromstring(contents)
    if tree.find('release') is None:
      continue
    if tree.find('release').find('messages') is None:
      continue
    messages = tree.find('release').find('messages')
    quotes = set()
    for child in messages:
      if child.tag == 'message':
        lines = child.text.split('\n')
        quotes.update(l for l in lines if regex.search(l))
    for line_number, line in f.ChangedContents():
      lineWithoutPh = re.sub(ph, '', line)
      if lineWithoutPh in quotes:
        warnings.append('  %s:%d\n    \t%s' %
                        (f.LocalPath(), line_number, line))
  if warnings:
    result += [output_api.PresubmitPromptWarning(warning, warnings)]
  return result
def _checkStringResourcePunctuations ( regex , warning , input_api , output_api ) : warnings = [ ] result = [ ] ph = re . compile ( r'<ph>.*</ph>' ) for f in IncludedFiles ( input_api , helpers . INCLUDED_GRD_PATHS ) : contents = input_api . ReadFile ( f ) contents = re . sub ( ph , '' , contents ) tree = ET . fromstring ( contents ) if tree . find ( 'release' ) is None : continue if tree . find ( 'release' ) . find ( 'messages' ) is None : continue messages = tree . find ( 'release' ) . find ( 'messages' ) quotes = set ( ) for child in messages : if child . tag == 'message' : lines = child . text . split ( '\n' ) quotes . update ( l for l in lines if regex . search ( l ) ) for line_number , line in f . ChangedContents ( ) : lineWithoutPh = re . sub ( ph , '' , line ) if lineWithoutPh in quotes : warnings . append ( '  %s:%d\n    \t%s' % ( f . LocalPath ( ) , line_number , line ) ) if warnings : result += [ output_api . PresubmitPromptWarning ( warning , warnings ) ] return result
Check whether inappropriate punctuations are used
Check whether inappropriate punctuations are used
"""Check whether inappropriate punctuations are used""" # Removing placeholders for parsing purpose: # placeholders will be parsed as children of the parent node. # some grds don't contain release and messages tags # Only report the lines in the changed contents of the current workspace
regex
warning
input_api
output_api