def sources(self, url, hostDict, hostprDict):
        try:
            sources = []

            if url == None: return sources

            year = url['year']
            h = {'User-Agent': client.randomagent()}
            title = cleantitle.geturl(url['title']).replace('-', '+')
            url = urlparse.urljoin(self.base_link, self.search_link % title)
            r = requests.get(url, headers=h)
            r = BeautifulSoup(r.text, 'html.parser').find('div', {'class': 'item'})
            r = r.find('a')['href']
            r = requests.get(r, headers=h)
            r = BeautifulSoup(r.content, 'html.parser')
            quality = r.find('span', {'class': 'calidad2'}).text
            url = r.find('div', {'class':'movieplay'}).find('iframe')['src']
            if not quality in ['1080p', '720p']:
                quality = 'SD'

            valid, host = source_utils.is_host_valid(url, hostDict)
            sources.append({'source': host, 'quality': quality, 'language': 'en', 'url': url, 'direct': False, 'debridonly': False})
            return sources
        except:
            print("Unexpected error in Furk Script: check_api", sys.exc_info()[0])
            exc_type, exc_obj, exc_tb = sys.exc_info()
            print(exc_type, exc_tb.tb_lineno)
            return sources
Example #2
0
    def testMarkExceptionChange(self):
        state = State(self.tempdir, 'repo')
        state._gmtime = lambda: (2012, 8, 13, 12, 15, 0, 0, 0, 0)
        state.markStarted()
        try:
            raise ValueError("the same exception")
        except:
            exType, exValue, exTraceback = exc_info()
            state.markException(exType, exValue, "9999/9999/9999/9999")
        state.close()
        self.assertEquals({"changedate": "2012-08-13 12:15:00", "status": "Error", "message": "the same exception"}, jsonLoad(open(join(self.tempdir, 'repo.running'))))

        state = State(self.tempdir, 'repo')
        state._gmtime = lambda: (2012, 8, 13, 12, 17, 0, 0, 0, 0)
        state.markStarted()
        try:
            raise ValueError("the same exception")
        except:
            exType, exValue, exTraceback = exc_info()
            state.markException(exType, exValue, "9999/9999/9999/9999")
        state.close()
        self.assertEquals({"changedate": "2012-08-13 12:15:00", "status": "Error", "message": "the same exception"}, jsonLoad(open(join(self.tempdir, 'repo.running'))))

        state = State(self.tempdir, 'repo')
        state._gmtime = lambda: (2012, 8, 13, 12, 19, 0, 0, 0, 0)
        state.markStarted()
        try:
            raise ValueError("the other exception")
        except:
            exType, exValue, exTraceback = exc_info()
            state.markException(exType, exValue, "9999/9999/9999/9999")
        state.close()
        self.assertEquals({"changedate": "2012-08-13 12:19:00", "status": "Error", "message": "the other exception"}, jsonLoad(open(join(self.tempdir, 'repo.running'))))
Example #3
0
    def __init__(self, body=None, delivery_tag=None,
                 content_type=None, content_encoding=None, delivery_info=None,
                 properties=None, headers=None, postencode=None,
                 accept=None, channel=None, **kwargs):
        delivery_info = {} if not delivery_info else delivery_info
        self.errors = [] if self.errors is None else self.errors
        self.channel = channel
        self.delivery_tag = delivery_tag
        self.content_type = content_type
        self.content_encoding = content_encoding
        self.delivery_info = delivery_info
        self.headers = headers or {}
        self.properties = properties or {}
        self._decoded_cache = None
        self._state = 'RECEIVED'
        self.accept = accept

        compression = self.headers.get('compression')
        if not self.errors and compression:
            try:
                body = decompress(body, compression)
            except Exception:
                self.errors.append(sys.exc_info())

        if not self.errors and postencode and isinstance(body, text_t):
            try:
                body = body.encode(postencode)
            except Exception:
                self.errors.append(sys.exc_info())
        self.body = body
