diff options
Diffstat (limited to 'Pb_Api')
| -rw-r--r-- | Pb_Api/ImPattern/Params.py | 14 | ||||
| -rw-r--r-- | Pb_Api/Param/__init__.py | 4 | ||||
| -rw-r--r-- | Pb_Api/Params.py | 56 | ||||
| -rw-r--r-- | Pb_Api/__init__.py | 1 |
4 files changed, 33 insertions, 42 deletions
diff --git a/Pb_Api/ImPattern/Params.py b/Pb_Api/ImPattern/Params.py index a046d5e..1d31645 100644 --- a/Pb_Api/ImPattern/Params.py +++ b/Pb_Api/ImPattern/Params.py @@ -17,24 +17,14 @@ class Pattern_Url_Option(Pb_Api_Param_Option): def from_name(cls, **kwargs): formatted = "{}/{}.png".format(PATTERN_BASE_URL, kwargs["value"]) return cls(weight=kwargs["weight"], value=formatted ) - -class Pattern_Url_Options: - def __init__(self, arr): - self._values = arr - def __iter__(self): - return self._values - def grep(self, s): - for i in self: - if re.match(s, i): - return i pattern_url_options = Pb_Api_Param_Options([ Pattern_Url_Option.from_name(weight=0, value=i) for i in range(1,100) ] + [ - Pattern_Url_Option.from_name(weight=0, value="A{}".format(i)) for i in range(0, 42) + Pattern_Url_Option.from_name(weight=0, value="a{}".format(i)) for i in range(0, 42) ]) -pattern_url_options.search("A10").weight = 20; +pattern_url_options.search("a10").weight = 20; class ImPattern_Params(Pb_Api_Params): def __init__(self): diff --git a/Pb_Api/Param/__init__.py b/Pb_Api/Param/__init__.py index 362a3f7..58b3eb0 100644 --- a/Pb_Api/Param/__init__.py +++ b/Pb_Api/Param/__init__.py @@ -6,7 +6,7 @@ class Pb_Api_Param(object): self._value_default = None self.name = name self.required = required - self.is_ready = 0 #should I try that? + self.is_ready = 0 self.value = value self.set_by_user = set_by_user def __str__(self): @@ -20,7 +20,7 @@ class Pb_Api_Param(object): self._value = value if not self._value is None: self.is_ready = 1 - self.set_by_user = 1 #like that? yeah also need method for setting default value + self.set_by_user = 1 value = property(get_value, set_value) def default(self, value): diff --git a/Pb_Api/Params.py b/Pb_Api/Params.py index fff0696..9ab90a9 100644 --- a/Pb_Api/Params.py +++ b/Pb_Api/Params.py @@ -1,34 +1,34 @@ import pprint class Pb_Api_Params(object): - #so how do we need to change these? - def param(self, name): - for p in self.params: - if p.name == name: - return p - return None + def param(self, name): + for p in self.params: + if p.name == name: + return p + return None +# def __iter__(self): +# return iter(self.params) - def __str__(self): - return pprint.pformat({ "params": map(lambda x: vars(x), self.params) }) + def __str__(self): + return pprint.pformat({ "params": map(lambda x: vars(x), self.params) }) -#do we need to add a simple __iter__ attribute to that class so that map will work, or is it already -#iterating? it is already + def randomize(self): + for el in self.params: + if el.set_by_user: + continue + el.randomize() + + def __dict__(self): + return dict(self) + - - def randomize(self): - for el in self.params: - if el.set_by_user: - continue - el.randomize() - - - def is_ready(self): - for p in self.params: - if not p.is_ready(): - return 0 - return 1 - def as_hash(self): - result = {} - for p in self.params: - result[p.name] = p.value - return result + def is_ready(self): + for p in self.params: + if not p.is_ready(): + return 0 + return 1 + def as_hash(self): + result = {} + for p in self.params: + result[p.name] = p.value + return result diff --git a/Pb_Api/__init__.py b/Pb_Api/__init__.py index ced9983..1b89b9b 100644 --- a/Pb_Api/__init__.py +++ b/Pb_Api/__init__.py @@ -18,6 +18,7 @@ class Pb_Api: def post_request(self, url, params): params = urllib.urlencode(params) sys.stderr.write(params) + sys.stderr.write(url) headers = { "Content-type": "application/x-www-form-urlencoded", "User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.94 Safari/537.36", |
