Ejemplo n.º 1
0
    def test_is_hashtag(self):
        valid = ['#turses', '#cúrcuma', '#4n_4Wfu1_H45hT46']
        for hashtag in valid:
            self.failUnless(is_hashtag(hashtag))

        invalid = ['s#turses', '#']
        for hashtag in invalid:
            self.failIf(is_hashtag(hashtag))
Ejemplo n.º 2
0
    def test_is_hashtag(self):
        valid = ['#turses', '#cúrcuma', '#4n_4Wfu1_H45hT46']
        for hashtag in valid:
            self.assertTrue(is_hashtag(hashtag))

        invalid = ['s#turses', '#']
        for hashtag in invalid:
            self.assertFalse(is_hashtag(hashtag))
Ejemplo n.º 3
0
    def test_is_hashtag(self):
        valid = ['#turses', '#cúrcuma', '#4n_4Wfu1_H45hT46']
        for hashtag in valid:
            self.assertTrue(is_hashtag(hashtag))

        invalid = ['s#turses', '#']
        for hashtag in invalid:
            self.assertFalse(is_hashtag(hashtag))
Ejemplo n.º 4
0
    def test_is_hashtag(self):
        valid = ['#turses', '#cúrcuma', '#4n_4Wfu1_H45hT46']
        for hashtag in valid:
            self.failUnless(is_hashtag(hashtag))

        invalid = ['s#turses', '#']
        for hashtag in invalid:
            self.failIf(is_hashtag(hashtag))
Ejemplo n.º 5
0
Archivo: ui.py Proyecto: Erik-k/turses
def apply_attribute(string,
                    hashtag='hashtag',
                    attag='attag',
                    url='url'):
    """
    Apply an attribute to `string` dependending on wether it is
    a hashtag, a Twitter username or an URL.

    >>> apply_attribute('#Python')
    ('hashtag', u'#Python')
    >>> apply_attribute('@dialelo')
    ('attag', u'@dialelo')
    >>> apply_attribute('@dialelo',
                        attag='username')
    ('username', u'@dialelo')
    >>> apply_attribute('http://www.dialelo.com')
    ('url', u'http://www.dialelo.com')
    >>> apply_attribute('turses')
    u'turses'
    """
    string = unicode(string)

    if is_hashtag(string):
        return (hashtag, string)
    elif string.startswith('@') and is_username(string[1:]):
        return (attag, string)
    elif is_url(string):
        return (url, string)
    else:
        return string
Ejemplo n.º 6
0
def apply_attribute(string,
                    hashtag='hashtag',
                    attag='attag',
                    url='url'):
    """
    Apply an attribute to `string` dependending on wether it is
    a hashtag, a Twitter username or an URL.

    >>> apply_attribute('#Python')
    ('hashtag', u'#Python')
    >>> apply_attribute('@dialelo')
    ('attag', u'@dialelo')
    >>> apply_attribute('@dialelo',
                        attag='username')
    ('username', u'@dialelo')
    >>> apply_attribute('http://www.dialelo.com')
    ('url', u'http://www.dialelo.com')
    >>> apply_attribute('turses')
    u'turses'
    """
    string = str(string)

    if is_hashtag(string):
        return (hashtag, string)
    elif string.startswith('@') and is_username(string[1:]):
        return (attag, string)
    elif is_url(string):
        return (url, string)
    else:
        return string