Exemple #1
0
    def test_baseexc(self):
        from exceptions import BaseException

        assert str(BaseException()) == ''
        assert repr(BaseException()) == 'BaseException()'
        assert BaseException().message == ''
        assert BaseException(3).message == 3
        assert repr(BaseException(3)) == 'BaseException(3,)'
        assert str(BaseException(3)) == '3'
        assert BaseException().args == ()
        assert BaseException(3).args == (3,)
        assert BaseException(3, "x").args == (3, "x")
        assert repr(BaseException(3, "x")) == "BaseException(3, 'x')"
        assert str(BaseException(3, "x")) == "(3, 'x')"
        assert BaseException(3, "x").message == ''
        x = BaseException()
        x.xyz = 3
        assert x.xyz == 3
        x.args = [42]
        assert x.args == (42,)
        assert str(x) == '42'
        assert x[0] == 42
        x.args = (1, 2, 3)
        assert x[1:2] == (2,)
        x.message = "xyz"
        assert x.message == "xyz"
        del x.message
        assert not hasattr(x, "message")
Exemple #2
0
 def _validate(self, field, value):
     if not isinstance(field, FieldDescriptor):
         raise (BaseException(
             "[Error] logic error in _validate, field must be type FieldDescriptor"
         ))
         return False
     t = ProtoRender.__maps[field.cpp_type]
     if ((isinstance(value, str) and len(value) == 0) or value
             == None) and field.label == FieldDescriptor.LABEL_OPTIONAL:
         return False
     if not isinstance(value, t):
         try:
             return t(value)
             return True
         except:
             raise (BaseException(
                 r"[Error] value error, %s need %s but %s" %
                 (field.name, t, type(value))))
             return False
     else:
         return value
     return False
 def _decorated(request, *args, **kwargs):
     if (request.user.is_authenticated()):
         user = request.user
         if (user.is_registration_complete()):
             return view_func(request, *args, **kwargs)
         else:
             return redirect('/core/user/edit?next=' +
                             request.get_full_path())
             #TODO
     else:
         raise BaseException(
             'decorator complete_registration_first invoked on unauthenticated session'
         )
Exemple #4
0
def difio_register(data, useragent, excluded_names=[]):
    """
        Register to Difio

        @data = {
            'user_id'    : int,
            'app_name'   : '',
            'app_uuid'   : '',
            'app_type'   : '',
            'app_url'    : '',
            'app_vendor' : int,
            'pkg_type'   : int,
            'installed'  : [{'n: 'name', 'v' : 'version' : 't' : int (optional)}],
        }

    """

    if not data.has_key('pkg_type'):
        data['pkg_type'] = 0  # Python

    if not data.has_key('app_type'):
        data['app_type'] = 'python-%d.%d.%d' % (
            sys.version_info[0], sys.version_info[1], sys.version_info[2])

    # make a list of package names
    for dist in get_installed_distributions(local_only=True):
        # skip some packages if told to
        if dist.project_name.lower() not in excluded_names:
            data['installed'].append({
                'n': dist.project_name,
                'v': dist.version
            })

    json_data = json.dumps(data)
    params = urllib.urlencode({'json_data': json_data})
    headers = {"User-agent": "%s" % useragent}

    conn = httplib.HTTPSConnection('difio-otb.rhcloud.com')
    conn.request('POST', '/application/register/', params, headers)
    response = conn.getresponse()

    if (response.status != 200) or (not response.getheader(
            'Content-type').startswith('application/json')):
        raise BaseException('Communication failed - %s' % response.read())

    result = json.loads(response.read())
    print result['message']
    sys.exit(result['exit_code'])
    def extract_from_wikipedia(self):
        try:
            print("extratcing from wikipedia")
            page_ = extract_main_page(self.query)

            page_url = page_.url
            print("page url: ", page_url)
            subdomain_names = extract_subdomain_names_from_dbpedia(page_url)
            print("subdomain names")

            all_links = page_.links

            all_links = merge_subdomain_and_links(subdomain_names, all_links)
            print("all links and subdomain")

            self.extract_text_from_wikipedia(all_links)
            print("extracted from wikipedia")
            return

        except Exception as e:
            #print ("error in extraction")
            raise BaseException(message="", description="", status_code=513)
Exemple #6
0
def main():
    arr = [
        "A10",
        "A11",
        "A2",
        "B1",
        "A2B1",
        "A2B11",
        "A2B2",
        "A2BCC",
        "A2BCC1",
        "A2BCC3",
        "B2",
        "A2BCC22",
    ]
    right_result = [
        "A2", "A2B1", "A2B2", "A2B11", "A2BCC", "A2BCC1", "A2BCC3", "A2BCC22",
        "A10", "A11", "B1", "B2"
    ]
    result = mega_sort(arr)
    if result != right_result:
        print result
        raise BaseException("Not equal")
Exemple #7
0
 def encode_params(self, data=None, **kwargs):
     """
     Build the body for a request.
     """
     raise BaseException("Not implemented yet")
Exemple #8
0
    def test_baseexc(self):
        from exceptions import BaseException

        assert str(BaseException()) == ''
        assert repr(BaseException()) == 'BaseException()'
        assert BaseException().message == ''
        assert BaseException(3).message == 3
        assert repr(BaseException(3)) == 'BaseException(3,)'
        assert str(BaseException(3)) == '3'
        assert BaseException().args == ()
        assert BaseException(3).args == (3,)
        assert BaseException(3, "x").args == (3, "x")
        assert repr(BaseException(3, "x")) == "BaseException(3, 'x')"
        assert str(BaseException(3, "x")) == "(3, 'x')"
        assert BaseException(3, "x").message == ''
        x = BaseException()
        x.xyz = 3
        assert x.xyz == 3
        x.args = [42]
        assert x.args == (42,)
        assert str(x) == '42'
        assert x[0] == 42
        x.args = (1, 2, 3)
        assert x[1:2] == (2,)
        x.message = "xyz"
        assert x.message == "xyz"
        del x.message
        assert not hasattr(x, "message")
 def __init__(self, *args):
     BaseException.__init__(self, *args)
Exemple #10
0
 def __init__(self, *args):
     BaseException.__init__(self, *args)