Example #4
0
File: compat.py Project: bpc/wand
 def nested(*managers):
     exits = []
     vars = []
     exc = (None, None, None)
     try:
         for mgr in managers:
             exit = mgr.__exit__
             enter = mgr.__enter__
             vars.append(enter())
             exits.append(exit)
         yield vars
     except:
         exc = sys.exc_info()
     finally:
         while exits:
             exit = exits.pop()
             try:
                 if exit(*exc):
                     exc = (None, None, None)
             except:
                 exc = sys.exc_info()
         if exc != (None, None, None):
             # PEP 3109
             e = exc[0](exc[1])
             e.__traceback__ = e[2]
             raise e
Example #5
0
def main():

    #for p in range(1,intGetMaxPage +1):
    #soup = BeautifulSoup()
    try:
        resp = urllib2.urlopen(getUrl,timeout=10)
        soup = BeautifulSoup(resp)
        soup = soup.find('div' ,{'id':'prodlist'})

    
        #for k in soup.findAll("div", {'class': 'p-name'}): # 抓< div class='p=name'>...< /div>
        for k in soup.findAll('a', href=True): 
            try:
            
                url = k.get('href') 
                print k.text
                print url 
        
                page_url = homeUrl + url
                print page_url
                resp_text_page = urllib2.urlopen(homeUrl + url, timeout=10)
            
                soup_text_page = BeautifulSoup(resp_text_page)
                contextPageUrl(soup_text_page,page_url)    
            except:
                print "Unexpected error:", sys.exc_info()[0]
                print "Unexpected error:", sys.exc_info()[1]
                continue
    except:
        #continue
        print "Unexpected error:", sys.exc_info()[0]
        print "Unexpected error:", sys.exc_info()[1]
        pass
def tokenize(n, tagsDict):
	cleaner = Cleaner()
	cleaner.javascript = True
	cleaner.style = True
	i = 0
	df = pandas.DataFrame(columns=[list(tagsDict)])

	while (i < n):
		allVector = {}
		if (os.path.isfile("spam/%d.txt" % i)):
			try:
				for word in tagsDict:
					allVector[word] = 0
				readInFile = open("spam/%d.txt" % i)
				content = readInFile.read()
				noSymbols = re.sub('[^A-Za-z-]+', ' ', content.lower())  # noSymbols is stripped of symbols
				allCopy = noSymbols.split()  # allCopy is the set of words without symbols
				for tag in allCopy:
					df.ix[i[tag]] = df.ix[i[tag]]  + 1
				df.ix[i['isSpam']] = 'spam'
				
			except Exception, err:
				print traceback.format_exc()
    			print sys.exc_info()[0]
		
		i = i + 1		
Example #7
0
 def _marshaled_dispatch(self, address, data):
     params, method = xmlrpclib.loads(data)
     if not self.instance.check_acls(address, method):
         raise XMLRPCACLCheckException
     try:
         if '.' not in method:
             params = (address, ) + params
         response = self.instance._dispatch(method, params, self.funcs)
         # py3k compatibility
         if type(response) not in [bool, str, list, dict]:
             response = (response.decode('utf-8'), )
         else:
             response = (response, )
         raw_response = xmlrpclib.dumps(response, methodresponse=True,
                                        allow_none=self.allow_none,
                                        encoding=self.encoding)
     except xmlrpclib.Fault:
         fault = sys.exc_info()[1]
         raw_response = xmlrpclib.dumps(fault, methodresponse=True,
                                        allow_none=self.allow_none,
                                        encoding=self.encoding)
     except:
         err = sys.exc_info()
         self.logger.error("Unexpected handler error", exc_info=1)
         # report exception back to server
         raw_response = xmlrpclib.dumps(
             xmlrpclib.Fault(1, "%s:%s" % (err[0].__name__, err[1])),
             methodresponse=True, allow_none=self.allow_none,
             encoding=self.encoding)
     return raw_response
Example #8
0
def sendData(sock, data):
    """
    Send some data over a socket.
    Some systems have problems with ``sendall()`` when the socket is in non-blocking mode.
    For instance, Mac OS X seems to be happy to throw EAGAIN errors too often.
    This function falls back to using a regular send loop if needed.
    """
    if sock.gettimeout() is None:
        # socket is in blocking mode, we can use sendall normally.
        try:
            sock.sendall(data)
            return
        except socket.timeout:
            raise TimeoutError("sending: timeout")
        except socket.error:
            x=sys.exc_info()[1]
            raise ConnectionClosedError("sending: connection lost: "+str(x))
    else:
        # Socket is in non-blocking mode, use regular send loop.
        retrydelay=0.0
        while data:
            try:
                sent = sock.send(data)
                data = data[sent:]
            except socket.timeout:
                raise TimeoutError("sending: timeout")
            except socket.error:
                x=sys.exc_info()[1]
                err=getattr(x, "errno", x.args[0])
                if err not in ERRNO_RETRIES:
                    raise ConnectionClosedError("sending: connection lost: "+str(x))
                time.sleep(0.00001+retrydelay)  # a slight delay to wait before retrying
                retrydelay=__nextRetrydelay(retrydelay)
