# Buggy code
def _escape_single_line_quoted_string(text):
    if six.PY2:
        return (
            text.encode("unicode-escape")
            .encode("string-escape")
            .replace('"', '\\"')
            .replace("\\'", "'")
        )
    else:
        return codecs.encode(text, "unicode-escape").decode().replace('"', '\\"')


# Traceback (prettytoml.tokens.error)
Requirements file provided! Importing into Pipfile...
Traceback (most recent call last):
File "/usr/bin/pipenv", line 11, in <module>
load_entry_point('pipenv==2018.7.1', 'console_scripts', 'pipenv')()
File "/usr/lib/python3.7/site-packages/pipenv/vendor/click/core.py", line 722, in __call__
return self.main(*args, **kwargs)
File "/usr/lib/python3.7/site-packages/pipenv/vendor/click/core.py", line 697, in main
rv = self.invoke(ctx)
File "/usr/lib/python3.7/site-packages/pipenv/vendor/click/core.py", line 1066, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/usr/lib/python3.7/site-packages/pipenv/vendor/click/core.py", line 895, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/usr/lib/python3.7/site-packages/pipenv/vendor/click/core.py", line 535, in invoke
return callback(*args, **kwargs)
File "/usr/lib/python3.7/site-packages/pipenv/cli.py", line 435, in install
selective_upgrade=selective_upgrade,
File "/usr/lib/python3.7/site-packages/pipenv/core.py", line 1890, in do_install
section = project.editable_packages if not dev else project.editable_dev_packages
File "/usr/lib/python3.7/site-packages/pipenv/project.py", line 524, in editable_packages
return self._get_editable_packages(dev=False)
File "/usr/lib/python3.7/site-packages/pipenv/project.py", line 508, in _get_editable_packages
for k, v in self.parsed_pipfile.get(section, {}).items()
File "/usr/lib/python3.7/site-packages/pipenv/project.py", line 509, in <dictcomp>
if is_editable(v)
File "/usr/lib/python3.7/site-packages/pipenv/utils.py", line 584, in is_editable
pipfile_entry.get(key) for key in ('file', 'path') + VCS_LIST
File "/usr/lib/python3.7/site-packages/pipenv/utils.py", line 584, in <genexpr>
pipfile_entry.get(key) for key in ('file', 'path') + VCS_LIST
File "/usr/lib/python3.7/site-packages/pipenv/patched/prettytoml/elements/abstracttable.py", line 73, in get
return self[key]
File "/usr/lib/python3.7/site-packages/pipenv/patched/prettytoml/elements/abstracttable.py", line 66, in __getitem__
for key, value in self.items():
File "/usr/lib/python3.7/site-packages/pipenv/patched/prettytoml/elements/abstracttable.py", line 34, in items
yield key.value, value.value
File "/usr/lib/python3.7/site-packages/pipenv/patched/prettytoml/elements/atomic.py", line 40, in value
return toml2py.deserialize(self._tokens[self._value_token_index()])
File "/usr/lib/python3.7/site-packages/pipenv/patched/prettytoml/tokens/toml2py.py", line 33, in deserialize
return _to_string(token)
File "/usr/lib/python3.7/site-packages/pipenv/patched/prettytoml/tokens/toml2py.py", line 86, in _to_string
return _unescape_str(escaped)
File "/usr/lib/python3.7/site-packages/pipenv/patched/prettytoml/tokens/toml2py.py", line 46, in _unescape_str
raise BadEscapeCharacter
prettytoml.tokens.errors.BadEscapeCharacter

# Fixed code
def _escape_single_line_quoted_string(text):
    text = text.decode("utf-8") if isinstance(text, six.binary_type) else text
    start = 0
    i = 0
    res = []
    _escapes = {
        "\n": "\\n",
        "\r": "\\r",
        "\\": "\\\\",
        "\t": "\\t",
        "\b": "\\b",
        "\f": "\\f",
        '"': '\\"',
    }

    def flush():
        if start < i:
            res.append(text[start:i])
        return i + 1

    while i < len(text):
        c = text[i]
        if c in _escapes:
            start = flush()
            res.append(_escapes[c])
        elif ord(c) < 0x20:
            start = flush()
            res.append("\\u%04x" % ord(c))
        i += 1

    flush()
    return "".join(res)