Skip to content

Commit

Permalink
Merge pull request #95 from fortable1999/master
Browse files Browse the repository at this point in the history
added python 3 support
  • Loading branch information
faceleg committed Jan 19, 2014
2 parents 4cd3787 + 68893b3 commit ea35be6
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 16 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ Sparkup
**Sparkup lets you write HTML code faster.** Don't believe us?
[See it in action!](http://www.youtube.com/watch?v=Jw3jipcenKc)

Fixed by Zhao:
This is a fork of original version. This version support both python 2 and 3.

You can write HTML in a CSS-like syntax, and have Sparkup handle the expansion to full HTML
code. It is meant to help you write long HTML blocks in your text editor by letting you
type less characters than needed.
Expand Down
39 changes: 23 additions & 16 deletions sparkup.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
version = "0.1.3"
version = "0.1.4"

import getopt
import sys
import re

# =============================================================================

def iteritems(obj):
"""iteritems() in python2 and items() in python3"""
if sys.version[0] == '2':
return obj.iteritems()
else:
return obj.items()

class Dialect:
shortcuts = {}
synonyms = {}
Expand Down Expand Up @@ -678,7 +685,7 @@ def get_default_tag(self):
"""

output = '%s' % (self.name)
for key, value in self.attributes.iteritems():
for key, value in iteritems(self.attributes):
output += ' %s="%s"' % (key, value)
return output

Expand Down Expand Up @@ -764,7 +771,7 @@ def _fill_attributes(self):
# Make sure <a>'s have a href, <img>'s have an src, etc.
required = self.parser.dialect.required

for element, attribs in required.iteritems():
for element, attribs in iteritems(required):
if self.name == element:
for attrib in attribs:
if attrib not in self.attributes:
Expand Down Expand Up @@ -860,7 +867,7 @@ def _init_element(self):
if ':' in name:
shortcuts = self.parser.dialect.shortcuts
if name in shortcuts.keys():
for key, value in shortcuts[name].iteritems():
for key, value in iteritems(shortcuts[name]):
setattr(self, key, value)
if 'html' in name:
return
Expand Down Expand Up @@ -972,20 +979,20 @@ def start(self, options=None, str=None, ret=None):
return self.parse(str=str, ret=ret)

def help(self):
print "Usage: %s [OPTIONS]" % sys.argv[0]
print "Expands input into HTML."
print ""
print("Usage: %s [OPTIONS]" % sys.argv[0])
print("Expands input into HTML.")
print("")
for short, long, info in self.options.cmdline_keys:
if "Deprecated" in info: continue
if not short == '': short = '-%s,' % short
if not long == '': long = '--%s' % long.replace("=", "=XXX")

print "%6s %-25s %s" % (short, long, info)
print ""
print "\n".join(self.help_content)
print("%6s %-25s %s" % (short, long, info))
print("")
print("\n".join(self.help_content))

def version(self):
print "Uhm, yeah."
print("Uhm, yeah.")

def parse(self, str=None, ret=None):
self.parser = Parser(self.options)
Expand Down Expand Up @@ -1013,8 +1020,8 @@ def parse(self, str=None, ret=None):

except:
sys.stderr.write("Parse error. Check your input.\n")
print sys.exc_info()[0]
print sys.exc_info()[1]
print(sys.exc_info()[0])
print(sys.exc_info()[1])

def exit(self):
sys.exit()
Expand All @@ -1032,7 +1039,7 @@ def __init__(self, router, argv, options=None):

# `options` can be given as a dict of stuff to preload
if options:
for k, v in options.iteritems():
for k, v in iteritems(options):
self.options[k] = v
return

Expand Down Expand Up @@ -1066,11 +1073,11 @@ def __init__(self, router, argv, options=None):
elif key[0:1] == '-':
for short, long, info in self.cmdline_keys:
if short == key[1:]:
print long
print(long)
options[long] = True

# Done
for k, v in options.iteritems():
for k, v in iteritems(options):
self.options[k] = v

def __getattr__(self, attr):
Expand Down

0 comments on commit ea35be6

Please sign in to comment.