import sublime, sublime_plugin

def extract_lines(view,edit):
	regions = [s for s in view.sel() if not s.empty]
	if not regions:
		regions = [sublime.Region(0,view.size())]
	for region in regions:
		text = view.substr(region)
		lines = text.splitlines()
		return lines

def get_line_value_pair(lines,duplicate_keys):
	i = 0
	duplicate_keys_occurance = {}
	result_lines=[]
	
	for x in duplicate_keys:
		duplicate_keys_occurance.setdefault(x,0)

	for line in reversed(lines):
		y = line.encode('ascii','ignore')
		pos = y.find('=')
		
		if(pos != -1):
			z = y[0:pos]
			z = z.strip()
			try:
				if (duplicate_keys.index(z) > -1):
					if (duplicate_keys_occurance[z] == 0):
						result_lines.append(line)
						duplicate_keys_occurance[z] = 1
			except Exception, e:
				result_lines.append(line)
				pass
		else:
			result_lines.append(line)
	return result_lines


def find_duplicate_keys(lines):
	specific_keys = []
	duplicate_keys  = []
	for x in lines:
			y = x.encode('ascii','ignore')
			pos = y.find("=")
			
			if (pos != -1):
				z = y[0:pos]
				z = z.strip()
				
				try:
					if(specific_keys.index(z) > -1):
						try:
							if(duplicate_keys.index(z) > -1):
								pass
						except Exception, e1:
							duplicate_keys.append(z)
				except Exception, e:
					specific_keys.append(z)
	print 'Duplicate keys are : ', duplicate_keys
	return duplicate_keys
		

class JpCleanerCommand(sublime_plugin.TextCommand):
	def run(self, edit):
		lines = extract_lines(self.view,edit)
		duplicate_keys  = find_duplicate_keys(lines)
		
		result_lines = get_line_value_pair(lines,duplicate_keys)
		status  = ""
		if( len(duplicate_keys) ==0 ):
			status = "No duplicates!!!!"
		else:	
			regionToErase = sublime.Region(0, self.view.size())
			self.view.erase(edit,regionToErase)
			status = "Done cleaning duplicates! Save file after reviewing the changes!!!"
			for line in reversed(result_lines):
				loc = self.view.sel()[0].a
				self.view.insert(edit, loc, line  +"\n")

		sublime.status_message(status)

@@ -365,17 +365,16 @@
 ines=%5B%5D%0A
-%09
 %0A%09for x 
@@ -472,17 +472,19 @@
 :%0A%09%09
-y
+pos
  = line.
 enco
@@ -483,43 +483,8 @@
 ine.
-encode('ascii','ignore')%0A%09%09pos = y.
 find
@@ -489,18 +489,16 @@
 nd('=')%0A
-%09%09
 %0A%09%09if(po
@@ -510,25 +510,28 @@
 -1):%0A%09%09%09z = 
-y
+line
 %5B0:pos%5D%0A%09%09%09z
@@ -715,33 +715,35 @@
 except Exception
-,
+ as
  e:%0A%09%09%09%09result_l
@@ -924,42 +924,8 @@
 es:%0A
-%09%09%09y = x.encode('ascii','ignore')%0A
 %09%09%09p
@@ -933,23 +933,20 @@
 s = 
-y
+x
 .find(
-%22=%22)%0A%09%09%09
+'=')%0A
 %0A%09%09%09
@@ -969,17 +969,17 @@
 %09%09%09%09z = 
-y
+x
 %5B0:pos%5D%0A
@@ -996,20 +996,16 @@
 strip()%0A
-%09%09%09%09
 %0A%09%09%09%09try
@@ -1131,17 +1131,19 @@
 xception
-,
+ as
  e1:%0A%09%09%09
@@ -1191,17 +1191,19 @@
 xception
-,
+ as
  e:%0A%09%09%09%09
@@ -1233,17 +1233,17 @@
 )%0A%09print
- 
+(
 'Duplica
@@ -1273,16 +1273,17 @@
 ate_keys
+)
 %0A%09return
@@ -1298,18 +1298,16 @@
 te_keys%0A
-%09%09
 %0A%0Aclass 
@@ -1461,18 +1461,16 @@
 (lines)%0A
-%09%09
 %0A%09%09resul
@@ -1608,17 +1608,16 @@
 %0A%09%09else:
-%09
 %0A%09%09%09regi

Make jpropCleaner.py compatible with Python3/ST3