|
5 | 5 | from collections import defaultdict
|
6 | 6 | from itertools import chain, dropwhile
|
7 | 7 | from re import compile as re
|
8 |
| -import redbaron |
9 | 8 |
|
10 | 9 | try:
|
11 | 10 | from StringIO import StringIO
|
@@ -506,140 +505,3 @@ def _parse_from_import_names(self, is_future_import):
|
506 | 505 | self.log.debug("parsing import, token is %r (%s)",
|
507 | 506 | self.current.kind, self.current.value)
|
508 | 507 |
|
509 |
| - |
510 |
| -class Parser(object): |
511 |
| - def handle_node(self, node, *args, **kwargs): |
512 |
| - node_handler = { |
513 |
| - redbaron.nodes.DefNode: self.handle_function, |
514 |
| - redbaron.nodes.ClassNode: self.handle_class, |
515 |
| - #astroid.ClassDef: self.handle_class, |
516 |
| - #astroid.ImportFrom: self.handle_from_import, |
517 |
| - } |
518 |
| - |
519 |
| - if node.__class__ in node_handler: |
520 |
| - return node_handler[node.__class__](node, *args, **kwargs) |
521 |
| - return None |
522 |
| - |
523 |
| - def parse(self, filelike, filename): |
524 |
| - # TODO: fix log |
525 |
| - self.log = logging.getLogger() |
526 |
| - self.source = filelike.readlines() |
527 |
| - nodes = redbaron.RedBaron(''.join(self.source)) |
528 |
| - |
529 |
| - module_children = [] |
530 |
| - for node in nodes: |
531 |
| - result = self.handle_node(node) |
532 |
| - if result is not None: |
533 |
| - module_children.append(result) |
534 |
| - |
535 |
| - module = Module(filename, |
536 |
| - self.source, |
537 |
| - 0, |
538 |
| - len(self.source), |
539 |
| - [], |
540 |
| - #module_node.doc, |
541 |
| - None, |
542 |
| - module_children, |
543 |
| - None, |
544 |
| - None, |
545 |
| - None) |
546 |
| - |
547 |
| - for node in module.children: |
548 |
| - node.parent = module |
549 |
| - |
550 |
| - return module |
551 |
| - |
552 |
| - def handle_function(self, node, nested=False, method=False, *args, **kwargs): |
553 |
| - if nested and not method: |
554 |
| - cls = NestedFunction |
555 |
| - else: |
556 |
| - cls = Method if method else Function |
557 |
| - |
558 |
| - docstring = None |
559 |
| - |
560 |
| - skip_nodes = ( |
561 |
| - redbaron.nodes.EndlNode, |
562 |
| - redbaron.nodes.CommentNode, |
563 |
| - ) |
564 |
| - for child in node: |
565 |
| - if not isinstance(child, skip_nodes): |
566 |
| - break |
567 |
| - |
568 |
| - if isinstance(child, redbaron.nodes.StringNode): |
569 |
| - # docstring! |
570 |
| - docstring = child.value |
571 |
| - |
572 |
| - children = [] |
573 |
| - for child in node: |
574 |
| - result = self.handle_node(child, nested=True) |
575 |
| - if result is not None: |
576 |
| - children.append(result) |
577 |
| - |
578 |
| - start = node.absolute_bounding_box.top_left.line |
579 |
| - bottom_right = node.absolute_bounding_box.bottom_right |
580 |
| - if bottom_right.line == start: |
581 |
| - end = start |
582 |
| - else: |
583 |
| - end = bottom_right.line - 1 |
584 |
| - |
585 |
| - function = cls(node.name, |
586 |
| - self.source, |
587 |
| - start, |
588 |
| - end, |
589 |
| - [decorator.name for decorator in node.decorators], |
590 |
| - docstring, |
591 |
| - children, |
592 |
| - None) |
593 |
| - |
594 |
| - for child in function.children: |
595 |
| - child.parent = function |
596 |
| - |
597 |
| - return function |
598 |
| - |
599 |
| - def handle_class(self, node, nested=False, *args, **kwargs): |
600 |
| - cls = NestedClass if nested else Class |
601 |
| - |
602 |
| - docstring = None |
603 |
| - |
604 |
| - skip_nodes = ( |
605 |
| - redbaron.nodes.EndlNode, |
606 |
| - redbaron.nodes.CommentNode, |
607 |
| - ) |
608 |
| - for child in node: |
609 |
| - if not isinstance(child, skip_nodes): |
610 |
| - break |
611 |
| - |
612 |
| - if isinstance(child, redbaron.nodes.StringNode): |
613 |
| - # docstring! |
614 |
| - docstring = child.value |
615 |
| - |
616 |
| - children = [] |
617 |
| - for child in node: |
618 |
| - result = self.handle_node(child, nested=True, method=True) |
619 |
| - if result is not None: |
620 |
| - children.append(result) |
621 |
| - |
622 |
| - start = node.absolute_bounding_box.top_left.line |
623 |
| - bottom_right = node.absolute_bounding_box.bottom_right |
624 |
| - if bottom_right.line == start: |
625 |
| - end = start |
626 |
| - else: |
627 |
| - end = bottom_right.line - 1 |
628 |
| - |
629 |
| - klass = cls(node.name, |
630 |
| - self.source, |
631 |
| - start, |
632 |
| - end, |
633 |
| - [decorator.name for decorator in node.decorators], |
634 |
| - docstring, |
635 |
| - children, |
636 |
| - None) |
637 |
| - |
638 |
| - for child in klass.children: |
639 |
| - child.parent = klass |
640 |
| - |
641 |
| - return klass |
642 |
| - |
643 |
| - # TODO: remove |
644 |
| - def __call__(self, *args, **kwargs): |
645 |
| - return self.parse(*args, **kwargs) |
0 commit comments