##// END OF EJS Templates
bundle2: enforce parttype as alphanumerical...
Pierre-Yves David -
r23868:405eacbe default
parent child Browse files
Show More
@@ -85,7 +85,7 b' Binary format is as follow'
85
85
86 :typesize: (one byte)
86 :typesize: (one byte)
87
87
88 :parttype: alphanumerical part name
88 :parttype: alphanumerical part name (restricted to ^a-zA-Z0-9_:-])
89
89
90 :partid: A 32bits integer (unique in the bundle) that can be used to refer
90 :partid: A 32bits integer (unique in the bundle) that can be used to refer
91 to this part.
91 to this part.
@@ -153,6 +153,7 b' import string'
153 import obsolete
153 import obsolete
154 import pushkey
154 import pushkey
155 import url
155 import url
156 import re
156
157
157 import changegroup, error
158 import changegroup, error
158 from i18n import _
159 from i18n import _
@@ -171,6 +172,13 b' from i18n import _'
171
172
172 preferedchunksize = 4096
173 preferedchunksize = 4096
173
174
175 _parttypeforbidden = re.compile('[^a-zA-Z0-9_:-]')
176
177 def validateparttype(parttype):
178 """raise ValueError if a parttype contains invalid character"""
179 if _parttypeforbidden.match(parttype):
180 raise ValueError(parttype)
181
174 def _makefpartparamsizes(nbparams):
182 def _makefpartparamsizes(nbparams):
175 """return a struct format to read part parameter sizes
183 """return a struct format to read part parameter sizes
176
184
@@ -191,6 +199,7 b' def parthandler(parttype, params=()):'
191 '''process a part of type "my part".'''
199 '''process a part of type "my part".'''
192 ...
200 ...
193 """
201 """
202 validateparttype(parttype)
194 def _decorator(func):
203 def _decorator(func):
195 lparttype = parttype.lower() # enforce lower case matching.
204 lparttype = parttype.lower() # enforce lower case matching.
196 assert lparttype not in parthandlermapping
205 assert lparttype not in parthandlermapping
@@ -590,6 +599,7 b' class bundlepart(object):'
590
599
591 def __init__(self, parttype, mandatoryparams=(), advisoryparams=(),
600 def __init__(self, parttype, mandatoryparams=(), advisoryparams=(),
592 data='', mandatory=True):
601 data='', mandatory=True):
602 validateparttype(parttype)
593 self.id = None
603 self.id = None
594 self.type = parttype
604 self.type = parttype
595 self._data = data
605 self._data = data
General Comments 0
You need to be logged in to leave comments. Login now