Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion zencoding.plugin
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[Plugin]
Loader=python
Loader=python3
Module=zencoding
IAge=3
Name=Zen Coding
Expand Down
13 changes: 7 additions & 6 deletions zencoding/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = """
<ui>
Expand Down Expand Up @@ -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:")
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion zencoding/html_matcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,4 +270,4 @@ def find_comment_start(start_pos):

ix += 1

return action(opening_tag, closing_tag, start_ix)
return action(opening_tag, closing_tag, start_ix)
18 changes: 9 additions & 9 deletions zencoding/html_navigation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand All @@ -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

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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\-_:\.]*|</[A-Za-z][A-Za-z0-9\-_:\.]*\s*>|/?>|["\'=]|\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')
Expand Down Expand Up @@ -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)

4 changes: 2 additions & 2 deletions zencoding/image_size.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down
2 changes: 1 addition & 1 deletion zencoding/lorem_ipsum.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
20 changes: 10 additions & 10 deletions zencoding/stparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand All @@ -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)


Expand All @@ -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)
Expand All @@ -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)


Expand All @@ -158,4 +158,4 @@ def get_settings(user_settings=None):
parse(settings)

return settings


4 changes: 2 additions & 2 deletions zencoding/zen_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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))
Expand Down
29 changes: 15 additions & 14 deletions zencoding/zen_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 ''
Expand All @@ -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:
Expand Down Expand Up @@ -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])
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
13 changes: 7 additions & 6 deletions zencoding/zen_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down