Example #9
0
    def handle(self, *args, **options):
        def get_tmdb_ids():
            def get_args():
                if args:
                    movie_id = args[0]
                    try:
                        batch = args[1]
                    except:
                        batch = False
                else:
                    movie_id = None
                    batch = None
                return movie_id, batch

            movie_id, batch = get_args()

            movies = Movie.objects.all()
            if movie_id is not None:
                if batch:
                    movies = movies.filter(pk__gte=movie_id)
                else:
                    movies = movies.filter(pk=movie_id)
            return movies.values_list("tmdb_id", flat=True)

        for tmdb_id in get_tmdb_ids():
            try:
                print add_movie_to_db(tmdb_id, True)
            except TMDBRequestInvalid:
                print "Movie id - %d" % Movie.objects.get(tmdb_id=tmdb_id).id
                print sys.exc_info()[1]
Example #10
0
  def create_pplan(self, topologyName, pplan):
    """ create physical plan """
    if not pplan or not pplan.IsInitialized():
      raise StateException("Physical Plan protobuf not init properly",
                           StateException.EX_TYPE_PROTOBUF_ERROR), None, sys.exc_info()[2]

    path = self.get_pplan_path(topologyName)
    LOG.info("Adding topology: {0} to path: {1}".format(
        topologyName, path))
    pplanString = pplan.SerializeToString()
    try:
      self.client.create(path, value=pplanString, makepath=True)
      return True
    except NoNodeError:
      raise StateException("NoNodeError while creating pplan",
                           StateException.EX_TYPE_NO_NODE_ERROR), None, sys.exc_info()[2]
    except NodeExistsError:
      raise StateException("NodeExistsError while creating pplan",
                           StateException.EX_TYPE_NODE_EXISTS_ERROR), None, sys.exc_info()[2]
    except ZookeeperError:
      raise StateException("Zookeeper while creating pplan",
                           StateException.EX_TYPE_ZOOKEEPER_ERROR), None, sys.exc_info()[2]
    except Exception:
      # Just re raise the exception.
      raise
Example #11
0
  def create_execution_state(self, topologyName, executionState):
    """ create execution state """
    if not executionState or not executionState.IsInitialized():
      raise StateException("Execution State protobuf not init properly",
                           StateException.EX_TYPE_PROTOBUF_ERROR), None, sys.exc_info()[2]

    path = self.get_execution_state_path(topologyName)
    LOG.info("Adding topology: {0} to path: {1}".format(
        topologyName, path))
    executionStateString = executionState.SerializeToString()
    try:
      self.client.create(path, value=executionStateString, makepath=True)
      return True
    except NoNodeError:
      raise StateException("NoNodeError while creating execution state",
                           StateException.EX_TYPE_NO_NODE_ERROR), None, sys.exc_info()[2]
    except NodeExistsError:
      raise StateException("NodeExistsError while creating execution state",
                           StateException.EX_TYPE_NODE_EXISTS_ERROR), None, sys.exc_info()[2]
    except ZookeeperError:
      raise StateException("Zookeeper while creating execution state",
                           StateException.EX_TYPE_ZOOKEEPER_ERROR), None, sys.exc_info()[2]
    except Exception:
      # Just re raise the exception.
      raise
