Ejemplo n.º 1
0
 def ScrubComment(self, comment_text, file_obj):
     for w in self._string_finder.FindSensitiveStrings(comment_text):
         filter_name = self._string_finder.FilterName()
         if self._whitelist.Allows(
                 base.ScrubberError(filter_name, w, '', file_obj)):
             continue
         return base.Revision('', 'Found sensitive string "%s"' % w)
Ejemplo n.º 2
0
    def ScrubComment(self, comment_text, file_obj):
        """Scrub usernames that should be scrubbed."""
        match = NOTE_RE.search(comment_text)
        if match:
            names = re.split('[|,]', match.group(1))
            names_to_scrub = []
            for username in names:
                if not username:
                    # some people put empty usernames
                    continue
                action = self._username_filter.DetermineScrubAction(username)
                if action is usernames.PUBLISH:
                    continue
                elif action is usernames.SCRUB:
                    names_to_scrub.append(username)
                else:
                    return TodoError(file_obj, username)

            if not names_to_scrub:
                return None
            else:
                for username in names_to_scrub:
                    comment_text = re.sub('([(|,])%s([)|,])' % username,
                                          '\\1user\\2', comment_text)

                msg = 'user %s has not opted-in to being published'
                return base.Revision(comment_text, msg)
Ejemplo n.º 3
0
 def ScrubLine(self, line, unused_file_obj):
     """Scrub author declaration from a single line."""
     author = self.AUTHOR_RE.search(line)
     if author:
         new_text = self.AUTHOR_RE.sub('', line)
         if self._email_address_filter.CanPublish(author.group(1)):
             return
         return base.Revision(new_text, 'Scrubbing __author__')
Ejemplo n.º 4
0
    def ScrubLine(self, line, unused_file_obj):
        if self._internal_directory not in line:
            return

        new_text = line.replace(self._internal_directory,
                                self._public_directory)
        return base.Revision(
            new_text, 'Rename javascript directory %s to %s' %
            (self._internal_directory, self._public_directory))
Ejemplo n.º 5
0
    def ScrubComment(self, comment_text, unused_file_obj):
        """Scrub author declaration from a single comment."""

        # TODO(user): Do we need to handle multiple author lines per comment?
        for author_re in self.AUTHOR_RE_LIST:
            author = author_re.search(comment_text)
            if author:
                new_text = author_re.sub('', comment_text)
                if self._email_address_filter.CanPublish(author.group(1)):
                    return
                return base.Revision(new_text, 'Scrubbing author declaration')
Ejemplo n.º 6
0
 def ScrubComment(self, comment_text, unused_file_obj):
     if COPYRIGHT_RE.match(comment_text):
         return None
     # Don't scrub GWT JSNI comments that contain executable JavaScript.
     if comment_text.startswith('/*-{'):
         return None
     if comment_text.startswith('//') or comment_text.startswith('#') or (
             comment_text.startswith('/*')
             and not comment_text.startswith('/**')):
         return base.Revision('',
                              'Removing non-doc comment: %s' % comment_text)
Ejemplo n.º 7
0
    def ScrubLine(self, line, unused_file_obj):
        """Rename Python modules on a single line."""
        import_line = ParseImportLine(line)
        new_text = None

        if import_line:
            import_type, module_name, indent, as_suffix = import_line

            if not as_suffix and self._as_name:
                as_suffix = ' as %s' % self._as_name

            if as_suffix and as_suffix.rsplit(' ',
                                              1)[-1] == self._public_module:
                as_suffix = ''

            if import_type == 'from':
                if module_name.startswith(self._internal_module):
                    module_name = self._ReplaceImport(module_name)
                    module_name_parts = module_name.rsplit('.', 1)

                    if len(module_name_parts) > 1:
                        package_name, module_name = module_name_parts
                        new_text = '%sfrom %s import %s%s' % (
                            indent, package_name, module_name, as_suffix)
                    else:
                        new_text = '%simport %s%s' % (indent, module_name,
                                                      as_suffix)
                else:
                    return
            elif import_type == 'import':
                old_module_name = module_name
                module_name = self._ReplaceImport(old_module_name)
                if module_name == old_module_name:
                    return
                if '.' not in old_module_name and '.' in module_name:
                    new_text = '%sfrom %s import %s%s' % (
                        indent, module_name[:module_name.rfind('.')],
                        module_name[module_name.rfind('.') + 1:], as_suffix)
                else:
                    new_text = '%simport %s%s' % (indent, module_name,
                                                  as_suffix)
            else:
                return  # shouldn't occur
        else:
            new_text = self._ReplaceLine(line)

        if new_text != line:
            return base.Revision(
                new_text, 'Rename Python module %s to %s' %
                (self._internal_module, self._public_module))
Ejemplo n.º 8
0
    def ScrubLine(self, line, unused_file_obj):
        """Remove Python imports from a single line."""
        new_text = None
        revision = None

        import_line = ParseImportLine(line)
        if not import_line:
            return

        module_name = import_line[1]

        if (module_name == self._import_module
                or (self._import_module.endswith('.')
                    and module_name.startswith(self._import_module))):
            new_text = None
            revision = 'Remove import of %s' % module_name

        if revision:
            return base.Revision(new_text, revision)
Ejemplo n.º 9
0
 def ScrubComment(self, unused_comment_text, unused_file_obj):
     return base.Revision('', 'Scrubbing to determine Java meaningfulness')
Ejemplo n.º 10
0
 def ScrubComment(self, comment_text, unused_file_obj):
     if GetMoeDirectives(comment_text) or COPYRIGHT_RE.match(comment_text):
         return None
     else:
         return base.Revision('', 'Removing comment: ' + comment_text)