예제 #1
0
 def handle_starttag(self, tag, attrs):
     attr_d = dict(attrs)
     title = attr_d.get('title', '').strip()
     if tag in self.link_types.keys():
         target = attr_d.get(self.link_types[tag], "")
         if target:
             if "#" in target:
                 target = target[:target.index('#')]
             self.process_link(target, tag, title)
     elif tag == 'base':
         self.base = attr_d.get('href', self.base)
     elif tag == 'meta' and \
       attr_d.get('http-equiv', '').lower() == 'content-type':
         ct = attr_d.get('content', None)
         if ct:
             try:
                 media_type, params = ct.split(";", 1)
             except ValueError:
                 media_type, params = ct, ''
             media_type = media_type.lower()
             param_dict = {}
             for param in rh.split_string(
                 params, syntax.PARAMETER, "\s*;\s*"
             ):
                 try:
                     a, v = param.split("=", 1)
                     param_dict[a.lower()] = rh.unquote_string(v)
                 except ValueError:
                     param_dict[param.lower()] = None
             self.doc_enc = param_dict.get('charset', self.doc_enc)
예제 #2
0
 def handle_starttag(self, tag, attrs):
     attr_d = dict(attrs)
     title = attr_d.get('title', '').strip()
     if tag in self.link_types.keys():
         target = attr_d.get(self.link_types[tag], "")
         if target:
             if "#" in target:
                 target = target[:target.index('#')]
             self.process_link(target, tag, title)
     elif tag == 'base':
         self.base = attr_d.get('href', self.base)
     elif tag == 'meta' and \
       attr_d.get('http-equiv', '').lower() == 'content-type':
         ct = attr_d.get('content', None)
         if ct:
             try:
                 media_type, params = ct.split(";", 1)
             except ValueError:
                 media_type, params = ct, ''
             media_type = media_type.lower()
             param_dict = {}
             for param in rh.split_string(params, syntax.PARAMETER,
                                          "\s*;\s*"):
                 try:
                     a, v = param.split("=", 1)
                     param_dict[a.lower()] = rh.unquote_string(v)
                 except ValueError:
                     param_dict[param.lower()] = None
             self.doc_enc = param_dict.get('charset', self.doc_enc)
예제 #3
0
def parse(subject, value, red):
    try:
        attr, attr_val = value.split("=", 1)
        attr_val = rh.unquote_string(attr_val)
    except ValueError:
        attr = value
        attr_val = None
    return (attr.lower(), attr_val)
예제 #4
0
def parse(subject, value, red):
    try:
        attr, attr_val = value.split("=", 1)
        attr_val = rh.unquote_string(attr_val)
    except ValueError:
        attr = value
        attr_val = None
    return (attr.lower(), attr_val)
예제 #5
0
def parse(subject, value, red):
    try:
        directive_name, directive_val = value.split("=", 1)
        directive_val = rh.unquote_string(directive_val)
    except ValueError:
        directive_name = value
        directive_val = None
    directive_name = directive_name.lower()
    # TODO: warn on upper-cased directives?
    if directive_name in ['max-age', 's-maxage']:
        try:
            directive_val = int(directive_val)
        except (ValueError, TypeError):
            red.set_message(subject, rs.BAD_CC_SYNTAX,
                            bad_cc_attr=directive_name
            )
            return None
    return (directive_name, directive_val)
예제 #6
0
 def test_unquote_string(self):
     i = 0
     for (instr, expected_str, expected_msgs) in [
         ('foo', 'foo', []),
         ('"foo"', 'foo', []),
         (r'"fo\"o"', 'fo"o', []),
         (r'"f\"o\"o"', 'f"o"o', []),
         (r'"fo\\o"', r'fo\o', []),
         (r'"f\\o\\o"', r'f\o\o', []),
         (r'"fo\o"', 'foo', []),
     ]:
         self.red.__init__()
         out_str = rh.unquote_string(unicode(instr))
         diff = set([n.__name__ for n in expected_msgs
                     ]).symmetric_difference(set(self.red.msg_classes))
         self.assertEqual(len(diff), 0,
                          "[%s] Mismatched messages: %s" % (i, diff))
         self.assertEqual(
             expected_str, out_str,
             "[%s] %s != %s" % (i, str(expected_str), str(out_str)))
         i += 1
예제 #7
0
 def test_unquote_string(self):
     i = 0
     for (instr, expected_str, expected_msgs) in [
         ('foo', 'foo', []),
         ('"foo"', 'foo', []),
         (r'"fo\"o"', 'fo"o', []),
         (r'"f\"o\"o"', 'f"o"o', []),
         (r'"fo\\o"', r'fo\o', []),
         (r'"f\\o\\o"', r'f\o\o', []),
         (r'"fo\o"', 'foo', []),
     ]:
         self.red.__init__()
         out_str = rh.unquote_string(unicode(instr))
         diff = set(
             [n.__name__ for n in expected_msgs]).symmetric_difference(
             set(self.red.msg_classes)
         )
         self.assertEqual(len(diff), 0, 
             "[%s] Mismatched messages: %s" % (i, diff)
         )
         self.assertEqual(expected_str, out_str, 
             "[%s] %s != %s" % (i, str(expected_str), str(out_str)))
         i += 1
예제 #8
0
파일: etag.py 프로젝트: bdarnell/redbot
def parse(subject, value, red):
    if value[:2] == 'W/':
        return (True, rh.unquote_string(value[2:]))
    else:
        return (False, rh.unquote_string(value))
예제 #9
0
파일: etag.py 프로젝트: hsavran/redbot
def parse(subject, value, red):
    if value[:2] == 'W/':
        return (True, rh.unquote_string(value[2:]))
    else:
        return (False, rh.unquote_string(value))