Example #12
0
File: gen.py Project: heewa/tornado
    def run(self):
        """Starts or resumes the generator, running until it reaches a
        yield point that is not ready.
        """
        if self.running or self.finished:
            return
        try:
            self.running = True
            while True:
                future = self.future
                if not future.done():
                    return
                self.future = None
                try:
                    orig_stack_contexts = stack_context._state.contexts
                    exc_info = None

                    try:
                        value = future.result()
                    except Exception:
                        self.had_exception = True
                        exc_info = sys.exc_info()

                    if exc_info is not None:
                        yielded = self.gen.throw(*exc_info)
                        exc_info = None
                    else:
                        yielded = self.gen.send(value)

                    if stack_context._state.contexts is not orig_stack_contexts:
                        self.gen.throw(
                            stack_context.StackContextInconsistentError(
                                'stack_context inconsistency (probably caused '
                                'by yield within a "with StackContext" block)'))
                except (StopIteration, Return) as e:
                    self.finished = True
                    self.future = _null_future
                    if self.pending_callbacks and not self.had_exception:
                        # If we ran cleanly without waiting on all callbacks
                        # raise an error (really more of a warning).  If we
                        # had an exception then some callbacks may have been
                        # orphaned, so skip the check in that case.
                        raise LeakedCallbackError(
                            "finished without waiting for callbacks %r" %
                            self.pending_callbacks)
                    self.result_future.set_result(_value_from_stopiteration(e))
                    self.result_future = None
                    self._deactivate_stack_context()
                    return
                except Exception:
                    self.finished = True
                    self.future = _null_future
                    self.result_future.set_exc_info(sys.exc_info())
                    self.result_future = None
                    self._deactivate_stack_context()
                    return
                if not self.handle_yield(yielded):
                    return
        finally:
            self.running = False
Example #13
0
def editar_campania(cid, nombre_empresa, ruc, text_content, fecha_publicacion, img_banner, url_banner, subject_email):
    m = get_mailchimp_api()
    campania = mailchimp.Campaigns(m)
    direccion = get_lan_ip()
    img_banner = img_banner[1:]

    try:
        result = campania.update(cid, 'content',
            {'sections': {
                'banner_img': '<a target="_blank" href="{0}"><img src="http://{1}/{2}" /></a>'.format(url_banner, direccion, img_banner),
                'text_content': text_content,
            }})
    except:
        print ('Error al editar campania:', sys.exc_info()[0])
    try:
        result = campania.update(cid, 'options', {'list_id': '25be04f5d4',
                                              'subject': subject_email,
                                              'from_email': 'info@innobee.com',
                                              'from_name': 'Innobee - Facturación electrónica',
                                              'to_name': 'Subscriptores Innobee Portal',
                                              'template_id': 111625,
                                              'title': 'campania---{0}---{1}'.format(nombre_empresa, hoy),
                                              'tracking': {'opens': True, 'html_clicks': True, 'text_clicks': True}
        },)
        print result
        campania.schedule(cid, fecha_publicacion)
    except:
        print ('Error al editar campania:', sys.exc_info()[0])
Example #14
0
    def _handle_request_exception(self, e):
        if not isinstance(e, Interruption):
            return tornado.web.RequestHandler._handle_request_exception(self, e)

        # copy of tornado.web.RequestHandler._handle_request_exception
        # but remove exception report
        if isinstance(e, tornado.web.Finish):
            # Not an error; just finish the request without logging.
            if not self._finished:
                self.finish()
            return

        # this is not an error
        # do not report exception
        # self.log_exception(*sys.exc_info())

        if self._finished:
            # Extra errors after the request has been finished should
            # be logged, but there is no reason to continue to try and
            # send a response.
            return
        if isinstance(e, tornado.web.HTTPError):
            if e.status_code not in tornado.httputil.responses and not e.reason:
                gen_log.error("Bad HTTP status code: %d", e.status_code)
            else:
                self.send_error(e.status_code, exc_info=sys.exc_info())
                return
        self.send_error(500, exc_info=sys.exc_info())
Example #15
0
    def write(self,text,last=False):
        try:
            raise "Dummy"
        except:
            lineText =  str(sys.exc_info()[2].tb_frame.f_back.f_lineno)
            codeObject = sys.exc_info()[2].tb_frame.f_back.f_code
            fileName = codeObject.co_filename
            funcName = codeObject.co_name


        if not hasattr(self,'text'):
            self.text=""

        self.text+=text

        lines=self.text.split("\n")
        linestoprint=lines if last else lines[:-1]

        self.text=lines[-1]



        for l in linestoprint:
            r=self.func(l.strip(),fileName,lineText,funcName)
            if r.strip()!="":
                self.get_origOut().write(r+"\n")
