This file is indexed.

/usr/share/perl5/Autodia/Handler/python.pm is in autodia 2.14-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
################################################################
# AutoDIA - Automatic Dia XML.   (C)Copyright 2001 A Trevena   #
#                                                              #
# AutoDIA comes with ABSOLUTELY NO WARRANTY; see COPYING file  #
# This is free software, and you are welcome to redistribute   #
# it under certain conditions; see COPYING file for details    #
################################################################
package Autodia::Handler::python;

require Exporter;

use strict;

use vars qw($VERSION @ISA @EXPORT);
use Autodia::Handler;

@ISA = qw(Autodia::Handler Exporter);

use Autodia::Diagram;
use Data::Dumper;

#---------------------------------------------------------------

#####################
# Constructor Methods

# new inherited from Autodia::Handler

#------------------------------------------------------------------------
# Access Methods

# parse_file inherited from Autodia::Handler

#-----------------------------------------------------------------------------
# Internal Methods

# _initialise inherited from Autodia::Handler

sub _parse {		# parses python source code
  my $self     = shift;
  my $fh       = shift;
  my $filename = shift;

  warn "_parse_file called with $self, $fh, $filename\n";

  my %config   = %{$self->{Config}};
  my $Diagram  = $self->{Diagram};

  # set up local variables for parsing
  $self->{in_comment} = 0;
  my $module_name = $filename;
  $module_name =~ s/^.*?\/?(\w+)\.py$/$1/;
  my $in_class = 0;
  my $current_class = $module_name;
  my $exit_depth = -1;

  my $Module = Autodia::Diagram::Class->new($module_name);
  my $exists = $Diagram->add_class($Module);
  my $Class = $Module = $exists if ($exists);

  my %aliases = ();

  # process file
  my $class_count = 0;
  foreach my $line (<$fh>) {
    next if  $self->_discard_line (\$line);
    # count spaces / tabs to see how deep indented
    my $depth = 0;
    foreach (split(//,$line)) {
      last if (/\S/);
      $depth++;
    }
    if ($depth == $exit_depth) {
      $in_class = 0;
      $current_class = $module_name;
      $Class = $Module;
    }

    # catch methods and subs
    if ( $line =~ m/^[\s\t]*def\s+(\S+)\s*\((.*)\):/ ) {
      my %method = ( "name" => $1, );
      $method{"visibility"} = ($method{"name"} =~ m/^\_/) ? 1 : 0;
      my $params = $2 || '';
      if ($params) {
	  foreach (split(/\s*,\s*/,$params)) {
	      push (@{$method{"Params"}},{Name => $_, Val => '',});
	  }
      }
      $Class->add_operation(\%method);
    }

    # catch class
    if ( $line =~ /^class\s+(\w+).*:/ ) {
      my $classname = $1;
      $current_class = "$module_name.$classname";
      last if ($self->skip($classname));
      $Class = Autodia::Diagram::Class->new("$module_name.$classname");
      my $exists = $Diagram->add_class($Class);
      $Class = $exists if ($exists);
      $aliases{$classname} = $Class;

      warn "got class name : $classname\n";
      warn " line : $line \n";
      if ( $line =~ /\((.*)\)/) {
	  my @superclasses = split(/[\,\s]/,$1);
	  foreach my $super (@superclasses) {
	      # create superclass
	      warn "have superclass : $super\n";
	      next unless ($super=~/\S/);
	      my $Superclass;
	      # check if superclass exists already
	      if ($aliases{$super}) {
		  $Superclass = $aliases{$super};
		  warn "found alias for superclass $super - ",$Superclass->Name , "\n";
	      } else {
		  $Superclass = Autodia::Diagram::Superclass->new($super);
		  # add superclass to diagram
		  my $exists_already = $Diagram->add_superclass($Superclass);
		  if (ref $exists_already) {
		      warn "superclass exists already";
		      $Superclass = $exists_already;
		  }
		  $aliases{$super} = $Superclass;
	      }
	      # create new inheritance
	      my $Inheritance = Autodia::Diagram::Inheritance->new($Class, $Superclass);
	      # add inheritance to superclass
	      $Superclass->add_inheritance($Inheritance);
	      # add inheritance to class
	      $Class->add_inheritance($Inheritance);
	      # add inheritance to diagram
	      $Diagram->add_inheritance($Inheritance);
	  }
      }
      $in_class = 1;
      $exit_depth = $depth;
    }

    # catch object attributes via self.foo or this.foo
    if ( $line =~ /(self|this)\.(\w+)\.?/ ) {
      my $attribute = $2;
      my $attribute_visibility = ( $attribute =~ m/^\_/ ) ? 1 : 0;
      $Class->add_attribute({
			     name => $attribute,
			     visibility => $attribute_visibility,
			     value => '',
			    });
    }
    if ( $line =~ /import/ ) {
      my $dependancy;
      if ($line =~ /from\s+(\w+)\s+import/) {
	$dependancy = $1;
      } elsif ($line =~ /\s*import\s+(\w+)/) {
	$dependancy = $1;
      } else {
	# not supported
      }
      if ($dependancy) {
	# create component
	my $Component = Autodia::Diagram::Component->new($dependancy);
	# add component to diagram
	my $exists = $Diagram->add_component($Component);
	# replace component if redundant
	if (ref $exists) {
	  $Component = $exists;
	}
	# create new dependancy
	my $Dependancy = Autodia::Diagram::Dependancy->new($Class, $Component);
	# add dependancy to diagram
	$Diagram->add_dependancy($Dependancy);
	# add dependancy to class
	$Class->add_dependancy($Dependancy);
	# add dependancy to component
	$Component->add_dependancy($Dependancy);
      }
    }
  }
}
##########################################


sub _discard_line
{
  my $self    = shift;
  my $line    = shift;
  my $discard = 0;

  SWITCH:
    {
	if ($$line =~ /"""/) # if line is a comment discard
	{
	  $$line =~ s/""".*"""//;
	  if ($self->{in_comment}) {
	    if ($$line =~ /"""(\s*\w[\w\s]*)/) {
	      $self->{in_comment} = 0;
	      $$line = $1;
	    } else {
	      $self->{in_comment} = 0;
	      $discard = 1;
	    }
	  } else {
	    if ($$line =~ /^(\s*[\w\s]*)"""/) {
	      $self->{in_comment} = 1;
	      $$line = $1;
	    } else {
	      $discard = 1;
	    }
	  }
	  last SWITCH;
	} else {
	  $discard = 1 if ($self->{in_comment});
	}

	if ($$line =~ /#/) {
	  if ($$line =~ /^(\s*\w[\w\s]*)#/) {
	    $$line = $1;
	  } else {
	    $discard = 1;
	  }
	  last SWITCH;
	}
    } # end SWITCH

  $discard = 1 if ($$line =~ m/^\s*$/); # if line is blank or white space discard
  return $discard;
}