コード例 #1
0
 def test__4(self):
     ''' Verify that append() ASCII-fies the path in any case '''
     self.assertEqual(
         utils_path.append("/foobar",
             six.u("'/cio\xe8'"), True),
         None
     )
     self.assertEqual(
         utils_path.append("/foobar",
             six.u("'/cio%e8'"), True),
         None
     )
コード例 #2
0
ファイル: raw_srvr.py プロジェクト: EverlastingFire/neubot
 def __init__(self):
     Brigade.__init__(self)
     self.ticks = 0.0
     self.count = 0
     self.message = six.b('')
     self.auth = six.b('')
     self.state = {}
     self.snap_ticks = 0.0
     self.snap_count = 0
     self.snap_utime = 0.0
     self.snap_stime = 0.0
     self.web100_dirname = six.u('')
コード例 #3
0
 def handle_end_of_body(self, stream):
     # Note: this function MUST be callable multiple times
     context = stream.opaque
     extra = context.extra
     if extra['requests'] <= 0:
         raise RuntimeError('skype_negotiate: unexpected response')
     extra['requests'] -= 1
     tmp = context.headers.get(CONTENT_TYPE)
     if context.code != CODE200 or tmp != APPLICATION_JSON:
         logging.error('skype_negotiate: bad response')
         stream.close()
         return
     response = json.loads(six.u(extra['body'].getvalue()))
     http_utils.prettyprint_json(response, '<')
     if STATE.current == 'negotiate':
         self._process_negotiate_response(stream, response)
     elif STATE.current == 'collect':
         self._process_collect_response(stream, response)
     else:
         raise RuntimeError('skype_negotiate: internal error')
コード例 #4
0
ファイル: utils_path.py プロジェクト: EverlastingFire/neubot
    # The boolean second argument to visit is to distinguish between
    # leaf and ordinary nodes.
    #
    # This function is more strict than needed and generates an
    # error for input like '/var/www', ['a/b/c', '../d'], but we
    # don't care because that case doesn't happen in Neubot.
    #
    components = collections.deque(components)
    while components:
        prefix = append(prefix, components.popleft(), False)
        if prefix == None:
            raise RuntimeError("utils_path: depth_visit(): append() failed")
        visit(prefix, not components)
    return prefix

STRING_CLASS = six.u("").__class__

def decode(string, encoding):
    """ Decode STRING from ENCODING to UNICODE """
    logging.debug("utils_path: decode('%s', '%s')", string, encoding)
    try:
        string = string.decode(encoding)
    except (KeyboardInterrupt, SystemExit):
        raise
    except:
        logging.warning("utils_path: decode() error", exc_info=1)
    else:
        return string

def encode(string, encoding):
    """ Encode STRING to ENCODING from UNICODE """
コード例 #5
0
 def test_ascii_str(self):
     ''' Test possibly_decode() with ascii string input '''
     self.assertEqual(
         utils_path.possibly_decode(six.u("abc"), 'utf-8'),
         six.u("abc")
     )
コード例 #6
0
 def test_nonascii_str(self):
     ''' Test possibly_decode() with unicode string input '''
     self.assertEqual(
         utils_path.possibly_decode(six.u("cio\xe8"), 'utf-8'),
         six.u("cio\xe8")
     )
コード例 #7
0
 def test_ascii_bytes(self):
     ''' Test possibly_decode() with ascii bytes input '''
     self.assertEqual(
         utils_path.possibly_decode(six.b('abc'), 'utf-8'),
         six.u('abc')
     )
コード例 #8
0
 def test_nonascii_bytes(self):
     ''' Test possibly_decode() with unicode bytes input '''
     self.assertEqual(
         utils_path.possibly_decode('cio\xc3\xa8', 'utf-8'),
         six.u("cio\xe8")
     )