Example #16
0
def exception_info(current_filename=None, index=-1):
    "Analizar el traceback y armar un dict con la info amigable user-friendly"
    # guardo el traceback original (por si hay una excepción):
    info = sys.exc_info() #         exc_type, exc_value, exc_traceback
    # importante: no usar unpacking porque puede causar memory leak
    if not current_filename:
        # genero un call stack para ver quien me llamó y limitar la traza: 
        # advertencia: esto es necesario ya que en py2exe no tengo __file__ 
        try:
            raise ZeroDivisionError
        except ZeroDivisionError:
            f = sys.exc_info()[2].tb_frame.f_back
        current_filename = os.path.normpath(os.path.abspath(f.f_code.co_filename))

    # extraer la última traza del archivo solicitado:
    # (útil para no alargar demasiado la traza con lineas de las librerías)
    ret = {'filename': "", 'lineno': 0, 'function_name': "", 'code': ""}
    try:
        for (filename, lineno, fn, text) in traceback.extract_tb(info[2]):
            if os.path.normpath(os.path.abspath(filename)) == current_filename:
                ret = {'filename': filename, 'lineno': lineno, 
                       'function_name': fn, 'code': text}
            else:
                print filename
    except Exception, e:
        pass
Example #17
0
def buildDicts(n):
	cleaner = Cleaner()
	cleaner.javascript = True
	cleaner.style = True
	i = 0 
	tagsDict = set()
	while (i < n):
		if (os.path.isfile("spam/%d.txt" % i)):
			try:
				readInFile = open("spam/%d.txt" % i)
				content = readInFile.read()
				noSymbols = re.sub('[^A-Za-z-]+', ' ', content.lower())  # noSymbols is stripped of symbols
				tags = set(noSymbols.split())  # allCopy is the set of words without symbols
				tagsDict = tagsDict.union(tags)
			except Exception, err:
				print traceback.format_exc()
				print sys.exc_info()[0]
		if (os.path.isfile("notspam/%d.txt" % i)):
			try:
				readInFile = open("notspam/%d.txt" % i)
				content = readInFile.read()
				noSymbols = re.sub('[^A-Za-z-]+', ' ', content.lower())  # noSymbols is stripped of symbols
				tags = set(noSymbols.split())  # allCopy is the set of words without symbols
				tagsDict = tagsDict.union(tags)
			except Exception, err:
				print traceback.format_exc()
				print sys.exc_info()[0]
Example #18
0
def nested(*managers):
    # Code from `contextlib`
    exits = []
    vars = []
    exc = (None, None, None)
    try:
        for mgr in managers:
            exit = mgr.__exit__
            enter = mgr.__enter__
            vars.append(enter())
            exits.append(exit)
        yield vars
    except:
        exc = sys.exc_info()
    finally:
        while exits:
            exit = exits.pop()
            try:
                if exit(*exc):
                    exc = (None, None, None)
            except:
                exc = sys.exc_info()
        if exc != (None, None, None):
            # Don't rely on sys.exc_info() still containing
            # the right information. Another exception may
            # have been raised and caught by an exit method
            raise exc[1].with_traceback(exc[2])
Example #19
0
    def run(self, result=None):
        orig_result = result
        if result is None:
            result = self.defaultTestResult()
            startTestRun = getattr(result, 'startTestRun', None)
            if startTestRun is not None:
                startTestRun()

        self._resultForDoCleanups = result
        result.startTest(self)
        if getattr(self.__class__, "__unittest_skip__", False):
            # If the whole class was skipped.
            try:
                result.addSkip(self, self.__class__.__unittest_skip_why__)
            finally:
                result.stopTest(self)
            return
        testMethod = getattr(self, self._testMethodName)
        try:
            success = False
            try:
                self.setUp()
            except SkipTest, e:
                result.addSkip(self, str(e))
            except Exception:
                result.addError(self, sys.exc_info())
            else:
                try:
                    testMethod()
                except self.failureException:
                    result.addFailure(self, sys.exc_info())
                except _ExpectedFailure, e:
                    result.addExpectedFailure(self, e.exc_info)
                except _UnexpectedSuccess:
                    result.addUnexpectedSuccess(self)
