# Path: supplement/fixer.py
# def fix(code, tries=10):
#     try:
#         return ast.parse(code), code
#     except Exception, e:
#         tries -= 1
#         if tries <= 0:
#             raise
# 
#         code, fixed_location = try_to_fix(e, code)
#         if fixed_location:
#             return fix(code, tries)
#         else:
#             raise
# 
# def sanitize_encoding(source):
#     if isinstance(source, unicode):
#         parts = source.split(u'\n', 4)
#         for i in range(min(3, len(parts))):
#             parts[i] = parts[i].replace(u'coding=', u'codang=').replace(u'coding:', u'codang:')
# 
#         return u'\n'.join(parts)
#     else:
#         return source
# 
# Path: supplement/scope.py
# def get_scope_at(project, source, lineno, filename=None, ast_node=None, continous=True):
#     ast_node = ast_node or ast.parse(source)
# 
#     scope = Scope(ast_node, '', None, 'module')
#     scope.project = project
#     scope.filename = filename
#     return scope.get_scope_at(source, lineno, continous)
# 
# Path: supplement/evaluator.py
# def infer(string, scope, lineno=None):
#     tree = ast.parse(string, '<string>', 'eval')
# 
#     if lineno:
#         ast.increment_lineno(tree, lineno-1)
# 
#     return Evaluator().process(tree, scope)


import logging
from keyword import iskeyword
from inspect import formatargspec
from tokenize import (NAME, NL, NEWLINE, TokenError, generate_tokens,
    untokenize, ERRORTOKEN, INDENT, DEDENT)
from .fixer import fix, sanitize_encoding
from .scope import get_scope_at
from .evaluator import infer

        return obj.get_location()

    elif ctx_type in ('import', 'from-import'):
        if ctx:
            if ctx[-1] == '.':
                ctx = ctx[:-1]

            module_name = ctx + '.' + match
        else:
            module_name = match

        try:
            module = project.get_module(module_name, filename)
        except ImportError:
            module_name, _, _ = module_name.rpartition('.')
            if module_name:
                module = project.get_module(module_name, filename)
                return module[match].get_location()
        else:
            return 1, module.filename

    return None, None

def get_docstring(project, source, position, filename):
    position = get_id_ending(source, position)
    ctx_type, lineno, ctx, match, fctx = get_context(source, position)
    if ctx_type == 'expr' and fctx:
        source = sanitize_encoding(source)
        ast_nodes, fixed_source = fix(source)

# Path: supplement/fixer.py
# def fix(code, tries=10):
#     try:
#         return ast.parse(code), code
#     except Exception, e:
#         tries -= 1
#         if tries <= 0:
#             raise
# 
#         code, fixed_location = try_to_fix(e, code)
#         if fixed_location:
#             return fix(code, tries)
#         else:
#             raise
# 
# def sanitize_encoding(source):
#     if isinstance(source, unicode):
#         parts = source.split(u'\n', 4)
#         for i in range(min(3, len(parts))):
#             parts[i] = parts[i].replace(u'coding=', u'codang=').replace(u'coding:', u'codang:')
# 
#         return u'\n'.join(parts)
#     else:
#         return source
# 
# Path: supplement/scope.py
# def get_scope_at(project, source, lineno, filename=None, ast_node=None, continous=True):
#     ast_node = ast_node or ast.parse(source)
# 
#     scope = Scope(ast_node, '', None, 'module')
#     scope.project = project
#     scope.filename = filename
#     return scope.get_scope_at(source, lineno, continous)
# 
# Path: supplement/evaluator.py
# def infer(string, scope, lineno=None):
#     tree = ast.parse(string, '<string>', 'eval')
# 
#     if lineno:
#         ast.increment_lineno(tree, lineno-1)
# 
#     return Evaluator().process(tree, scope)


# Path: supplement/assistant.py
import logging
from keyword import iskeyword
from inspect import formatargspec
from tokenize import (NAME, NL, NEWLINE, TokenError, generate_tokens,
    untokenize, ERRORTOKEN, INDENT, DEDENT)
from .fixer import fix, sanitize_encoding
from .scope import get_scope_at
from .evaluator import infer


        return obj.get_location()

    elif ctx_type in ('import', 'from-import'):
        if ctx:
            if ctx[-1] == '.':
                ctx = ctx[:-1]

            module_name = ctx + '.' + match
        else:
            module_name = match

        try:
            module = project.get_module(module_name, filename)
        except ImportError:
            module_name, _, _ = module_name.rpartition('.')
            if module_name:
                module = project.get_module(module_name, filename)
                return module[match].get_location()
        else:
            return 1, module.filename

    return None, None

def get_docstring(project, source, position, filename):
    position = get_id_ending(source, position)
    ctx_type, lineno, ctx, match, fctx = get_context(source, position)
    if ctx_type == 'expr' and fctx:
        source = sanitize_encoding(source)
        ast_nodes, fixed_source = fix(source)

        scope = get_scope_at(project, fixed_source, lineno, filename, ast_nodes)