Example #1
0
 def lookup_country(self, address):
     ''' Lookup for country entry '''
     country = self.countries.country_code_by_addr(address)
     if not country:
         logging.error("Geolocator: %s: not found", address)
         return ""
     return utils.stringify(country)
Example #2
0
    def serialize_headers(self):
        v = []

        if self.method:
            v.append(self.method)
            v.append(" ")
            if self.pathquery:
                v.append(self.pathquery)
            elif self.uri:
                v.append(self.uri)
            else:
                v.append("/")
            v.append(" ")
            v.append(self.protocol)

        else:
            v.append(self.protocol)
            v.append(" ")
            v.append(self.code)
            v.append(" ")
            v.append(self.reason)

        LOG.debug("> %s" % ("".join(v)))
        v.append("\r\n")

        for key, value in self.headers.items():
            key = "-".join(map(lambda s: s.capitalize(), key.split("-")))
            v.append(key)
            v.append(": ")
            v.append(value)

            LOG.debug("> %s: %s" % (key, value))
            v.append("\r\n")

        LOG.debug(">")
        v.append("\r\n")

        s = "".join(v)
        s = utils.stringify(s)
        return StringIO.StringIO(s)
Example #3
0
def kv_to_string(kv):

    """Convert (key,value) to string.  Adds a trailing newline so
       we can pass the return value directly to fp.write()."""

    return "%s=%s\n" % (utils.stringify(kv[0]), utils.stringify(kv[1]))
Example #4
0
 def lookup_country(self, address):
     country = self.countries.country_code_by_addr(address)
     if not country:
         LOG.error("Geolocator: %s: not found" % address)
         return ""
     return utils.stringify(country)
Example #5
0
def object_to_qs(obj):
    dictionary = {}
    for name, value in obj.__dict__.items():
        dictionary[name] = stringify(value)
    s = urllib.urlencode(dictionary)
    return s