Example #20
0
    def getAnyChecksum(self, info, username=None, password=None, session=None, is_source=0):
        """ returns checksum info of available packages
            also does an existance check on the filesystem.
        """
        log_debug(3)

        pkg_infos = info.get('packages')
        channels = info.get('channels', [])
        force = info.get('force', 0)
        orgid = info.get('org_id')

        if orgid == 'null':
            null_org = 1
        else:
            null_org = None

        if not session:
            org_id, force = rhnPackageUpload.authenticate(username, password,
                                                          channels=channels,
                                                          null_org=null_org,
                                                          force=force)
        else:
            try:
                org_id, force = rhnPackageUpload.authenticate_session(
                    session, channels=channels, null_org=null_org, force=force)
            except rhnSession.InvalidSessionError:
                raise_with_tb(rhnFault(33), sys.exc_info()[2])
            except rhnSession.ExpiredSessionError:
                raise_with_tb(rhnFault(34), sys.exc_info()[2])

        if is_source:
            ret = self._getSourcePackageChecksum(org_id, pkg_infos)
        else:
            ret = self._getPackageChecksum(org_id, pkg_infos)
        return ret
    def sortnums(self, model, iter1, iter2, nums):
        try:
            ret = 0
            (n, grid) = nums
            a = self.liststore[grid].get_value(iter1, n)
            b = self.liststore[grid].get_value(iter2, n)
            if 'f' in self.cols_to_show[n][4]:
                try:     a = float(a)
                except:  a = 0.0
                try:     b = float(b)
                except:  b = 0.0
            if n == 0 and grid == 1: #make sure it only works on the starting hands
                a1,a2,a3 = ranks[a[0]], ranks[a[1]], (a+'o')[2]
                b1,b2,b3 = ranks[b[0]], ranks[b[1]], (b+'o')[2]
                if a1 > b1 or ( a1 == b1 and (a2 > b2 or (a2 == b2 and a3 > b3) ) ):
                    ret = 1
                else:
                    ret = -1
            else:
                if a < b:
                    ret = -1
                elif a == b:
                    ret = 0
                else:
                    ret = 1
            #print "n =", n, "iter1[n] =", self.liststore[grid].get_value(iter1,n), "iter2[n] =", self.liststore[grid].get_value(iter2,n), "ret =", ret
        except:
            err = traceback.extract_tb(sys.exc_info()[2])
            print _("***sortnums error: ") + str(sys.exc_info()[1])
            print "\n".join( [e[0]+':'+str(e[1])+" "+e[2] for e in err] )

        return(ret)
Example #22
0
def _read_raw_athena(filename):
    """try to read athena project file as plain text,
    to determine validity
    """
    # try gzip
    text = None
    try:
        fh = GzipFile(filename)
        text = bytes2str(fh.read())
    except Exception:
        errtype, errval, errtb = sys.exc_info()
        text = None
    finally:
        fh.close()

    if text is None:
        # try plain text file
        try:
            fh = open(filename, 'r')
            text = bytes2str(fh.read())
        except Exception:
            errtype, errval, errtb = sys.exc_info()
            text = None
        finally:
            fh.close()
    return text
Example #23
0
 def send(self, data, flags=0, timeout=timeout_default):
     sock = self._sock
     if timeout is timeout_default:
         timeout = self.timeout
     try:
         return sock.send(data, flags)
     except error:
         ex = sys.exc_info()[1]
         if ex.args[0] != EWOULDBLOCK or timeout == 0.0:
             raise
         sys.exc_clear()
         try:
             self._wait(self._write_event)
         except error:
             ex = sys.exc_info()[1]
             if ex.args[0] == EBADF:
                 return 0
             raise
         try:
             return sock.send(data, flags)
         except error:
             ex2 = sys.exc_info()[1]
             if ex2.args[0] == EWOULDBLOCK:
                 return 0
             raise
