def respond_status(self, code, message = None, break_now = True): ''' Set the response status. *code* is a HTTP status code in interger. *message* is a response reason. *break_now* is a boolean. If *True*, this method will raise CherryPy's HTTPError exception. Otherwise, return status. ''' if not base.isString(message) or len(message) == 0: message = None if 300 <= code < 400: del cherrypy.response.headers['Content-Type'] if code >= 400 and break_now: if message: raise cherrypy.HTTPError(code, message) else: raise cherrypy.HTTPError(code) else: if message: cherrypy.response.status = u"%d %s" % (code, message) else: cherrypy.response.status = code return base.convertToUnicode(cherrypy.response.status)
def get(url, data = None, headers = None, bypass_url_encoding=False): response = None if LOAD_GAE: # Use Google API # Set the optional parameters data = data and data or {} headers = headers and headers or {} # Prepare the data url = base.convertToUnicode(url) form_data = urllib.urlencode(data) #query_string = Http.build_data(data) # Merge data #url = url + query_string # Make a call raw_response = urlfetch.fetch(url, form_data) response = Response(raw_response.status_code, raw_response.headers, raw_response.content) # free memory #del query_string del url del raw_response else: response = Http.do("get", url, data, headers, bypass_url_encoding) return response
def to_xml_data_block(self): __r = self.__reference if self.__type not in [int, float]: __r = "<![CDATA[%s]]>" % base.convertToUnicode(self.__reference) return { 'reference': __r, 'type': TegamiEntityProperty.type_to_string(self.__reference) }
def to_dict(self): __r = self.__reference if self.__type not in [int, float, str, unicode, tuple, list, dict]: __r = base.convertToUnicode(self.__reference) return { 'reference': __r, 'type': TegamiEntityProperty.type_to_string(self.__reference) }
def init(self, combinators): # Check type if not base.isString(combinators): raise KotobaInvalidSelection("Not a string") self.combinators = combinators # Prepare data raw_combinators = base.convertToUnicode(combinators) raw_combinators = re.split("\s*,\s*", raw_combinators.strip()) for raw_combinator in raw_combinators: if raw_combinator == '': raise KotobaInvalidSelectionException("Invalid multiple combinators. Perhaps there is a leading/tailing comma or an empty combinator/selector.") combinator = Combinator(raw_combinator) self.append(combinator)
def doTest(tester, retest): global totalUsageTime maxRepeat = retest result = "o" startingTime = None elapsedTimes = [0, 0] reason = '' val = None tb = None repeat = 0 while repeat < maxRepeat: try: startingTime = time() tester() except: result = "x" reason = " (E: %s)" % base.convertToUnicode(exc_info()[0]) val, tb = exc_info()[1], exc_info()[2] finally: elapsedTime = time() - startingTime totalUsageTime += elapsedTime elapsedTimes[repeat] = elapsedTime repeat += 1 if len(reason) > 0: break print " %s\t%2.4f\t%2.4f\t%s%s" % (result, elapsedTimes[0], elapsedTimes[1], tester.__doc__, reason) if tb is not None: print "."*80 print_tb(tb) print " Given value: %s" % val print "."*80
def init(self, combinator): # Check type if not base.isString(combinator): raise KotobaInvalidSelectionException("Not a string") self.combinator = combinator # Check for invalid combinator (part 1: not start or end with combining instruction) if re.search("^(>|\+|~)", combinator) or re.search("(>|\+|~)$", combinator): raise KotobaInvalidSelectionException("Not start or end with combining instruction (>, +, ~)") # Prepare data raw_combinator = base.convertToUnicode(combinator) raw_combinator = re.split("\s+", raw_combinator.strip()) # Local buffer raise_on_next_combiner = False # Note: at this point, there is no combiners leading or tailing the combinator. for combo_block in raw_combinator: if combo_block in Selector.combination_map.keys(): # [If it is a registered combiner] if not raise_on_next_combiner: raise_on_next_combiner = True self[-1].combo_method = Selector.combination_map[combo_block] log.debug("Combinator.init: Reset the iteration method of the last selector (%s) to %s" % (self[-1].name, self[-1].combo_method)) else: raise KotobaInvalidSelectionException("No consecutive combiners allowed") else: # [Not registered combiner] raise_on_next_combiner = False selector = Selector(combo_block) self.append(selector) #print "Combinators >> init >> combo not registered" #print self[-1] self[-1].end_of_query = True
def type_to_string(reference): return sub("^[^']+'", "", sub("'[^']+$", "", base.convertToUnicode(type(reference))))
def __extract_class_name(self, class_ref): match = re.search("\.([^.]+)'>", ybase.convertToUnicode(class_ref)) return match.groups()[0]