1# Copyright 2014 The Chromium Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5"""
6A 2to3 fixer that converts all string literals to use single quotes.
7
8Strings that contain single quotes will not be modified. Prefixed string
9literals will also not be modified. This affect double-quoted strings but
10not triple-double-quote strings.
11
12"""
13
14from lib2to3.fixer_base import BaseFix
15from lib2to3.pgen2 import token
16
17
18class FixSingleQuoteStrings(BaseFix):
19
20    explicit = True
21    _accept_type = token.STRING
22
23    def match(self, node):
24        res = node.value.startswith('"') and not node.value.startswith('"""') and "'" not in node.value[1:-1]
25        return res
26
27    def transform(self, node, results):
28        node.value = node.value.replace('"', "'")
29        node.changed()
30