Example #24
0
 def __call__(self, environ, start_response):
     try:
         return self.app(environ, start_response)
     except:
         traceback.print_exception(*sys.exc_info())
         pdb.post_mortem(sys.exc_info()[2])
         raise
 def _handleConnection(self, sock):
     try:
         if sock is None:
             return
         csock, caddr = sock.accept()
         if pyro4.config.COMMTIMEOUT:
             csock.settimeout(pyro4.config.COMMTIMEOUT)
     except socket.error:
         x = sys.exc_info()[1]
         err = getattr(x, "errno", x.args[0])
         if err in socketutil.ERRNO_RETRIES:
             # just ignore this error for now and continue
             log.warning("accept() failed errno=%d, shouldn't happen", err)
             return None
         if err in socketutil.ERRNO_BADF or err in socketutil.ERRNO_ENOTSOCK:
             # our server socket got destroyed
             raise errors.ConnectionClosedError("server socket closed")
         raise
     try:
         conn = socketutil.SocketConnection(csock)
         if self.daemon._handshake(conn):
             return conn
     except:  # catch all errors, otherwise the event loop could terminate
         ex_t, ex_v, ex_tb = sys.exc_info()
         tb = util.formatTraceback(ex_t, ex_v, ex_tb)
         log.warning("error during connect/handshake: %s; %s", ex_v, "\n".join(tb))
         try:
             csock.shutdown(socket.SHUT_RDWR)
         except (OSError, socket.error):
             pass
         csock.close()
     return None
Example #26
0
def testScript():
    OSHVResult = ObjectStateHolderVector()
    DebugMode = 'false'
    DateParsePattern = 'EEE MMM dd HH:mm:ss z yyyy'
    userExtDir = 'E:\\data\\Desktop\\Pull_From_Remedy_backup\\'
    if (DebugMode != None):
        DebugMode = DebugMode.lower()
        if DebugMode == "true":
            logger.info ('[NOTE] UCMDB Integration is running in DEBUG mode. No data will be pushed to the destination server.')
            return
    filePathDir = userExtDir + 'TQLExport\\Atrium\\results\\'
    directory = File(filePathDir)
    files = directory.listFiles()
    try:
        for file in files:
            if file != None or file != '':
                builder = SAXBuilder ()
                doc = builder.build(file)
                logger.info("Start processing CIs to update in the destination server...")
                allObjects = doc.getRootElement().getChild('data').getChild('objects').getChildren('Object')
                (objVector, ciDict) = processObjects(allObjects, DateParsePattern)
                OSHVResult.addAll(objVector)
                logger.info("Start processing Relationships to update in the destination server...")
                allLinks = doc.getRootElement().getChild('data').getChild('links').getChildren('link')
                linkVector = processLinks(allLinks, ciDict)
                OSHVResult.addAll(linkVector)
                print OSHVResult.toXmlString()
    except:
        stacktrace = traceback.format_exception(sys.exc_info()[0], sys.exc_info()[1], sys.exc_info()[2])
        logger.info('Failure in processing data %s' % stacktrace)
    logger.info('Ending Push to UCMDB')

#testScript()
    
Example #27
0
def test_logger():
    fn = setup_file('test_logger.log')
    rep = LogReporter(
        filename=fn,
        show_hidden_frames=False)
    try:
        int('a')
    except:
        exc_data = collector.collect_exception(*sys.exc_info())
    else:
        assert 0
    rep.report(exc_data)
    content = open(fn).read()
    assert len(content.splitlines()) == 4
    assert 'ValueError' in content
    assert 'int' in content
    assert 'test_reporter.py' in content
    assert 'test_logger' in content
    
    try:
        1 / 0
    except:
        exc_data = collector.collect_exception(*sys.exc_info())
    else:
        assert 0
    rep.report(exc_data)
    content = open(fn).read()
    print content
    assert len(content.splitlines()) == 8
    assert 'ZeroDivisionError' in content
