HTD

Merge lp:~ahayzen/htd/3.0.regular_expressions_fix into lp:htd/3.0

Proposed by Andrew Hayzen
Status: Merged
Approved by: Andrew Hayzen
Approved revision: 20
Merged at revision: 19
Proposed branch: lp:~ahayzen/htd/3.0.regular_expressions_fix
Merge into: lp:htd/3.0
Diff against target: 130 lines (+25/-17)
3 files modified
src/htd30/_objects/attribute.py (+2/-0)
src/htd30/_workers/__init__.py (+4/-7)
src/htd30/_workers/file_fix.py (+19/-10)
To merge this branch: bzr merge lp:~ahayzen/htd/3.0.regular_expressions_fix
Reviewer Review Type Date Requested Status
Andrew Hayzen Approve
Review via email: mp+115037@code.launchpad.net
To post a comment you must log in.
20. By Andrew Hayzen

Added fix, so that if reg expr is NULL HTD does not try to parse a blank expression.

Revision history for this message
Andrew Hayzen (ahayzen) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/htd30/_objects/attribute.py'
2--- src/htd30/_objects/attribute.py 2012-07-13 20:47:16 +0000
3+++ src/htd30/_objects/attribute.py 2012-07-15 20:16:23 +0000
4@@ -135,6 +135,8 @@
5
6 @reg_expr.setter
7 def reg_expr(self, expr):
8+ if type(expr) is not bytes and not not expr:
9+ expr = str(expr).encode("ISO-8859-1")
10 self._re = expr
11
12 @property
13
14=== modified file 'src/htd30/_workers/__init__.py'
15--- src/htd30/_workers/__init__.py 2012-07-13 17:48:21 +0000
16+++ src/htd30/_workers/__init__.py 2012-07-15 20:16:23 +0000
17@@ -24,8 +24,8 @@
18 from .. import AuthenticationError
19 from .._base import File, convert_location
20 import os
21-import re
22 from random import choice
23+from re import sub
24 from struct import unpack, pack
25 from sys import platform
26 from time import time
27@@ -66,12 +66,6 @@
28 else:
29 continue
30
31- if attr.reg_expr is not None: # Filter Check
32- x = re.findall(attr.reg_expr, tmp)
33- if x[0] != tmp:
34- raise ValueError('Filter failed to match pattern for "%s".' %
35- att)
36-
37 typed = attr.dtype # Load dtype
38
39 if typed.f(tmp) is False: # Type check
40@@ -103,7 +97,10 @@
41 """ Unsantise data so that it can be used by the client """
42 for att in data:
43 dtype = attributes[att].dtype
44+ patt = attributes[att].reg_expr
45 if data[att] is not None:
46+ if not not patt: # Run reg expr
47+ data[att] = sub(patt, b"", data[att])
48 data[att] = dtype.u(data[att])
49
50 return data
51
52=== modified file 'src/htd30/_workers/file_fix.py'
53--- src/htd30/_workers/file_fix.py 2012-07-11 21:02:52 +0000
54+++ src/htd30/_workers/file_fix.py 2012-07-15 20:16:23 +0000
55@@ -91,7 +91,7 @@
56
57 data = data.rsplit(b".", 1)
58
59- if len(data) == 1:
60+ if len(data[0]) == 0:
61 output[atts[att][1]] = None
62 else:
63 output[atts[att][1]] = data[0]
64@@ -112,8 +112,9 @@
65 atts = self.header["ATTBYID"]
66
67 for att in atts:
68- string.append((value[atts[att][1]] + b".").ljust(atts[att][0] + 1,
69- self.escape_char))
70+ string.append(b"".join([value[atts[att][1]] or
71+ b"", b"."]).ljust(atts[att][0] + 1,
72+ self.escape_char))
73
74 string = b"".join(string)
75
76@@ -221,8 +222,9 @@
77 atts = self.header["ATTBYID"]
78
79 for att in atts:
80- string.append((data[atts[att][1]] + b".").ljust(atts[att][0] + 1,
81- self.escape_char))
82+ string.append(b"".join([data[atts[att][1]] or
83+ b"", b"."]).ljust(atts[att][0] + 1,
84+ self.escape_char))
85
86 string = b"".join(string)
87
88@@ -257,14 +259,21 @@
89
90 raw = raw.rsplit(b".", 1)
91
92- if len(raw) == 1:
93+ if len(raw[0]) == 0:
94 raw = None
95 else:
96 raw = raw[0]
97
98 tmp = (yield {attribute: raw})
99- output = (tmp[attribute] + b".").ljust(nsize,
100- self.escape_char)
101+
102+ string.append(b"".join([data[atts[att][1]] or
103+ b"", b"."]).ljust(atts[att][0] + 1,
104+ self.escape_char))
105+
106+ output = b"".join([tmp[attribute] or
107+ b"", b"."]).ljust(nsize,
108+ self.escape_char)
109+
110 self._file[pos:pos + osize] = output
111
112 pos += nsize
113@@ -274,7 +283,7 @@
114
115 raise StopIteration
116
117- def select(self, attribute, start=0, stop=-1):
118+ def select(self, attribute, start=0, stop= -1):
119 pos = start
120 atts = self.header["ATTBYID"]
121 s = self._file.seek
122@@ -296,7 +305,7 @@
123
124 d = d.rsplit(b".", 1)
125
126- if len(d) == 1:
127+ if len(d[0]) == 0:
128 d = None
129 else:
130 d = d[0]

Subscribers

People subscribed via source and target branches

to all changes: