Permalink
Browse files

Replaces "dict.has_key(k)" with "k in dict" plus a few nitpicks.

  • Loading branch information...
1 parent 5bc1328 commit e00a937715950a4b1fe99c0a40a910571dac1f52 @BertrandBordage BertrandBordage committed Jun 12, 2012
@@ -23,7 +23,7 @@ def entangle(func):
def decorated(func, *args, **kw):
def kwpop(default, *names):
for name in names:
- if kw.has_key(name):
+ if name in kw:
return kw.pop(name)
return default
View
@@ -204,14 +204,14 @@ def atPage(self, name, pseudopage, declarations):
data = result[0].values()[0]
pageBorder = data.get("-pdf-frame-border", None)
- if c.templateList.has_key(name):
+ if name in c.templateList:
log.warn(self.c.warning("template '%s' has already been defined", name))
- if data.has_key("-pdf-page-size"):
+ if "-pdf-page-size" in data:
c.pageSize = xhtml2pdf.default.PML_PAGESIZES.get(str(data["-pdf-page-size"]).lower(), c.pageSize)
isLandscape = False
- if data.has_key("size"):
+ if "size" in data:
size = data["size"]
# print size, c.pageSize
if type(size) is not types.ListType:
@@ -223,7 +223,7 @@ def atPage(self, name, pseudopage, declarations):
sizeList.append(getSize(value))
elif valueStr == "landscape":
isLandscape = True
- elif xhtml2pdf.default.PML_PAGESIZES.has_key(valueStr):
+ elif valueStr in xhtml2pdf.default.PML_PAGESIZES:
c.pageSize = xhtml2pdf.default.PML_PAGESIZES[valueStr]
else:
log.warn(c.warning("Unknown size value for @page"))
@@ -235,7 +235,7 @@ def atPage(self, name, pseudopage, declarations):
for prop in ("margin-top", "margin-left", "margin-right", "margin-bottom",
"top", "left", "right", "bottom", "width", "height"):
- if data.has_key(prop):
+ if prop in data:
c.frameList.append(self._pisaAddFrame(name, data, first=True, border=pageBorder, size=c.pageSize))
break
# self._drawing = PmlPageDrawing(self._pagesize)
View
@@ -102,7 +102,7 @@ def pisaDocument(src, dest=None, path=None, link_callback=None, debug=0,
allowSplitting=1)
# Prepare templates and their frames
- if context.templateList.has_key("body"):
+ if "body" in context.templateList:
body = context.templateList["body"]
del context.templateList["body"]
else:
View
@@ -60,7 +60,7 @@ def pisaGetAttributes(c, tag, attributes):
attrs[k] = v
nattrs = {}
- if TAGS.has_key(tag):
+ if tag in TAGS:
block, adef = TAGS[tag]
adef["id"] = STRING
# print block, adef
@@ -70,7 +70,7 @@ def pisaGetAttributes(c, tag, attributes):
# defaults, wenn vorhanden
if type(v) == types.TupleType:
if v[1] == MUST:
- if not attrs.has_key(k):
+ if k not in attrs:
log.warn(c.warning("Attribute '%s' must be set!", k))
nattrs[k] = None
continue
@@ -197,7 +197,7 @@ def getCSSAttr(self, cssCascade, attrName, default=NotImplemented):
style = self.cssStyle
except:
style = self.cssStyle = cssCascade.parser.parseInline(self.cssElement.getStyleAttr() or '')[0]
- if style.has_key(attrName):
+ if attrName in style:
result = style[attrName]
if result == 'inherit':
@@ -256,26 +256,26 @@ def CSSCollect(node, c):
def CSS2Frag(c, kw, isBlock):
# COLORS
- if c.cssAttr.has_key("color"):
+ if "color" in c.cssAttr:
c.frag.textColor = getColor(c.cssAttr["color"])
- if c.cssAttr.has_key("background-color"):
+ if "background-color" in c.cssAttr:
c.frag.backColor = getColor(c.cssAttr["background-color"])
# FONT SIZE, STYLE, WEIGHT
- if c.cssAttr.has_key("font-family"):
+ if "font-family" in c.cssAttr:
c.frag.fontName = c.getFontName(c.cssAttr["font-family"])
- if c.cssAttr.has_key("font-size"):
+ if "font-size" in c.cssAttr:
# XXX inherit
c.frag.fontSize = max(getSize("".join(c.cssAttr["font-size"]), c.frag.fontSize, c.baseFontSize), 1.0)
- if c.cssAttr.has_key("line-height"):
+ if "line-height" in c.cssAttr:
leading = "".join(c.cssAttr["line-height"])
c.frag.leading = getSize(leading, c.frag.fontSize)
c.frag.leadingSource = leading
else:
c.frag.leading = getSize(c.frag.leadingSource, c.frag.fontSize)
- if c.cssAttr.has_key("-pdf-line-spacing"):
+ if "-pdf-line-spacing" in c.cssAttr:
c.frag.leadingSpace = getSize("".join(c.cssAttr["-pdf-line-spacing"]))
# print "line-spacing", c.cssAttr["-pdf-line-spacing"], c.frag.leading
- if c.cssAttr.has_key("font-weight"):
+ if "font-weight" in c.cssAttr:
value = c.cssAttr["font-weight"].lower()
if value in ("bold", "bolder", "500", "600", "700", "800", "900"):
c.frag.bold = 1
@@ -289,94 +289,94 @@ def CSS2Frag(c, kw, isBlock):
if "none" in value:
c.frag.underline = 0
c.frag.strike = 0
- if c.cssAttr.has_key("font-style"):
+ if "font-style" in c.cssAttr:
value = c.cssAttr["font-style"].lower()
if value in ("italic", "oblique"):
c.frag.italic = 1
else:
c.frag.italic = 0
- if c.cssAttr.has_key("white-space"):
+ if "white-space" in c.cssAttr:
# normal | pre | nowrap
c.frag.whiteSpace = str(c.cssAttr["white-space"]).lower()
# ALIGN & VALIGN
- if c.cssAttr.has_key("text-align"):
+ if "text-align" in c.cssAttr:
c.frag.alignment = getAlign(c.cssAttr["text-align"])
- if c.cssAttr.has_key("vertical-align"):
+ if "vertical-align" in c.cssAttr:
c.frag.vAlign = c.cssAttr["vertical-align"]
# HEIGHT & WIDTH
- if c.cssAttr.has_key("height"):
+ if "height" in c.cssAttr:
c.frag.height = "".join(toList(c.cssAttr["height"])) # XXX Relative is not correct!
if c.frag.height in ("auto",):
c.frag.height = None
- if c.cssAttr.has_key("width"):
+ if "width" in c.cssAttr:
# print c.cssAttr["width"]
c.frag.width = "".join(toList(c.cssAttr["width"])) # XXX Relative is not correct!
if c.frag.width in ("auto",):
c.frag.width = None
# ZOOM
- if c.cssAttr.has_key("zoom"):
+ if "zoom" in c.cssAttr:
# print c.cssAttr["width"]
zoom = "".join(toList(c.cssAttr["zoom"])) # XXX Relative is not correct!
if zoom.endswith("%"):
zoom = float(zoom[: - 1]) / 100.0
c.frag.zoom = float(zoom)
# MARGINS & LIST INDENT, STYLE
if isBlock:
- if c.cssAttr.has_key("margin-top"):
+ if "margin-top" in c.cssAttr:
c.frag.spaceBefore = getSize(c.cssAttr["margin-top"], c.frag.fontSize)
- if c.cssAttr.has_key("margin-bottom"):
+ if "margin-bottom" in c.cssAttr:
c.frag.spaceAfter = getSize(c.cssAttr["margin-bottom"], c.frag.fontSize)
- if c.cssAttr.has_key("margin-left"):
+ if "margin-left" in c.cssAttr:
c.frag.bulletIndent = kw["margin-left"] # For lists
kw["margin-left"] += getSize(c.cssAttr["margin-left"], c.frag.fontSize)
c.frag.leftIndent = kw["margin-left"]
# print "MARGIN LEFT", kw["margin-left"], c.frag.bulletIndent
- if c.cssAttr.has_key("margin-right"):
+ if "margin-right" in c.cssAttr:
kw["margin-right"] += getSize(c.cssAttr["margin-right"], c.frag.fontSize)
c.frag.rightIndent = kw["margin-right"]
# print c.frag.rightIndent
- if c.cssAttr.has_key("text-indent"):
+ if "text-indent" in c.cssAttr:
c.frag.firstLineIndent = getSize(c.cssAttr["text-indent"], c.frag.fontSize)
- if c.cssAttr.has_key("list-style-type"):
+ if "list-style-type" in c.cssAttr:
c.frag.listStyleType = str(c.cssAttr["list-style-type"]).lower()
- if c.cssAttr.has_key("list-style-image"):
+ if "list-style-image" in c.cssAttr:
c.frag.listStyleImage = c.getFile(c.cssAttr["list-style-image"])
# PADDINGS
if isBlock:
- if c.cssAttr.has_key("padding-top"):
+ if "padding-top" in c.cssAttr:
c.frag.paddingTop = getSize(c.cssAttr["padding-top"], c.frag.fontSize)
- if c.cssAttr.has_key("padding-bottom"):
+ if "padding-bottom" in c.cssAttr:
c.frag.paddingBottom = getSize(c.cssAttr["padding-bottom"], c.frag.fontSize)
- if c.cssAttr.has_key("padding-left"):
+ if "padding-left" in c.cssAttr:
c.frag.paddingLeft = getSize(c.cssAttr["padding-left"], c.frag.fontSize)
- if c.cssAttr.has_key("padding-right"):
+ if "padding-right" in c.cssAttr:
c.frag.paddingRight = getSize(c.cssAttr["padding-right"], c.frag.fontSize)
# BORDERS
if isBlock:
- if c.cssAttr.has_key("border-top-width"):
+ if "border-top-width" in c.cssAttr:
# log.debug(c.cssAttr["border-top-width"])
c.frag.borderTopWidth = getSize(c.cssAttr["border-top-width"], c.frag.fontSize)
- if c.cssAttr.has_key("border-bottom-width"):
+ if "border-bottom-width" in c.cssAttr:
c.frag.borderBottomWidth = getSize(c.cssAttr["border-bottom-width"], c.frag.fontSize)
- if c.cssAttr.has_key("border-left-width"):
+ if "border-left-width" in c.cssAttr:
c.frag.borderLeftWidth = getSize(c.cssAttr["border-left-width"], c.frag.fontSize)
- if c.cssAttr.has_key("border-right-width"):
+ if "border-right-width" in c.cssAttr:
c.frag.borderRightWidth = getSize(c.cssAttr["border-right-width"], c.frag.fontSize)
- if c.cssAttr.has_key("border-top-style"):
+ if "border-top-style" in c.cssAttr:
c.frag.borderTopStyle = c.cssAttr["border-top-style"]
- if c.cssAttr.has_key("border-bottom-style"):
+ if "border-bottom-style" in c.cssAttr:
c.frag.borderBottomStyle = c.cssAttr["border-bottom-style"]
- if c.cssAttr.has_key("border-left-style"):
+ if "border-left-style" in c.cssAttr:
c.frag.borderLeftStyle = c.cssAttr["border-left-style"]
- if c.cssAttr.has_key("border-right-style"):
+ if "border-right-style" in c.cssAttr:
c.frag.borderRightStyle = c.cssAttr["border-right-style"]
- if c.cssAttr.has_key("border-top-color"):
+ if "border-top-color" in c.cssAttr:
c.frag.borderTopColor = getColor(c.cssAttr["border-top-color"])
- if c.cssAttr.has_key("border-bottom-color"):
+ if "border-bottom-color" in c.cssAttr:
c.frag.borderBottomColor = getColor(c.cssAttr["border-bottom-color"])
- if c.cssAttr.has_key("border-left-color"):
+ if "border-left-color" in c.cssAttr:
c.frag.borderLeftColor = getColor(c.cssAttr["border-left-color"])
- if c.cssAttr.has_key("border-right-color"):
+ if "border-right-color" in c.cssAttr:
c.frag.borderRightColor = getColor(c.cssAttr["border-right-color"])
def pisaPreLoop(node, context, collect=False):
@@ -479,17 +479,17 @@ def pisaLoop(node, context, path=[], **kw):
context.addPara()
# Page break by CSS
- if context.cssAttr.has_key("-pdf-next-page"):
+ if "-pdf-next-page" in context.cssAttr:
context.addStory(NextPageTemplate(str(context.cssAttr["-pdf-next-page"])))
- if context.cssAttr.has_key("-pdf-page-break"):
+ if "-pdf-page-break" in context.cssAttr:
if str(context.cssAttr["-pdf-page-break"]).lower() == "before":
context.addStory(PageBreak())
- if context.cssAttr.has_key("-pdf-frame-break"):
+ if "-pdf-frame-break" in context.cssAttr:
if str(context.cssAttr["-pdf-frame-break"]).lower() == "before":
context.addStory(FrameBreak())
if str(context.cssAttr["-pdf-frame-break"]).lower() == "after":
frameBreakAfter = True
- if context.cssAttr.has_key("page-break-before"):
+ if "page-break-before" in context.cssAttr:
if str(context.cssAttr["page-break-before"]).lower() == "always":
context.addStory(PageBreak())
if str(context.cssAttr["page-break-before"]).lower() == "right":
@@ -498,7 +498,7 @@ def pisaLoop(node, context, path=[], **kw):
if str(context.cssAttr["page-break-before"]).lower() == "left":
context.addStory(PageBreak())
context.addStory(PmlLeftPageBreak())
- if context.cssAttr.has_key("page-break-after"):
+ if "page-break-after" in context.cssAttr:
if str(context.cssAttr["page-break-after"]).lower() == "always":
pageBreakAfter = PAGE_BREAK
if str(context.cssAttr["page-break-after"]).lower() == "right":
@@ -519,28 +519,28 @@ def pisaLoop(node, context, path=[], **kw):
CSS2Frag(context, kw, isBlock)
# EXTRAS
- if context.cssAttr.has_key("-pdf-keep-with-next"):
+ if "-pdf-keep-with-next" in context.cssAttr:
context.frag.keepWithNext = getBool(context.cssAttr["-pdf-keep-with-next"])
- if context.cssAttr.has_key("-pdf-outline"):
+ if "-pdf-outline" in context.cssAttr:
context.frag.outline = getBool(context.cssAttr["-pdf-outline"])
- if context.cssAttr.has_key("-pdf-outline-level"):
+ if "-pdf-outline-level" in context.cssAttr:
context.frag.outlineLevel = int(context.cssAttr["-pdf-outline-level"])
- if context.cssAttr.has_key("-pdf-outline-open"):
+ if "-pdf-outline-open" in context.cssAttr:
context.frag.outlineOpen = getBool(context.cssAttr["-pdf-outline-open"])
- if context.cssAttr.has_key("-pdf-word-wrap"):
+ if "-pdf-word-wrap" in context.cssAttr:
context.frag.wordWrap = context.cssAttr["-pdf-word-wrap"]
# handle keep-in-frame
keepInFrameMode = None
keepInFrameMaxWidth = 0
keepInFrameMaxHeight = 0
- if context.cssAttr.has_key("-pdf-keep-in-frame-mode"):
+ if "-pdf-keep-in-frame-mode" in context.cssAttr:
value = str(context.cssAttr["-pdf-keep-in-frame-mode"]).strip().lower()
if value in ("shrink", "error", "overflow", "truncate"):
keepInFrameMode = value
- if context.cssAttr.has_key("-pdf-keep-in-frame-max-width"):
+ if "-pdf-keep-in-frame-max-width" in context.cssAttr:
keepInFrameMaxWidth = getSize("".join(context.cssAttr["-pdf-keep-in-frame-max-width"]))
- if context.cssAttr.has_key("-pdf-keep-in-frame-max-height"):
+ if "-pdf-keep-in-frame-max-height" in context.cssAttr:
keepInFrameMaxHeight = getSize("".join(context.cssAttr["-pdf-keep-in-frame-max-height"]))
# ignore nested keep-in-frames, tables have their own KIF handling
View
@@ -535,7 +535,7 @@ def start(self, c):
name = attrs["name"]
c.frameList = []
c.frameStaticList = []
- if c.templateList.has_key(name):
+ if name in c.templateList:
log.warn(c.warning("template '%s' has already been defined", name))
'''
View
@@ -263,11 +263,11 @@ def getSize(value, relative=0, base=None, default=0.0):
return (relative * float(value[:-1].strip())) / 100.0 # 1% = (fontSize * 1) / 100
elif value in ("normal", "inherit"):
return relative
- elif _relativeSizeTable.has_key(value):
+ elif value in _relativeSizeTable:
if base:
return max(MIN_FONT_SIZE, base * _relativeSizeTable[value])
return max(MIN_FONT_SIZE, relative * _relativeSizeTable[value])
- elif _absoluteSizeTable.has_key(value):
+ elif value in _absoluteSizeTable:
if base:
return max(MIN_FONT_SIZE, base * _absoluteSizeTable[value])
return max(MIN_FONT_SIZE, relative * _absoluteSizeTable[value])
Oops, something went wrong.

0 comments on commit e00a937

Please sign in to comment.