diff --git a/zencoding.plugin b/zencoding.plugin index d68901a..3f795fd 100644 --- a/zencoding.plugin +++ b/zencoding.plugin @@ -1,5 +1,5 @@ [Plugin] -Loader=python +Loader=python3 Module=zencoding IAge=3 Name=Zen Coding diff --git a/zencoding/__init__.py b/zencoding/__init__.py index 6ce69f5..b6b526c 100644 --- a/zencoding/__init__.py +++ b/zencoding/__init__.py @@ -22,7 +22,7 @@ from gi.repository import GObject, Gedit, Gtk, Gio import os -from zen_editor import ZenEditor +from .zen_editor import ZenEditor zencoding_ui_str = """ @@ -144,8 +144,9 @@ def update_ui(self): modified = os.path.getmtime(os.path.join(os.path.dirname(__file__), 'my_zen_settings.py')) if modified != self.modified: try: - import my_zen_settings - reload(my_zen_settings) + from . import my_zen_settings + import imp + imp.reload(my_zen_settings) except Exception as error: md = Gtk.MessageDialog(self.window, Gtk.DIALOG_MODAL, Gtk.MESSAGE_ERROR, Gtk.BUTTONS_CLOSE, "An error occured in user settings:") @@ -243,9 +244,9 @@ def __init__(self): GObject.Object.__init__(self) self.instances = {} - def deactivate(self, window): - self.instances[window].deactivate() - del self.instances[window] + def deactivate(self, window): + self.instances[window].deactivate() + del self.instances[window] def do_activate(self): self.instances[self.window] = ZenCodingWindowHelper(self.window) diff --git a/zencoding/html_matcher.py b/zencoding/html_matcher.py index 4d336b4..4bf41c9 100644 --- a/zencoding/html_matcher.py +++ b/zencoding/html_matcher.py @@ -270,4 +270,4 @@ def find_comment_start(start_pos): ix += 1 - return action(opening_tag, closing_tag, start_ix) \ No newline at end of file + return action(opening_tag, closing_tag, start_ix) diff --git a/zencoding/html_navigation.py b/zencoding/html_navigation.py index b956a39..b63c5b8 100644 --- a/zencoding/html_navigation.py +++ b/zencoding/html_navigation.py @@ -19,7 +19,7 @@ def factorize(zen_children): - zen_children = filter(lambda s: s, zen_children) + zen_children = [s for s in zen_children if s] if len(zen_children) > 1: @@ -44,7 +44,7 @@ def factorize(zen_children): zen_children[index] += '>' + '>'.join(parts[1:]) index += 1 - zen_children = filter(lambda s: s, zen_children) + zen_children = [s for s in zen_children if s] return zen_children @@ -235,9 +235,9 @@ def zenify(self, content, mode): for grand_child in child.children: if grand_child.type == 'value' and grand_child.start < grand_child.end and not grand_child.children: if name == 'id': - zen_id = '#' + '#'.join(filter(lambda s: s, re.split('\s+', content[grand_child.start:grand_child.end]))) + zen_id = '#' + '#'.join([s for s in re.split('\s+', content[grand_child.start:grand_child.end]) if s]) elif name == 'class': - zen_class = '.' + '.'.join(filter(lambda s: s, re.split('\s+', content[grand_child.start:grand_child.end]))) + zen_class = '.' + '.'.join([s for s in re.split('\s+', content[grand_child.start:grand_child.end]) if s]) elif mode > 1 and child.type == 'attribute': for grand_child in child.children: @@ -286,21 +286,21 @@ def _parse(self, content, print_and_exit = False): def tokens_feed(): tokens_re = '(|<\!\[CDATA\[|\]\]>|<\?|\?>|<\!|<[A-Za-z][A-Za-z0-9\-_:\.]*||/?>|["\'=]|\s+)' - tokens = filter(lambda s: s, re.split(tokens_re, content)) + tokens = [s for s in re.split(tokens_re, content) if s] for token in tokens: yield token def get_next_token(): try: - return tokens.next() + return next(tokens) except StopIteration: return None tokens = tokens_feed() if print_and_exit: - for token in tokens: print token, '|', - print + for token in tokens: print(token, '|', end=' ') + print() return None root = Node('root') @@ -670,6 +670,6 @@ def zenify(self, offset_start, offset_end, content, mode = 3): ''' test = HtmlNavigation(content) if test.tree: - print test.tree.show() + print(test.tree.show()) test._parse(content, True) diff --git a/zencoding/image_size.py b/zencoding/image_size.py index 1446112..e805c84 100644 --- a/zencoding/image_size.py +++ b/zencoding/image_size.py @@ -9,10 +9,10 @@ ''' from subprocess import Popen, PIPE -import urllib +import urllib.request, urllib.parse, urllib.error import os import re -import zen_file, zen_core +from . import zen_file, zen_core def replace_or_append(img_tag, attr_name, attr_value): """ diff --git a/zencoding/lorem_ipsum.py b/zencoding/lorem_ipsum.py index 91e5d8a..98638db 100644 --- a/zencoding/lorem_ipsum.py +++ b/zencoding/lorem_ipsum.py @@ -223,7 +223,7 @@ def lorem_ipsum(command): if __name__ == '__main__': def echo(x): - print x + ':', '(' + lorem_ipsum(x) + ')' + print(x + ':', '(' + lorem_ipsum(x) + ')') echo('') echo('characters') echo('characters 10') diff --git a/zencoding/stparser.py b/zencoding/stparser.py index 75d81bb..73e9ecc 100644 --- a/zencoding/stparser.py +++ b/zencoding/stparser.py @@ -6,9 +6,9 @@ ''' from copy import deepcopy +from .zen_settings import zen_settings import re import types -from zen_settings import zen_settings _original_settings = deepcopy(zen_settings) @@ -79,7 +79,7 @@ def _parse_abbreviations(obj): Parses all abbreviations inside dictionary @param obj: dict """ - for key, value in obj.items(): + for key, value in list(obj.items()): key = key.strip() if key[-1] == '+': # this is expando, leave 'value' as is @@ -98,12 +98,12 @@ def parse(settings): in zen coding (for example, expanding abbreviation) @type settings: dict """ - for p, value in settings.items(): + for p, value in list(settings.items()): if p == 'abbreviations': _parse_abbreviations(value) elif p == 'extends': settings[p] = [v.strip() for v in value.split(',')] - elif type(value) == types.DictType: + elif type(value) == dict: parse(value) @@ -114,8 +114,8 @@ def extend(parent, child): @type parent: dict @type child: dict """ - for p, value in child.items(): - if type(value) == types.DictType: + for p, value in list(child.items()): + if type(value) == dict: if p not in parent: parent[p] = {} extend(parent[p], value) @@ -129,12 +129,12 @@ def create_maps(obj): Create hash maps on certain string properties of zen settings @type obj: dict """ - for p, value in obj.items(): + for p, value in list(obj.items()): if p == 'element_types': - for k, v in value.items(): + for k, v in list(value.items()): if isinstance(v, str): value[k] = [el.strip() for el in v.split(',')] - elif type(value) == types.DictType: + elif type(value) == dict: create_maps(value) @@ -158,4 +158,4 @@ def get_settings(user_settings=None): parse(settings) return settings - \ No newline at end of file + diff --git a/zencoding/zen_actions.py b/zencoding/zen_actions.py index f28f325..153920a 100644 --- a/zencoding/zen_actions.py +++ b/zencoding/zen_actions.py @@ -10,7 +10,7 @@ """ from zencoding import zen_core as zen_coding from zencoding import html_matcher, zen_file -from zen_core import char_at, ZenError +from .zen_core import char_at, ZenError import re import base64 @@ -404,7 +404,7 @@ def merge_lines(editor): if start != end: # got range, merge lines text = editor.get_content()[start:end] - lines = map(lambda s: re.sub(r'^\s+', '', s), zen_coding.split_by_lines(text)) + lines = [re.sub(r'^\s+', '', s) for s in zen_coding.split_by_lines(text)] text = re.sub(r'\s{2,}', ' ', ''.join(lines)) editor.replace_content(text, start, end) editor.create_selection(start, start + len(text)) diff --git a/zencoding/zen_core.py b/zencoding/zen_core.py index a07daab..1a3b41a 100644 --- a/zencoding/zen_core.py +++ b/zencoding/zen_core.py @@ -24,9 +24,10 @@ @author: Sergey Chikuyonok (http://chikuyonok.ru) ''' -from zen_settings import zen_settings +from .zen_settings import zen_settings import re -import stparser +from . import stparser +import collections newline = '\n' "Newline symbol" @@ -90,7 +91,7 @@ def has_deep_key(obj, key): for v in key: if hasattr(last_obj, v): last_obj = getattr(last_obj, v) - elif last_obj.has_key(v): + elif v in last_obj: last_obj = last_obj[v] else: return False @@ -137,7 +138,7 @@ def create_profile(options): @param options: Profile options @type options: dict """ - for k, v in default_profile.items(): + for k, v in list(default_profile.items()): options.setdefault(k, v) return options @@ -189,7 +190,7 @@ def pad_string(text, pad): """ pad_str = '' result = '' - if isinstance(pad, basestring): + if isinstance(pad, str): pad_str = pad else: pad_str = get_indentation() * pad @@ -572,7 +573,7 @@ def rollout_tree(tree, parent=None): add_point = tag.find_deepest_child() or tag if tag_content: - if isinstance(tag_content, basestring): + if isinstance(tag_content, str): add_point.content = tag_content else: add_point.content = tag_content[j] or '' @@ -587,15 +588,15 @@ def run_filters(tree, profile, filter_list): @param filter_list: str, list @return: ZenNode """ - import filters + from . import filters - if isinstance(profile, basestring) and profile in profiles: + if isinstance(profile, str) and profile in profiles: profile = profiles[profile]; if not profile: profile = profiles['plain'] - if isinstance(filter_list, basestring): + if isinstance(filter_list, str): filter_list = re.split(r'[\|,]', filter_list) for name in filter_list: @@ -735,7 +736,7 @@ def replace_unescaped_symbol(text, symbol, replace): cur_sl = sl match_count += 1 new_value = replace - if callable(new_value): + if isinstance(new_value, collections.Callable): replace_data = replace(text, symbol, i, match_count) if replace_data: cur_sl = len(replace_data[0]) @@ -769,7 +770,7 @@ def run_action(name, *args, **kwargs): zen_coding.run_actions('expand_abbreviation', zen_editor) zen_coding.run_actions('wrap_with_abbreviation', zen_editor, 'div') """ - import zen_actions + from . import zen_actions if hasattr(zen_actions, name): return getattr(zen_actions, name)(*args, **kwargs) @@ -908,7 +909,7 @@ def get_caret_placeholder(): Returns caret placeholder @return: str """ - if callable(caret_placeholder): + if isinstance(caret_placeholder, collections.Callable): return caret_placeholder() else: return caret_placeholder @@ -942,7 +943,7 @@ def apply_filters(tree, syntax, profile, additional_filters=None): if additional_filters: _filters += '|' - if isinstance(additional_filters, basestring): + if isinstance(additional_filters, str): _filters += additional_filters else: _filters += '|'.join(additional_filters) @@ -1092,7 +1093,7 @@ def __init__(self, name, count=1, doc_type='html'): self._abbr = abbr self.__content = '' self.repeat_by_lines = False - self._res = zen_settings.has_key(doc_type) and zen_settings[doc_type] or {} + self._res = doc_type in zen_settings and zen_settings[doc_type] or {} self.parent = None # add default attributes diff --git a/zencoding/zen_editor.py b/zencoding/zen_editor.py index 3a9e98f..a0a61ba 100644 --- a/zencoding/zen_editor.py +++ b/zencoding/zen_editor.py @@ -17,19 +17,20 @@ import sys, os, re, locale -import zen_core, zen_actions, zen_file, html_matcher -from image_size import update_image_size +from .import zen_core, zen_actions, zen_file, html_matcher +from .image_size import update_image_size -import zen_dialog -from html_navigation import HtmlNavigation -from lorem_ipsum import lorem_ipsum +from .import zen_dialog + +from .html_navigation import HtmlNavigation +from .lorem_ipsum import lorem_ipsum try: sys.path.append('/usr/lib/gedit/plugins/') from snippets import Document as SnippetDocument USE_SNIPPETS = True except: - print 'failed importing snippets' + print('failed importing snippets') USE_SNIPPETS = False