code:
;;;; vlist.test --- VLists.       -*- mode: scheme; coding: utf-8; -*-
;;;;
;;;; Ludovic Courtès <ludo@gnu.org>
;;;;
;;;; 	Copyright (C) 2009, 2010 Free Software Foundation, Inc.
;;;;
;;;; This library is free software; you can redistribute it and/or
;;;; modify it under the terms of the GNU Lesser General Public
;;;; License as published by the Free Software Foundation; either
;;;; version 3 of the License, or (at your option) any later version.
;;;;
;;;; This library is distributed in the hope that it will be useful,
;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
;;;; Lesser General Public License for more details.
;;;;
;;;; You should have received a copy of the GNU Lesser General Public
;;;; License along with this library; if not, write to the Free Software
;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

(define-module (test-vlist)
  #:use-module (test-suite lib)
  #:use-module (ice-9 vlist)
  #:use-module (srfi srfi-1)
  #:use-module (srfi srfi-26))

;;;
;;; VLists.
;;;

(with-test-prefix "vlist"

  (pass-if "vlist?"
    (and (vlist? vlist-null)
         (vlist? (vlist-cons 'a vlist-null))))

  (pass-if "vlist-null?"
    (vlist-null? vlist-null))

  (pass-if "vlist-cons"
    (let* ((v1 (vlist-cons 1 vlist-null))
           (v2 (vlist-cons 2 v1))
           (v3 (vlist-cons 3 v2))
           (v4 (vlist-cons 4 v3)))
      (every vlist? (list v1 v2 v3 v4))))

  (pass-if "vlist-head"
    (let* ((v1 (vlist-cons 1 vlist-null))
           (v2 (vlist-cons 2 v1))
           (v3 (vlist-cons 3 v2))
           (v4 (vlist-cons 4 v3)))
      (equal? (map vlist-head (list v1 v2 v3 v4))
              '(1 2 3 4))))

  (pass-if "vlist-tail"
    (let* ((v1 (vlist-cons 1 vlist-null))
           (v2 (vlist-cons 2 v1))
           (v3 (vlist-cons 3 v2))
           (v4 (vlist-cons 4 v3)))
      (equal? (map vlist-head
                   (map vlist-tail (list v2 v3 v4)))
              '(1 2 3))))

  (pass-if "vlist->list"
    (let* ((v1 (vlist-cons 1 vlist-null))
           (v2 (vlist-cons 2 v1))
           (v3 (vlist-cons 3 v2))
           (v4 (vlist-cons 4 v3)))
      (equal? '(4 3 2 1)
              (vlist->list v4))))

  (pass-if "list->vlist"
    (equal? (vlist->list (list->vlist '(1 2 3 4 5)))
            '(1 2 3 4 5)))

  (pass-if "vlist-drop"
    (equal? (vlist->list (vlist-drop (list->vlist (iota 77)) 7))
            (drop (iota 77) 7)))

  (pass-if "vlist-cons2"
    ;; Example from Bagwell's paper, Figure 2.
    (let* ((top  (list->vlist '(8 7 6 5 4 3)))
           (part (vlist-tail (vlist-tail top)))
           (test (vlist-cons 9 part)))
      (equal? (vlist->list test)
              '(9 6 5 4 3))))

  (pass-if "vlist-cons3"
    (let ((vlst (vlist-cons 'a
                            (vlist-cons 'b
                                        (vlist-drop (list->vlist (iota 5))
                                                    3)))))
      (equal? (vlist->list vlst)
              '(a b 3 4))))

  (pass-if "vlist-map"
    (equal? (vlist->list (vlist-map 1+ (list->vlist '(1 2 3 4 5))))
            '(2 3 4 5 6)))

  (pass-if "vlist-length"
    (= (vlist-length (list->vlist (iota 77)))
       77))

  (pass-if "vlist-length complex"
    (= (vlist-length (fold vlist-cons
                           (vlist-drop (list->vlist (iota 77)) 33)
                           (iota (- 33 7))))
       70))

  (pass-if "vlist-ref"
    (let* ((indices (iota 111))
           (vlst    (list->vlist indices)))
      (equal? (map (lambda (i)
                     (vlist-ref vlst i))
                   indices)
              indices)))

  (pass-if "vlist-ref degenerate"
    ;; Degenerate case where VLST contains only 1-element blocks.
    (let* ((indices (iota 111))
           (vlst    (fold (lambda (i vl)
                            (let ((vl (vlist-cons 'x vl)))
                              (vlist-cons i (vlist-tail vl))))
                          vlist-null
                          indices)))
      (equal? (map (lambda (i)
                     (vlist-ref vlst i))
                   (reverse indices))
              indices)))

  (pass-if "vlist-filter"
    (let* ((lst  (iota 33))
           (vlst (fold-right vlist-cons vlist-null lst)))
      (equal? (vlist->list (vlist-filter even? vlst))
              (filter even? lst))))

  (pass-if "vlist-delete"
    (let* ((lst  '(a b c d e))
           (vlst (fold-right vlist-cons vlist-null lst)))
      (equal? (vlist->list (vlist-delete 'c vlst))
              (delete 'c lst))))

  (pass-if "vlist-take"
    (let* ((lst  (iota 77))
           (vlst (fold-right vlist-cons vlist-null lst)))
      (equal? (vlist->list (vlist-take vlst 44))
              (take lst 44))))

  (pass-if "vlist-unfold"
    (let ((results (map (lambda (unfold)
                          (unfold (lambda (i) (> i 100))
                                  (lambda (i) i)
                                  (lambda (i) (+ i 1))
                                  0))
                        (list unfold vlist-unfold))))
      (equal? (car results)
              (vlist->list (cadr results)))))

  (pass-if "vlist-append"
    (let* ((lists '((a) (b c) (d e f) (g)))
           (vlst  (apply vlist-append (map list->vlist lists)))
           (lst   (apply append lists)))
      (equal? lst (vlist->list vlst)))))

;;;
;;; VHash.
;;;

(with-test-prefix "vhash"

  (pass-if "vhash?"
    (vhash? (vhash-cons "hello" "world" vlist-null)))

  (pass-if "vhash-assoc vlist-null"
    (not (vhash-assq 'a vlist-null)))

  (pass-if "vhash-assoc simple"
    (let ((vh (vhash-cons "hello" "world" vlist-null)))
      (equal? (cons "hello" "world")
              (vhash-assoc "hello" vh))))

  (pass-if "vhash-assoc regular"
    (let* ((keys   '(a b c d e f g h i))
           (values '(1 2 3 4 5 6 7 8 9))
           (vh     (fold vhash-cons vlist-null keys values)))
      (fold (lambda (k v result)
              (and result
                   (equal? (cons k v)
                           (vhash-assoc k vh eq?))))
            #t
            keys
            values)))

  (pass-if "vhash-assoc tail"
    (let* ((keys   '(a b c d e f g h i))
           (values '(1 2 3 4 5 6 7 8 9))
           (vh1    (fold vhash-consq vlist-null keys values))
           (vh2    (vhash-consq 'x 'x (vlist-tail vh1))))
      (and (fold (lambda (k v result)
                   (and result
                        (equal? (cons k v)
                                (vhash-assq k vh2))))
                 #t
                 (cons 'x (delq 'i keys))
                 (cons 'x (delv 9 values)))
           (not (vhash-assq 'i  vh2)))))

  (pass-if "vhash-assoc degenerate"
    (let* ((keys   '(a b c d e f g h i))
           (values '(1 2 3 4 5 6 7 8 9))
           (vh     (fold (lambda (k v vh)
                           ;; Degenerate case where VH2 contains only
                           ;; 1-element blocks.
                           (let* ((vh1 (vhash-cons 'x 'x vh))
                                  (vh2 (vlist-tail vh1)))
                             (vhash-cons k v vh2)))
                         vlist-null keys values)))
      (and (fold (lambda (k v result)
                   (and result
                        (equal? (cons k v)
                                (vhash-assq k vh))))
                 #t
                 keys
                 values)
           (not (vhash-assq 'x vh)))))

  (pass-if "vhash as vlist"
    (let* ((keys   '(a b c d e f g h i))
           (values '(1 2 3 4 5 6 7 8 9))
           (vh     (fold vhash-cons vlist-null keys values))
           (alist  (fold alist-cons '() keys values)))
      (and (equal? (vlist->list vh) alist)
           (= (length alist) (vlist-length vh))
           (fold (lambda (i result)
                   (and result
                        (equal? (list-ref alist i)
                                (vlist-ref vh i))))
                 #t
                 (iota (vlist-length vh))))))

  (pass-if "vhash entry shadowed"
    (let* ((a (vhash-consq 'a 1 vlist-null))
           (b (vhash-consq 'a 2 a)))
      (and (= 1 (cdr (vhash-assq 'a a)))
           (= 2 (cdr (vhash-assq 'a b)))
           (= 1 (cdr (vhash-assq 'a (vlist-tail b)))))))

  (pass-if "vlist-filter"
    (let* ((keys   '(a b c d e f g h i))
           (values '(1 2 3 4 5 6 7 8 9))
           (vh     (fold vhash-cons vlist-null keys values))
           (alist  (fold alist-cons '() keys values))
           (pred   (lambda (k+v)
                     (case (car k+v)
                       ((c f) #f)
                       (else  #t)))))
      (let ((vh    (vlist-filter pred vh))
            (alist (filter pred alist)))
        (and (equal? (vlist->list vh) alist)
             (= (length alist) (vlist-length vh))
             (fold (lambda (i result)
                     (and result
                          (equal? (list-ref alist i)
                                  (vlist-ref vh i))))
                   #t
                   (iota (vlist-length vh)))))))

  (pass-if "vhash-delete"
    (let* ((keys   '(a b c d e f g d h i))
           (values '(1 2 3 4 5 6 7 0 8 9))
           (vh     (fold vhash-cons vlist-null keys values))
           (alist  (fold alist-cons '() keys values)))
      (let ((vh    (vhash-delete 'd vh))
            (alist (alist-delete 'd alist)))
        (and (= (length alist) (vlist-length vh))
             (fold (lambda (k result)
                     (and result
                          (equal? (assq k alist)
                                  (vhash-assoc k vh eq?))))
                   #t
                   keys)))))

  (pass-if "vhash-fold"
    (let* ((keys   '(a b c d e f g d h i))
           (values '(1 2 3 4 5 6 7 0 8 9))
           (vh     (fold vhash-cons vlist-null keys values))
           (alist  (fold alist-cons '() keys values)))
      (equal? alist (reverse (vhash-fold alist-cons '() vh)))))

  (pass-if "alist->vhash"
    (let* ((keys   '(a b c d e f g d h i))
           (values '(1 2 3 4 5 6 7 0 8 9))
           (alist  (fold alist-cons '() keys values))
           (vh     (alist->vhash alist))
           (alist2 (vlist-fold cons '() vh)))
      (and (equal? alist (reverse alist2))
           (fold (lambda (k result)
                   (and result
                        (equal? (assq k alist)
                                (vhash-assoc k vh eq?))))
                 #t
                 keys))))

  (pass-if "vhash-fold*"
    (let* ((keys   (make-list 10 'a))
           (values (iota 10))
           (vh     (fold vhash-cons vlist-null keys values)))
      (equal? (vhash-fold* cons '() 'a vh)
              values)))

  (pass-if "vhash-fold* tail"
    (let* ((keys   (make-list 100 'a))
           (values (iota 100))
           (vh     (fold vhash-cons vlist-null keys values)))
      (equal? (vhash-fold* cons '() 'a (vlist-drop vh 42))
              (take values (- 100 42)))))

  (pass-if "vhash-fold* interleaved"
    (let* ((keys   '(a b a b a b a b a b c d e a b))
           (values '(1 0 2 0 3 0 4 0 5 0 0 0 0 6 0))
           (vh     (fold vhash-cons vlist-null keys values)))
      (equal? (vhash-fold* cons '() 'a vh)
              (filter (cut > <> 0) values))))

  (pass-if "vhash-foldq* degenerate"
    (let* ((keys   '(a b a b a a a b a b a a a z))
           (values '(1 0 2 0 3 4 5 0 6 0 7 8 9 0))
           (vh     (fold (lambda (k v vh)
                           ;; Degenerate case where VH2 contains only
                           ;; 1-element blocks.
                           (let* ((vh1 (vhash-consq 'x 'x vh))
                                  (vh2 (vlist-tail vh1)))
                             (vhash-consq k v vh2)))
                         vlist-null keys values)))
      (equal? (vhash-foldq* cons '() 'a vh)
              (filter (cut > <> 0) values)))))


code:
;;;; weaks.test --- tests guile's weaks     -*- scheme -*-
;;;; Copyright (C) 1999, 2001, 2003, 2006, 2009 Free Software Foundation, Inc.
;;;;
;;;; This library is free software; you can redistribute it and/or
;;;; modify it under the terms of the GNU Lesser General Public
;;;; License as published by the Free Software Foundation; either
;;;; version 3 of the License, or (at your option) any later version.
;;;;
;;;; This library is distributed in the hope that it will be useful,
;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
;;;; Lesser General Public License for more details.
;;;;
;;;; You should have received a copy of the GNU Lesser General Public
;;;; License along with this library; if not, write to the Free Software
;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

;;; {Description}

;;; This is a semi test suite for weaks; I say semi, because weaks
;;; are pretty non-deterministic given the amount of information we
;;; can infer from scheme.
;;;
;;; In particular, we can't always reliably test the more important
;;; aspects of weaks (i.e., that an object is removed when it's dead)
;;; because we have no way of knowing for certain that the object is
;;; really dead. It tests it anyway, but the failures of any `death'
;;; tests really shouldn't be surprising.
;;;
;;; Interpret failures in the dying functions here as a hint that you
;;; should look at any changes you've made involving weaks
;;; (everything else should always pass), but there are a host of
;;; other reasons why they might not work as tested here, so if you
;;; haven't done anything to weaks, don't sweat it :)

(use-modules (test-suite lib)
	     (ice-9 weak-vector))

;;; Creation functions

(with-test-prefix
 "weak-creation"
 (with-test-prefix "make-weak-vector"
  (pass-if "normal"
    (make-weak-vector 10 #f)
    #t)
  (pass-if-exception "bad size"
    exception:wrong-type-arg
    (make-weak-vector 'foo)))

 (with-test-prefix "list->weak-vector"
		   (pass-if "create"
			    (let* ((lst '(a b c d e f g))
				   (wv (list->weak-vector lst)))
			      (and (eq? (vector-ref wv 0) 'a)
				   (eq? (vector-ref wv 1) 'b)
				   (eq? (vector-ref wv 2) 'c)
				   (eq? (vector-ref wv 3) 'd)
				   (eq? (vector-ref wv 4) 'e)
				   (eq? (vector-ref wv 5) 'f)
				   (eq? (vector-ref wv 6) 'g))))
		   (pass-if-exception "bad-args"
		     exception:wrong-type-arg
		     (list->weak-vector 32)))

 (with-test-prefix "make-weak-key-alist-vector"
		   (pass-if "create"
		     (make-weak-key-alist-vector 17)
		     #t)
		   (pass-if-exception "bad-args"
		     exception:wrong-type-arg
		     (make-weak-key-alist-vector '(bad arg))))
 (with-test-prefix "make-weak-value-alist-vector"
		   (pass-if "create"
		     (make-weak-value-alist-vector 17)
		     #t)
		   (pass-if-exception "bad-args"
		     exception:wrong-type-arg
		     (make-weak-value-alist-vector '(bad arg))))

 (with-test-prefix "make-doubly-weak-alist-vector"
		   (pass-if "create"
		     (make-doubly-weak-alist-vector 17)
		     #t)
		   (pass-if-exception "bad-args"
		     exception:wrong-type-arg
		     (make-doubly-weak-alist-vector '(bad arg)))))

;; This should remove most of the non-dying problems associated with
;; trying this inside a closure

(define global-weak (make-weak-vector 10 #f))
(begin
  (vector-set! global-weak 0 (string-copy "string"))
  (vector-set! global-weak 1 (string-copy "beans"))
  (vector-set! global-weak 2 (string-copy "to"))
  (vector-set! global-weak 3 (string-copy "utah"))
  (vector-set! global-weak 4 (string-copy "yum yum"))
  (gc))

;;; Normal weak vectors
(let ((x (make-weak-vector 10 #f))
      (bar "bar"))
  (with-test-prefix
   "weak-vector"
   (pass-if "lives"
	    (begin
	      (vector-set! x 0 bar)
	      (gc)
	      (and (vector-ref x 0) (eq? bar (vector-ref x 0)))))
   (pass-if "dies"
	    (begin
	      (gc)
	      (or (and (not (vector-ref global-weak 0))
		       (not (vector-ref global-weak 1))
		       (not (vector-ref global-weak 2))
		       (not (vector-ref global-weak 3))
		       (not (vector-ref global-weak 4)))
		  (throw 'unresolved))))))

 (let ((x (make-weak-key-alist-vector 17))
      (y (make-weak-value-alist-vector 17))
      (z (make-doubly-weak-alist-vector 17))
      (test-key "foo")
      (test-value "bar"))
  (with-test-prefix
   "weak-hash"
   (pass-if "lives"
	    (begin
	      (hashq-set! x test-key test-value)
	      (hashq-set! y test-key test-value)
	      (hashq-set! z test-key test-value)
	      (gc)
	      (gc)
	      (and (hashq-ref x test-key)
		   (hashq-ref y test-key)
		   (hashq-ref z test-key)
		   #t)))
   (pass-if "weak-key dies"
	    (begin
	      (hashq-set! x "this" "is")
	      (hashq-set! x "a" "test")
	      (hashq-set! x "of" "the")
	      (hashq-set! x "emergency" "weak")
	      (hashq-set! x "key" "hash system")
	      (gc)
	      (and
	       (or (not (hashq-ref x "this"))
		   (not (hashq-ref x "a"))
		   (not (hashq-ref x "of"))
		   (not (hashq-ref x "emergency"))
		   (not (hashq-ref x "key")))
	       (hashq-ref x test-key)
	       #t)))

   (pass-if "weak-value dies"
	    (begin
	      (hashq-set! y "this" "is")
	      (hashq-set! y "a" "test")
	      (hashq-set! y "of" "the")
	      (hashq-set! y "emergency" "weak")
	      (hashq-set! y "value" "hash system")
	      (gc)
	      (and (or (not (hashq-ref y "this"))
		       (not (hashq-ref y "a"))
		       (not (hashq-ref y "of"))
		       (not (hashq-ref y "emergency"))
		       (not (hashq-ref y "value")))
		   (hashq-ref y test-key)
		   #t)))
   (pass-if "doubly-weak dies"
	    (begin
	      (hashq-set! z "this" "is")
	      (hashq-set! z "a" "test")
	      (hashq-set! z "of" "the")
	      (hashq-set! z "emergency" "weak")
	      (hashq-set! z "all" "hash system")
	      (gc)
	      (and (or (not (hashq-ref z "this"))
		       (not (hashq-ref z "a"))
		       (not (hashq-ref z "of"))
		       (not (hashq-ref z "emergency"))
		       (not (hashq-ref z "all")))
		   (hashq-ref z test-key)
		   #t)))))

license: mit


code:
## Process this file with automake to produce Makefile.in.
##
## Copyright 2005, 2006, 2008, 2009, 2010 Software Foundation, Inc.
##
## This file is part of GUILE.
##
##   GUILE is free software; you can redistribute it and/or modify it
##   under the terms of the GNU Lesser General Public License as
##   published by the Free Software Foundation; either version 3, or
##   (at your option) any later version.
##
##   GUILE is distributed in the hope that it will be useful, but
##   WITHOUT ANY WARRANTY; without even the implied warranty of
##   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
##   GNU Lesser General Public License for more details.
##
##   You should have received a copy of the GNU Lesser General Public
##   License along with GUILE; see the file COPYING.LESSER.  If not,
##   write to the Free Software Foundation, Inc., 51 Franklin Street,
##   Fifth Floor, Boston, MA 02110-1301 USA

TESTS_ENVIRONMENT = \
	$(top_builddir)/meta/guile \
	-l $(srcdir)/run-vm-tests.scm -e run-vm-tests

TESTS =						\
      t-basic-contructs.scm			\
      t-global-bindings.scm			\
      t-catch.scm				\
      t-call-cc.scm				\
      t-closure.scm				\
      t-closure2.scm				\
      t-closure3.scm				\
      t-closure4.scm				\
      t-do-loop.scm				\
      t-literal-integers.scm			\
      t-macros.scm				\
      t-macros2.scm				\
      t-map.scm					\
      t-or.scm					\
      t-proc-with-setter.scm			\
      t-quasiquote.scm				\
      t-values.scm				\
      t-records.scm				\
      t-match.scm				\
      t-mutual-toplevel-defines.scm

EXTRA_DIST = run-vm-tests.scm $(TESTS)


code:
;;; run-vm-tests.scm -- Run Guile-VM's test suite.
;;;
;;; Copyright 2005, 2009 Free Software Foundation, Inc.
;;;
;;; This program is free software; you can redistribute it and/or
;;; modify it under the terms of the GNU Lesser General Public License
;;; as published by the Free Software Foundation; either version 3 of
;;; the License, or (at your option) any later version.
;;;
;;; This program is distributed in the hope that it will be useful,
;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;; GNU Lesser General Public License for more details.
;;;
;;; You should have received a copy of the GNU Lesser General Public License
;;; along with this program; if not, write to the Free Software
;;; Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA

(use-modules (system vm vm)
	     (system base compile)
	     (system base language)
             (language scheme spec)
             (language objcode spec)
	     (srfi srfi-1)
	     (ice-9 r5rs))

(define (fetch-sexp-from-file file)
  (with-input-from-file file
    (lambda ()
      (let loop ((sexp (read))
		 (result '()))
	(if (eof-object? sexp)
	    (cons 'begin (reverse result))
	    (loop (read) (cons sexp result)))))))

(define (compile-to-objcode sexp)
  "Compile the expression @var{sexp} into a VM program and return it."
  (compile sexp #:from scheme #:to objcode))

(define (run-vm-program objcode)
  "Run VM program contained into @var{objcode}."
  (vm-load (the-vm) objcode))

(define (compile/run-test-from-file file)
  "Run test from source file @var{file} and return a value indicating whether
it succeeded."
  (run-vm-program (compile-to-objcode (fetch-sexp-from-file file))))

(define-macro (watch-proc proc-name str)
  `(let ((orig-proc ,proc-name))
     (set! ,proc-name
	   (lambda args
	     (format #t (string-append ,str "...  "))
	     (apply orig-proc args)))))

(watch-proc fetch-sexp-from-file  "reading")
(watch-proc compile-to-objcode    "compiling")
(watch-proc run-vm-program        "running")

;; The program.

(define (run-vm-tests files)
  "For each file listed in @var{files}, load it and run it through both the
interpreter and the VM (after having it compiled).  Both results must be
equal in the sense of @var{equal?}."
  (let* ((res (map (lambda (file)
		     (format #t "running `~a'...  " file)
		     (if (catch #t
				(lambda ()
				  (equal? (compile/run-test-from-file file)
					  (primitive-eval (fetch-sexp-from-file file))))
				(lambda (key . args)
				  (format #t "[~a/~a] " key args)
				  #f))
			 (format #t "ok~%")
			 (begin (format #t "FAILED~%") #f)))
		   files))
	 (total (length files))
	 (failed (length (filter not res))))

    (if (= 0 failed)
        (exit 0)
	(begin
	  (format #t "~%~a tests failed out of ~a~%"
		  failed total)
	  (exit failed)))))


code:
;;; Basic RnRS constructs.

(and (eq? 2 (begin (+ 2 4) 5 2))
     ((lambda (x y)
	(and (eq? x 1) (eq? y 2)
	     (begin
	       (set! x 11) (set! y 22)
	       (and (eq? x 11) (eq? y 22)))))
      1 2)
     (let ((x 1) (y 3))
       (and (eq? x 1) (eq? y 3)))
     (let loop ((x #t))
       (if (not x)
	   #t
	   (loop #f))))


code:
(let ((set-counter2 #f))
  (define (get-counter2)
    (call/cc
     (lambda (k)
       (set! set-counter2 k)
       1)))
  (define (loop counter1)
    (let ((counter2 (get-counter2)))
      (set! counter1 (1+ counter1))
      (cond ((not (= counter1 counter2))
             (error "bad call/cc behaviour" counter1 counter2))
            ((> counter1 10)
             #t)
            (else
             (set-counter2 (1+ counter2))))))
  (loop 0))


code:
;; Test that nonlocal exits of the VM work.

(begin
  (define (foo thunk)
    (catch #t thunk (lambda args args)))
  (foo
   (lambda ()
     (let ((a 'one))
       (1+ a)))))


code:
(define func
  (let ((x 2))
    (lambda ()
      (let ((x++ (+ 1 x)))
	(set! x x++)
	x++))))

(list (func) (func) (func))


code:
(define (uid)
  (let* ((x 2)
	 (do-uid (lambda ()
		   (let ((x++ (+ 1 x)))
		     (set! x x++)
		     x++))))
    (do-uid)))

(list (uid) (uid) (uid))


code:
(define (stuff)
  (let* ((x 2)
	 (chbouib (lambda (z)
		    (+ 7 z x))))
    (chbouib 77)))

(stuff)


code:
(define (extract-symbols exp)
  (define (process x out cont)
    (cond ((pair? x)
           (process (car x)
                    out
                    (lambda (car-x out)
                      ;; used to have a bug here whereby `x' was
                      ;; modified in the self-tail-recursion to (process
                      ;; (cdr x) ...), because we didn't allocate fresh
                      ;; externals when doing self-tail-recursion.
                      (process (cdr x)
                               out
                               (lambda (cdr-x out)
                                 (cont (cons car-x cdr-x)
                                       out))))))
          ((symbol? x)
           (cont x (cons x out)))
          (else
           (cont x out))))
  (process exp '() (lambda (x out) out)))

(extract-symbols '(a b . c))


code:
;; Are global bindings reachable at run-time?  This relies on the
;; `object-ref' and `object-set' instructions.

(begin

  (define the-binding "hello")

  ((lambda () the-binding))

  ((lambda () (set! the-binding "world")))

  ((lambda () the-binding)))


code:
;; Check whether literal integers are correctly signed.

(and (=  4294967295 (- (expt 2 32) 1))      ;; unsigned
     (= -2147483648 (- (expt 2 31)))        ;; signed
     (=  2147483648 (expt 2 31)))           ;; unsigned


code:
;; Are built-in macros well-expanded at compilation-time?

(false-if-exception (+ 2 2))
(read-options)


code:
;; Are macros well-expanded at compilation-time?

(defmacro minus-binary (a b)
  `(- ,a ,b))

(define-macro (plus . args)
  `(let ((res (+ ,@args)))
     ;;(format #t "plus -> ~a~%" res)
     res))

(plus (let* ((x (minus-binary 12 7)) ;; 5
	     (y (minus-binary x 1))) ;; 4
	(plus x y 5)) ;; 14
      12              ;; 26
      (expt 2 3))     ;; => 34


code:
; Currently, map is a C function, so this is a way of testing that the
; VM is reentrant.

(begin

  (define (square x)
    (* x x))

  (map (lambda (x) (square x))
       '(1 2 3)))


code:
;;; Pattern matching with `(ice-9 match)'.
;;;

(use-modules (ice-9 match)
             (srfi srfi-9))  ;; record type (FIXME: See `t-records.scm')

(define-record-type <stuff>
  (%make-stuff chbouib)
  stuff?
  (chbouib stuff:chbouib stuff:set-chbouib!))

(define (matches? obj)
;  (format #t "matches? ~a~%" obj)
  (match obj
	 (($ stuff) #t)
;	 (blurps    #t)
	 ("hello"   #t)
	 (else #f)))

;(format #t "go!~%")
(and (matches? (%make-stuff 12))
     (matches? (%make-stuff 7))
     (matches? "hello")
;     (matches? 'blurps)
     (not (matches? 66)))


code:
(define (even? x)
  (or (zero? x)
      (not (odd? (1- x)))))

(define (odd? x)
  (not (even? (1- x))))

(even? 20)


code:
;; all the different permutations of or
(list
 ;; not in tail position, no args
 (or)
 ;; not in tail position, one arg
 (or 'what)
 (or #f)
 ;; not in tail position, two arg
 (or 'what 'where)
 (or #f 'where)
 (or #f #f)
 (or 'what #f)
 ;; not in tail position, value discarded
 (begin (or 'what (error "two")) 'two)
 ;; in tail position (within the lambdas)
 ((lambda ()
    (or)))
 ((lambda ()
    (or 'what)))
 ((lambda ()
    (or #f)))
 ((lambda ()
    (or 'what 'where)))
 ((lambda ()
    (or #f 'where)))
 ((lambda ()
    (or #f #f)))
 ((lambda ()
    (or 'what #f))))


code:
(define the-struct (vector 1 2))

(define get/set
  (make-procedure-with-setter
   (lambda (struct name)
     (case name
       ((first)  (vector-ref struct 0))
       ((second) (vector-ref struct 1))
       (else     #f)))
   (lambda (struct name val)
     (case name
       ((first)  (vector-set! struct 0 val))
       ((second) (vector-set! struct 1 val))
       (else     #f)))))

(and (eq? (vector-ref the-struct 0) (get/set the-struct 'first))
     (eq? (vector-ref the-struct 1) (get/set the-struct 'second))
     (begin
       (set! (get/set the-struct 'second) 77)
       (eq? (vector-ref the-struct 1) (get/set the-struct 'second))))


code:
;;; SRFI-9 Records.
;;;

(use-modules (srfi srfi-9))

(define-record-type <stuff>
  (%make-stuff chbouib)
  stuff?
  (chbouib stuff:chbouib stuff:set-chbouib!))

(and (stuff? (%make-stuff 12))
     (= 7 (stuff:chbouib (%make-stuff 7)))
     (not (stuff? 12)))


code:
(list (call-with-values
          (lambda () (values 1 2))
        (lambda (x y) (cons x y)))

      ;; the start-stack forces a bounce through the interpreter
      (call-with-values
          (lambda () (start-stack 'foo (values 1 2)))
        list)

      (call-with-values
          (lambda () (apply values '(1)))
        list))


code:
import time

def mult():
    x = pow(2, 40)
    y = pow(2, 40)

    z = 0

    while y > 0:
        if y % 2 == 1:
            z = z + x
        x = x << 1
        y = y >> 1
    return z
    # print(suma)

def mult2():
    i = pow(2, 40)
    ii = pow(2, 40)
    s = i * ii

def refetse():
    s = 'This is a stroka of an effect'
    s_rev = s[::-1]
    return s, s_rev

print(refetse())
#print(s_rev)

n = 10000
t0 = time.time()
for i in range(n):
    refetse()
t1 = time.time()

total_n = t1-t0

print(total_n)

license: unknown


code:
import sys

class MyC:
    def __init__(self, x):
        self.x = x

    def inc(self, x):
        for i in range(len(self.x)):
            self.x[i] += x

def main():
    myc = MyC([1, 2, 3, 4])
    myc.inc(2)
    print(myc.x)

if __name__ == '__main__':
    sys.exit(main())


code:
import pygame
import sys
from random import randint

FPS = 60
speed = 3
t_speed = 60
BLACK = (0, 0, 0)
W, H = 1000, 570
game_score = 0

pygame.init()

clock = pygame.time.Clock()
pygame.time.set_timer(pygame.USEREVENT, 2000)

balls_data = ({'path': 'ball_bear.png', 'score': 100},
              {'path': 'ball_fox.png', 'score': 150},
              {'path': 'ball_panda.png', 'score': 200})

sc = pygame.display.set_mode((W, H))
icon = pygame.display.set_icon(pygame.image.load('icon/rur.png'))
balls_images = ['ball_bear.png', 'ball_fox.png', 'ball_panda.png']
balls_surf = [pygame.image.load('images/'+data['path']).convert_alpha()
              for data in balls_data]
bg = pygame.image.load('images/back1.jpg').convert()
telega = pygame.image.load('images/telega.png').convert_alpha()
t_rect = telega.get_rect(centerx=W//2, bottom=H-5)
score = pygame.image.load('images/score_fon.png').convert_alpha()
f = pygame.font.SysFont('arial', 30)

balls = pygame.sprite.Group()

'''
clip = VideoFileClip('video/kek.avi').speedx(2).volumex(0.2).subclip(600)
clip.preview(fps=25)
'''

class Ball(pygame.sprite.Sprite):
    def __init__(self, x, speed, surf, score, group):
        pygame.sprite.Sprite.__init__(self)
        self.image = surf
        self.rect = self.image.get_rect(center=(x, 0))
        self.speed = speed
        self.score = score
        self.add(group)

    def update(self, H):
        if self.rect.y < H - self.rect.height:
            self.rect.y += self.speed
        else:
            self.kill()

def createBall(group):
    indx = randint(0, len(balls_surf)-1)
    x = randint(20, W-20)
    speed = randint(1, 4)

    return Ball(x, speed, balls_surf[indx], balls_data[indx]['score'], group)

def collideBalls():
    global game_score
    for ball in balls:
        if t_rect.collidepoint(ball.rect.center):
            game_score += ball.score
            ball.kill()

createBall(balls)
run = True
#some = True

while run:
    keys = pygame.key.get_pressed()

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            run = False
        elif event.type == pygame.KEYDOWN:
            if event.key == pygame.K_ESCAPE:
                run = False
        elif event.type == pygame.USEREVENT:
            createBall(balls)
        elif keys[pygame.K_LEFT]:
            t_rect.x -= t_speed
            if t_rect.x < 0:
                t_rect.x = 0
        elif keys[pygame.K_RIGHT]:
            t_rect.x += t_speed
            if t_rect.x > W-t_rect.width:
                t_rect.x = W-t_rect.width

    collideBalls()

    sc.blit(bg, (0, 0))
    balls.draw(sc)
    sc.blit(score, (0, 0))
    sc_text = f.render(str(game_score), 1, (94, 138, 14))
    sc.blit(sc_text, (20, 10))
    sc.blit(telega, t_rect)

    pygame.display.update()
    clock.tick(FPS)
    balls.update(H)

'''
pygame.mixer.music.load('V.flac')
pygame.mixer.music.set_volume(0.2)
pygame.mixer.music.play()

TRUE = 1
UNTRUE = 0
W = 600
H = 400

sc = pygame.display.set_mode((W, H))
pygame.display.set_caption("Класс Surface")
pygame.display.set_icon(pygame.image.load("rur.png"))

car_surf = pygame.image.load("images/car.bmp").convert()
car_rect = car_surf.get_rect(center=(W//2, H//2))
bg_surf = pygame.image.load("images/sand.jpg").convert()
car_surf.set_colorkey((255, 255, 255))
finish_surf = pygame.image.load("images/finish.png").convert_alpha()
bg_surf = pygame.transform.scale(
    bg_surf, (bg_surf.get_width()//3, bg_surf.get_height()//3))

WHITE = (255, 255, 255)
BLUE = (0, 0, 255)
GREEN = (0, 255, 0)
RED = (255, 0, 0)
BLACK = (0, 0, 0)
YELLOW = (239, 228, 176)

FPS = 60        # число кадров в секунду
clock = pygame.time.Clock()

car_up = car_surf
car_down = pygame.transform.flip(car_surf, 0, 1)
car_left = pygame.transform.rotate(car_surf, 90)
car_right = pygame.transform.rotate(car_surf, -90)

car = car_up
speed = 5

while TRUE:

    keys = pygame.key.get_pressed()
    mouses = pygame.mouse.get_pressed()[0]

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            TRUE = UNTRUE
        if keys[pygame.K_ESCAPE]:
            TRUE = UNTRUE
        if keys[pygame.K_LEFT]:
            car = car_left
            car_rect.x -= speed
            if car_rect.x < 0:
                car_rect.x = 0
        elif keys[pygame.K_RIGHT]:
            car = car_right
            car_rect.x += speed
            if car_rect.x > W-car_rect.height:
                car_rect.x = W-car_rect.height
        elif keys[pygame.K_UP]:
            car = car_up
            car_rect.y -= speed
            if car_rect.y < 0:
                car_rect.y = 0
        elif keys[pygame.K_DOWN]:
            car = car_down
            car_rect.y += speed
            if car_rect.y > H-car_rect.height:
                car_rect.y = H-car_rect.height

    sc.blit(bg_surf, (0, 0))
    sc.blit(finish_surf, (0, 0))
    sc.blit(car, car_rect)

    clock.tick(FPS)
    pygame.display.update()
'''
'''
x, y = 10, 10
surf = pygame.Surface((x, y))
penny = 0
coor_x = W // 2
coor_y = H // 2

surf.fill(RED)

while TRUE:

    keys = pygame.key.get_pressed()

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            TRUE = UNTRUE
        if keys[pygame.K_ESCAPE]:
            TRUE = UNTRUE
        if keys[pygame.K_UP]:
            x += 1
            y += 1
            penny += 1
            if penny == 2:
                coor_x -= 1
                coor_y -= 1
                penny = 0
        if keys[pygame.K_DOWN]:
            x -= 1
            y -= 1
            penny += 1
            if penny == 2:
                coor_x += 1
                coor_y += 1
                penny = 0

    clock.tick(FPS)

    surf = pygame.Surface((x, y))
    surf.fill(RED)
    sc.fill(BLACK)
    sc.blit(surf, (coor_x, coor_y))
    pygame.display.update()
'''
'''
    surf = pygame.Surface((200, 200))
    surf.fill(RED)
    pygame.draw.circle(surf, GREEN, (100, 100), 80)
    # surf.set_alpha(128)

    surf_alpha = pygame.Surface((W, 200))
    pygame.draw.rect(surf_alpha, BLUE, (0, 0, W, 100))
    surf.set_alpha(128)

    surf_alpha.blit(surf, (0, 0))
    sc.blit(surf_alpha, (50, 50))
    pygame.display.update()
'''
pygame.quit()
sys.exit()
'''
import pygame as pg
from pygame.locals import *

from OpenGL.GL import *
from OpenGL.GLU import *

cubeVertices = ((1, 1, 1), (1, 1, -1), (1, -1, -1), (1, -1, 1),
                (-1, 1, 1), (-1, -1, -1), (-1, -1, 1), (-1, 1, -1))
cubeEdges = ((0, 1), (0, 3), (0, 4), (1, 2), (1, 7), (2, 5),
             (2, 3), (3, 6), (4, 6), (4, 7), (5, 6), (5, 7))
cubeQuads = ((0, 3, 6, 4), (2, 5, 6, 3), (1, 2, 5, 7),
             (1, 0, 4, 7), (7, 4, 6, 5), (2, 3, 0, 1))

def wireCube():
    glBegin(GL_LINES)
    for cubeEdge in cubeEdges:
        for cubeVertex in cubeEdge:
            glVertex3fv(cubeVertices[cubeVertex])
    glEnd()

def solidCube():
    glBegin(GL_QUADS)
    for cubeQuad in cubeQuads:
        for cubeVertex in cubeQuad:
            glVertex3fv(cubeVertices[cubeVertex])
    glEnd()

def main():
    pg.init()
    display = (1680, 1050)
    pg.display.set_mode(display, DOUBLEBUF | OPENGL)

    gluPerspective(45, (display[0]/display[1]), 0.1, 50.0)

    glTranslatef(0.0, 0.0, -5)

    while True:
        for event in pg.event.get():
            if event.type == pg.QUIT:
                pg.quit()
                quit()

        glRotatef(1, 1, 1, 1)
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
        solidCube()
        # wireCube()
        pg.display.flip()
        pg.time.wait(10)

if __name__ == "__main__":
    main()
'''


code:
import new
import sys

def main():
    new.func5()

if __name__ == '__main__':
    sys.exit(main())


code:
from datetime import datetime
import time
import random
import sys

ranha = 7

class Output:
    def __init__(self):
        self.odds = list(range(1, 60, 2))
        #self.rtm = datetime.today().minute
        #self.wait_time = random.randint(0, 30)

    def hoop(self, something):
        self.rtm = datetime.today().minute
        self.wait_time = random.randint(0, 10)
        if self.rtm in self.odds:
            print("This minute seems a little odd.")
        else:
            print("Not an odd minute.")
        if something == ranha-1:
            time.sleep(0)
        else:
            time.sleep(self.wait_time)

def func1():
    ou1 = Output()
    for i in range(ranha):
        ou1.hoop(i)

def func2():
    vowel = ['a', 'e', 'i', 'o', 'u']
    word = input("Provide a word to search for vowels: ")
    found = []
    for letter in word:
        if letter in vowel:
            if letter not in found:
                found.append(letter)
    print(found)

    remov = [1, 2, 3, 4, 5]
    print(remov)
    remov.remove(5)
    print(remov)
    remov.pop(2)
    print(remov)
    remov.extend([5, 6])
    remov.insert(2, 3)
    print(remov)

def func3():
    phrase = "Don't panic!"
    plist = list(phrase)
    print(phrase)
    print(plist)

    new_phrase = ''.join(plist[1:3])
    new_phrase = new_phrase + ''.join([plist[5], plist[4], plist[7], plist[6]])

    print(plist)
    print(new_phrase)

def func4():
    paranoid_android = "Marvin, the Paranoid Android"
    letters = list(paranoid_android)
    for char in letters[:6]:
        print('\t', char)
    #print()
    for char in letters[-7:]:
        print('\t'*2, char)
    #print()
    for char in letters[12:20]:
        print('\t'*3, char)
    #print()

def func5():
    vowel = set('aeiou')
    found = {}
    phrase = input('put something here: ')

    for char in phrase:
        if char in vowel:
            found.setdefault(char, 0)
            found[char] += 1
    for k, v in sorted(found.items()):
        if v != 0:
            print(k, 'was found', v, 'time(s)')

def func6():
    vowel = set('aeiou')
    word = input('something: ')
    found = vowel.intersection(set(word))

    for vowel in sorted(found):
        print(vowel)

def main():
    func6()

if __name__ == '__main__':
    sys.exit(main())


code:
import pygame
import sys
import random
# import time
from pygame import gfxdraw

GREEN = (0, 255, 0)
RED = (255, 0, 0)
BLACK = (0, 0, 0)
BLUE = (0, 0, 128)
WID = 800
HEG = 800
FPS = 60
SPEED = 3

# scope1 = 0
# scope2 = 0
score = 0
WALL = pygame.sprite.Group()
TAR = pygame.sprite.Group()
SPRITES = pygame.sprite.Group()

pygame.init()

clock = pygame.time.Clock()
screen = pygame.display.set_mode((WID, HEG))

font = pygame.font.Font('freesansbold.ttf', 16)

sc_wall = font.render('#', 1, BLUE, BLACK)
wall_rect = sc_wall.get_rect(topleft=(0, HEG//2))

def IntersectEndlessLineLine(l1_p1, l1_p2, l2_p1, l2_p2):

    # calculate the line vectors and test if both lengths are > 0
    P = pygame.math.Vector2(*l1_p1)
    Q = pygame.math.Vector2(*l2_p1)
    line1 = pygame.math.Vector2(*l1_p2) - P
    line2 = pygame.math.Vector2(*l2_p2) - Q
    if line1.length() == 0 or line2.length() == 0:
        return (False, (0, 0))

    # check if the lines are not parallel
    R, S = (line1.normalize(), line2.normalize())
    dot_R_nvS = R.dot(pygame.math.Vector2(S[1], -S[0]))
    if abs(dot_R_nvS) < 0.001:
        return (False, (0, 0))

    # calculate the intersection point of the lines
    # t  =  dot(Q-P, (S.y, -S.x)) / dot(R, (S.y, -S.x))
    # X  = P + R * t
    ptVec = Q-P
    t = ptVec.dot(pygame.math.Vector2(S[1], -S[0])) / dot_R_nvS
    xPt = P + R * t
    return (True, (xPt[0], xPt[1]))

def InRange(coord, range_s, range_e):
    if range_s < range_e:
        return coord >= range_s and coord <= range_e
    return coord >= range_e and coord <= range_s

def PtInRect(pt, lp1, lp2):
    return InRange(pt[0], lp1[0], lp2[0]) and InRange(pt[1], lp1[1], lp2[1])

def IntersectLineLine(l1_p1, l1_p2, l2_p1, l2_p2):
    isect, xPt = IntersectEndlessLineLine(l1_p1, l1_p2, l2_p1, l2_p2)
    isect = isect and PtInRect(
        xPt, l1_p1, l1_p2) and PtInRect(xPt, l2_p1, l2_p2)
    return isect, xPt

def IntersectLineRec(p1, p2, rect):
    iL = [
        IntersectLineLine(p1, p2, rect.bottomleft, rect.bottomright),
        IntersectLineLine(p1, p2, rect.bottomright, rect.topright),
        IntersectLineLine(p1, p2, rect.topright, rect.topleft),
        IntersectLineLine(p1, p2, rect.topleft, rect.bottomleft)]
    iDist = [(i[1], pygame.math.Vector2(i[1][0] - p1[0], i[1]
              [1] - p1[1]).length()) for i in iL if i[0]]
    iDist.sort(key=lambda t: t[1])
    return iDist

class Player(pygame.sprite.Sprite):

    def __init__(self, x, y, w, h):
        super().__init__()
        self.w = w
        self.h = h
        self.walls = None
        self.target = None
        self.x = 0
        self.y = 0

        self.image = pygame.Surface([w, h])
        self.image.fill(GREEN)
        self.rect = self.image.get_rect()
        self.rect.x = x
        self.rect.y = y

    def speed(self, x, y):
        self.x += x
        self.y += y

    def update(self):

        if self.rect.x > 0:
            self.rect.x += self.x
        else:
            self.rect.x = 1
        if self.rect.x < WID-self.rect.height:
            self.rect.x += self.x
        else:
            self.rect.x = WID-self.rect.height-1

        if self.rect.y > 0:
            self.rect.y += self.y
        else:
            self.rect.y = 1
        if self.rect.y < HEG-self.rect.height:
            self.rect.y += self.y
        else:
            self.rect.y = HEG-self.rect.height-1

        block_hit_list = pygame.sprite.spritecollide(self, self.walls, False)

        #print(self.rect.x, self.rect.y)

        for block in block_hit_list:
            if self.x > 0:
                self.rect.right = block.rect.left
            elif self.x < 0:
                self.rect.left = block.rect.right
            elif self.y > 0:
                self.rect.bottom = block.rect.top
            elif self.y < 0:
                self.rect.top = block.rect.bottom

        block_hit_tar = pygame.sprite.spritecollide(self, self.target, False)

        for block in block_hit_tar:
            target.draw()

player = Player(0, 0, 10, 10)

class Target(pygame.sprite.Sprite):

    def __init__(self):
        super().__init__()
        self.x = random.randint(1, HEG)
        self.y = random.randint(1, WID)
        self.r = 10

        self.image = pygame.image.load('images/ball_cr.png')
        self.rect = self.image.get_rect(center=(self.x, self.y))

    def draw(self):
        global score
        self.x = random.randint(1, HEG)
        self.y = random.randint(1, WID)
        score += 1
        self.rect = self.image.get_rect(center=(self.x, self.y))

target = Target()
TAR.add(target)
SPRITES.add(TAR)

class Wall(pygame.sprite.Sprite):

    def __init__(self, x, y, w, h):
        pygame.sprite.Sprite.__init__(self)
        self.x = x
        self.y = y
        self.w = w
        self.h = h

        self.image = pygame.Surface((self.w, self.h))
        self.image.fill(BLUE)
        self.rect = pygame.Rect(self.x, self.y, self.w, self.h)
        self.prev_loc = None

    def collision(self, object_location):

        if not self.prev_loc:
            self.prev_loc = object_location
            return None

        intersect = IntersectLineRec(self.prev_loc, object_location, self.rect)
        self.prev_loc = object_location

        if intersect:
            ip = [*intersect[0][0]]
            for i in range(2):
                tp = self.rect.center[i] if ip[i] == object_location[i] else object_location[i]
                ip[i] += -3 if ip[i] < tp else 3
                print(ip)
            self.prev_loc = ip
            return intersect, ip

        return None

wall = Wall(0, HEG//2, 100, 20)
WALL.add(wall)
SPRITES.add(WALL)

pygame.mouse.set_visible(False)
pygame.event.set_grab(True)
loop = True
player.walls = WALL
player.target = TAR
SPRITES.add(player)

while loop:
    keys = pygame.key.get_pressed()

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            loop = False
        elif event.type == pygame.KEYDOWN:
            if event.key == pygame.K_ESCAPE:
                loop = False
            elif event.key == pygame.K_LEFT:
                player.speed(-SPEED, 0)
            elif event.key == pygame.K_RIGHT:
                player.speed(SPEED, 0)
            elif event.key == pygame.K_UP:
                player.speed(0, -SPEED)
            elif event.key == pygame.K_DOWN:
                player.speed(0, SPEED)

        elif event.type == pygame.KEYUP:
            if event.key == pygame.K_LEFT:
                player.speed(SPEED, 0)
            elif event.key == pygame.K_RIGHT:
                player.speed(-SPEED, 0)
            elif event.key == pygame.K_UP:
                player.speed(0, SPEED)
            elif event.key == pygame.K_DOWN:
                player.speed(0, -SPEED)

        elif event.type == pygame.MOUSEMOTION:

            player.rect.center = pygame.mouse.get_pos()
            '''

            collide = wall.rect.colliderect(wall)
            if collide:

                if player.rect.y < wall.rect.y+1:
                    player.rect.bottom = wall.rect.top
                elif player.rect.y > wall.rect.y-1:
                    player.rect.top = wall.rect.bottom
            '''
            intersect_information = wall.collision(pygame.mouse.get_pos())
            if intersect_information:
                intersect, new_location = intersect_information
                pygame.mouse.set_pos(new_location)

    SPRITES.update()
    screen.fill(BLACK)
    SPRITES.draw(screen)

    sc_text = font.render('Score '+str(score), 1, GREEN, BLACK)
    screen.blit(sc_text, (10, 10))

    pygame.display.update()
    clock.tick(FPS)

pygame.quit()
sys.exit()


code:
import pygame
'''
import pygame
import sys
import pyglet
import pyglet.window.key as key
from pygame import gfxdraw

pygame.init()

BLACK = (0, 0, 0)
RED = (255, 0, 0)
GREEN = (0, 255, 0)
BLUE = (0, 0, 255)

scorep1 = 0
scorep2 = 0

clock = pygame.time.Clock()
screen = pygame.display.set_mode((500, 500))

Font = pygame.font.SysFont('timesnewroman', 20)
'''
'''
class Bar(pygame.sprite.Sprite):
    "This is the bar class"

    def __init__(self, x, y, w=10, h=60):
        super().__init__()
        self.x = x
        self.y = y
        self.w = w
        self.h = h
        self.rect = pygame.Rect(self.x, self.y, self.w, self.h)

    def update(self):
        self.y = pygame.mouse.get_pos()[1]
        self.rect = pygame.Rect(self.x, self.y, self.w, self.h)
        pygame.draw.rect(screen, RED, self.rect)

bar1 = Bar(0, 0)
bar2 = Bar(490, 0)

class Ball:
    "Draw the ball"

    def __init__(self, x, y):
        self.dirh = 0
        self.dirv = 0
        self.speed = 5
        self.x = x
        self.y = y
        # self.rect = pygame.Rect(self.x, self.y, 10, 10)

    def update(self):

        if self.dirh == 0:
            self.x -= self.speed
        if self.dirv == 0:
            self.y += self.speed
            if self.y > 490:
                self.dirv = 1
        if self.dirv:
            self.y -= self.speed
            if self.y < self.speed:
                self.dirv = 0
        if self.dirh:
            self.x += self.speed
        gfxdraw.filled_circle(screen, self.x, self.y, 5, (0, 255, 0))
        self.rect = pygame.Rect(self.x, self.y, 10, 10)

ball = Ball(480, 20)

def collision():
    global scorep1, scorep2

    pygame.display.set_caption(
        f"Player 1: {scorep1} - Player 2: {scorep2}")

    if ball.rect.colliderect(bar2):
        ball.dirh = 0
    if ball.rect.colliderect(bar1):
        ball.dirh = 1
    if ball.x > 500:
        ball.x, ball.y = 10, 20
    if ball.x < 0:
        gfxdraw.filled_circle(screen, ball.x, ball.y, 5, (0, 0, 0))
        ball.x, ball.y = 480, 20

pygame.mouse.set_visible(False)
pygame.event.set_grab(True)
loop = 1
while loop:
    keys = pygame.key.get_pressed()
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            loop = 0
        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_ESCAPE:
                loop = 0
    gfxdraw.filled_circle(screen, ball.x, ball.y, 5, (0, 0, 0))
    ball.update()
    pygame.draw.rect(screen, BLACK, bar1.rect)
    bar1.update()
    pygame.draw.rect(screen, BLACK, bar2.rect)
    bar2.update()
    collision()
    pygame.display.update()
    # screen.fill((0, 0, 0))
    clock.tick(60)

pygame.quit()
sys.exit()
'''

'''
symbol = Font.render('#', False, GREEN, BLACK)

loop = 1

while loop:
    keys = pygame.key.get_pressed()
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            loop = 0
        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_ESCAPE:
                loop = 0
    x = 0
    for i in range(10):
        screen.blit(symbol, (0+x, 200))
        x += 15
    pygame.display.update()
    clock.tick(60)

pygame.quit()
sys.exit()
'''
'''
import pygame

pygame.init()

window = pygame.display.set_mode((600, 600))

clock = pygame.time.Clock()

player_rect = pygame.Rect(200, 500, 50, 50)

player_rect2 = pygame.Rect(200, 0, 50, 50)

run = True

while run:

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            run  = False
        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_ESCAPE:
                run = False

    clock.tick(60)

    player_rect2.center = pygame.mouse.get_pos()
    collide = pygame.Rect.colliderect(player_rect,
                                      player_rect2)

    if collide:
        player_rect2.bottom = player_rect.top

    pygame.draw.rect(window, (0, 255, 0),
                     player_rect)
    pygame.draw.rect(window, (0, 0, 255),
                     player_rect2)

    pygame.display.update()

    window.fill((255, 255, 255))
'''

class Player(object):
    def __init__(self, x, y, w, h):
        self.rect = pygame.rect.Rect(x, y, w, h)

    def handle_keys(self):
        key = pygame.key.get_pressed()
        if key[pygame.K_LEFT]:
            self.rect.left = max(20, self.rect.left - 1)
        if key[pygame.K_RIGHT]:
            self.rect.right = min(window.get_height() -
                                  20, self.rect.right + 1)
        if key[pygame.K_UP]:
            self.rect.top = max(20, self.rect.top - 1)
        if key[pygame.K_DOWN]:
            self.rect.bottom = min(
                window.get_width() - 20, self.rect.bottom + 1)

    def draw(self, surface):
        pygame.draw.rect(surface, (0, 0, 128), self.rect)

pygame.init()
window = pygame.display.set_mode((240, 240))
clock = pygame.time.Clock()

player = Player(20, 20, 50, 50)
v, vel = pygame.math.Vector2(1, 1), 0.5
ballPosX, ballPosY, ballRadius = 120, 120, 10

run = True
while run:
    clock.tick(120)
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            run = False
    player.handle_keys()

    min_x, min_y, max_x, max_y = 20, 20, window.get_width()-20, window.get_height()-20
    ballPosX += v[0] * vel
    ballPosY += v[1] * vel
    if ballPosX - ballRadius < min_x:
        ballPosX = ballRadius + min_x
        v[0] = -v[0]
    if ballPosY - ballRadius < min_y:
        ballPosY = ballRadius + min_y
        v[1] = -v[1]
    if ballPosX + ballRadius > max_x:
        ballPosX = max_x - ballRadius
        v[0] = -v[0]
    if ballPosY + ballRadius > max_y:
        ballPosY = max_y - ballRadius
        v[1] = -v[1]

    ball = pygame.Rect((0, 0), (ballRadius*2, ballRadius*2))
    ball.center = int(ballPosX), int(ballPosY)
    if player.rect.colliderect(ball):
        dx = ballPosX - player.rect.centerx
        dy = ballPosY - player.rect.centery
        if abs(dx) > abs(dy):
            if dx < 0:
                ballPosX = max(player.rect.left-ballRadius, ballRadius+min_x)
                player.rect.left = int(ballPosX)+ballRadius
            else:
                ballPosX = min(player.rect.right+ballRadius, max_x-ballRadius)
                player.rect.right = int(ballPosX)-ballRadius
            if (dx < 0 and v[0] > 0) or (dx > 0 and v[0] < 0):
                v.reflect_ip(pygame.math.Vector2(1, 0))
        else:
            if dy < 0:
                ballPosY = max(player.rect.top-ballRadius, ballRadius+min_y)
                player.rect.top = int(ballPosY)+ballRadius
            else:
                ballPosY = min(player.rect.bottom+ballRadius, max_y-ballRadius)
                player.rect.bottom = int(ballPosY)-ballRadius
            ballPosY = player.rect.top-ballRadius if dy < 0 else player.rect.bottom+ballRadius
            if (dy < 0 and v[1] > 0) or (dy > 0 and v[1] < 0):
                v.reflect_ip(pygame.math.Vector2(0, 1))

    window.fill((255, 255, 255))
    pygame.draw.rect(window, (255, 0, 0), (18, 18, 203, 203), 2)
    player.draw(window)
    pygame.draw.circle(window, (0, 255, 0), (round(
        ballPosX), round(ballPosY)), ballRadius)
    pygame.display.update()

pygame.quit()
exit()


code:
# Contributor Code of Conduct

As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.

We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.

Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.

Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.

Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.

This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at https://www.contributor-covenant.org/version/1/0/0/code-of-conduct.html

repo_name: chen/Catiptv


code:
# Contributing Guide

If you want to help the project you can do this in several ways. Here are some options:

- [Add channel](#add-channel)
- [Sort channels by category](#sort-channels-by-category)
- [Sort channels by country](#sort-channels-by-country)
- [Remove broken broadcasts](#remove-broken-broadcasts)
- [Add EPG source](#add-epg-source)

## Add channel

To add a channel to one of the playlists, you first need to make sure that the channel broadcast is working stably. Otherwise, we just have to delete the channel you just added.

To do this, start the broadcast in one of the players (preferably a VLC player) and keep it on for at least a minute. The fact is that some broadcasts are configured to automatically turn off after 10-15 seconds or sometimes after a couple of minutes.

You should also make sure that this is a live broadcast and not a looped video (this also happens). The easiest way is to start the broadcast several times in a row after a short period of time and compare the beginning.

If everything is fine, then you can proceed to add the channel to the playlist.

If you know exactly in which country this channel is broadcast, then simply select the appropriate playlist from the `channels/` folder and add the channel to it.

If you are not sure which playlist to add this channel to, you can add it to the `channels/unsorted.m3u` file. It was created specifically for such cases.

Further on the format of links in the playlist. For the broadcast to work in the playlist, you need to add at least minimal information about the channel, like so:

```xml
#EXTINF:-1,Example TV
http://example.com/stream.m3u8
```

But of course, the more channel information you add, the better. Here's an example of what a full version of a link in a playlist might look like:

```xml
#EXTINF:-1 tvg-id="exampletv.us" tvg-name="Example TV" tvg-language="English" tvg-logo="http://example.com/channel-logo.png" group-title="News",Example TV
http://example.com/stream.m3u8
```

More details about each attribute:

| Attribute    | Description
| ------------ | ---
| tvg-id       | Channel ID that is used to load EPG. Must match `id` from the EPG file. (optional)
| tvg-name     | Channel name that is also sometimes used to load EPG. Must match `display-name` from the EPG file. (optional)
| tvg-language | Channel language. The name of the language must conform to the standard [ISO 639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) (optional)
| tvg-logo     | The logo of the channel that will be displayed in the player if it supports it (optional)
| group-title  | The category to which the channel belongs. These categories are also displayed in some players, and grouped playlists are also generated based on them. The list of currently supported categories can be found [here](https://github.com/iptv-org/iptv#playlists-by-category) (optional)

## Sort channels by category

To help sort channels by category, you need to add the corresponding category in the description of the channel, like this:

```xml
#EXTINF:-1 group-title="News",CNN
http://example.com/cnn.m3u8
```

For convenience, `https://iptv-org.github.io/iptv/categories/other.m3u` contains all the channels for which a category has not yet been specified. But be careful, changes can only be made in the playlists located in the `channels/` folder, since the other playlists are automatically generated.

A complete list of supported categories can be found [here](https://github.com/iptv-org/iptv#playlists-by-category).

## Sort channels by country

You can help sorting channels by country by moving the link to the channel with the entire description from one playlist in the `channels/` folder to another. Be careful, any changes outside the `channels/` folder will not be accepted, since the rest of the playlists are generated automatically.

To determine which country the channel belongs to you can search for it on the [LyngSat](https://www.lyngsat.com/search.html). This site contains a short description for most satellite TV channels, but in this case we are only interested in the country name written under the channel logo, as here: https://www.lyngsat.com/radiochannels/us/CNN-USA.html

Also you can try searching for a channel on [Wikipedia](https://www.wikipedia.org/). Usually channels have a separate raw in the description indicating the country. You can see what it looks like on this page - https://en.wikipedia.org/wiki/CNN

It also happens that a channel belongs to more than one country. In this case, it should be saved to all relevant playlists.

However, there are situations when the channel is literally not assigned to any country (for example, DJing or Red Bull TV). In this case, you can simply move the link to a special international playlist - `channels/int.m3u`.

## Remove broken broadcasts

To make sure that the broadcast works you need to run it in two main applications: VLC player (https://www.videolan.org/) and Kodi (https://kodi.tv/). After starting, do not forget to wait at least a minute, as some broadcasts are started with a delay due to the location of the source.

If it turns out that the broadcast still does not start, this means that it can be safely deleted from the playlist. At the same time, you should delete not only the link to the channel but also the description for it.

It would also be nice if you indicated in the description of the PR the reason for the removal of the channel, so that other members of the community could also double-check the channel for their part.

It is also possible to automatically find broken broadcasts. To do this, you first need to install [Node.js](https://nodejs.org/en/) and [ffmpeg](https://www.ffmpeg.org) on your computer.

After that copy this repository to your computer, open it in the console and install all the dependencies from it by running this command:

```sh
npm install
```

And as soon as everything is installed, you can run tests, like this:

```sh
npm test
```

And be prepared test may take a long time.

If you want to test the playlist of a particular country, you can specify the [ISO 3166 code](https://en.wikipedia.org/wiki/ISO_3166) of the country as an argument when running the test.

```sh
npm test --country=uk
```

Another option to exclude specific playlists from tests:

```sh
npm test --exclude=cn,int
```

After the test is over all broken links will be saved to the file `error.log`.

## Add EPG source

To add a new source of EPG (Electronic Program Guide), you must add the `x-tvg-url` attribute to the beginning of the corresponding playlist, like this:

```xml
#EXTM3U x-tvg-url="http://example.com/epg.xml.gz"
```

The next step is to copy the corresponding `tvg-id` and `tvg-name` from EPG into the description of the channels. To do this, we need to open the EPG file in a browser or any text editor, find the list of channels. Usually it looks like this:

```xml
<tv>
  <channel id="cnn">
    <display-name>CNN</display-name>
  </channel>
  <channel id="nbc">
    <display-name>NBC</display-name>
  </channel>
  ...
</tv>
```

Copy `id` and `display-name` from it and paste it to the channel description, like this:

```xml
#EXTINF:-1 tvg-id="cnn" tvg-name="CNN",CNN
http://example.com/cnn.m3u8
```

And if you did everything right, then by opening a playlist in a player that supports EPG, you should see the program guide for all updated channels. In some cases, it may also be necessary to manually specify the source of EPG in the player itself.


code:
# These are supported funding model platforms

github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
patreon: # Replace with a single Patreon username
open_collective: # Replace with a single Open Collective username
ko_fi: # Replace with a single Ko-fi username
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
liberapay: # Replace with a single Liberapay username
issuehunt: # Replace with a single IssueHunt username
otechie: # Replace with a single Otechie username
custom: []


code:
name: Auto-merge PRs

on:
  pull_request:
    types:
      - labeled
      - unlabeled
      - synchronize
      - opened
      - edited
      - ready_for_review
      - reopened
      - unlocked
  pull_request_review:
    types:
      - submitted
  status: {}
jobs:
  automerge:
    runs-on: ubuntu-latest
    steps:
      - name: automerge
        uses: "pascalgn/automerge-action@f84dd310ea4a19890c70a4ff11ab282a872fb94b"
        env:
          GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
          AUTOMERGE: "automerge"


code:
name: Format playlists

on:
  schedule:
    - cron:  '0 0 * * *'

jobs:
  format:
    runs-on: ubuntu-latest
    steps:
    - name: Checkout
      uses: actions/checkout@master

    - name: Install Dependencies
      run: npm install

    - name: Format Playlists
      run: npm run format

    - name: Create Pull Request
      uses: peter-evans/create-pull-request@v1.6.0
      env:
        GITHUB_TOKEN: ${{ secrets.REPO_SCOPED_TOKEN }}
        COMMIT_MESSAGE: 'Formatted playlists'
        PULL_REQUEST_BRANCH: bot-patch
        PULL_REQUEST_TITLE: '[Bot] Format playlists'
        PULL_REQUEST_LABELS: automerge
        PULL_REQUEST_BODY: >
            This pull request is auto-generated by GitHub action.


code:
name: Publish playlists

on:
  schedule:
    - cron:  '0 1 * * *'

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
    - name: Checkout
      uses: actions/checkout@v1

    - name: Install Dependencies
      run: npm install

    - name: Generate Playlists
      run: npm run generate

    - name: Deploy to GitHub Pages
      uses: JamesIves/github-pages-deploy-action@master
      env:
        ACCESS_TOKEN: ${{ secrets.REPO_SCOPED_TOKEN }}
        BASE_BRANCH: master
        BRANCH: gh-pages
        FOLDER: .gh-pages
  update-readme:
    runs-on: ubuntu-latest
    needs: deploy
    steps:
    - name: Checkout
      uses: actions/checkout@master

    - name: Install Dependencies
      run: npm install

    - name: Update README.md
      run: npm run update-readme

    - name: Create Pull Request
      uses: peter-evans/create-pull-request@v1.5.1
      env:
        GITHUB_TOKEN: ${{ secrets.REPO_SCOPED_TOKEN }}
        COMMIT_MESSAGE: 'Update README.md'
        PULL_REQUEST_BRANCH: bot-patch
        PULL_REQUEST_TITLE: '[Bot] Update README.md'
        PULL_REQUEST_LABELS: automerge
        PULL_REQUEST_BODY: >
            This pull request is auto-generated by GitHub action.


code:
node_modules/
error.log
helpers/categories.md
helpers/countries.md

# IDE
*.sublime-project
*.sublime-workspace
.idea

# OS
.DS_Store

path: .gitignore


code:
Category	Channels	Playlist

Auto	3	https://iptv-org.github.io/iptv/categories/auto.m3u

Business	37	https://iptv-org.github.io/iptv/categories/business.m3u

Classic	1	https://iptv-org.github.io/iptv/categories/classic.m3u

Comedy	3	https://iptv-org.github.io/iptv/categories/comedy.m3u

Documentary	11	https://iptv-org.github.io/iptv/categories/documentary.m3u

Education	4	https://iptv-org.github.io/iptv/categories/education.m3u

Entertainment	91	https://iptv-org.github.io/iptv/categories/entertainment.m3u

Family	6	https://iptv-org.github.io/iptv/categories/family.m3u

Fashion	31	https://iptv-org.github.io/iptv/categories/fashion.m3u

Food	6	https://iptv-org.github.io/iptv/categories/food.m3u

General	58	https://iptv-org.github.io/iptv/categories/general.m3u

History	6	https://iptv-org.github.io/iptv/categories/history.m3u

Hobby	2	https://iptv-org.github.io/iptv/categories/hobby.m3u

Kids	44	https://iptv-org.github.io/iptv/categories/kids.m3u

Legislative	10	https://iptv-org.github.io/iptv/categories/legislative.m3u

Lifestyle	5	https://iptv-org.github.io/iptv/categories/lifestyle.m3u

Local	250	https://iptv-org.github.io/iptv/categories/local.m3u

Movies	120	https://iptv-org.github.io/iptv/categories/movies.m3u

Music	234	https://iptv-org.github.io/iptv/categories/music.m3u

News	320	https://iptv-org.github.io/iptv/categories/news.m3u

Religious	109	https://iptv-org.github.io/iptv/categories/religious.m3u

Shop	21	https://iptv-org.github.io/iptv/categories/shop.m3u

Sport	180	https://iptv-org.github.io/iptv/categories/sport.m3u

Travel	6	https://iptv-org.github.io/iptv/categories/travel.m3u

Weather	5	https://iptv-org.github.io/iptv/categories/weather.m3u

XXX	71	https://iptv-org.github.io/iptv/categories/xxx.m3u

Other	5297	https://iptv-org.github.io/iptv/categories/other.m3u


code:
Country	Channels	Playlist	EPG

Afghanistan	18	https://iptv-org.github.io/iptv/countries/af.m3u

Albania	29	https://iptv-org.github.io/iptv/countries/al.m3u	http://195.154.221.171/epg/guidealbania.xml.gz

Algeria	2	https://iptv-org.github.io/iptv/countries/dz.m3u	http://195.154.221.171/epg/guidearab.xml.gz

Andorra	4	https://iptv-org.github.io/iptv/countries/ad.m3u

Angola	1	https://iptv-org.github.io/iptv/countries/ao.m3u

Argentina	81	https://iptv-org.github.io/iptv/countries/ar.m3u

Armenia	9	https://iptv-org.github.io/iptv/countries/am.m3u

Aruba	3	https://iptv-org.github.io/iptv/countries/aw.m3u

Australia	20	https://iptv-org.github.io/iptv/countries/au.m3u	http://i.mjh.nz/nzau/epg.xml.gz

Austria	20	https://iptv-org.github.io/iptv/countries/at.m3u	http://epg.streamstv.me/epg/guide-austria.xml.gz

Azerbaijan	17	https://iptv-org.github.io/iptv/countries/az.m3u	https://iptvx.one/epg/epg.xml.gz

Bahamas	1	https://iptv-org.github.io/iptv/countries/bs.m3u

Bahrain	5	https://iptv-org.github.io/iptv/countries/bh.m3u	http://195.154.221.171/epg/guidearab.xml.gz

Bangladesh	11	https://iptv-org.github.io/iptv/countries/bd.m3u

Barbados	1	https://iptv-org.github.io/iptv/countries/bb.m3u

Belarus	7	https://iptv-org.github.io/iptv/countries/by.m3u	https://iptvx.one/epg/epg.xml.gz

Belgium	38	https://iptv-org.github.io/iptv/countries/be.m3u	http://195.154.221.171/epg/guidebelgium.xml.gz

Bolivia	15	https://iptv-org.github.io/iptv/countries/bo.m3u

Bosnia and Herzegovina	8	https://iptv-org.github.io/iptv/countries/ba.m3u	http://epg.streamstv.me/epg/guide-exyu.xml.gz

Brazil	74	https://iptv-org.github.io/iptv/countries/br.m3u	http://infinitytv.xyz/guide.xml

Brunei	3	https://iptv-org.github.io/iptv/countries/bn.m3u

Bulgaria	54	https://iptv-org.github.io/iptv/countries/bg.m3u	http://195.154.221.171/epg/guidebulgaria.xml.gz

Burkina Faso	1	https://iptv-org.github.io/iptv/countries/bf.m3u

Cambodia	25	https://iptv-org.github.io/iptv/countries/kh.m3u

Cameroon	17	https://iptv-org.github.io/iptv/countries/cm.m3u

Canada	36	https://iptv-org.github.io/iptv/countries/ca.m3u	http://epg.streamstv.me/epg/guide-canada.xml.gz

Cape Verde	1	https://iptv-org.github.io/iptv/countries/cv.m3u

Chile	62	https://iptv-org.github.io/iptv/countries/cl.m3u

China	2230	https://iptv-org.github.io/iptv/countries/cn.m3u	http://epg.51zmt.top:8000/e.xml.gz

Colombia	31	https://iptv-org.github.io/iptv/countries/co.m3u

Costa Rica	13	https://iptv-org.github.io/iptv/countries/cr.m3u

Croatia	35	https://iptv-org.github.io/iptv/countries/hr.m3u	http://tvprofil.net/xmltv/data/epg_tvprofil.net.xml

Curaçao	3	https://iptv-org.github.io/iptv/countries/cw.m3u

Cyprus	15	https://iptv-org.github.io/iptv/countries/cy.m3u	http://195.154.221.171/epg/guidegreece.xml.gz

Czech Republic	32	https://iptv-org.github.io/iptv/countries/cz.m3u	http://epg.streamstv.me/epg/guide-cz.xml.gz

Democratic Republic of the Congo	5	https://iptv-org.github.io/iptv/countries/cd.m3u

Denmark	16	https://iptv-org.github.io/iptv/countries/dk.m3u	http://195.154.221.171/epg/guidedenmark.xml.gz

Dominican Republic	41	https://iptv-org.github.io/iptv/countries/do.m3u

Ecuador	9	https://iptv-org.github.io/iptv/countries/ec.m3u

Egypt	56	https://iptv-org.github.io/iptv/countries/eg.m3u	http://195.154.221.171/epg/guidearab.xml.gz

El Salvador	2	https://iptv-org.github.io/iptv/countries/sv.m3u

Equatorial Guinea	3	https://iptv-org.github.io/iptv/countries/gq.m3u

Estonia	11	https://iptv-org.github.io/iptv/countries/ee.m3u	http://195.154.221.171/epg/guideestonia.xml.gz

Ethiopia	2	https://iptv-org.github.io/iptv/countries/et.m3u

Faroe Islands	2	https://iptv-org.github.io/iptv/countries/fo.m3u

Finland	3	https://iptv-org.github.io/iptv/countries/fi.m3u	http://195.154.221.171/epg/guidefinland.xml.gz

Fiji	1	https://iptv-org.github.io/iptv/countries/fj.m3u

France	97	https://iptv-org.github.io/iptv/countries/fr.m3u	http://195.154.221.171/epg/guidefrance.xml.gz

Gambia	1	https://iptv-org.github.io/iptv/countries/gm.m3u

Georgia	14	https://iptv-org.github.io/iptv/countries/ge.m3u

Germany	173	https://iptv-org.github.io/iptv/countries/de.m3u	http://195.154.221.171/epg/guidegermany.xml.gz

Ghana	4	https://iptv-org.github.io/iptv/countries/gh.m3u

Greece	61	https://iptv-org.github.io/iptv/countries/gr.m3u	http://195.154.221.171/epg/guidegreece.xml.gz

Grenada	1	https://iptv-org.github.io/iptv/countries/gd.m3u

Guadeloupe	2	https://iptv-org.github.io/iptv/countries/gp.m3u

Guatemala	2	https://iptv-org.github.io/iptv/countries/gt.m3u

Guyana	2	https://iptv-org.github.io/iptv/countries/gy.m3u

Haiti	16	https://iptv-org.github.io/iptv/countries/ht.m3u

Honduras	27	https://iptv-org.github.io/iptv/countries/hn.m3u

Hong Kong	40	https://iptv-org.github.io/iptv/countries/hk.m3u

Hungary	26	https://iptv-org.github.io/iptv/countries/hu.m3u	http://epg.streamstv.me/epg/guide-hungry.xml.gz

Iceland	6	https://iptv-org.github.io/iptv/countries/is.m3u

India	254	https://iptv-org.github.io/iptv/countries/in.m3u	http://epg.streamstv.me/epg/guide-india.xml.gz

Indonesia	129	https://iptv-org.github.io/iptv/countries/id.m3u

International	97	https://iptv-org.github.io/iptv/countries/int.m3u

Iran	78	https://iptv-org.github.io/iptv/countries/ir.m3u	http://195.154.221.171/epg/guideiran.xml.gz

Iraq	51	https://iptv-org.github.io/iptv/countries/iq.m3u	http://195.154.221.171/epg/guidearab.xml.gz

Ireland	2	https://iptv-org.github.io/iptv/countries/ie.m3u

Israel	21	https://iptv-org.github.io/iptv/countries/il.m3u	http://epg.streamstv.me/epg/guide-israel.xml.gz

Italy	221	https://iptv-org.github.io/iptv/countries/it.m3u	http://195.154.221.171/epg/guideitaly.xml.gz

Ivory Coast	4	https://iptv-org.github.io/iptv/countries/ci.m3u

Jamaica	6	https://iptv-org.github.io/iptv/countries/jm.m3u

Japan	32	https://iptv-org.github.io/iptv/countries/jp.m3u

Jordan	13	https://iptv-org.github.io/iptv/countries/jo.m3u	http://195.154.221.171/epg/guidearab.xml.gz

Kazakhstan	19	https://iptv-org.github.io/iptv/countries/kz.m3u	https://iptvx.one/epg/epg.xml.gz

Kenya	5	https://iptv-org.github.io/iptv/countries/ke.m3u

Kosovo	11	https://iptv-org.github.io/iptv/countries/xk.m3u

Kuwait	31	https://iptv-org.github.io/iptv/countries/kw.m3u	http://195.154.221.171/epg/guidearab.xml.gz

Kyrgyzstan	6	https://iptv-org.github.io/iptv/countries/kg.m3u

Laos	4	https://iptv-org.github.io/iptv/countries/la.m3u

Latvia	19	https://iptv-org.github.io/iptv/countries/lv.m3u	https://iptvx.one/epg/epg.xml.gz

Lebanon	32	https://iptv-org.github.io/iptv/countries/lb.m3u	http://195.154.221.171/epg/guidearab.xml.gz

Libya	7	https://iptv-org.github.io/iptv/countries/ly.m3u

Liechtenstein	2	https://iptv-org.github.io/iptv/countries/li.m3u

Lithuania	8	https://iptv-org.github.io/iptv/countries/lt.m3u	https://iptvx.one/epg/epg.xml.gz

Luxembourg	5	https://iptv-org.github.io/iptv/countries/lu.m3u

Macau	14	https://iptv-org.github.io/iptv/countries/mo.m3u

Malaysia	18	https://iptv-org.github.io/iptv/countries/my.m3u

Maldives	5	https://iptv-org.github.io/iptv/countries/mv.m3u

Malta	1	https://iptv-org.github.io/iptv/countries/mt.m3u	http://epg.streamstv.me/epg/guide-malta.xml.gz

Mexico	56	https://iptv-org.github.io/iptv/countries/mx.m3u

Moldova	16	https://iptv-org.github.io/iptv/countries/md.m3u	https://iptvx.one/epg/epg.xml.gz

Mongolia	6	https://iptv-org.github.io/iptv/countries/mn.m3u

Montenegro	4	https://iptv-org.github.io/iptv/countries/me.m3u

Morocco	23	https://iptv-org.github.io/iptv/countries/ma.m3u	http://195.154.221.171/epg/guidearab.xml.gz

Mozambique	5	https://iptv-org.github.io/iptv/countries/mz.m3u

Myanmar	5	https://iptv-org.github.io/iptv/countries/mm.m3u

Nepal	2	https://iptv-org.github.io/iptv/countries/np.m3u

Netherlands	67	https://iptv-org.github.io/iptv/countries/nl.m3u	http://195.154.221.171/epg/guidenetherlands.xml.gz

New Zealand	19	https://iptv-org.github.io/iptv/countries/nz.m3u	http://i.mjh.nz/nzau/epg.xml.gz

Nicaragua	10	https://iptv-org.github.io/iptv/countries/ni.m3u

Nigeria	14	https://iptv-org.github.io/iptv/countries/ng.m3u

North Korea	1	https://iptv-org.github.io/iptv/countries/kp.m3u

North Macedonia	4	https://iptv-org.github.io/iptv/countries/mk.m3u

Norway	4	https://iptv-org.github.io/iptv/countries/no.m3u	http://epg.streamstv.me/epg/guide-norway.xml.gz

Oman	8	https://iptv-org.github.io/iptv/countries/om.m3u	http://195.154.221.171/epg/guidearab.xml.gz

Pakistan	32	https://iptv-org.github.io/iptv/countries/pk.m3u

Palestine	17	https://iptv-org.github.io/iptv/countries/ps.m3u	http://195.154.221.171/epg/guidearab.xml.gz

Panama	4	https://iptv-org.github.io/iptv/countries/pa.m3u

Paraguay	1	https://iptv-org.github.io/iptv/countries/py.m3u

Peru	28	https://iptv-org.github.io/iptv/countries/pe.m3u

Philippines	11	https://iptv-org.github.io/iptv/countries/ph.m3u

Poland	12	https://iptv-org.github.io/iptv/countries/pl.m3u	http://195.154.221.171/epg/guidepoland.xml.gz

Portugal	34	https://iptv-org.github.io/iptv/countries/pt.m3u	http://195.154.221.171/epg/guideportugal.xml.gz

Puerto Rico	6	https://iptv-org.github.io/iptv/countries/pr.m3u

Qatar	15	https://iptv-org.github.io/iptv/countries/qa.m3u	http://195.154.221.171/epg/guidearab.xml.gz

Republic of the Congo	1	https://iptv-org.github.io/iptv/countries/cg.m3u

Romania	89	https://iptv-org.github.io/iptv/countries/ro.m3u	http://195.154.221.171/epg/guideromania.xml.gz

Russia	233	https://iptv-org.github.io/iptv/countries/ru.m3u	https://iptvx.one/epg/epg.xml.gz

Rwanda	2	https://iptv-org.github.io/iptv/countries/rw.m3u

Saint Kitts and Nevis	3	https://iptv-org.github.io/iptv/countries/kn.m3u

San Marino	2	https://iptv-org.github.io/iptv/countries/sm.m3u

Saudi Arabia	18	https://iptv-org.github.io/iptv/countries/sa.m3u	http://195.154.221.171/epg/guidearab.xml.gz

Senegal	4	https://iptv-org.github.io/iptv/countries/sn.m3u

Serbia	10	https://iptv-org.github.io/iptv/countries/rs.m3u	http://epg.streamstv.me/epg/guide-exyu.xml.gz

Sierra Leone	1	https://iptv-org.github.io/iptv/countries/sl.m3u

Singapore	12	https://iptv-org.github.io/iptv/countries/sg.m3u

Sint Maarten	1	https://iptv-org.github.io/iptv/countries/sx.m3u

Slovakia	39	https://iptv-org.github.io/iptv/countries/sk.m3u

Slovenia	6	https://iptv-org.github.io/iptv/countries/si.m3u	http://195.154.221.171/epg/guideslovenia.xml.gz

Somalia	10	https://iptv-org.github.io/iptv/countries/so.m3u

South Africa	2	https://iptv-org.github.io/iptv/countries/za.m3u	http://i.mjh.nz/za/DStv/epg.xml.gz

South Korea	45	https://iptv-org.github.io/iptv/countries/kr.m3u

Spain	176	https://iptv-org.github.io/iptv/countries/es.m3u	http://195.154.221.171/epg/guidespain.xml.gz

Sri Lanka	7	https://iptv-org.github.io/iptv/countries/lk.m3u

Sudan	7	https://iptv-org.github.io/iptv/countries/sd.m3u

Sweden	11	https://iptv-org.github.io/iptv/countries/se.m3u	http://195.154.221.171/epg/guidesweden.xml.gz

Switzerland	27	https://iptv-org.github.io/iptv/countries/ch.m3u	http://195.154.221.171/epg/guideswitzerland.xml.gz

Syria	10	https://iptv-org.github.io/iptv/countries/sy.m3u	http://195.154.221.171/epg/guidearab.xml.gz

Taiwan	54	https://iptv-org.github.io/iptv/countries/tw.m3u

Tanzania	2	https://iptv-org.github.io/iptv/countries/tz.m3u

Thailand	71	https://iptv-org.github.io/iptv/countries/th.m3u

Togo	1	https://iptv-org.github.io/iptv/countries/tg.m3u

Trinidad and Tobago	1	https://iptv-org.github.io/iptv/countries/tt.m3u

Tunisia	4	https://iptv-org.github.io/iptv/countries/tn.m3u	http://195.154.221.171/epg/guidearab.xml.gz

Turkey	108	https://iptv-org.github.io/iptv/countries/tr.m3u	http://195.154.221.171/epg/guideturkey.xml.gz

Turkmenistan	10	https://iptv-org.github.io/iptv/countries/tm.m3u

Uganda	3	https://iptv-org.github.io/iptv/countries/ug.m3u

Ukraine	161	https://iptv-org.github.io/iptv/countries/ua.m3u	https://iptvx.one/epg/epg.xml.gz

United Arab Emirates	141	https://iptv-org.github.io/iptv/countries/ae.m3u	http://195.154.221.171/epg/guidearab.xml.gz

United Kingdom	70	https://iptv-org.github.io/iptv/countries/uk.m3u	http://195.154.221.171/epg/guideuk.xml.gz

United States	460	https://iptv-org.github.io/iptv/countries/us.m3u	http://epg.streamstv.me/epg/guide-usa.xml.gz

Uruguay	5	https://iptv-org.github.io/iptv/countries/uy.m3u

Venezuela	10	https://iptv-org.github.io/iptv/countries/ve.m3u

Vietnam	62	https://iptv-org.github.io/iptv/countries/vn.m3u

Virgin Islands of the United States	1	https://iptv-org.github.io/iptv/countries/vi.m3u

Western Sahara	2	https://iptv-org.github.io/iptv/countries/eh.m3u

Yemen	3	https://iptv-org.github.io/iptv/countries/ye.m3u

Zimbabwe	2	https://iptv-org.github.io/iptv/countries/zw.m3u


code:
Language	Channels	Playlist

Akan	3	https://iptv-org.github.io/iptv/languages/ak.m3u

Albanian	40	https://iptv-org.github.io/iptv/languages/sq.m3u

Amharic	2	https://iptv-org.github.io/iptv/languages/am.m3u

Arabic	452	https://iptv-org.github.io/iptv/languages/ar.m3u

Armenian	9	https://iptv-org.github.io/iptv/languages/hy.m3u

Azerbaijani	17	https://iptv-org.github.io/iptv/languages/az.m3u

Bengali	11	https://iptv-org.github.io/iptv/languages/bn.m3u

Bosnian	4	https://iptv-org.github.io/iptv/languages/bs.m3u

Bulgarian	54	https://iptv-org.github.io/iptv/languages/bg.m3u

Burmese	5	https://iptv-org.github.io/iptv/languages/my.m3u

Catalan	4	https://iptv-org.github.io/iptv/languages/ca.m3u

Chinese	2343	https://iptv-org.github.io/iptv/languages/zh.m3u

Croatian	37	https://iptv-org.github.io/iptv/languages/hr.m3u

Czech	32	https://iptv-org.github.io/iptv/languages/cs.m3u

Danish	16	https://iptv-org.github.io/iptv/languages/da.m3u

Divehi	5	https://iptv-org.github.io/iptv/languages/dv.m3u

Dutch	85	https://iptv-org.github.io/iptv/languages/nl.m3u

English	758	https://iptv-org.github.io/iptv/languages/en.m3u

Estonian	11	https://iptv-org.github.io/iptv/languages/et.m3u

Faroese	2	https://iptv-org.github.io/iptv/languages/fo.m3u

Finnish	3	https://iptv-org.github.io/iptv/languages/fi.m3u

French	163	https://iptv-org.github.io/iptv/languages/fr.m3u

Georgian	14	https://iptv-org.github.io/iptv/languages/ka.m3u

German	219	https://iptv-org.github.io/iptv/languages/de.m3u

Greek	76	https://iptv-org.github.io/iptv/languages/el.m3u

Hausa	1	https://iptv-org.github.io/iptv/languages/ha.m3u

Hebrew	20	https://iptv-org.github.io/iptv/languages/he.m3u

Hindi	218	https://iptv-org.github.io/iptv/languages/hi.m3u

Hungarian	27	https://iptv-org.github.io/iptv/languages/hu.m3u

Icelandic	6	https://iptv-org.github.io/iptv/languages/is.m3u

Indonesian	129	https://iptv-org.github.io/iptv/languages/id.m3u

Italian	223	https://iptv-org.github.io/iptv/languages/it.m3u

Japanese	33	https://iptv-org.github.io/iptv/languages/ja.m3u

Kazakh	19	https://iptv-org.github.io/iptv/languages/kk.m3u

Khmer	25	https://iptv-org.github.io/iptv/languages/km.m3u

Kinyarwanda	2	https://iptv-org.github.io/iptv/languages/rw.m3u

Korean	46	https://iptv-org.github.io/iptv/languages/ko.m3u

Kurdish	17	https://iptv-org.github.io/iptv/languages/ku.m3u

Kyrgyz	6	https://iptv-org.github.io/iptv/languages/ky.m3u

Lao	4	https://iptv-org.github.io/iptv/languages/lo.m3u

Latvian	19	https://iptv-org.github.io/iptv/languages/lv.m3u

Lithuanian	8	https://iptv-org.github.io/iptv/languages/lt.m3u

Luxembourgish	5	https://iptv-org.github.io/iptv/languages/lb.m3u

Macedonian	4	https://iptv-org.github.io/iptv/languages/mk.m3u

Malay	25	https://iptv-org.github.io/iptv/languages/ms.m3u

Maltese	1	https://iptv-org.github.io/iptv/languages/mt.m3u

Mongolian	6	https://iptv-org.github.io/iptv/languages/mn.m3u

Māori	3	https://iptv-org.github.io/iptv/languages/mi.m3u

Nepali	2	https://iptv-org.github.io/iptv/languages/ne.m3u

Norwegian Bokmål	4	https://iptv-org.github.io/iptv/languages/nb.m3u

Pashto	18	https://iptv-org.github.io/iptv/languages/ps.m3u

Persian	61	https://iptv-org.github.io/iptv/languages/fa.m3u

Polish	12	https://iptv-org.github.io/iptv/languages/pl.m3u

Portuguese	115	https://iptv-org.github.io/iptv/languages/pt.m3u

Romanian	104	https://iptv-org.github.io/iptv/languages/ro.m3u

Russian	234	https://iptv-org.github.io/iptv/languages/ru.m3u

Serbian	16	https://iptv-org.github.io/iptv/languages/sr.m3u

Sinhala	7	https://iptv-org.github.io/iptv/languages/si.m3u

Slovak	39	https://iptv-org.github.io/iptv/languages/sk.m3u

Slovene	6	https://iptv-org.github.io/iptv/languages/sl.m3u

Somali	10	https://iptv-org.github.io/iptv/languages/so.m3u

Spanish	586	https://iptv-org.github.io/iptv/languages/es.m3u

Swahili	7	https://iptv-org.github.io/iptv/languages/sw.m3u

Swedish	11	https://iptv-org.github.io/iptv/languages/sv.m3u

Tagalog	11	https://iptv-org.github.io/iptv/languages/tl.m3u

Tamil	23	https://iptv-org.github.io/iptv/languages/ta.m3u

Telugu	1	https://iptv-org.github.io/iptv/languages/te.m3u

Thai	71	https://iptv-org.github.io/iptv/languages/th.m3u

Turkish	110	https://iptv-org.github.io/iptv/languages/tr.m3u

Turkmen	10	https://iptv-org.github.io/iptv/languages/tk.m3u

Ukrainian	161	https://iptv-org.github.io/iptv/languages/uk.m3u

Urdu	37	https://iptv-org.github.io/iptv/languages/ur.m3u

Vietnamese	62	https://iptv-org.github.io/iptv/languages/vi.m3u

Undefined	1	https://iptv-org.github.io/iptv/languages/undefined.m3u


code:
# IPTV

Collection of 8000+ publicly available IPTV channels from all over the world.

Internet Protocol television (IPTV) is the delivery of television content over Internet Protocol (IP) networks.

## Usage

To watch IPTV you just need to paste this link `https://iptv-org.github.io/iptv/index.m3u` to any player with support M3U-playlists.

![VLC Network Panel](preview.png)

Also you can instead use one of these playlists:

- `https://iptv-org.github.io/iptv/index.country.m3u` (grouped by country)
- `https://iptv-org.github.io/iptv/index.category.m3u` (grouped by category)
- `https://iptv-org.github.io/iptv/index.language.m3u` (grouped by language)

Or select one of the playlists from the list below.

## Playlists by category

#include "./.readme/_categories.md"

## Playlists by language

#include "./.readme/_languages.md"

## Playlists by country

#include "./.readme/_countries.md"

## Resources

You can find links to various IPTV related resources in this repository [iptv-org/awesome-iptv](https://github.com/iptv-org/awesome-iptv).

## Contribution

Please make sure to read the [Contributing Guide](.github/CONTRIBUTING.md) before making a pull request.

If you find an error or have any suggestions on how to organize a playlist, please send an [issue](https://github.com/iptv-org/iptv/issues).