Example #28
0
File: report.py Project: 0k/odoo
def exp_render_report(db, uid, object, ids, datas=None, context=None):
    if not datas:
        datas={}
    if not context:
        context={}

    self_id_protect.acquire()
    global self_id
    self_id += 1
    id = self_id
    self_id_protect.release()

    self_reports[id] = {'uid': uid, 'result': False, 'state': False, 'exception': None}

    cr = openerp.registry(db).cursor()
    try:
        result, format = openerp.report.render_report(cr, uid, ids, object, datas, context)
        if not result:
            tb = sys.exc_info()
            self_reports[id]['exception'] = openerp.exceptions.DeferredException('RML is not available at specified location or not enough data to print!', tb)
        self_reports[id]['result'] = result
        self_reports[id]['format'] = format
        self_reports[id]['state'] = True
    except Exception, exception:

        _logger.exception('Exception: %s\n', exception)
        if hasattr(exception, 'name') and hasattr(exception, 'value'):
            self_reports[id]['exception'] = openerp.exceptions.DeferredException(tools.ustr(exception.name), tools.ustr(exception.value))
        else:
            tb = sys.exc_info()
            self_reports[id]['exception'] = openerp.exceptions.DeferredException(tools.exception_to_unicode(exception), tb)
        self_reports[id]['state'] = True
Example #29
0
	def downloadFile(self, listadapter, *args):
		try:
			self.interface.log("ABOUT TO DOWNLOAD FROM " + listadapter.selection[0].text)
			s = listadapter.selection[0].text
			i = self.app.context["peers_addr"].index(s)
			print("INSIDE DOWNLOAD ")
			key = str(i)+"_"+str(s)
			if(self.app.context["downloads_available"][str(key)]):
				peer = self.app.context["downloads_available"][str(key)]
				print(peer)
				##possiamo far partire il download del file
				destination = (s , int(peer["porta"]))
				print(destination)
				print(peer["md5"])
				self.connection_socket = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
				self.connection_socket.connect(destination)
				message = "RETR"+str(peer["md5"])
				self.connection_socket.send(message)
				message_type = self.connection_socket.recv(4)
				num_chunks = self.connection_socket.recv(6)
				f = open('shared/'+peer["nome"].strip(" "), "wb")
				if int(num_chunks) > 0 :
					print("num chunks " + str(num_chunks))
					self.interface.progress.max = int(num_chunks)
					for i in range(int(num_chunks)):
						len_chunk = self.connection_socket.recv(5)
						if (int(len_chunk) > 0):
							self.interface.progress.value = self.interface.progress.value + 1
							chunk = self.connection_socket.recv(int(len_chunk))
							#f.write(chunk)
							#print("downloading chunk " + str(len_chunk))
							while len(chunk) < int(len_chunk):
								new_data = self.connection_socket.recv(int(len_chunk)-len(chunk))
								#f.write(new_data)
								chunk = chunk + new_data
							f.write(chunk)
					f.close()

				self.connection_socket.close()
				self.interface.progress.value = 0

				## scriviamo alla directory che abbiamo finito il download
				self.connection_socket = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
				self.connection_socket.connect(self.directory)

				message = "DREG" + self.app.context["sessionid"] + peer["md5"]
				self.connection_socket.send(message)

				ack = self.connection_socket.recv(4)
				n_down = self.connection_socket.recv(5)
				self.interface.log("RECEIVED "+ str(ack))
				self.interface.log("#DOWNLOAD " + str(n_down))
				self.connection_socket.close()
			else:
				print("NOT AVAILABLE")
		except:
			print("exception!!")
			print(sys.exc_info()[0])
			print(sys.exc_info()[1])
			print(sys.exc_info()[2])
 def run_keyword(self, name, args, kwargs=None):
     args, kwargs = self._handle_binary_args(args, kwargs or {})
     result = {'status': 'FAIL'}
     self._intercept_std_streams()
     try:
         return_value = self._get_keyword(name)(*args, **kwargs)
     except:
         exc_type, exc_value, exc_tb = sys.exc_info()
         self._add_to_result(result, 'error',
                             self._get_error_message(exc_type, exc_value))
         self._add_to_result(result, 'traceback',
                             self._get_error_traceback(exc_tb))
         self._add_to_result(result, 'continuable',
                             self._get_error_attribute(exc_value, 'CONTINUE'),
                             default=False)
         self._add_to_result(result, 'fatal',
                             self._get_error_attribute(exc_value, 'EXIT'),
                             default=False)
     else:
         try:
             self._add_to_result(result, 'return',
                                 self._handle_return_value(return_value))
         except:
             exc_type, exc_value, _ = sys.exc_info()
             self._add_to_result(result, 'error',
                                 self._get_error_message(exc_type, exc_value))
         else:
             result['status'] = 'PASS'
     self._add_to_result(result, 'output', self._restore_std_streams())
     return result